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 case ST_OMP_DECLARE_TARGET
:
1173 case ST_OMP_TARGET_DATA
:
1174 case ST_OMP_TARGET_ENTER_DATA
:
1175 case ST_OMP_TARGET_EXIT_DATA
:
1176 case ST_OMP_TARGET_TEAMS
:
1177 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
1178 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
1179 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1180 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1181 case ST_OMP_TARGET_TEAMS_LOOP
:
1182 case ST_OMP_TARGET_PARALLEL
:
1183 case ST_OMP_TARGET_PARALLEL_DO
:
1184 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
1185 case ST_OMP_TARGET_PARALLEL_LOOP
:
1186 case ST_OMP_TARGET_SIMD
:
1187 case ST_OMP_TARGET_UPDATE
:
1189 gfc_namespace
*prog_unit
= gfc_current_ns
;
1190 while (prog_unit
->parent
)
1192 if (gfc_state_stack
->previous
1193 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1195 prog_unit
= prog_unit
->parent
;
1197 prog_unit
->omp_target_seen
= true;
1201 if (new_st
.ext
.omp_clauses
->at
!= OMP_AT_EXECUTION
)
1209 reject_statement ();
1211 gfc_buffer_error (false);
1212 gfc_current_locus
= old_locus
;
1213 return ST_GET_FCN_CHARACTERISTICS
;
1216 static gfc_statement
1217 decode_gcc_attribute (void)
1221 gfc_enforce_clean_symbol_state ();
1223 gfc_clear_error (); /* Clear any pending errors. */
1224 gfc_clear_warning (); /* Clear any pending warnings. */
1225 old_locus
= gfc_current_locus
;
1227 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1228 match ("unroll", gfc_match_gcc_unroll
, ST_NONE
);
1229 match ("builtin", gfc_match_gcc_builtin
, ST_NONE
);
1230 match ("ivdep", gfc_match_gcc_ivdep
, ST_NONE
);
1231 match ("vector", gfc_match_gcc_vector
, ST_NONE
);
1232 match ("novector", gfc_match_gcc_novector
, ST_NONE
);
1234 /* All else has failed, so give up. See if any of the matchers has
1235 stored an error message of some sort. */
1237 if (!gfc_error_check ())
1240 gfc_error_now ("Unclassifiable GCC directive at %C");
1242 gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
1245 reject_statement ();
1247 gfc_error_recovery ();
1254 /* Assert next length characters to be equal to token in free form. */
1257 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1262 c
= gfc_next_ascii_char ();
1263 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1264 gcc_assert (c
== token
[i
]);
1266 gcc_assert (gfc_is_whitespace(c
));
1267 gfc_gobble_whitespace ();
1268 if (last_was_use_stmt
)
1272 /* Get the next statement in free form source. */
1274 static gfc_statement
1281 at_bol
= gfc_at_bol ();
1282 gfc_gobble_whitespace ();
1284 c
= gfc_peek_ascii_char ();
1290 /* Found a statement label? */
1291 m
= gfc_match_st_label (&gfc_statement_label
);
1293 d
= gfc_peek_ascii_char ();
1294 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1296 gfc_match_small_literal_int (&i
, &cnt
);
1299 gfc_error_now ("Too many digits in statement label at %C");
1302 gfc_error_now ("Zero is not a valid statement label at %C");
1305 c
= gfc_next_ascii_char ();
1308 if (!gfc_is_whitespace (c
))
1309 gfc_error_now ("Non-numeric character in statement label at %C");
1315 label_locus
= gfc_current_locus
;
1317 gfc_gobble_whitespace ();
1319 if (at_bol
&& gfc_peek_ascii_char () == ';')
1321 gfc_error_now ("Semicolon at %C needs to be preceded by "
1323 gfc_next_ascii_char (); /* Eat up the semicolon. */
1327 if (gfc_match_eos () == MATCH_YES
)
1328 gfc_error_now ("Statement label without statement at %L",
1334 /* Comments have already been skipped by the time we get here,
1335 except for GCC attributes and OpenMP/OpenACC directives. */
1337 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1338 c
= gfc_peek_ascii_char ();
1344 c
= gfc_next_ascii_char ();
1345 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1346 gcc_assert (c
== "gcc$"[i
]);
1348 gfc_gobble_whitespace ();
1349 return decode_gcc_attribute ();
1354 /* Since both OpenMP and OpenACC directives starts with
1355 !$ character sequence, we must check all flags combinations */
1356 if ((flag_openmp
|| flag_openmp_simd
)
1359 verify_token_free ("$omp", 4, last_was_use_stmt
);
1360 return decode_omp_directive ();
1362 else if ((flag_openmp
|| flag_openmp_simd
)
1365 gfc_next_ascii_char (); /* Eat up dollar character */
1366 c
= gfc_peek_ascii_char ();
1370 verify_token_free ("omp", 3, last_was_use_stmt
);
1371 return decode_omp_directive ();
1375 verify_token_free ("acc", 3, last_was_use_stmt
);
1376 return decode_oacc_directive ();
1379 else if (flag_openacc
)
1381 verify_token_free ("$acc", 4, last_was_use_stmt
);
1382 return decode_oacc_directive ();
1388 if (at_bol
&& c
== ';')
1390 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1391 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1393 gfc_next_ascii_char (); /* Eat up the semicolon. */
1397 return decode_statement ();
1400 /* Assert next length characters to be equal to token in fixed form. */
1403 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1406 char c
= gfc_next_char_literal (NONSTRING
);
1408 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1409 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1411 if (c
!= ' ' && c
!= '0')
1413 gfc_buffer_error (false);
1414 gfc_error ("Bad continuation line at %C");
1417 if (last_was_use_stmt
)
1423 /* Get the next statement in fixed-form source. */
1425 static gfc_statement
1428 int label
, digit_flag
, i
;
1433 return decode_statement ();
1435 /* Skip past the current label field, parsing a statement label if
1436 one is there. This is a weird number parser, since the number is
1437 contained within five columns and can have any kind of embedded
1438 spaces. We also check for characters that make the rest of the
1444 for (i
= 0; i
< 5; i
++)
1446 c
= gfc_next_char_literal (NONSTRING
);
1463 label
= label
* 10 + ((unsigned char) c
- '0');
1464 label_locus
= gfc_current_locus
;
1468 /* Comments have already been skipped by the time we get
1469 here, except for GCC attributes and OpenMP directives. */
1472 c
= gfc_next_char_literal (NONSTRING
);
1474 if (TOLOWER (c
) == 'g')
1476 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1477 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1479 return decode_gcc_attribute ();
1483 if ((flag_openmp
|| flag_openmp_simd
)
1486 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1488 return decode_omp_directive ();
1490 else if ((flag_openmp
|| flag_openmp_simd
)
1493 c
= gfc_next_char_literal(NONSTRING
);
1494 if (c
== 'o' || c
== 'O')
1496 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1498 return decode_omp_directive ();
1500 else if (c
== 'a' || c
== 'A')
1502 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1504 return decode_oacc_directive ();
1507 else if (flag_openacc
)
1509 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1511 return decode_oacc_directive ();
1516 /* Comments have already been skipped by the time we get
1517 here so don't bother checking for them. */
1520 gfc_buffer_error (false);
1521 gfc_error ("Non-numeric character in statement label at %C");
1529 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1532 /* We've found a valid statement label. */
1533 gfc_statement_label
= gfc_get_st_label (label
);
1537 /* Since this line starts a statement, it cannot be a continuation
1538 of a previous statement. If we see something here besides a
1539 space or zero, it must be a bad continuation line. */
1541 c
= gfc_next_char_literal (NONSTRING
);
1545 if (c
!= ' ' && c
!= '0')
1547 gfc_buffer_error (false);
1548 gfc_error ("Bad continuation line at %C");
1552 /* Now that we've taken care of the statement label columns, we have
1553 to make sure that the first nonblank character is not a '!'. If
1554 it is, the rest of the line is a comment. */
1558 loc
= gfc_current_locus
;
1559 c
= gfc_next_char_literal (NONSTRING
);
1561 while (gfc_is_whitespace (c
));
1565 gfc_current_locus
= loc
;
1570 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1571 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1572 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1577 if (gfc_match_eos () == MATCH_YES
)
1580 /* At this point, we've got a nonblank statement to parse. */
1581 return decode_statement ();
1585 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1587 gfc_current_locus
.lb
->truncated
= 0;
1588 gfc_advance_line ();
1593 /* Return the next non-ST_NONE statement to the caller. We also worry
1594 about including files and the ends of include files at this stage. */
1596 static gfc_statement
1597 next_statement (void)
1602 gfc_enforce_clean_symbol_state ();
1604 gfc_new_block
= NULL
;
1606 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1607 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1610 gfc_statement_label
= NULL
;
1611 gfc_buffer_error (true);
1614 gfc_advance_line ();
1616 gfc_skip_comments ();
1624 if (gfc_define_undef_line ())
1627 old_locus
= gfc_current_locus
;
1629 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1635 gfc_buffer_error (false);
1637 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1639 if (gfc_statement_label
!= NULL
)
1641 gfc_free_st_label (gfc_statement_label
);
1642 gfc_statement_label
= NULL
;
1644 gfc_current_locus
= old_locus
;
1648 check_statement_label (st
);
1654 /****************************** Parser ***********************************/
1656 /* The parser subroutines are of type 'try' that fail if the file ends
1659 /* Macros that expand to case-labels for various classes of
1660 statements. Start with executable statements that directly do
1663 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1664 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1665 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1666 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1667 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1668 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1669 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1670 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1671 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1672 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
1673 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1674 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
1675 case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
1676 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1677 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1678 case ST_END_TEAM: case ST_SYNC_TEAM: \
1679 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1680 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1681 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1683 /* Statements that mark other executable statements. */
1685 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1686 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1687 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1688 case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
1689 case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
1690 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
1691 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
1692 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
1693 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1694 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
1695 case ST_OMP_MASKED_TASKLOOP_SIMD: \
1696 case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
1697 case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
1698 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1699 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1700 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1701 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1702 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1703 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1704 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1705 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1706 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1707 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1708 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1709 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1710 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1711 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1712 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1713 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1714 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1715 case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
1716 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
1718 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1719 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1720 case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
1723 /* Declaration statements */
1725 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1726 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1727 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
1729 /* OpenMP and OpenACC declaration statements, which may appear anywhere in
1730 the specification part. */
1732 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1733 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
1734 case ST_OMP_DECLARE_VARIANT: \
1735 case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1737 /* Block end statements. Errors associated with interchanging these
1738 are detected in gfc_match_end(). */
1740 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1741 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1742 case ST_END_BLOCK: case ST_END_ASSOCIATE
1745 /* Push a new state onto the stack. */
1748 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1750 p
->state
= new_state
;
1751 p
->previous
= gfc_state_stack
;
1753 p
->head
= p
->tail
= NULL
;
1754 p
->do_variable
= NULL
;
1755 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1756 p
->ext
.oacc_declare_clauses
= NULL
;
1758 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1759 construct statement was accepted right before pushing the state. Thus,
1760 the construct's gfc_code is available as tail of the parent state. */
1761 gcc_assert (gfc_state_stack
);
1762 p
->construct
= gfc_state_stack
->tail
;
1764 gfc_state_stack
= p
;
1768 /* Pop the current state. */
1772 gfc_state_stack
= gfc_state_stack
->previous
;
1776 /* Try to find the given state in the state stack. */
1779 gfc_find_state (gfc_compile_state state
)
1783 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1784 if (p
->state
== state
)
1787 return (p
== NULL
) ? false : true;
1791 /* Starts a new level in the statement list. */
1794 new_level (gfc_code
*q
)
1798 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1800 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1806 /* Add the current new_st code structure and adds it to the current
1807 program unit. As a side-effect, it zeroes the new_st. */
1810 add_statement (void)
1814 p
= XCNEW (gfc_code
);
1817 p
->loc
= gfc_current_locus
;
1819 if (gfc_state_stack
->head
== NULL
)
1820 gfc_state_stack
->head
= p
;
1822 gfc_state_stack
->tail
->next
= p
;
1824 while (p
->next
!= NULL
)
1827 gfc_state_stack
->tail
= p
;
1829 gfc_clear_new_st ();
1835 /* Frees everything associated with the current statement. */
1838 undo_new_statement (void)
1840 gfc_free_statements (new_st
.block
);
1841 gfc_free_statements (new_st
.next
);
1842 gfc_free_statement (&new_st
);
1843 gfc_clear_new_st ();
1847 /* If the current statement has a statement label, make sure that it
1848 is allowed to, or should have one. */
1851 check_statement_label (gfc_statement st
)
1855 if (gfc_statement_label
== NULL
)
1857 if (st
== ST_FORMAT
)
1858 gfc_error ("FORMAT statement at %L does not have a statement label",
1865 case ST_END_PROGRAM
:
1866 case ST_END_FUNCTION
:
1867 case ST_END_SUBROUTINE
:
1871 case ST_END_CRITICAL
:
1873 case ST_END_ASSOCIATE
:
1876 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1877 type
= ST_LABEL_DO_TARGET
;
1879 type
= ST_LABEL_TARGET
;
1883 type
= ST_LABEL_FORMAT
;
1886 /* Statement labels are not restricted from appearing on a
1887 particular line. However, there are plenty of situations
1888 where the resulting label can't be referenced. */
1891 type
= ST_LABEL_BAD_TARGET
;
1895 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1897 new_st
.here
= gfc_statement_label
;
1901 /* Figures out what the enclosing program unit is. This will be a
1902 function, subroutine, program, block data or module. */
1905 gfc_enclosing_unit (gfc_compile_state
* result
)
1909 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1910 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1911 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1912 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1921 *result
= COMP_PROGRAM
;
1926 /* Translate a statement enum to a string. */
1929 gfc_ascii_statement (gfc_statement st
)
1935 case ST_ARITHMETIC_IF
:
1936 p
= _("arithmetic IF");
1945 p
= _("attribute declaration");
1981 p
= _("data declaration");
1995 case ST_STRUCTURE_DECL
:
1998 case ST_DERIVED_DECL
:
1999 p
= _("derived type declaration");
2022 case ST_CHANGE_TEAM
:
2034 case ST_END_ASSOCIATE
:
2035 p
= "END ASSOCIATE";
2040 case ST_END_BLOCK_DATA
:
2041 p
= "END BLOCK DATA";
2043 case ST_END_CRITICAL
:
2055 case ST_END_FUNCTION
:
2061 case ST_END_INTERFACE
:
2062 p
= "END INTERFACE";
2067 case ST_END_SUBMODULE
:
2068 p
= "END SUBMODULE";
2070 case ST_END_PROGRAM
:
2076 case ST_END_SUBROUTINE
:
2077 p
= "END SUBROUTINE";
2082 case ST_END_STRUCTURE
:
2083 p
= "END STRUCTURE";
2097 case ST_EQUIVALENCE
:
2109 case ST_FORALL_BLOCK
: /* Fall through */
2131 case ST_IMPLICIT_NONE
:
2132 p
= "IMPLICIT NONE";
2134 case ST_IMPLIED_ENDDO
:
2135 p
= _("implied END DO");
2167 case ST_MODULE_PROC
:
2168 p
= "MODULE PROCEDURE";
2200 case ST_SYNC_IMAGES
:
2203 case ST_SYNC_MEMORY
:
2218 case ST_WHERE_BLOCK
: /* Fall through */
2229 p
= _("assignment");
2231 case ST_POINTER_ASSIGNMENT
:
2232 p
= _("pointer assignment");
2234 case ST_SELECT_CASE
:
2237 case ST_SELECT_TYPE
:
2240 case ST_SELECT_RANK
:
2258 case ST_STATEMENT_FUNCTION
:
2259 p
= "STATEMENT FUNCTION";
2261 case ST_LABEL_ASSIGNMENT
:
2262 p
= "LABEL ASSIGNMENT";
2265 p
= "ENUM DEFINITION";
2268 p
= "ENUMERATOR DEFINITION";
2273 case ST_OACC_PARALLEL_LOOP
:
2274 p
= "!$ACC PARALLEL LOOP";
2276 case ST_OACC_END_PARALLEL_LOOP
:
2277 p
= "!$ACC END PARALLEL LOOP";
2279 case ST_OACC_PARALLEL
:
2280 p
= "!$ACC PARALLEL";
2282 case ST_OACC_END_PARALLEL
:
2283 p
= "!$ACC END PARALLEL";
2285 case ST_OACC_KERNELS
:
2286 p
= "!$ACC KERNELS";
2288 case ST_OACC_END_KERNELS
:
2289 p
= "!$ACC END KERNELS";
2291 case ST_OACC_KERNELS_LOOP
:
2292 p
= "!$ACC KERNELS LOOP";
2294 case ST_OACC_END_KERNELS_LOOP
:
2295 p
= "!$ACC END KERNELS LOOP";
2297 case ST_OACC_SERIAL_LOOP
:
2298 p
= "!$ACC SERIAL LOOP";
2300 case ST_OACC_END_SERIAL_LOOP
:
2301 p
= "!$ACC END SERIAL LOOP";
2303 case ST_OACC_SERIAL
:
2306 case ST_OACC_END_SERIAL
:
2307 p
= "!$ACC END SERIAL";
2312 case ST_OACC_END_DATA
:
2313 p
= "!$ACC END DATA";
2315 case ST_OACC_HOST_DATA
:
2316 p
= "!$ACC HOST_DATA";
2318 case ST_OACC_END_HOST_DATA
:
2319 p
= "!$ACC END HOST_DATA";
2324 case ST_OACC_END_LOOP
:
2325 p
= "!$ACC END LOOP";
2327 case ST_OACC_DECLARE
:
2328 p
= "!$ACC DECLARE";
2330 case ST_OACC_UPDATE
:
2339 case ST_OACC_ENTER_DATA
:
2340 p
= "!$ACC ENTER DATA";
2342 case ST_OACC_EXIT_DATA
:
2343 p
= "!$ACC EXIT DATA";
2345 case ST_OACC_ROUTINE
:
2346 p
= "!$ACC ROUTINE";
2348 case ST_OACC_ATOMIC
:
2351 case ST_OACC_END_ATOMIC
:
2352 p
= "!$ACC END ATOMIC";
2357 case ST_OMP_BARRIER
:
2358 p
= "!$OMP BARRIER";
2363 case ST_OMP_CANCELLATION_POINT
:
2364 p
= "!$OMP CANCELLATION POINT";
2366 case ST_OMP_CRITICAL
:
2367 p
= "!$OMP CRITICAL";
2369 case ST_OMP_DECLARE_REDUCTION
:
2370 p
= "!$OMP DECLARE REDUCTION";
2372 case ST_OMP_DECLARE_SIMD
:
2373 p
= "!$OMP DECLARE SIMD";
2375 case ST_OMP_DECLARE_TARGET
:
2376 p
= "!$OMP DECLARE TARGET";
2378 case ST_OMP_DECLARE_VARIANT
:
2379 p
= "!$OMP DECLARE VARIANT";
2384 case ST_OMP_DISTRIBUTE
:
2385 p
= "!$OMP DISTRIBUTE";
2387 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2388 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2390 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2391 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2393 case ST_OMP_DISTRIBUTE_SIMD
:
2394 p
= "!$OMP DISTRIBUTE SIMD";
2399 case ST_OMP_DO_SIMD
:
2400 p
= "!$OMP DO SIMD";
2402 case ST_OMP_END_ATOMIC
:
2403 p
= "!$OMP END ATOMIC";
2405 case ST_OMP_END_CRITICAL
:
2406 p
= "!$OMP END CRITICAL";
2408 case ST_OMP_END_DISTRIBUTE
:
2409 p
= "!$OMP END DISTRIBUTE";
2411 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2412 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2414 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2415 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2417 case ST_OMP_END_DISTRIBUTE_SIMD
:
2418 p
= "!$OMP END DISTRIBUTE SIMD";
2423 case ST_OMP_END_DO_SIMD
:
2424 p
= "!$OMP END DO SIMD";
2426 case ST_OMP_END_SCOPE
:
2427 p
= "!$OMP END SCOPE";
2429 case ST_OMP_END_SIMD
:
2430 p
= "!$OMP END SIMD";
2432 case ST_OMP_END_LOOP
:
2433 p
= "!$OMP END LOOP";
2435 case ST_OMP_END_MASKED
:
2436 p
= "!$OMP END MASKED";
2438 case ST_OMP_END_MASKED_TASKLOOP
:
2439 p
= "!$OMP END MASKED TASKLOOP";
2441 case ST_OMP_END_MASKED_TASKLOOP_SIMD
:
2442 p
= "!$OMP END MASKED TASKLOOP SIMD";
2444 case ST_OMP_END_MASTER
:
2445 p
= "!$OMP END MASTER";
2447 case ST_OMP_END_MASTER_TASKLOOP
:
2448 p
= "!$OMP END MASTER TASKLOOP";
2450 case ST_OMP_END_MASTER_TASKLOOP_SIMD
:
2451 p
= "!$OMP END MASTER TASKLOOP SIMD";
2453 case ST_OMP_END_ORDERED
:
2454 p
= "!$OMP END ORDERED";
2456 case ST_OMP_END_PARALLEL
:
2457 p
= "!$OMP END PARALLEL";
2459 case ST_OMP_END_PARALLEL_DO
:
2460 p
= "!$OMP END PARALLEL DO";
2462 case ST_OMP_END_PARALLEL_DO_SIMD
:
2463 p
= "!$OMP END PARALLEL DO SIMD";
2465 case ST_OMP_END_PARALLEL_LOOP
:
2466 p
= "!$OMP END PARALLEL LOOP";
2468 case ST_OMP_END_PARALLEL_MASKED
:
2469 p
= "!$OMP END PARALLEL MASKED";
2471 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP
:
2472 p
= "!$OMP END PARALLEL MASKED TASKLOOP";
2474 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
:
2475 p
= "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
2477 case ST_OMP_END_PARALLEL_MASTER
:
2478 p
= "!$OMP END PARALLEL MASTER";
2480 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP
:
2481 p
= "!$OMP END PARALLEL MASTER TASKLOOP";
2483 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
:
2484 p
= "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
2486 case ST_OMP_END_PARALLEL_SECTIONS
:
2487 p
= "!$OMP END PARALLEL SECTIONS";
2489 case ST_OMP_END_PARALLEL_WORKSHARE
:
2490 p
= "!$OMP END PARALLEL WORKSHARE";
2492 case ST_OMP_END_SECTIONS
:
2493 p
= "!$OMP END SECTIONS";
2495 case ST_OMP_END_SINGLE
:
2496 p
= "!$OMP END SINGLE";
2498 case ST_OMP_END_TASK
:
2499 p
= "!$OMP END TASK";
2501 case ST_OMP_END_TARGET
:
2502 p
= "!$OMP END TARGET";
2504 case ST_OMP_END_TARGET_DATA
:
2505 p
= "!$OMP END TARGET DATA";
2507 case ST_OMP_END_TARGET_PARALLEL
:
2508 p
= "!$OMP END TARGET PARALLEL";
2510 case ST_OMP_END_TARGET_PARALLEL_DO
:
2511 p
= "!$OMP END TARGET PARALLEL DO";
2513 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2514 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2516 case ST_OMP_END_TARGET_PARALLEL_LOOP
:
2517 p
= "!$OMP END TARGET PARALLEL LOOP";
2519 case ST_OMP_END_TARGET_SIMD
:
2520 p
= "!$OMP END TARGET SIMD";
2522 case ST_OMP_END_TARGET_TEAMS
:
2523 p
= "!$OMP END TARGET TEAMS";
2525 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2526 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2528 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2529 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2531 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2532 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2534 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2535 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2537 case ST_OMP_END_TARGET_TEAMS_LOOP
:
2538 p
= "!$OMP END TARGET TEAMS LOOP";
2540 case ST_OMP_END_TASKGROUP
:
2541 p
= "!$OMP END TASKGROUP";
2543 case ST_OMP_END_TASKLOOP
:
2544 p
= "!$OMP END TASKLOOP";
2546 case ST_OMP_END_TASKLOOP_SIMD
:
2547 p
= "!$OMP END TASKLOOP SIMD";
2549 case ST_OMP_END_TEAMS
:
2550 p
= "!$OMP END TEAMS";
2552 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2553 p
= "!$OMP END TEAMS DISTRIBUTE";
2555 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2556 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2558 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2559 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2561 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2562 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2564 case ST_OMP_END_TEAMS_LOOP
:
2565 p
= "!$OMP END TEAMS LOOP";
2567 case ST_OMP_END_WORKSHARE
:
2568 p
= "!$OMP END WORKSHARE";
2582 case ST_OMP_MASKED_TASKLOOP
:
2583 p
= "!$OMP MASKED TASKLOOP";
2585 case ST_OMP_MASKED_TASKLOOP_SIMD
:
2586 p
= "!$OMP MASKED TASKLOOP SIMD";
2591 case ST_OMP_MASTER_TASKLOOP
:
2592 p
= "!$OMP MASTER TASKLOOP";
2594 case ST_OMP_MASTER_TASKLOOP_SIMD
:
2595 p
= "!$OMP MASTER TASKLOOP SIMD";
2597 case ST_OMP_ORDERED
:
2598 case ST_OMP_ORDERED_DEPEND
:
2599 p
= "!$OMP ORDERED";
2601 case ST_OMP_PARALLEL
:
2602 p
= "!$OMP PARALLEL";
2604 case ST_OMP_PARALLEL_DO
:
2605 p
= "!$OMP PARALLEL DO";
2607 case ST_OMP_PARALLEL_LOOP
:
2608 p
= "!$OMP PARALLEL LOOP";
2610 case ST_OMP_PARALLEL_DO_SIMD
:
2611 p
= "!$OMP PARALLEL DO SIMD";
2613 case ST_OMP_PARALLEL_MASKED
:
2614 p
= "!$OMP PARALLEL MASKED";
2616 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
2617 p
= "!$OMP PARALLEL MASKED TASKLOOP";
2619 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
2620 p
= "!$OMP PARALLEL MASKED TASKLOOP SIMD";
2622 case ST_OMP_PARALLEL_MASTER
:
2623 p
= "!$OMP PARALLEL MASTER";
2625 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
2626 p
= "!$OMP PARALLEL MASTER TASKLOOP";
2628 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
2629 p
= "!$OMP PARALLEL MASTER TASKLOOP SIMD";
2631 case ST_OMP_PARALLEL_SECTIONS
:
2632 p
= "!$OMP PARALLEL SECTIONS";
2634 case ST_OMP_PARALLEL_WORKSHARE
:
2635 p
= "!$OMP PARALLEL WORKSHARE";
2637 case ST_OMP_REQUIRES
:
2638 p
= "!$OMP REQUIRES";
2646 case ST_OMP_SECTIONS
:
2647 p
= "!$OMP SECTIONS";
2649 case ST_OMP_SECTION
:
2650 p
= "!$OMP SECTION";
2661 case ST_OMP_TARGET_DATA
:
2662 p
= "!$OMP TARGET DATA";
2664 case ST_OMP_TARGET_ENTER_DATA
:
2665 p
= "!$OMP TARGET ENTER DATA";
2667 case ST_OMP_TARGET_EXIT_DATA
:
2668 p
= "!$OMP TARGET EXIT DATA";
2670 case ST_OMP_TARGET_PARALLEL
:
2671 p
= "!$OMP TARGET PARALLEL";
2673 case ST_OMP_TARGET_PARALLEL_DO
:
2674 p
= "!$OMP TARGET PARALLEL DO";
2676 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
2677 p
= "!$OMP TARGET PARALLEL DO SIMD";
2679 case ST_OMP_TARGET_PARALLEL_LOOP
:
2680 p
= "!$OMP TARGET PARALLEL LOOP";
2682 case ST_OMP_TARGET_SIMD
:
2683 p
= "!$OMP TARGET SIMD";
2685 case ST_OMP_TARGET_TEAMS
:
2686 p
= "!$OMP TARGET TEAMS";
2688 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2689 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2691 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2692 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2694 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2695 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2697 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2698 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2700 case ST_OMP_TARGET_TEAMS_LOOP
:
2701 p
= "!$OMP TARGET TEAMS LOOP";
2703 case ST_OMP_TARGET_UPDATE
:
2704 p
= "!$OMP TARGET UPDATE";
2709 case ST_OMP_TASKGROUP
:
2710 p
= "!$OMP TASKGROUP";
2712 case ST_OMP_TASKLOOP
:
2713 p
= "!$OMP TASKLOOP";
2715 case ST_OMP_TASKLOOP_SIMD
:
2716 p
= "!$OMP TASKLOOP SIMD";
2718 case ST_OMP_TASKWAIT
:
2719 p
= "!$OMP TASKWAIT";
2721 case ST_OMP_TASKYIELD
:
2722 p
= "!$OMP TASKYIELD";
2727 case ST_OMP_TEAMS_DISTRIBUTE
:
2728 p
= "!$OMP TEAMS DISTRIBUTE";
2730 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2731 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2733 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2734 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2736 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2737 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2739 case ST_OMP_TEAMS_LOOP
:
2740 p
= "!$OMP TEAMS LOOP";
2742 case ST_OMP_THREADPRIVATE
:
2743 p
= "!$OMP THREADPRIVATE";
2745 case ST_OMP_WORKSHARE
:
2746 p
= "!$OMP WORKSHARE";
2749 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2756 /* Create a symbol for the main program and assign it to ns->proc_name. */
2759 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2761 gfc_symbol
*main_program
;
2762 symbol_attribute attr
;
2764 gfc_get_symbol (name
, ns
, &main_program
);
2765 gfc_clear_attr (&attr
);
2766 attr
.flavor
= FL_PROGRAM
;
2767 attr
.proc
= PROC_UNKNOWN
;
2768 attr
.subroutine
= 1;
2769 attr
.access
= ACCESS_PUBLIC
;
2770 attr
.is_main_program
= 1;
2771 main_program
->attr
= attr
;
2772 main_program
->declared_at
= gfc_current_locus
;
2773 ns
->proc_name
= main_program
;
2774 gfc_commit_symbols ();
2778 /* Do whatever is necessary to accept the last statement. */
2781 accept_statement (gfc_statement st
)
2785 case ST_IMPLICIT_NONE
:
2793 gfc_current_ns
->proc_name
= gfc_new_block
;
2796 /* If the statement is the end of a block, lay down a special code
2797 that allows a branch to the end of the block from within the
2798 construct. IF and SELECT are treated differently from DO
2799 (where EXEC_NOP is added inside the loop) for two
2801 1. END DO has a meaning in the sense that after a GOTO to
2802 it, the loop counter must be increased.
2803 2. IF blocks and SELECT blocks can consist of multiple
2804 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2805 Putting the label before the END IF would make the jump
2806 from, say, the ELSE IF block to the END IF illegal. */
2810 case ST_END_CRITICAL
:
2811 if (gfc_statement_label
!= NULL
)
2813 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2818 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2819 one parallel block. Thus, we add the special code to the nested block
2820 itself, instead of the parent one. */
2822 case ST_END_ASSOCIATE
:
2823 if (gfc_statement_label
!= NULL
)
2825 new_st
.op
= EXEC_END_BLOCK
;
2830 /* The end-of-program unit statements do not get the special
2831 marker and require a statement of some sort if they are a
2834 case ST_END_PROGRAM
:
2835 case ST_END_FUNCTION
:
2836 case ST_END_SUBROUTINE
:
2837 if (gfc_statement_label
!= NULL
)
2839 new_st
.op
= EXEC_RETURN
;
2844 new_st
.op
= EXEC_END_PROCEDURE
;
2860 gfc_commit_symbols ();
2861 gfc_warning_check ();
2862 gfc_clear_new_st ();
2866 /* Undo anything tentative that has been built for the current statement,
2867 except if a gfc_charlen structure has been added to current namespace's
2868 list of gfc_charlen structure. */
2871 reject_statement (void)
2873 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2874 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2876 gfc_reject_data (gfc_current_ns
);
2878 gfc_new_block
= NULL
;
2879 gfc_undo_symbols ();
2880 gfc_clear_warning ();
2881 undo_new_statement ();
2885 /* Generic complaint about an out of order statement. We also do
2886 whatever is necessary to clean up. */
2889 unexpected_statement (gfc_statement st
)
2891 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2893 reject_statement ();
2897 /* Given the next statement seen by the matcher, make sure that it is
2898 in proper order with the last. This subroutine is initialized by
2899 calling it with an argument of ST_NONE. If there is a problem, we
2900 issue an error and return false. Otherwise we return true.
2902 Individual parsers need to verify that the statements seen are
2903 valid before calling here, i.e., ENTRY statements are not allowed in
2904 INTERFACE blocks. The following diagram is taken from the standard:
2906 +---------------------------------------+
2907 | program subroutine function module |
2908 +---------------------------------------+
2910 +---------------------------------------+
2912 +---------------------------------------+
2914 | +-----------+------------------+
2915 | | parameter | implicit |
2916 | +-----------+------------------+
2917 | format | | derived type |
2918 | entry | parameter | interface |
2919 | | data | specification |
2920 | | | statement func |
2921 | +-----------+------------------+
2922 | | data | executable |
2923 +--------+-----------+------------------+
2925 +---------------------------------------+
2926 | internal module/subprogram |
2927 +---------------------------------------+
2929 +---------------------------------------+
2938 ORDER_IMPLICIT_NONE
,
2946 enum state_order state
;
2947 gfc_statement last_statement
;
2953 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2959 p
->state
= ORDER_START
;
2963 if (p
->state
> ORDER_USE
)
2965 p
->state
= ORDER_USE
;
2969 if (p
->state
> ORDER_IMPORT
)
2971 p
->state
= ORDER_IMPORT
;
2974 case ST_IMPLICIT_NONE
:
2975 if (p
->state
> ORDER_IMPLICIT
)
2978 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2979 statement disqualifies a USE but not an IMPLICIT NONE.
2980 Duplicate IMPLICIT NONEs are caught when the implicit types
2983 p
->state
= ORDER_IMPLICIT_NONE
;
2987 if (p
->state
> ORDER_IMPLICIT
)
2989 p
->state
= ORDER_IMPLICIT
;
2994 if (p
->state
< ORDER_IMPLICIT_NONE
)
2995 p
->state
= ORDER_IMPLICIT_NONE
;
2999 if (p
->state
>= ORDER_EXEC
)
3001 if (p
->state
< ORDER_IMPLICIT
)
3002 p
->state
= ORDER_IMPLICIT
;
3006 if (p
->state
< ORDER_SPEC
)
3007 p
->state
= ORDER_SPEC
;
3012 case ST_STRUCTURE_DECL
:
3013 case ST_DERIVED_DECL
:
3015 if (p
->state
>= ORDER_EXEC
)
3017 if (p
->state
< ORDER_SPEC
)
3018 p
->state
= ORDER_SPEC
;
3022 /* The OpenMP/OpenACC directives have to be somewhere in the specification
3023 part, but there are no further requirements on their ordering.
3024 Thus don't adjust p->state, just ignore them. */
3025 if (p
->state
>= ORDER_EXEC
)
3031 if (p
->state
< ORDER_EXEC
)
3032 p
->state
= ORDER_EXEC
;
3039 /* All is well, record the statement in case we need it next time. */
3040 p
->where
= gfc_current_locus
;
3041 p
->last_statement
= st
;
3046 gfc_error ("%s statement at %C cannot follow %s statement at %L",
3047 gfc_ascii_statement (st
),
3048 gfc_ascii_statement (p
->last_statement
), &p
->where
);
3054 /* Handle an unexpected end of file. This is a show-stopper... */
3056 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
3059 unexpected_eof (void)
3063 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
3065 /* Memory cleanup. Move to "second to last". */
3066 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
3069 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
3072 longjmp (eof_buf
, 1);
3074 /* Avoids build error on systems where longjmp is not declared noreturn. */
3079 /* Parse the CONTAINS section of a derived type definition. */
3081 gfc_access gfc_typebound_default_access
;
3084 parse_derived_contains (void)
3087 bool seen_private
= false;
3088 bool seen_comps
= false;
3089 bool error_flag
= false;
3092 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3093 gcc_assert (gfc_current_block ());
3095 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
3097 if (gfc_current_block ()->attr
.sequence
)
3098 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
3099 " section at %C", gfc_current_block ()->name
);
3100 if (gfc_current_block ()->attr
.is_bind_c
)
3101 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
3102 " section at %C", gfc_current_block ()->name
);
3104 accept_statement (ST_CONTAINS
);
3105 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
3107 gfc_typebound_default_access
= ACCESS_PUBLIC
;
3113 st
= next_statement ();
3121 gfc_error ("Components in TYPE at %C must precede CONTAINS");
3125 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
3128 accept_statement (ST_PROCEDURE
);
3133 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
3136 accept_statement (ST_GENERIC
);
3141 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
3145 accept_statement (ST_FINAL
);
3153 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
3154 "at %C with empty CONTAINS section")))
3157 /* ST_END_TYPE is accepted by parse_derived after return. */
3161 if (!gfc_find_state (COMP_MODULE
))
3163 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3170 gfc_error ("PRIVATE statement at %C must precede procedure"
3177 gfc_error ("Duplicate PRIVATE statement at %C");
3181 accept_statement (ST_PRIVATE
);
3182 gfc_typebound_default_access
= ACCESS_PRIVATE
;
3183 seen_private
= true;
3187 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
3191 gfc_error ("Already inside a CONTAINS block at %C");
3195 unexpected_statement (st
);
3203 reject_statement ();
3207 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3213 /* Set attributes for the parent symbol based on the attributes of a component
3214 and raise errors if conflicting attributes are found for the component. */
3217 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
3218 gfc_component
**eventp
)
3220 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
3221 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
3222 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
3224 if (lockp
) lock_comp
= *lockp
;
3225 if (eventp
) event_comp
= *eventp
;
3227 /* Look for allocatable components. */
3228 if (c
->attr
.allocatable
3229 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3230 && CLASS_DATA (c
)->attr
.allocatable
)
3231 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
3232 && c
->ts
.u
.derived
->attr
.alloc_comp
))
3235 sym
->attr
.alloc_comp
= 1;
3238 /* Look for pointer components. */
3240 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3241 && CLASS_DATA (c
)->attr
.class_pointer
)
3242 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
3245 sym
->attr
.pointer_comp
= 1;
3248 /* Look for procedure pointer components. */
3249 if (c
->attr
.proc_pointer
3250 || (c
->ts
.type
== BT_DERIVED
3251 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
3252 sym
->attr
.proc_pointer_comp
= 1;
3254 /* Looking for coarray components. */
3255 if (c
->attr
.codimension
3256 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3257 && CLASS_DATA (c
)->attr
.codimension
))
3260 sym
->attr
.coarray_comp
= 1;
3263 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
3264 && !c
->attr
.pointer
)
3267 sym
->attr
.coarray_comp
= 1;
3270 /* Looking for lock_type components. */
3271 if ((c
->ts
.type
== BT_DERIVED
3272 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3273 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
3274 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3275 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3276 == INTMOD_ISO_FORTRAN_ENV
3277 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3278 == ISOFORTRAN_LOCK_TYPE
)
3279 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
3280 && !allocatable
&& !pointer
))
3284 sym
->attr
.lock_comp
= 1;
3287 /* Looking for event_type components. */
3288 if ((c
->ts
.type
== BT_DERIVED
3289 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3290 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
3291 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3292 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3293 == INTMOD_ISO_FORTRAN_ENV
3294 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3295 == ISOFORTRAN_EVENT_TYPE
)
3296 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
3297 && !allocatable
&& !pointer
))
3301 sym
->attr
.event_comp
= 1;
3304 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
3305 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
3306 unless there are nondirect [allocatable or pointer] components
3307 involved (cf. 1.3.33.1 and 1.3.33.3). */
3309 if (pointer
&& !coarray
&& lock_type
)
3310 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3311 "codimension or be a subcomponent of a coarray, "
3312 "which is not possible as the component has the "
3313 "pointer attribute", c
->name
, &c
->loc
);
3314 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3315 && c
->ts
.u
.derived
->attr
.lock_comp
)
3316 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3317 "of type LOCK_TYPE, which must have a codimension or be a "
3318 "subcomponent of a coarray", c
->name
, &c
->loc
);
3320 if (lock_type
&& allocatable
&& !coarray
)
3321 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3322 "a codimension", c
->name
, &c
->loc
);
3323 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3324 && c
->ts
.u
.derived
->attr
.lock_comp
)
3325 gfc_error ("Allocatable component %s at %L must have a codimension as "
3326 "it has a noncoarray subcomponent of type LOCK_TYPE",
3329 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
3330 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3331 "subcomponent of type LOCK_TYPE must have a codimension or "
3332 "be a subcomponent of a coarray. (Variables of type %s may "
3333 "not have a codimension as already a coarray "
3334 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3336 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
3337 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3338 "subcomponent of type LOCK_TYPE must have a codimension or "
3339 "be a subcomponent of a coarray. (Variables of type %s may "
3340 "not have a codimension as %s at %L has a codimension or a "
3341 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3342 sym
->name
, c
->name
, &c
->loc
);
3344 /* Similarly for EVENT TYPE. */
3346 if (pointer
&& !coarray
&& event_type
)
3347 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3348 "codimension or be a subcomponent of a coarray, "
3349 "which is not possible as the component has the "
3350 "pointer attribute", c
->name
, &c
->loc
);
3351 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3352 && c
->ts
.u
.derived
->attr
.event_comp
)
3353 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3354 "of type EVENT_TYPE, which must have a codimension or be a "
3355 "subcomponent of a coarray", c
->name
, &c
->loc
);
3357 if (event_type
&& allocatable
&& !coarray
)
3358 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3359 "a codimension", c
->name
, &c
->loc
);
3360 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3361 && c
->ts
.u
.derived
->attr
.event_comp
)
3362 gfc_error ("Allocatable component %s at %L must have a codimension as "
3363 "it has a noncoarray subcomponent of type EVENT_TYPE",
3366 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3367 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3368 "subcomponent of type EVENT_TYPE must have a codimension or "
3369 "be a subcomponent of a coarray. (Variables of type %s may "
3370 "not have a codimension as already a coarray "
3371 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3373 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3374 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3375 "subcomponent of type EVENT_TYPE must have a codimension or "
3376 "be a subcomponent of a coarray. (Variables of type %s may "
3377 "not have a codimension as %s at %L has a codimension or a "
3378 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3379 sym
->name
, c
->name
, &c
->loc
);
3381 /* Look for private components. */
3382 if (sym
->component_access
== ACCESS_PRIVATE
3383 || c
->attr
.access
== ACCESS_PRIVATE
3384 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3385 sym
->attr
.private_comp
= 1;
3387 if (lockp
) *lockp
= lock_comp
;
3388 if (eventp
) *eventp
= event_comp
;
3392 static void parse_struct_map (gfc_statement
);
3394 /* Parse a union component definition within a structure definition. */
3402 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3405 accept_statement(ST_UNION
);
3406 push_state (&s
, COMP_UNION
, gfc_new_block
);
3413 st
= next_statement ();
3414 /* Only MAP declarations valid within a union. */
3421 accept_statement (ST_MAP
);
3422 parse_struct_map (ST_MAP
);
3423 /* Add a component to the union for each map. */
3424 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3426 gfc_internal_error ("failed to create map component '%s'",
3427 gfc_new_block
->name
);
3428 reject_statement ();
3431 c
->ts
.type
= BT_DERIVED
;
3432 c
->ts
.u
.derived
= gfc_new_block
;
3433 /* Normally components get their initialization expressions when they
3434 are created in decl.c (build_struct) so we can look through the
3435 flat component list for initializers during resolution. Unions and
3436 maps create components along with their type definitions so we
3437 have to generate initializers here. */
3438 c
->initializer
= gfc_default_initializer (&c
->ts
);
3443 accept_statement (ST_END_UNION
);
3447 unexpected_statement (st
);
3452 for (c
= un
->components
; c
; c
= c
->next
)
3453 check_component (un
, c
, &lock_comp
, &event_comp
);
3455 /* Add the union as a component in its parent structure. */
3457 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3459 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3460 reject_statement ();
3463 c
->ts
.type
= BT_UNION
;
3464 c
->ts
.u
.derived
= un
;
3465 c
->initializer
= gfc_default_initializer (&c
->ts
);
3467 un
->attr
.zero_comp
= un
->components
== NULL
;
3471 /* Parse a STRUCTURE or MAP. */
3474 parse_struct_map (gfc_statement block
)
3480 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3481 gfc_compile_state comp
;
3484 if (block
== ST_STRUCTURE_DECL
)
3486 comp
= COMP_STRUCTURE
;
3487 ends
= ST_END_STRUCTURE
;
3491 gcc_assert (block
== ST_MAP
);
3496 accept_statement(block
);
3497 push_state (&s
, comp
, gfc_new_block
);
3499 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3502 while (compiling_type
)
3504 st
= next_statement ();
3510 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3511 case ST_STRUCTURE_DECL
:
3512 /* Let a more specific error make it to decode_statement(). */
3513 if (gfc_error_check () == 0)
3514 gfc_error ("Syntax error in nested structure declaration at %C");
3515 reject_statement ();
3516 /* Skip the rest of this statement. */
3517 gfc_error_recovery ();
3521 accept_statement (ST_UNION
);
3526 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3527 accept_statement (ST_DATA_DECL
);
3528 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3529 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3530 parse_struct_map (ST_STRUCTURE_DECL
);
3533 case ST_END_STRUCTURE
:
3537 accept_statement (st
);
3541 unexpected_statement (st
);
3545 unexpected_statement (st
);
3550 /* Validate each component. */
3551 sym
= gfc_current_block ();
3552 for (c
= sym
->components
; c
; c
= c
->next
)
3553 check_component (sym
, c
, &lock_comp
, &event_comp
);
3555 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3557 /* Allow parse_union to find this structure to add to its list of maps. */
3558 if (block
== ST_MAP
)
3559 gfc_new_block
= gfc_current_block ();
3565 /* Parse a derived type. */
3568 parse_derived (void)
3570 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3574 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3576 accept_statement (ST_DERIVED_DECL
);
3577 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3579 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3586 while (compiling_type
)
3588 st
= next_statement ();
3596 accept_statement (st
);
3601 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3608 if (!seen_component
)
3609 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3610 "definition at %C without components");
3612 accept_statement (ST_END_TYPE
);
3616 if (!gfc_find_state (COMP_MODULE
))
3618 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3625 gfc_error ("PRIVATE statement at %C must precede "
3626 "structure components");
3631 gfc_error ("Duplicate PRIVATE statement at %C");
3633 s
.sym
->component_access
= ACCESS_PRIVATE
;
3635 accept_statement (ST_PRIVATE
);
3642 gfc_error ("SEQUENCE statement at %C must precede "
3643 "structure components");
3647 if (gfc_current_block ()->attr
.sequence
)
3648 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3653 gfc_error ("Duplicate SEQUENCE statement at %C");
3657 gfc_add_sequence (&gfc_current_block ()->attr
,
3658 gfc_current_block ()->name
, NULL
);
3662 gfc_notify_std (GFC_STD_F2003
,
3663 "CONTAINS block in derived type"
3664 " definition at %C");
3666 accept_statement (ST_CONTAINS
);
3667 parse_derived_contains ();
3671 unexpected_statement (st
);
3676 /* need to verify that all fields of the derived type are
3677 * interoperable with C if the type is declared to be bind(c)
3679 sym
= gfc_current_block ();
3680 for (c
= sym
->components
; c
; c
= c
->next
)
3681 check_component (sym
, c
, &lock_comp
, &event_comp
);
3683 if (!seen_component
)
3684 sym
->attr
.zero_comp
= 1;
3690 /* Parse an ENUM. */
3698 int seen_enumerator
= 0;
3700 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3704 while (compiling_enum
)
3706 st
= next_statement ();
3714 seen_enumerator
= 1;
3715 accept_statement (st
);
3720 if (!seen_enumerator
)
3721 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3722 accept_statement (st
);
3726 gfc_free_enum_history ();
3727 unexpected_statement (st
);
3735 /* Parse an interface. We must be able to deal with the possibility
3736 of recursive interfaces. The parse_spec() subroutine is mutually
3737 recursive with parse_interface(). */
3739 static gfc_statement
parse_spec (gfc_statement
);
3742 parse_interface (void)
3744 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3745 gfc_symbol
*prog_unit
, *sym
;
3746 gfc_interface_info save
;
3747 gfc_state_data s1
, s2
;
3750 accept_statement (ST_INTERFACE
);
3752 current_interface
.ns
= gfc_current_ns
;
3753 save
= current_interface
;
3755 sym
= (current_interface
.type
== INTERFACE_GENERIC
3756 || current_interface
.type
== INTERFACE_USER_OP
)
3757 ? gfc_new_block
: NULL
;
3759 push_state (&s1
, COMP_INTERFACE
, sym
);
3760 current_state
= COMP_NONE
;
3763 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3765 st
= next_statement ();
3773 if (st
== ST_SUBROUTINE
)
3774 new_state
= COMP_SUBROUTINE
;
3775 else if (st
== ST_FUNCTION
)
3776 new_state
= COMP_FUNCTION
;
3777 if (gfc_new_block
->attr
.pointer
)
3779 gfc_new_block
->attr
.pointer
= 0;
3780 gfc_new_block
->attr
.proc_pointer
= 1;
3782 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3783 gfc_new_block
->formal
, NULL
))
3785 reject_statement ();
3786 gfc_free_namespace (gfc_current_ns
);
3789 /* F2008 C1210 forbids the IMPORT statement in module procedure
3790 interface bodies and the flag is set to import symbols. */
3791 if (gfc_new_block
->attr
.module_procedure
)
3792 gfc_current_ns
->has_import_set
= 1;
3796 case ST_MODULE_PROC
: /* The module procedure matcher makes
3797 sure the context is correct. */
3798 accept_statement (st
);
3799 gfc_free_namespace (gfc_current_ns
);
3802 case ST_END_INTERFACE
:
3803 gfc_free_namespace (gfc_current_ns
);
3804 gfc_current_ns
= current_interface
.ns
;
3808 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3809 gfc_ascii_statement (st
));
3810 reject_statement ();
3811 gfc_free_namespace (gfc_current_ns
);
3816 /* Make sure that the generic name has the right attribute. */
3817 if (current_interface
.type
== INTERFACE_GENERIC
3818 && current_state
== COMP_NONE
)
3820 if (new_state
== COMP_FUNCTION
&& sym
)
3821 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3822 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3823 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3825 current_state
= new_state
;
3828 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3830 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3831 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3832 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3833 "cannot be the same as an intrinsic type",
3834 gfc_new_block
->name
);
3837 push_state (&s2
, new_state
, gfc_new_block
);
3838 accept_statement (st
);
3839 prog_unit
= gfc_new_block
;
3840 prog_unit
->formal_ns
= gfc_current_ns
;
3841 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3842 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3846 /* Read data declaration statements. */
3847 st
= parse_spec (ST_NONE
);
3848 in_specification_block
= true;
3850 /* Since the interface block does not permit an IMPLICIT statement,
3851 the default type for the function or the result must be taken
3852 from the formal namespace. */
3853 if (new_state
== COMP_FUNCTION
)
3855 if (prog_unit
->result
== prog_unit
3856 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3857 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3858 else if (prog_unit
->result
!= prog_unit
3859 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3860 gfc_set_default_type (prog_unit
->result
, 1,
3861 prog_unit
->formal_ns
);
3864 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3866 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3867 gfc_ascii_statement (st
));
3868 reject_statement ();
3872 /* Add EXTERNAL attribute to function or subroutine. */
3873 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3874 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3876 current_interface
= save
;
3877 gfc_add_interface (prog_unit
);
3880 if (current_interface
.ns
3881 && current_interface
.ns
->proc_name
3882 && strcmp (current_interface
.ns
->proc_name
->name
,
3883 prog_unit
->name
) == 0)
3884 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3885 "enclosing procedure", prog_unit
->name
,
3886 ¤t_interface
.ns
->proc_name
->declared_at
);
3895 /* Associate function characteristics by going back to the function
3896 declaration and rematching the prefix. */
3899 match_deferred_characteristics (gfc_typespec
* ts
)
3902 match m
= MATCH_ERROR
;
3903 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3905 loc
= gfc_current_locus
;
3907 gfc_current_locus
= gfc_current_block ()->declared_at
;
3910 gfc_buffer_error (true);
3911 m
= gfc_match_prefix (ts
);
3912 gfc_buffer_error (false);
3914 if (ts
->type
== BT_DERIVED
)
3922 /* Only permit one go at the characteristic association. */
3926 /* Set the function locus correctly. If we have not found the
3927 function name, there is an error. */
3929 && gfc_match ("function% %n", name
) == MATCH_YES
3930 && strcmp (name
, gfc_current_block ()->name
) == 0)
3932 gfc_current_block ()->declared_at
= gfc_current_locus
;
3933 gfc_commit_symbols ();
3938 gfc_undo_symbols ();
3941 gfc_current_locus
=loc
;
3946 /* Check specification-expressions in the function result of the currently
3947 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3948 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3949 scope are not yet parsed so this has to be delayed up to parse_spec. */
3952 check_function_result_typed (void)
3956 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3958 if (!gfc_current_ns
->proc_name
->result
) return;
3960 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3962 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3963 /* TODO: Extend when KIND type parameters are implemented. */
3964 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3965 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3969 /* Parse a set of specification statements. Returns the statement
3970 that doesn't fit. */
3972 static gfc_statement
3973 parse_spec (gfc_statement st
)
3976 bool function_result_typed
= false;
3977 bool bad_characteristic
= false;
3980 in_specification_block
= true;
3982 verify_st_order (&ss
, ST_NONE
, false);
3984 st
= next_statement ();
3986 /* If we are not inside a function or don't have a result specified so far,
3987 do nothing special about it. */
3988 if (gfc_current_state () != COMP_FUNCTION
)
3989 function_result_typed
= true;
3992 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3995 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3996 function_result_typed
= true;
4001 /* If we're inside a BLOCK construct, some statements are disallowed.
4002 Check this here. Attribute declaration statements like INTENT, OPTIONAL
4003 or VALUE are also disallowed, but they don't have a particular ST_*
4004 key so we have to check for them individually in their matcher routine. */
4005 if (gfc_current_state () == COMP_BLOCK
)
4009 case ST_IMPLICIT_NONE
:
4012 case ST_EQUIVALENCE
:
4013 case ST_STATEMENT_FUNCTION
:
4014 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
4015 gfc_ascii_statement (st
));
4016 reject_statement ();
4022 else if (gfc_current_state () == COMP_BLOCK_DATA
)
4023 /* Fortran 2008, C1116. */
4030 case ST_DERIVED_DECL
:
4031 case ST_END_BLOCK_DATA
:
4032 case ST_EQUIVALENCE
:
4034 case ST_IMPLICIT_NONE
:
4035 case ST_OMP_THREADPRIVATE
:
4037 case ST_STRUCTURE_DECL
:
4046 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
4047 gfc_ascii_statement (st
));
4048 reject_statement ();
4052 /* If we find a statement that cannot be followed by an IMPLICIT statement
4053 (and thus we can expect to see none any further), type the function result
4054 if it has not yet been typed. Be careful not to give the END statement
4055 to verify_st_order! */
4056 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
4058 bool verify_now
= false;
4060 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
4065 verify_st_order (&dummyss
, ST_NONE
, false);
4066 verify_st_order (&dummyss
, st
, false);
4068 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
4074 check_function_result_typed ();
4075 function_result_typed
= true;
4084 case ST_IMPLICIT_NONE
:
4086 if (!function_result_typed
)
4088 check_function_result_typed ();
4089 function_result_typed
= true;
4095 case ST_DATA
: /* Not allowed in interfaces */
4096 if (gfc_current_state () == COMP_INTERFACE
)
4106 case ST_STRUCTURE_DECL
:
4107 case ST_DERIVED_DECL
:
4111 if (!verify_st_order (&ss
, st
, false))
4113 reject_statement ();
4114 st
= next_statement ();
4124 case ST_STRUCTURE_DECL
:
4125 parse_struct_map (ST_STRUCTURE_DECL
);
4128 case ST_DERIVED_DECL
:
4134 if (gfc_current_state () != COMP_MODULE
)
4136 gfc_error ("%s statement must appear in a MODULE",
4137 gfc_ascii_statement (st
));
4138 reject_statement ();
4142 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
4144 gfc_error ("%s statement at %C follows another accessibility "
4145 "specification", gfc_ascii_statement (st
));
4146 reject_statement ();
4150 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
4151 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
4155 case ST_STATEMENT_FUNCTION
:
4156 if (gfc_current_state () == COMP_MODULE
4157 || gfc_current_state () == COMP_SUBMODULE
)
4159 unexpected_statement (st
);
4167 accept_statement (st
);
4168 st
= next_statement ();
4172 accept_statement (st
);
4174 st
= next_statement ();
4177 case ST_GET_FCN_CHARACTERISTICS
:
4178 /* This statement triggers the association of a function's result
4180 ts
= &gfc_current_block ()->result
->ts
;
4181 if (match_deferred_characteristics (ts
) != MATCH_YES
)
4182 bad_characteristic
= true;
4184 st
= next_statement ();
4191 /* If match_deferred_characteristics failed, then there is an error. */
4192 if (bad_characteristic
)
4194 ts
= &gfc_current_block ()->result
->ts
;
4195 if (ts
->type
!= BT_DERIVED
)
4196 gfc_error ("Bad kind expression for function %qs at %L",
4197 gfc_current_block ()->name
,
4198 &gfc_current_block ()->declared_at
);
4200 gfc_error ("The type for function %qs at %L is not accessible",
4201 gfc_current_block ()->name
,
4202 &gfc_current_block ()->declared_at
);
4204 gfc_current_block ()->ts
.kind
= 0;
4205 /* Keep the derived type; if it's bad, it will be discovered later. */
4206 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
4207 ts
->type
= BT_UNKNOWN
;
4210 in_specification_block
= false;
4216 /* Parse a WHERE block, (not a simple WHERE statement). */
4219 parse_where_block (void)
4221 int seen_empty_else
;
4226 accept_statement (ST_WHERE_BLOCK
);
4227 top
= gfc_state_stack
->tail
;
4229 push_state (&s
, COMP_WHERE
, gfc_new_block
);
4231 d
= add_statement ();
4232 d
->expr1
= top
->expr1
;
4238 seen_empty_else
= 0;
4242 st
= next_statement ();
4248 case ST_WHERE_BLOCK
:
4249 parse_where_block ();
4254 accept_statement (st
);
4258 if (seen_empty_else
)
4260 gfc_error ("ELSEWHERE statement at %C follows previous "
4261 "unmasked ELSEWHERE");
4262 reject_statement ();
4266 if (new_st
.expr1
== NULL
)
4267 seen_empty_else
= 1;
4269 d
= new_level (gfc_state_stack
->head
);
4271 d
->expr1
= new_st
.expr1
;
4273 accept_statement (st
);
4278 accept_statement (st
);
4282 gfc_error ("Unexpected %s statement in WHERE block at %C",
4283 gfc_ascii_statement (st
));
4284 reject_statement ();
4288 while (st
!= ST_END_WHERE
);
4294 /* Parse a FORALL block (not a simple FORALL statement). */
4297 parse_forall_block (void)
4303 accept_statement (ST_FORALL_BLOCK
);
4304 top
= gfc_state_stack
->tail
;
4306 push_state (&s
, COMP_FORALL
, gfc_new_block
);
4308 d
= add_statement ();
4309 d
->op
= EXEC_FORALL
;
4314 st
= next_statement ();
4319 case ST_POINTER_ASSIGNMENT
:
4322 accept_statement (st
);
4325 case ST_WHERE_BLOCK
:
4326 parse_where_block ();
4329 case ST_FORALL_BLOCK
:
4330 parse_forall_block ();
4334 accept_statement (st
);
4341 gfc_error ("Unexpected %s statement in FORALL block at %C",
4342 gfc_ascii_statement (st
));
4344 reject_statement ();
4348 while (st
!= ST_END_FORALL
);
4354 static gfc_statement
parse_executable (gfc_statement
);
4356 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4359 parse_if_block (void)
4368 accept_statement (ST_IF_BLOCK
);
4370 top
= gfc_state_stack
->tail
;
4371 push_state (&s
, COMP_IF
, gfc_new_block
);
4373 new_st
.op
= EXEC_IF
;
4374 d
= add_statement ();
4376 d
->expr1
= top
->expr1
;
4382 st
= parse_executable (ST_NONE
);
4392 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4393 "statement at %L", &else_locus
);
4395 reject_statement ();
4399 d
= new_level (gfc_state_stack
->head
);
4401 d
->expr1
= new_st
.expr1
;
4403 accept_statement (st
);
4410 gfc_error ("Duplicate ELSE statements at %L and %C",
4412 reject_statement ();
4417 else_locus
= gfc_current_locus
;
4419 d
= new_level (gfc_state_stack
->head
);
4422 accept_statement (st
);
4430 unexpected_statement (st
);
4434 while (st
!= ST_ENDIF
);
4437 accept_statement (st
);
4441 /* Parse a SELECT block. */
4444 parse_select_block (void)
4450 accept_statement (ST_SELECT_CASE
);
4452 cp
= gfc_state_stack
->tail
;
4453 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4455 /* Make sure that the next statement is a CASE or END SELECT. */
4458 st
= next_statement ();
4461 if (st
== ST_END_SELECT
)
4463 /* Empty SELECT CASE is OK. */
4464 accept_statement (st
);
4471 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4474 reject_statement ();
4477 /* At this point, we've got a nonempty select block. */
4478 cp
= new_level (cp
);
4481 accept_statement (st
);
4485 st
= parse_executable (ST_NONE
);
4492 cp
= new_level (gfc_state_stack
->head
);
4494 gfc_clear_new_st ();
4496 accept_statement (st
);
4502 /* Can't have an executable statement because of
4503 parse_executable(). */
4505 unexpected_statement (st
);
4509 while (st
!= ST_END_SELECT
);
4512 accept_statement (st
);
4516 /* Pop the current selector from the SELECT TYPE stack. */
4519 select_type_pop (void)
4521 gfc_select_type_stack
*old
= select_type_stack
;
4522 select_type_stack
= old
->prev
;
4527 /* Parse a SELECT TYPE construct (F03:R821). */
4530 parse_select_type_block (void)
4536 gfc_current_ns
= new_st
.ext
.block
.ns
;
4537 accept_statement (ST_SELECT_TYPE
);
4539 cp
= gfc_state_stack
->tail
;
4540 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4542 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4546 st
= next_statement ();
4549 if (st
== ST_END_SELECT
)
4550 /* Empty SELECT CASE is OK. */
4552 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4555 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4556 "following SELECT TYPE at %C");
4558 reject_statement ();
4561 /* At this point, we've got a nonempty select block. */
4562 cp
= new_level (cp
);
4565 accept_statement (st
);
4569 st
= parse_executable (ST_NONE
);
4577 cp
= new_level (gfc_state_stack
->head
);
4579 gfc_clear_new_st ();
4581 accept_statement (st
);
4587 /* Can't have an executable statement because of
4588 parse_executable(). */
4590 unexpected_statement (st
);
4594 while (st
!= ST_END_SELECT
);
4598 accept_statement (st
);
4599 gfc_current_ns
= gfc_current_ns
->parent
;
4604 /* Parse a SELECT RANK construct. */
4607 parse_select_rank_block (void)
4613 gfc_current_ns
= new_st
.ext
.block
.ns
;
4614 accept_statement (ST_SELECT_RANK
);
4616 cp
= gfc_state_stack
->tail
;
4617 push_state (&s
, COMP_SELECT_RANK
, gfc_new_block
);
4619 /* Make sure that the next statement is a RANK IS or RANK DEFAULT. */
4622 st
= next_statement ();
4625 if (st
== ST_END_SELECT
)
4626 /* Empty SELECT CASE is OK. */
4631 gfc_error ("Expected RANK or RANK DEFAULT "
4632 "following SELECT RANK at %C");
4634 reject_statement ();
4637 /* At this point, we've got a nonempty select block. */
4638 cp
= new_level (cp
);
4641 accept_statement (st
);
4645 st
= parse_executable (ST_NONE
);
4652 cp
= new_level (gfc_state_stack
->head
);
4654 gfc_clear_new_st ();
4656 accept_statement (st
);
4662 /* Can't have an executable statement because of
4663 parse_executable(). */
4665 unexpected_statement (st
);
4669 while (st
!= ST_END_SELECT
);
4673 accept_statement (st
);
4674 gfc_current_ns
= gfc_current_ns
->parent
;
4679 /* Given a symbol, make sure it is not an iteration variable for a DO
4680 statement. This subroutine is called when the symbol is seen in a
4681 context that causes it to become redefined. If the symbol is an
4682 iterator, we generate an error message and return nonzero. */
4685 gfc_check_do_variable (gfc_symtree
*st
)
4692 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4693 if (s
->do_variable
== st
)
4695 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4696 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4704 /* Checks to see if the current statement label closes an enddo.
4705 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4706 an error) if it incorrectly closes an ENDDO. */
4709 check_do_closure (void)
4713 if (gfc_statement_label
== NULL
)
4716 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4717 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4721 return 0; /* No loops to close */
4723 if (p
->ext
.end_do_label
== gfc_statement_label
)
4725 if (p
== gfc_state_stack
)
4728 gfc_error ("End of nonblock DO statement at %C is within another block");
4732 /* At this point, the label doesn't terminate the innermost loop.
4733 Make sure it doesn't terminate another one. */
4734 for (; p
; p
= p
->previous
)
4735 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4736 && p
->ext
.end_do_label
== gfc_statement_label
)
4738 gfc_error ("End of nonblock DO statement at %C is interwoven "
4739 "with another DO loop");
4747 /* Parse a series of contained program units. */
4749 static void parse_progunit (gfc_statement
);
4752 /* Parse a CRITICAL block. */
4755 parse_critical_block (void)
4758 gfc_state_data s
, *sd
;
4761 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4762 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4763 gfc_error_now (is_oacc (sd
)
4764 ? G_("CRITICAL block inside of OpenACC region at %C")
4765 : G_("CRITICAL block inside of OpenMP region at %C"));
4767 s
.ext
.end_do_label
= new_st
.label1
;
4769 accept_statement (ST_CRITICAL
);
4770 top
= gfc_state_stack
->tail
;
4772 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4774 d
= add_statement ();
4775 d
->op
= EXEC_CRITICAL
;
4780 st
= parse_executable (ST_NONE
);
4788 case ST_END_CRITICAL
:
4789 if (s
.ext
.end_do_label
!= NULL
4790 && s
.ext
.end_do_label
!= gfc_statement_label
)
4791 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4792 "match CRITICAL label");
4794 if (gfc_statement_label
!= NULL
)
4796 new_st
.op
= EXEC_NOP
;
4802 unexpected_statement (st
);
4806 while (st
!= ST_END_CRITICAL
);
4809 accept_statement (st
);
4813 /* Set up the local namespace for a BLOCK construct. */
4816 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4818 gfc_namespace
* my_ns
;
4819 static int numblock
= 1;
4821 my_ns
= gfc_get_namespace (parent_ns
, 1);
4822 my_ns
->construct_entities
= 1;
4824 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4825 code generation (so it must not be NULL).
4826 We set its recursive argument if our container procedure is recursive, so
4827 that local variables are accordingly placed on the stack when it
4828 will be necessary. */
4830 my_ns
->proc_name
= gfc_new_block
;
4834 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4836 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4837 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4838 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4839 my_ns
->proc_name
->name
, NULL
);
4841 gfc_commit_symbol (my_ns
->proc_name
);
4844 if (parent_ns
->proc_name
)
4845 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4851 /* Parse a BLOCK construct. */
4854 parse_block_construct (void)
4856 gfc_namespace
* my_ns
;
4857 gfc_namespace
* my_parent
;
4860 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4862 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4864 new_st
.op
= EXEC_BLOCK
;
4865 new_st
.ext
.block
.ns
= my_ns
;
4866 new_st
.ext
.block
.assoc
= NULL
;
4867 accept_statement (ST_BLOCK
);
4869 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4870 gfc_current_ns
= my_ns
;
4871 my_parent
= my_ns
->parent
;
4873 parse_progunit (ST_NONE
);
4875 /* Don't depend on the value of gfc_current_ns; it might have been
4876 reset if the block had errors and was cleaned up. */
4877 gfc_current_ns
= my_parent
;
4883 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4884 behind the scenes with compiler-generated variables. */
4887 parse_associate (void)
4889 gfc_namespace
* my_ns
;
4892 gfc_association_list
* a
;
4894 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4896 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4898 new_st
.op
= EXEC_BLOCK
;
4899 new_st
.ext
.block
.ns
= my_ns
;
4900 gcc_assert (new_st
.ext
.block
.assoc
);
4902 /* Add all associate-names as BLOCK variables. Creating them is enough
4903 for now, they'll get their values during trans-* phase. */
4904 gfc_current_ns
= my_ns
;
4905 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4909 gfc_array_ref
*array_ref
;
4911 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4915 sym
->attr
.flavor
= FL_VARIABLE
;
4917 sym
->declared_at
= a
->where
;
4918 gfc_set_sym_referenced (sym
);
4920 /* Initialize the typespec. It is not available in all cases,
4921 however, as it may only be set on the target during resolution.
4922 Still, sometimes it helps to have it right now -- especially
4923 for parsing component references on the associate-name
4924 in case of association to a derived-type. */
4925 sym
->ts
= a
->target
->ts
;
4927 /* Check if the target expression is array valued. This cannot always
4928 be done by looking at target.rank, because that might not have been
4929 set yet. Therefore traverse the chain of refs, looking for the last
4930 array ref and evaluate that. */
4932 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4933 if (ref
->type
== REF_ARRAY
)
4934 array_ref
= &ref
->u
.ar
;
4935 if (array_ref
|| a
->target
->rank
)
4942 /* Count the dimension, that have a non-scalar extend. */
4943 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4944 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4945 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4946 && array_ref
->end
[dim
] == NULL
4947 && array_ref
->start
[dim
] != NULL
))
4951 rank
= a
->target
->rank
;
4952 /* When the rank is greater than zero then sym will be an array. */
4953 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
4955 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4956 || (CLASS_DATA (sym
)->as
4957 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4959 /* Don't just (re-)set the attr and as in the sym.ts,
4960 because this modifies the target's attr and as. Copy the
4961 data and do a build_class_symbol. */
4962 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4963 int corank
= gfc_get_corank (a
->target
);
4968 as
= gfc_get_array_spec ();
4969 as
->type
= AS_DEFERRED
;
4971 as
->corank
= corank
;
4972 attr
.dimension
= rank
? 1 : 0;
4973 attr
.codimension
= corank
? 1 : 0;
4978 attr
.dimension
= attr
.codimension
= 0;
4981 type
= CLASS_DATA (sym
)->ts
;
4982 if (!gfc_build_class_symbol (&type
,
4986 sym
->ts
.type
= BT_CLASS
;
4987 sym
->attr
.class_ok
= 1;
4990 sym
->attr
.class_ok
= 1;
4992 else if ((!sym
->as
&& rank
!= 0)
4993 || (sym
->as
&& sym
->as
->rank
!= rank
))
4995 as
= gfc_get_array_spec ();
4996 as
->type
= AS_DEFERRED
;
4998 as
->corank
= gfc_get_corank (a
->target
);
5000 sym
->attr
.dimension
= 1;
5002 sym
->attr
.codimension
= 1;
5007 accept_statement (ST_ASSOCIATE
);
5008 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
5011 st
= parse_executable (ST_NONE
);
5018 accept_statement (st
);
5019 my_ns
->code
= gfc_state_stack
->head
;
5023 unexpected_statement (st
);
5027 gfc_current_ns
= gfc_current_ns
->parent
;
5032 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
5033 handled inside of parse_executable(), because they aren't really
5037 parse_do_block (void)
5046 s
.ext
.end_do_label
= new_st
.label1
;
5048 if (new_st
.ext
.iterator
!= NULL
)
5050 stree
= new_st
.ext
.iterator
->var
->symtree
;
5051 if (directive_unroll
!= -1)
5053 new_st
.ext
.iterator
->unroll
= directive_unroll
;
5054 directive_unroll
= -1;
5056 if (directive_ivdep
)
5058 new_st
.ext
.iterator
->ivdep
= directive_ivdep
;
5059 directive_ivdep
= false;
5061 if (directive_vector
)
5063 new_st
.ext
.iterator
->vector
= directive_vector
;
5064 directive_vector
= false;
5066 if (directive_novector
)
5068 new_st
.ext
.iterator
->novector
= directive_novector
;
5069 directive_novector
= false;
5075 accept_statement (ST_DO
);
5077 top
= gfc_state_stack
->tail
;
5078 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
5081 s
.do_variable
= stree
;
5083 top
->block
= new_level (top
);
5084 top
->block
->op
= EXEC_DO
;
5087 st
= parse_executable (ST_NONE
);
5095 if (s
.ext
.end_do_label
!= NULL
5096 && s
.ext
.end_do_label
!= gfc_statement_label
)
5097 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
5100 if (gfc_statement_label
!= NULL
)
5102 new_st
.op
= EXEC_NOP
;
5107 case ST_IMPLIED_ENDDO
:
5108 /* If the do-stmt of this DO construct has a do-construct-name,
5109 the corresponding end-do must be an end-do-stmt (with a matching
5110 name, but in that case we must have seen ST_ENDDO first).
5111 We only complain about this in pedantic mode. */
5112 if (gfc_current_block () != NULL
)
5113 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
5114 &gfc_current_block()->declared_at
);
5119 unexpected_statement (st
);
5124 accept_statement (st
);
5128 /* Parse the statements of OpenMP do/parallel do. */
5130 static gfc_statement
5131 parse_omp_do (gfc_statement omp_st
)
5137 accept_statement (omp_st
);
5139 cp
= gfc_state_stack
->tail
;
5140 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5141 np
= new_level (cp
);
5147 st
= next_statement ();
5150 else if (st
== ST_DO
)
5153 unexpected_statement (st
);
5157 if (gfc_statement_label
!= NULL
5158 && gfc_state_stack
->previous
!= NULL
5159 && gfc_state_stack
->previous
->state
== COMP_DO
5160 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5168 there should be no !$OMP END DO. */
5170 return ST_IMPLIED_ENDDO
;
5173 check_do_closure ();
5176 st
= next_statement ();
5177 gfc_statement omp_end_st
= ST_OMP_END_DO
;
5180 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
5181 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5182 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5184 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5185 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5187 case ST_OMP_DISTRIBUTE_SIMD
:
5188 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
5190 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
5191 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
5192 case ST_OMP_LOOP
: omp_end_st
= ST_OMP_END_LOOP
; break;
5193 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
5194 case ST_OMP_PARALLEL_DO_SIMD
:
5195 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
5197 case ST_OMP_PARALLEL_LOOP
:
5198 omp_end_st
= ST_OMP_END_PARALLEL_LOOP
;
5200 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
5201 case ST_OMP_TARGET_PARALLEL_DO
:
5202 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO
;
5204 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5205 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
5207 case ST_OMP_TARGET_PARALLEL_LOOP
:
5208 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_LOOP
;
5210 case ST_OMP_TARGET_SIMD
: omp_end_st
= ST_OMP_END_TARGET_SIMD
; break;
5211 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5212 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5214 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5215 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5217 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5218 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5220 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5221 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5223 case ST_OMP_TARGET_TEAMS_LOOP
:
5224 omp_end_st
= ST_OMP_END_TARGET_TEAMS_LOOP
;
5226 case ST_OMP_TASKLOOP
: omp_end_st
= ST_OMP_END_TASKLOOP
; break;
5227 case ST_OMP_TASKLOOP_SIMD
: omp_end_st
= ST_OMP_END_TASKLOOP_SIMD
; break;
5228 case ST_OMP_MASKED_TASKLOOP
: omp_end_st
= ST_OMP_END_MASKED_TASKLOOP
; break;
5229 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5230 omp_end_st
= ST_OMP_END_MASKED_TASKLOOP_SIMD
;
5232 case ST_OMP_MASTER_TASKLOOP
: omp_end_st
= ST_OMP_END_MASTER_TASKLOOP
; break;
5233 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5234 omp_end_st
= ST_OMP_END_MASTER_TASKLOOP_SIMD
;
5236 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5237 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP
;
5239 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5240 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
;
5242 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5243 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP
;
5245 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5246 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
;
5248 case ST_OMP_TEAMS_DISTRIBUTE
:
5249 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5251 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5252 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5254 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5255 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5257 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5258 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5260 case ST_OMP_TEAMS_LOOP
:
5261 omp_end_st
= ST_OMP_END_TEAMS_LOOP
;
5263 default: gcc_unreachable ();
5265 if (st
== omp_end_st
)
5267 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
5268 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5270 gcc_assert (new_st
.op
== EXEC_NOP
);
5271 gfc_clear_new_st ();
5272 gfc_commit_symbols ();
5273 gfc_warning_check ();
5274 st
= next_statement ();
5280 /* Parse the statements of OpenMP atomic directive. */
5282 static gfc_statement
5283 parse_omp_oacc_atomic (bool omp_p
)
5285 gfc_statement st
, st_atomic
, st_end_atomic
;
5292 st_atomic
= ST_OMP_ATOMIC
;
5293 st_end_atomic
= ST_OMP_END_ATOMIC
;
5297 st_atomic
= ST_OACC_ATOMIC
;
5298 st_end_atomic
= ST_OACC_END_ATOMIC
;
5300 accept_statement (st_atomic
);
5302 cp
= gfc_state_stack
->tail
;
5303 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5304 np
= new_level (cp
);
5307 np
->ext
.omp_clauses
= cp
->ext
.omp_clauses
;
5308 cp
->ext
.omp_clauses
= NULL
;
5309 count
= 1 + np
->ext
.omp_clauses
->capture
;
5313 st
= next_statement ();
5316 else if (np
->ext
.omp_clauses
->compare
5317 && (st
== ST_SIMPLE_IF
|| st
== ST_IF_BLOCK
))
5320 if (st
== ST_IF_BLOCK
)
5323 /* With else (or elseif). */
5324 if (gfc_state_stack
->tail
->block
->block
)
5327 accept_statement (st
);
5329 else if (st
== ST_ASSIGNMENT
5330 && (!np
->ext
.omp_clauses
->compare
5331 || np
->ext
.omp_clauses
->capture
))
5333 accept_statement (st
);
5337 unexpected_statement (st
);
5342 st
= next_statement ();
5343 if (st
== st_end_atomic
)
5345 gfc_clear_new_st ();
5346 gfc_commit_symbols ();
5347 gfc_warning_check ();
5348 st
= next_statement ();
5354 /* Parse the statements of an OpenACC structured block. */
5357 parse_oacc_structured_block (gfc_statement acc_st
)
5359 gfc_statement st
, acc_end_st
;
5361 gfc_state_data s
, *sd
;
5363 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5364 if (sd
->state
== COMP_CRITICAL
)
5365 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5367 accept_statement (acc_st
);
5369 cp
= gfc_state_stack
->tail
;
5370 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5371 np
= new_level (cp
);
5376 case ST_OACC_PARALLEL
:
5377 acc_end_st
= ST_OACC_END_PARALLEL
;
5379 case ST_OACC_KERNELS
:
5380 acc_end_st
= ST_OACC_END_KERNELS
;
5382 case ST_OACC_SERIAL
:
5383 acc_end_st
= ST_OACC_END_SERIAL
;
5386 acc_end_st
= ST_OACC_END_DATA
;
5388 case ST_OACC_HOST_DATA
:
5389 acc_end_st
= ST_OACC_END_HOST_DATA
;
5397 st
= parse_executable (ST_NONE
);
5400 else if (st
!= acc_end_st
)
5402 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
5403 reject_statement ();
5406 while (st
!= acc_end_st
);
5408 gcc_assert (new_st
.op
== EXEC_NOP
);
5410 gfc_clear_new_st ();
5411 gfc_commit_symbols ();
5412 gfc_warning_check ();
5416 /* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */
5418 static gfc_statement
5419 parse_oacc_loop (gfc_statement acc_st
)
5423 gfc_state_data s
, *sd
;
5425 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5426 if (sd
->state
== COMP_CRITICAL
)
5427 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5429 accept_statement (acc_st
);
5431 cp
= gfc_state_stack
->tail
;
5432 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5433 np
= new_level (cp
);
5439 st
= next_statement ();
5442 else if (st
== ST_DO
)
5446 gfc_error ("Expected DO loop at %C");
5447 reject_statement ();
5452 if (gfc_statement_label
!= NULL
5453 && gfc_state_stack
->previous
!= NULL
5454 && gfc_state_stack
->previous
->state
== COMP_DO
5455 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5458 return ST_IMPLIED_ENDDO
;
5461 check_do_closure ();
5464 st
= next_statement ();
5465 if (st
== ST_OACC_END_LOOP
)
5466 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
5467 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
5468 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
5469 (acc_st
== ST_OACC_SERIAL_LOOP
&& st
== ST_OACC_END_SERIAL_LOOP
) ||
5470 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
5472 gcc_assert (new_st
.op
== EXEC_NOP
);
5473 gfc_clear_new_st ();
5474 gfc_commit_symbols ();
5475 gfc_warning_check ();
5476 st
= next_statement ();
5482 /* Parse the statements of an OpenMP structured block. */
5484 static gfc_statement
5485 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
5487 gfc_statement st
, omp_end_st
;
5491 accept_statement (omp_st
);
5493 cp
= gfc_state_stack
->tail
;
5494 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5495 np
= new_level (cp
);
5501 case ST_OMP_PARALLEL
:
5502 omp_end_st
= ST_OMP_END_PARALLEL
;
5504 case ST_OMP_PARALLEL_MASKED
:
5505 omp_end_st
= ST_OMP_END_PARALLEL_MASKED
;
5507 case ST_OMP_PARALLEL_MASTER
:
5508 omp_end_st
= ST_OMP_END_PARALLEL_MASTER
;
5510 case ST_OMP_PARALLEL_SECTIONS
:
5511 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
5514 omp_end_st
= ST_OMP_END_SCOPE
;
5516 case ST_OMP_SECTIONS
:
5517 omp_end_st
= ST_OMP_END_SECTIONS
;
5519 case ST_OMP_ORDERED
:
5520 omp_end_st
= ST_OMP_END_ORDERED
;
5522 case ST_OMP_CRITICAL
:
5523 omp_end_st
= ST_OMP_END_CRITICAL
;
5526 omp_end_st
= ST_OMP_END_MASKED
;
5529 omp_end_st
= ST_OMP_END_MASTER
;
5532 omp_end_st
= ST_OMP_END_SINGLE
;
5535 omp_end_st
= ST_OMP_END_TARGET
;
5537 case ST_OMP_TARGET_DATA
:
5538 omp_end_st
= ST_OMP_END_TARGET_DATA
;
5540 case ST_OMP_TARGET_PARALLEL
:
5541 omp_end_st
= ST_OMP_END_TARGET_PARALLEL
;
5543 case ST_OMP_TARGET_TEAMS
:
5544 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
5547 omp_end_st
= ST_OMP_END_TASK
;
5549 case ST_OMP_TASKGROUP
:
5550 omp_end_st
= ST_OMP_END_TASKGROUP
;
5553 omp_end_st
= ST_OMP_END_TEAMS
;
5555 case ST_OMP_TEAMS_DISTRIBUTE
:
5556 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5558 case ST_OMP_DISTRIBUTE
:
5559 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
5561 case ST_OMP_WORKSHARE
:
5562 omp_end_st
= ST_OMP_END_WORKSHARE
;
5564 case ST_OMP_PARALLEL_WORKSHARE
:
5565 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
5571 bool block_construct
= false;
5572 gfc_namespace
*my_ns
= NULL
;
5573 gfc_namespace
*my_parent
= NULL
;
5575 st
= next_statement ();
5579 /* Adjust state to a strictly-structured block, now that we found that
5580 the body starts with a BLOCK construct. */
5581 s
.state
= COMP_OMP_STRICTLY_STRUCTURED_BLOCK
;
5583 block_construct
= true;
5584 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
5586 my_ns
= gfc_build_block_ns (gfc_current_ns
);
5587 gfc_current_ns
= my_ns
;
5588 my_parent
= my_ns
->parent
;
5590 new_st
.op
= EXEC_BLOCK
;
5591 new_st
.ext
.block
.ns
= my_ns
;
5592 new_st
.ext
.block
.assoc
= NULL
;
5593 accept_statement (ST_BLOCK
);
5594 st
= parse_spec (ST_NONE
);
5599 if (workshare_stmts_only
)
5601 /* Inside of !$omp workshare, only
5604 where statements and constructs
5605 forall statements and constructs
5609 are allowed. For !$omp critical these
5610 restrictions apply recursively. */
5623 accept_statement (st
);
5626 case ST_WHERE_BLOCK
:
5627 parse_where_block ();
5630 case ST_FORALL_BLOCK
:
5631 parse_forall_block ();
5634 case ST_OMP_PARALLEL
:
5635 case ST_OMP_PARALLEL_MASKED
:
5636 case ST_OMP_PARALLEL_MASTER
:
5637 case ST_OMP_PARALLEL_SECTIONS
:
5638 st
= parse_omp_structured_block (st
, false);
5641 case ST_OMP_PARALLEL_WORKSHARE
:
5642 case ST_OMP_CRITICAL
:
5643 st
= parse_omp_structured_block (st
, true);
5646 case ST_OMP_PARALLEL_DO
:
5647 case ST_OMP_PARALLEL_DO_SIMD
:
5648 st
= parse_omp_do (st
);
5652 st
= parse_omp_oacc_atomic (true);
5663 st
= next_statement ();
5667 st
= parse_executable (st
);
5670 else if (st
== ST_OMP_SECTION
5671 && (omp_st
== ST_OMP_SECTIONS
5672 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
5674 np
= new_level (np
);
5677 st
= next_statement ();
5679 else if (block_construct
&& st
== ST_END_BLOCK
)
5681 accept_statement (st
);
5682 gfc_current_ns
= my_parent
;
5685 st
= next_statement ();
5686 if (st
== omp_end_st
)
5688 accept_statement (st
);
5689 st
= next_statement ();
5693 else if (st
!= omp_end_st
)
5695 unexpected_statement (st
);
5696 st
= next_statement ();
5699 while (st
!= omp_end_st
);
5703 case EXEC_OMP_END_NOWAIT
:
5704 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5706 case EXEC_OMP_END_CRITICAL
:
5707 if (((cp
->ext
.omp_clauses
->critical_name
== NULL
)
5708 ^ (new_st
.ext
.omp_name
== NULL
))
5709 || (new_st
.ext
.omp_name
!= NULL
5710 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
5711 new_st
.ext
.omp_name
) != 0))
5712 gfc_error ("Name after !$omp critical and !$omp end critical does "
5714 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
5715 new_st
.ext
.omp_name
= NULL
;
5717 case EXEC_OMP_END_SINGLE
:
5718 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
5719 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
5720 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
5721 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5729 gfc_clear_new_st ();
5730 gfc_commit_symbols ();
5731 gfc_warning_check ();
5733 st
= next_statement ();
5738 /* Accept a series of executable statements. We return the first
5739 statement that doesn't fit to the caller. Any block statements are
5740 passed on to the correct handler, which usually passes the buck
5743 static gfc_statement
5744 parse_executable (gfc_statement st
)
5749 st
= next_statement ();
5753 close_flag
= check_do_closure ();
5758 case ST_END_PROGRAM
:
5761 case ST_END_FUNCTION
:
5766 case ST_END_SUBROUTINE
:
5771 case ST_SELECT_CASE
:
5772 gfc_error ("%s statement at %C cannot terminate a non-block "
5773 "DO loop", gfc_ascii_statement (st
));
5786 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5787 "first executable statement");
5793 accept_statement (st
);
5794 if (close_flag
== 1)
5795 return ST_IMPLIED_ENDDO
;
5799 parse_block_construct ();
5810 case ST_SELECT_CASE
:
5811 parse_select_block ();
5814 case ST_SELECT_TYPE
:
5815 parse_select_type_block ();
5818 case ST_SELECT_RANK
:
5819 parse_select_rank_block ();
5824 if (check_do_closure () == 1)
5825 return ST_IMPLIED_ENDDO
;
5829 parse_critical_block ();
5832 case ST_WHERE_BLOCK
:
5833 parse_where_block ();
5836 case ST_FORALL_BLOCK
:
5837 parse_forall_block ();
5840 case ST_OACC_PARALLEL_LOOP
:
5841 case ST_OACC_KERNELS_LOOP
:
5842 case ST_OACC_SERIAL_LOOP
:
5844 st
= parse_oacc_loop (st
);
5845 if (st
== ST_IMPLIED_ENDDO
)
5849 case ST_OACC_PARALLEL
:
5850 case ST_OACC_KERNELS
:
5851 case ST_OACC_SERIAL
:
5853 case ST_OACC_HOST_DATA
:
5854 parse_oacc_structured_block (st
);
5857 case ST_OMP_PARALLEL
:
5858 case ST_OMP_PARALLEL_MASKED
:
5859 case ST_OMP_PARALLEL_MASTER
:
5860 case ST_OMP_PARALLEL_SECTIONS
:
5861 case ST_OMP_ORDERED
:
5862 case ST_OMP_CRITICAL
:
5866 case ST_OMP_SECTIONS
:
5869 case ST_OMP_TARGET_DATA
:
5870 case ST_OMP_TARGET_PARALLEL
:
5871 case ST_OMP_TARGET_TEAMS
:
5874 case ST_OMP_TASKGROUP
:
5875 st
= parse_omp_structured_block (st
, false);
5878 case ST_OMP_WORKSHARE
:
5879 case ST_OMP_PARALLEL_WORKSHARE
:
5880 st
= parse_omp_structured_block (st
, true);
5883 case ST_OMP_DISTRIBUTE
:
5884 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5885 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5886 case ST_OMP_DISTRIBUTE_SIMD
:
5888 case ST_OMP_DO_SIMD
:
5890 case ST_OMP_PARALLEL_DO
:
5891 case ST_OMP_PARALLEL_DO_SIMD
:
5892 case ST_OMP_PARALLEL_LOOP
:
5893 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5894 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5895 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5896 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5897 case ST_OMP_MASKED_TASKLOOP
:
5898 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5899 case ST_OMP_MASTER_TASKLOOP
:
5900 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5902 case ST_OMP_TARGET_PARALLEL_DO
:
5903 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5904 case ST_OMP_TARGET_PARALLEL_LOOP
:
5905 case ST_OMP_TARGET_SIMD
:
5906 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5907 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5908 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5909 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5910 case ST_OMP_TARGET_TEAMS_LOOP
:
5911 case ST_OMP_TASKLOOP
:
5912 case ST_OMP_TASKLOOP_SIMD
:
5913 case ST_OMP_TEAMS_DISTRIBUTE
:
5914 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5915 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5916 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5917 case ST_OMP_TEAMS_LOOP
:
5918 st
= parse_omp_do (st
);
5919 if (st
== ST_IMPLIED_ENDDO
)
5923 case ST_OACC_ATOMIC
:
5924 st
= parse_omp_oacc_atomic (false);
5928 st
= parse_omp_oacc_atomic (true);
5935 if (directive_unroll
!= -1)
5936 gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
5938 if (directive_ivdep
)
5939 gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
5941 if (directive_vector
)
5942 gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
5944 if (directive_novector
)
5945 gfc_error ("%<GCC novector%> "
5946 "directive not at the start of a loop at %C");
5948 st
= next_statement ();
5953 /* Fix the symbols for sibling functions. These are incorrectly added to
5954 the child namespace as the parser didn't know about this procedure. */
5957 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5961 gfc_symbol
*old_sym
;
5963 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5965 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5967 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5968 goto fixup_contained
;
5970 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5971 && sym
->attr
.generic
&& sym
->attr
.function
)
5972 ||(sym
->attr
.flavor
== FL_DERIVED
5973 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5974 goto fixup_contained
;
5976 old_sym
= st
->n
.sym
;
5977 if (old_sym
->ns
== ns
5978 && !old_sym
->attr
.contained
5980 /* By 14.6.1.3, host association should be excluded
5981 for the following. */
5982 && !(old_sym
->attr
.external
5983 || (old_sym
->ts
.type
!= BT_UNKNOWN
5984 && !old_sym
->attr
.implicit_type
)
5985 || old_sym
->attr
.flavor
== FL_PARAMETER
5986 || old_sym
->attr
.use_assoc
5987 || old_sym
->attr
.in_common
5988 || old_sym
->attr
.in_equivalence
5989 || old_sym
->attr
.data
5990 || old_sym
->attr
.dummy
5991 || old_sym
->attr
.result
5992 || old_sym
->attr
.dimension
5993 || old_sym
->attr
.allocatable
5994 || old_sym
->attr
.intrinsic
5995 || old_sym
->attr
.generic
5996 || old_sym
->attr
.flavor
== FL_NAMELIST
5997 || old_sym
->attr
.flavor
== FL_LABEL
5998 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
6000 /* Replace it with the symbol from the parent namespace. */
6004 gfc_release_symbol (old_sym
);
6008 /* Do the same for any contained procedures. */
6009 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
6014 parse_contained (int module
)
6016 gfc_namespace
*ns
, *parent_ns
, *tmp
;
6017 gfc_state_data s1
, s2
;
6022 int contains_statements
= 0;
6025 push_state (&s1
, COMP_CONTAINS
, NULL
);
6026 parent_ns
= gfc_current_ns
;
6030 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
6032 gfc_current_ns
->sibling
= parent_ns
->contained
;
6033 parent_ns
->contained
= gfc_current_ns
;
6036 /* Process the next available statement. We come here if we got an error
6037 and rejected the last statement. */
6038 old_loc
= gfc_current_locus
;
6039 st
= next_statement ();
6048 contains_statements
= 1;
6049 accept_statement (st
);
6052 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
6055 /* For internal procedures, create/update the symbol in the
6056 parent namespace. */
6060 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
6061 gfc_error ("Contained procedure %qs at %C is already "
6062 "ambiguous", gfc_new_block
->name
);
6065 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
6067 &gfc_new_block
->declared_at
))
6069 if (st
== ST_FUNCTION
)
6070 gfc_add_function (&sym
->attr
, sym
->name
,
6071 &gfc_new_block
->declared_at
);
6073 gfc_add_subroutine (&sym
->attr
, sym
->name
,
6074 &gfc_new_block
->declared_at
);
6078 gfc_commit_symbols ();
6081 sym
= gfc_new_block
;
6083 /* Mark this as a contained function, so it isn't replaced
6084 by other module functions. */
6085 sym
->attr
.contained
= 1;
6087 /* Set implicit_pure so that it can be reset if any of the
6088 tests for purity fail. This is used for some optimisation
6089 during translation. */
6090 if (!sym
->attr
.pure
)
6091 sym
->attr
.implicit_pure
= 1;
6093 parse_progunit (ST_NONE
);
6095 /* Fix up any sibling functions that refer to this one. */
6096 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
6097 /* Or refer to any of its alternate entry points. */
6098 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
6099 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
6101 gfc_current_ns
->code
= s2
.head
;
6102 gfc_current_ns
= parent_ns
;
6107 /* These statements are associated with the end of the host unit. */
6108 case ST_END_FUNCTION
:
6110 case ST_END_SUBMODULE
:
6111 case ST_END_PROGRAM
:
6112 case ST_END_SUBROUTINE
:
6113 accept_statement (st
);
6114 gfc_current_ns
->code
= s1
.head
;
6118 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
6119 gfc_ascii_statement (st
));
6120 reject_statement ();
6126 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
6127 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
6128 && st
!= ST_END_PROGRAM
);
6130 /* The first namespace in the list is guaranteed to not have
6131 anything (worthwhile) in it. */
6132 tmp
= gfc_current_ns
;
6133 gfc_current_ns
= parent_ns
;
6134 if (seen_error
&& tmp
->refs
> 1)
6135 gfc_free_namespace (tmp
);
6137 ns
= gfc_current_ns
->contained
;
6138 gfc_current_ns
->contained
= ns
->sibling
;
6139 gfc_free_namespace (ns
);
6142 if (!contains_statements
)
6143 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
6144 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
6148 /* The result variable in a MODULE PROCEDURE needs to be created and
6149 its characteristics copied from the interface since it is neither
6150 declared in the procedure declaration nor in the specification
6154 get_modproc_result (void)
6157 if (gfc_state_stack
->previous
6158 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
6159 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
6161 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
6163 && proc
->attr
.function
6165 && proc
->tlink
->result
6166 && proc
->tlink
->result
!= proc
->tlink
)
6168 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
6169 gfc_set_sym_referenced (proc
->result
);
6170 proc
->result
->attr
.if_source
= IFSRC_DECL
;
6171 gfc_commit_symbol (proc
->result
);
6177 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
6180 parse_progunit (gfc_statement st
)
6185 gfc_adjust_builtins ();
6188 && gfc_new_block
->abr_modproc_decl
6189 && gfc_new_block
->attr
.function
)
6190 get_modproc_result ();
6192 st
= parse_spec (st
);
6199 /* This is not allowed within BLOCK! */
6200 if (gfc_current_state () != COMP_BLOCK
)
6205 accept_statement (st
);
6212 if (gfc_current_state () == COMP_FUNCTION
)
6213 gfc_check_function_type (gfc_current_ns
);
6218 st
= parse_executable (st
);
6226 /* This is not allowed within BLOCK! */
6227 if (gfc_current_state () != COMP_BLOCK
)
6232 accept_statement (st
);
6239 unexpected_statement (st
);
6240 reject_statement ();
6241 st
= next_statement ();
6247 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
6248 if (p
->state
== COMP_CONTAINS
)
6251 if (gfc_find_state (COMP_MODULE
) == true
6252 || gfc_find_state (COMP_SUBMODULE
) == true)
6257 gfc_error ("CONTAINS statement at %C is already in a contained "
6259 reject_statement ();
6260 st
= next_statement ();
6264 parse_contained (0);
6267 gfc_current_ns
->code
= gfc_state_stack
->head
;
6271 /* Come here to complain about a global symbol already in use as
6275 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
6280 where
= &gfc_current_locus
;
6290 case GSYM_SUBROUTINE
:
6291 name
= "SUBROUTINE";
6296 case GSYM_BLOCK_DATA
:
6297 name
= "BLOCK DATA";
6308 if (sym
->binding_label
)
6309 gfc_error ("Global binding name %qs at %L is already being used "
6310 "as a %s at %L", sym
->binding_label
, where
, name
,
6313 gfc_error ("Global name %qs at %L is already being used as "
6314 "a %s at %L", sym
->name
, where
, name
, &sym
->where
);
6318 if (sym
->binding_label
)
6319 gfc_error ("Global binding name %qs at %L is already being used "
6320 "at %L", sym
->binding_label
, where
, &sym
->where
);
6322 gfc_error ("Global name %qs at %L is already being used at %L",
6323 sym
->name
, where
, &sym
->where
);
6328 /* Parse a block data program unit. */
6331 parse_block_data (void)
6334 static locus blank_locus
;
6335 static int blank_block
=0;
6338 gfc_current_ns
->proc_name
= gfc_new_block
;
6339 gfc_current_ns
->is_block_data
= 1;
6341 if (gfc_new_block
== NULL
)
6344 gfc_error ("Blank BLOCK DATA at %C conflicts with "
6345 "prior BLOCK DATA at %L", &blank_locus
);
6349 blank_locus
= gfc_current_locus
;
6354 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6356 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
6357 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6360 s
->type
= GSYM_BLOCK_DATA
;
6361 s
->where
= gfc_new_block
->declared_at
;
6366 st
= parse_spec (ST_NONE
);
6368 while (st
!= ST_END_BLOCK_DATA
)
6370 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
6371 gfc_ascii_statement (st
));
6372 reject_statement ();
6373 st
= next_statement ();
6378 /* Following the association of the ancestor (sub)module symbols, they
6379 must be set host rather than use associated and all must be public.
6380 They are flagged up by 'used_in_submodule' so that they can be set
6381 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
6382 linker chokes on multiple symbol definitions. */
6385 set_syms_host_assoc (gfc_symbol
*sym
)
6388 const char dot
[2] = ".";
6389 /* Symbols take the form module.submodule_ or module.name_. */
6390 char parent1
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6391 char parent2
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6396 if (sym
->attr
.module_procedure
)
6397 sym
->attr
.external
= 0;
6399 sym
->attr
.use_assoc
= 0;
6400 sym
->attr
.host_assoc
= 1;
6401 sym
->attr
.used_in_submodule
=1;
6403 if (sym
->attr
.flavor
== FL_DERIVED
)
6405 /* Derived types with PRIVATE components that are declared in
6406 modules other than the parent module must not be changed to be
6407 PUBLIC. The 'use-assoc' attribute must be reset so that the
6408 test in symbol.c(gfc_find_component) works correctly. This is
6409 not necessary for PRIVATE symbols since they are not read from
6411 memset(parent1
, '\0', sizeof(parent1
));
6412 memset(parent2
, '\0', sizeof(parent2
));
6413 strcpy (parent1
, gfc_new_block
->name
);
6414 strcpy (parent2
, sym
->module
);
6415 if (strcmp (strtok (parent1
, dot
), strtok (parent2
, dot
)) == 0)
6417 for (c
= sym
->components
; c
; c
= c
->next
)
6418 c
->attr
.access
= ACCESS_PUBLIC
;
6422 sym
->attr
.use_assoc
= 1;
6423 sym
->attr
.host_assoc
= 0;
6428 /* Parse a module subprogram. */
6437 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6438 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
6439 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6442 s
->type
= GSYM_MODULE
;
6443 s
->where
= gfc_new_block
->declared_at
;
6447 /* Something is nulling the module_list after this point. This is good
6448 since it allows us to 'USE' the parent modules that the submodule
6449 inherits and to set (most) of the symbols as host associated. */
6450 if (gfc_current_state () == COMP_SUBMODULE
)
6453 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
6456 st
= parse_spec (ST_NONE
);
6466 parse_contained (1);
6470 case ST_END_SUBMODULE
:
6471 accept_statement (st
);
6475 gfc_error ("Unexpected %s statement in MODULE at %C",
6476 gfc_ascii_statement (st
));
6479 reject_statement ();
6480 st
= next_statement ();
6484 /* Make sure not to free the namespace twice on error. */
6486 s
->ns
= gfc_current_ns
;
6490 /* Add a procedure name to the global symbol table. */
6493 add_global_procedure (bool sub
)
6497 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
6498 name is a global identifier. */
6499 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
6501 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6504 || (s
->type
!= GSYM_UNKNOWN
6505 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6507 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6508 /* Silence follow-up errors. */
6509 gfc_new_block
->binding_label
= NULL
;
6513 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6514 s
->sym_name
= gfc_new_block
->name
;
6515 s
->where
= gfc_new_block
->declared_at
;
6517 s
->ns
= gfc_current_ns
;
6521 /* Don't add the symbol multiple times. */
6522 if (gfc_new_block
->binding_label
6523 && (!gfc_notification_std (GFC_STD_F2008
)
6524 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
6526 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
, true);
6529 || (s
->type
!= GSYM_UNKNOWN
6530 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6532 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6533 /* Silence follow-up errors. */
6534 gfc_new_block
->binding_label
= NULL
;
6538 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6539 s
->sym_name
= gfc_new_block
->name
;
6540 s
->binding_label
= gfc_new_block
->binding_label
;
6541 s
->where
= gfc_new_block
->declared_at
;
6543 s
->ns
= gfc_current_ns
;
6549 /* Add a program to the global symbol table. */
6552 add_global_program (void)
6556 if (gfc_new_block
== NULL
)
6558 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6560 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
6561 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6564 s
->type
= GSYM_PROGRAM
;
6565 s
->where
= gfc_new_block
->declared_at
;
6567 s
->ns
= gfc_current_ns
;
6572 /* Resolve all the program units. */
6574 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6576 gfc_derived_types
= NULL
;
6577 gfc_current_ns
= gfc_global_ns_list
;
6578 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6580 if (gfc_current_ns
->proc_name
6581 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6582 continue; /* Already resolved. */
6584 if (gfc_current_ns
->proc_name
)
6585 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6586 gfc_resolve (gfc_current_ns
);
6587 gfc_current_ns
->derived_types
= gfc_derived_types
;
6588 gfc_derived_types
= NULL
;
6594 clean_up_modules (gfc_gsymbol
*&gsym
)
6599 clean_up_modules (gsym
->left
);
6600 clean_up_modules (gsym
->right
);
6602 if (gsym
->type
!= GSYM_MODULE
)
6607 gfc_current_ns
= gsym
->ns
;
6608 gfc_derived_types
= gfc_current_ns
->derived_types
;
6617 /* Translate all the program units. This could be in a different order
6618 to resolution if there are forward references in the file. */
6620 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6624 gfc_current_ns
= gfc_global_ns_list
;
6625 gfc_get_errors (NULL
, &errors
);
6627 /* We first translate all modules to make sure that later parts
6628 of the program can use the decl. Then we translate the nonmodules. */
6630 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6632 if (!gfc_current_ns
->proc_name
6633 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6636 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6637 gfc_derived_types
= gfc_current_ns
->derived_types
;
6638 gfc_generate_module_code (gfc_current_ns
);
6639 gfc_current_ns
->translated
= 1;
6642 gfc_current_ns
= gfc_global_ns_list
;
6643 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6645 if (gfc_current_ns
->proc_name
6646 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6649 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6650 gfc_derived_types
= gfc_current_ns
->derived_types
;
6651 gfc_generate_code (gfc_current_ns
);
6652 gfc_current_ns
->translated
= 1;
6655 /* Clean up all the namespaces after translation. */
6656 gfc_current_ns
= gfc_global_ns_list
;
6657 for (;gfc_current_ns
;)
6661 if (gfc_current_ns
->proc_name
6662 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6664 gfc_current_ns
= gfc_current_ns
->sibling
;
6668 ns
= gfc_current_ns
->sibling
;
6669 gfc_derived_types
= gfc_current_ns
->derived_types
;
6671 gfc_current_ns
= ns
;
6674 clean_up_modules (gfc_gsym_root
);
6678 /* Top level parser. */
6681 gfc_parse_file (void)
6683 int seen_program
, errors_before
, errors
;
6684 gfc_state_data top
, s
;
6687 gfc_namespace
*next
;
6689 gfc_start_source_files ();
6691 top
.state
= COMP_NONE
;
6693 top
.previous
= NULL
;
6694 top
.head
= top
.tail
= NULL
;
6695 top
.do_variable
= NULL
;
6697 gfc_state_stack
= &top
;
6699 gfc_clear_new_st ();
6701 gfc_statement_label
= NULL
;
6703 if (setjmp (eof_buf
))
6704 return false; /* Come here on unexpected EOF */
6706 /* Prepare the global namespace that will contain the
6708 gfc_global_ns_list
= next
= NULL
;
6713 /* Exit early for empty files. */
6717 in_specification_block
= true;
6720 st
= next_statement ();
6729 goto duplicate_main
;
6731 prog_locus
= gfc_current_locus
;
6733 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6734 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
6735 accept_statement (st
);
6736 add_global_program ();
6737 parse_progunit (ST_NONE
);
6741 add_global_procedure (true);
6742 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
6743 accept_statement (st
);
6744 parse_progunit (ST_NONE
);
6748 add_global_procedure (false);
6749 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
6750 accept_statement (st
);
6751 parse_progunit (ST_NONE
);
6755 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
6756 accept_statement (st
);
6757 parse_block_data ();
6761 push_state (&s
, COMP_MODULE
, gfc_new_block
);
6762 accept_statement (st
);
6764 gfc_get_errors (NULL
, &errors_before
);
6769 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
6770 accept_statement (st
);
6772 gfc_get_errors (NULL
, &errors_before
);
6776 /* Anything else starts a nameless main program block. */
6779 goto duplicate_main
;
6781 prog_locus
= gfc_current_locus
;
6783 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6784 main_program_symbol (gfc_current_ns
, "MAIN__");
6785 parse_progunit (st
);
6789 /* Handle the non-program units. */
6790 gfc_current_ns
->code
= s
.head
;
6792 gfc_resolve (gfc_current_ns
);
6794 /* Fix the implicit_pure attribute for those procedures who should
6796 while (gfc_fix_implicit_pure (gfc_current_ns
))
6799 /* Dump the parse tree if requested. */
6800 if (flag_dump_fortran_original
)
6801 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6803 gfc_get_errors (NULL
, &errors
);
6804 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
6806 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
6807 gfc_current_ns
->derived_types
= gfc_derived_types
;
6808 gfc_derived_types
= NULL
;
6814 gfc_generate_code (gfc_current_ns
);
6822 /* The main program and non-contained procedures are put
6823 in the global namespace list, so that they can be processed
6824 later and all their interfaces resolved. */
6825 gfc_current_ns
->code
= s
.head
;
6828 for (; next
->sibling
; next
= next
->sibling
)
6830 next
->sibling
= gfc_current_ns
;
6833 gfc_global_ns_list
= gfc_current_ns
;
6835 next
= gfc_current_ns
;
6841 /* Do the resolution. */
6842 resolve_all_program_units (gfc_global_ns_list
);
6844 /* Go through all top-level namespaces and unset the implicit_pure
6845 attribute for any procedures that call something not pure or
6846 implicit_pure. Because the a procedure marked as not implicit_pure
6847 in one sweep may be called by another routine, we repeat this
6848 process until there are no more changes. */
6853 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6854 gfc_current_ns
= gfc_current_ns
->sibling
)
6856 if (gfc_fix_implicit_pure (gfc_current_ns
))
6862 /* Fixup for external procedures and resolve 'omp requires'. */
6865 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6866 gfc_current_ns
= gfc_current_ns
->sibling
)
6868 omp_requires
|= gfc_current_ns
->omp_requires
;
6869 gfc_check_externals (gfc_current_ns
);
6871 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6872 gfc_current_ns
= gfc_current_ns
->sibling
)
6873 gfc_check_omp_requires (gfc_current_ns
, omp_requires
);
6875 /* Populate omp_requires_mask (needed for resolving OpenMP
6876 metadirectives and declare variant). */
6877 switch (omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
6879 case OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
:
6881 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_SEQ_CST
);
6883 case OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
:
6885 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_ACQ_REL
);
6887 case OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
:
6889 = (enum omp_requires
) (omp_requires_mask
| OMP_MEMORY_ORDER_RELAXED
);
6893 /* Do the parse tree dump. */
6894 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6896 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6897 if (!gfc_current_ns
->proc_name
6898 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6900 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6901 fputs ("------------------------------------------\n\n", stdout
);
6904 /* Dump C prototypes. */
6905 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6908 "#include <stddef.h>\n"
6909 "#ifdef __cplusplus\n"
6910 "#include <complex>\n"
6911 "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
6912 "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
6913 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
6916 "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
6917 "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
6918 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
6922 /* First dump BIND(C) prototypes. */
6923 if (flag_c_prototypes
)
6925 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6926 gfc_current_ns
= gfc_current_ns
->sibling
)
6927 gfc_dump_c_prototypes (gfc_current_ns
, stdout
);
6930 /* Dump external prototypes. */
6931 if (flag_c_prototypes_external
)
6932 gfc_dump_external_c_prototypes (stdout
);
6934 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6935 fprintf (stdout
, "\n#ifdef __cplusplus\n}\n#endif\n");
6937 /* Do the translation. */
6938 translate_all_program_units (gfc_global_ns_list
);
6940 /* Dump the global symbol ist. We only do this here because part
6941 of it is generated after mangling the identifiers in
6944 if (flag_dump_fortran_global
)
6945 gfc_dump_global_symbols (stdout
);
6947 gfc_end_source_files ();
6951 /* If we see a duplicate main program, shut down. If the second
6952 instance is an implied main program, i.e. data decls or executable
6953 statements, we're in for lots of errors. */
6954 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6955 reject_statement ();
6960 /* Return true if this state data represents an OpenACC region. */
6962 is_oacc (gfc_state_data
*sd
)
6964 switch (sd
->construct
->op
)
6966 case EXEC_OACC_PARALLEL_LOOP
:
6967 case EXEC_OACC_PARALLEL
:
6968 case EXEC_OACC_KERNELS_LOOP
:
6969 case EXEC_OACC_KERNELS
:
6970 case EXEC_OACC_SERIAL_LOOP
:
6971 case EXEC_OACC_SERIAL
:
6972 case EXEC_OACC_DATA
:
6973 case EXEC_OACC_HOST_DATA
:
6974 case EXEC_OACC_LOOP
:
6975 case EXEC_OACC_UPDATE
:
6976 case EXEC_OACC_WAIT
:
6977 case EXEC_OACC_CACHE
:
6978 case EXEC_OACC_ENTER_DATA
:
6979 case EXEC_OACC_EXIT_DATA
:
6980 case EXEC_OACC_ATOMIC
:
6981 case EXEC_OACC_ROUTINE
: