2 Copyright (C) 2000-2015 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"
30 /* Current statement label. Zero means no statement label. Because new_st
31 can get wiped during statement matching, we have to keep it separate. */
33 gfc_st_label
*gfc_statement_label
;
35 static locus label_locus
;
36 static jmp_buf eof_buf
;
38 gfc_state_data
*gfc_state_stack
;
39 static bool last_was_use_stmt
= false;
41 /* TODO: Re-order functions to kill these forward decls. */
42 static void check_statement_label (gfc_statement
);
43 static void undo_new_statement (void);
44 static void reject_statement (void);
47 /* A sort of half-matching function. We try to match the word on the
48 input with the passed string. If this succeeds, we call the
49 keyword-dependent matching function that will match the rest of the
50 statement. For single keywords, the matching subroutine is
54 match_word (const char *str
, match (*subr
) (void), locus
*old_locus
)
69 gfc_current_locus
= *old_locus
;
77 /* Like match_word, but if str is matched, set a flag that it
80 match_word_omp_simd (const char *str
, match (*subr
) (void), locus
*old_locus
,
97 gfc_current_locus
= *old_locus
;
105 /* Load symbols from all USE statements encountered in this scoping unit. */
110 gfc_error_buffer old_error
;
112 gfc_push_error (&old_error
);
113 gfc_buffer_error (false);
115 gfc_buffer_error (true);
116 gfc_pop_error (&old_error
);
117 gfc_commit_symbols ();
118 gfc_warning_check ();
119 gfc_current_ns
->old_cl_list
= gfc_current_ns
->cl_list
;
120 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
121 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
122 last_was_use_stmt
= false;
126 /* Figure out what the next statement is, (mostly) regardless of
127 proper ordering. The do...while(0) is there to prevent if/else
130 #define match(keyword, subr, st) \
132 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
135 undo_new_statement (); \
139 /* This is a specialist version of decode_statement that is used
140 for the specification statements in a function, whose
141 characteristics are deferred into the specification statements.
142 eg.: INTEGER (king = mykind) foo ()
143 USE mymodule, ONLY mykind.....
144 The KIND parameter needs a return after USE or IMPORT, whereas
145 derived type declarations can occur anywhere, up the executable
146 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
147 out of the correct kind of specification statements. */
149 decode_specification_statement (void)
155 if (gfc_match_eos () == MATCH_YES
)
158 old_locus
= gfc_current_locus
;
160 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
162 last_was_use_stmt
= true;
167 undo_new_statement ();
168 if (last_was_use_stmt
)
172 match ("import", gfc_match_import
, ST_IMPORT
);
174 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
177 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
178 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
179 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
181 /* General statement matching: Instead of testing every possible
182 statement, we eliminate most possibilities by peeking at the
185 c
= gfc_peek_ascii_char ();
190 match ("abstract% interface", gfc_match_abstract_interface
,
192 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
193 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
197 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
201 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
202 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
206 match ("data", gfc_match_data
, ST_DATA
);
207 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
211 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
212 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
213 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
214 match ("external", gfc_match_external
, ST_ATTR_DECL
);
218 match ("format", gfc_match_format
, ST_FORMAT
);
225 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
226 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
227 match ("interface", gfc_match_interface
, ST_INTERFACE
);
228 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
229 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
236 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
240 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
244 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
245 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
246 if (gfc_match_private (&st
) == MATCH_YES
)
248 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
249 if (gfc_match_public (&st
) == MATCH_YES
)
251 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
258 match ("save", gfc_match_save
, ST_ATTR_DECL
);
262 match ("target", gfc_match_target
, ST_ATTR_DECL
);
263 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
270 match ("value", gfc_match_value
, ST_ATTR_DECL
);
271 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
278 /* This is not a specification statement. See if any of the matchers
279 has stored an error message of some sort. */
283 gfc_buffer_error (false);
284 gfc_current_locus
= old_locus
;
286 return ST_GET_FCN_CHARACTERISTICS
;
289 static bool in_specification_block
;
291 /* This is the primary 'decode_statement'. */
293 decode_statement (void)
301 gfc_enforce_clean_symbol_state ();
303 gfc_clear_error (); /* Clear any pending errors. */
304 gfc_clear_warning (); /* Clear any pending warnings. */
306 gfc_matching_function
= false;
308 if (gfc_match_eos () == MATCH_YES
)
311 if (gfc_current_state () == COMP_FUNCTION
312 && gfc_current_block ()->result
->ts
.kind
== -1)
313 return decode_specification_statement ();
315 old_locus
= gfc_current_locus
;
317 c
= gfc_peek_ascii_char ();
321 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
323 last_was_use_stmt
= true;
327 undo_new_statement ();
330 if (last_was_use_stmt
)
333 /* Try matching a data declaration or function declaration. The
334 input "REALFUNCTIONA(N)" can mean several things in different
335 contexts, so it (and its relatives) get special treatment. */
337 if (gfc_current_state () == COMP_NONE
338 || gfc_current_state () == COMP_INTERFACE
339 || gfc_current_state () == COMP_CONTAINS
)
341 gfc_matching_function
= true;
342 m
= gfc_match_function_decl ();
345 else if (m
== MATCH_ERROR
)
349 gfc_current_locus
= old_locus
;
351 gfc_matching_function
= false;
354 /* Match statements whose error messages are meant to be overwritten
355 by something better. */
357 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
358 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
360 if (in_specification_block
)
362 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
364 return ST_STATEMENT_FUNCTION
;
367 if (!(in_specification_block
&& m
== MATCH_ERROR
))
369 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
372 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
373 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
375 /* Try to match a subroutine statement, which has the same optional
376 prefixes that functions can have. */
378 if (gfc_match_subroutine () == MATCH_YES
)
379 return ST_SUBROUTINE
;
381 gfc_current_locus
= old_locus
;
383 if (gfc_match_submod_proc () == MATCH_YES
)
385 if (gfc_new_block
->attr
.subroutine
)
386 return ST_SUBROUTINE
;
387 else if (gfc_new_block
->attr
.function
)
391 gfc_current_locus
= old_locus
;
393 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
394 statements, which might begin with a block label. The match functions for
395 these statements are unusual in that their keyword is not seen before
396 the matcher is called. */
398 if (gfc_match_if (&st
) == MATCH_YES
)
401 gfc_current_locus
= old_locus
;
403 if (gfc_match_where (&st
) == MATCH_YES
)
406 gfc_current_locus
= old_locus
;
408 if (gfc_match_forall (&st
) == MATCH_YES
)
411 gfc_current_locus
= old_locus
;
413 match (NULL
, gfc_match_do
, ST_DO
);
414 match (NULL
, gfc_match_block
, ST_BLOCK
);
415 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
416 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
417 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
419 gfc_current_ns
= gfc_build_block_ns (gfc_current_ns
);
420 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
422 gfc_current_ns
= gfc_current_ns
->parent
;
423 gfc_free_namespace (ns
);
425 /* General statement matching: Instead of testing every possible
426 statement, we eliminate most possibilities by peeking at the
432 match ("abstract% interface", gfc_match_abstract_interface
,
434 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
435 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
436 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
437 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
441 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
442 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
443 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
447 match ("call", gfc_match_call
, ST_CALL
);
448 match ("close", gfc_match_close
, ST_CLOSE
);
449 match ("continue", gfc_match_continue
, ST_CONTINUE
);
450 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
451 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
452 match ("case", gfc_match_case
, ST_CASE
);
453 match ("common", gfc_match_common
, ST_COMMON
);
454 match ("contains", gfc_match_eos
, ST_CONTAINS
);
455 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
456 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
460 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
461 match ("data", gfc_match_data
, ST_DATA
);
462 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
466 match ("end file", gfc_match_endfile
, ST_END_FILE
);
467 match ("exit", gfc_match_exit
, ST_EXIT
);
468 match ("else", gfc_match_else
, ST_ELSE
);
469 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
470 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
471 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
);
472 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
474 if (gfc_match_end (&st
) == MATCH_YES
)
477 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
478 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
479 match ("external", gfc_match_external
, ST_ATTR_DECL
);
483 match ("final", gfc_match_final_decl
, ST_FINAL
);
484 match ("flush", gfc_match_flush
, ST_FLUSH
);
485 match ("format", gfc_match_format
, ST_FORMAT
);
489 match ("generic", gfc_match_generic
, ST_GENERIC
);
490 match ("go to", gfc_match_goto
, ST_GOTO
);
494 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
495 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
496 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
497 match ("import", gfc_match_import
, ST_IMPORT
);
498 match ("interface", gfc_match_interface
, ST_INTERFACE
);
499 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
500 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
504 match ("lock", gfc_match_lock
, ST_LOCK
);
508 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
509 match ("module", gfc_match_module
, ST_MODULE
);
513 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
514 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
518 match ("open", gfc_match_open
, ST_OPEN
);
519 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
523 match ("print", gfc_match_print
, ST_WRITE
);
524 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
525 match ("pause", gfc_match_pause
, ST_PAUSE
);
526 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
527 if (gfc_match_private (&st
) == MATCH_YES
)
529 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
530 match ("program", gfc_match_program
, ST_PROGRAM
);
531 if (gfc_match_public (&st
) == MATCH_YES
)
533 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
537 match ("read", gfc_match_read
, ST_READ
);
538 match ("return", gfc_match_return
, ST_RETURN
);
539 match ("rewind", gfc_match_rewind
, ST_REWIND
);
543 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
544 match ("stop", gfc_match_stop
, ST_STOP
);
545 match ("save", gfc_match_save
, ST_ATTR_DECL
);
546 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
547 match ("sync all", gfc_match_sync_all
, ST_SYNC_ALL
);
548 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
549 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
553 match ("target", gfc_match_target
, ST_ATTR_DECL
);
554 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
555 match ("type is", gfc_match_type_is
, ST_TYPE_IS
);
559 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
563 match ("value", gfc_match_value
, ST_ATTR_DECL
);
564 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
568 match ("wait", gfc_match_wait
, ST_WAIT
);
569 match ("write", gfc_match_write
, ST_WRITE
);
573 /* All else has failed, so give up. See if any of the matchers has
574 stored an error message of some sort. */
576 if (!gfc_error_check ())
577 gfc_error_now ("Unclassifiable statement at %C");
581 gfc_error_recovery ();
586 /* Like match, but set a flag simd_matched if keyword matched. */
587 #define matchs(keyword, subr, st) \
589 if (match_word_omp_simd (keyword, subr, &old_locus, \
590 &simd_matched) == MATCH_YES) \
593 undo_new_statement (); \
596 /* Like match, but don't match anything if not -fopenmp. */
597 #define matcho(keyword, subr, st) \
601 else if (match_word (keyword, subr, &old_locus) \
605 undo_new_statement (); \
609 decode_oacc_directive (void)
614 gfc_enforce_clean_symbol_state ();
616 gfc_clear_error (); /* Clear any pending errors. */
617 gfc_clear_warning (); /* Clear any pending warnings. */
621 gfc_error_now ("OpenACC directives at %C may not appear in PURE "
623 gfc_error_recovery ();
627 gfc_unset_implicit_pure (NULL
);
629 old_locus
= gfc_current_locus
;
631 /* General OpenACC directive matching: Instead of testing every possible
632 statement, we eliminate most possibilities by peeking at the
635 c
= gfc_peek_ascii_char ();
640 match ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
643 match ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
646 match ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
647 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
650 match ("end atomic", gfc_match_omp_eos
, ST_OACC_END_ATOMIC
);
651 match ("end data", gfc_match_omp_eos
, ST_OACC_END_DATA
);
652 match ("end host_data", gfc_match_omp_eos
, ST_OACC_END_HOST_DATA
);
653 match ("end kernels loop", gfc_match_omp_eos
, ST_OACC_END_KERNELS_LOOP
);
654 match ("end kernels", gfc_match_omp_eos
, ST_OACC_END_KERNELS
);
655 match ("end loop", gfc_match_omp_eos
, ST_OACC_END_LOOP
);
656 match ("end parallel loop", gfc_match_omp_eos
, ST_OACC_END_PARALLEL_LOOP
);
657 match ("end parallel", gfc_match_omp_eos
, ST_OACC_END_PARALLEL
);
658 match ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
659 match ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
662 match ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
665 match ("parallel loop", gfc_match_oacc_parallel_loop
, ST_OACC_PARALLEL_LOOP
);
666 match ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
669 match ("kernels loop", gfc_match_oacc_kernels_loop
, ST_OACC_KERNELS_LOOP
);
670 match ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
673 match ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
676 match ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
679 match ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
682 match ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
686 /* Directive not found or stored an error message.
687 Check and give up. */
689 if (gfc_error_check () == 0)
690 gfc_error_now ("Unclassifiable OpenACC directive at %C");
694 gfc_error_recovery ();
700 decode_omp_directive (void)
704 bool simd_matched
= false;
706 gfc_enforce_clean_symbol_state ();
708 gfc_clear_error (); /* Clear any pending errors. */
709 gfc_clear_warning (); /* Clear any pending warnings. */
713 gfc_error_now ("OpenMP directives at %C may not appear in PURE "
714 "or ELEMENTAL procedures");
715 gfc_error_recovery ();
719 gfc_unset_implicit_pure (NULL
);
721 old_locus
= gfc_current_locus
;
723 /* General OpenMP directive matching: Instead of testing every possible
724 statement, we eliminate most possibilities by peeking at the
727 c
= gfc_peek_ascii_char ();
729 /* match is for directives that should be recognized only if
730 -fopenmp, matchs for directives that should be recognized
731 if either -fopenmp or -fopenmp-simd. */
735 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
738 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
741 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
742 ST_OMP_CANCELLATION_POINT
);
743 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
744 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
747 matchs ("declare reduction", gfc_match_omp_declare_reduction
,
748 ST_OMP_DECLARE_REDUCTION
);
749 matchs ("declare simd", gfc_match_omp_declare_simd
,
750 ST_OMP_DECLARE_SIMD
);
751 matcho ("declare target", gfc_match_omp_declare_target
,
752 ST_OMP_DECLARE_TARGET
);
753 matchs ("distribute parallel do simd",
754 gfc_match_omp_distribute_parallel_do_simd
,
755 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
756 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
757 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
758 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
759 ST_OMP_DISTRIBUTE_SIMD
);
760 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
761 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
762 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
765 matcho ("end atomic", gfc_match_omp_eos
, ST_OMP_END_ATOMIC
);
766 matcho ("end critical", gfc_match_omp_critical
, ST_OMP_END_CRITICAL
);
767 matchs ("end distribute parallel do simd", gfc_match_omp_eos
,
768 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
769 matcho ("end distribute parallel do", gfc_match_omp_eos
,
770 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
771 matchs ("end distribute simd", gfc_match_omp_eos
,
772 ST_OMP_END_DISTRIBUTE_SIMD
);
773 matcho ("end distribute", gfc_match_omp_eos
, ST_OMP_END_DISTRIBUTE
);
774 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
775 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
776 matchs ("end simd", gfc_match_omp_eos
, ST_OMP_END_SIMD
);
777 matcho ("end master", gfc_match_omp_eos
, ST_OMP_END_MASTER
);
778 matcho ("end ordered", gfc_match_omp_eos
, ST_OMP_END_ORDERED
);
779 matchs ("end parallel do simd", gfc_match_omp_eos
,
780 ST_OMP_END_PARALLEL_DO_SIMD
);
781 matcho ("end parallel do", gfc_match_omp_eos
, ST_OMP_END_PARALLEL_DO
);
782 matcho ("end parallel sections", gfc_match_omp_eos
,
783 ST_OMP_END_PARALLEL_SECTIONS
);
784 matcho ("end parallel workshare", gfc_match_omp_eos
,
785 ST_OMP_END_PARALLEL_WORKSHARE
);
786 matcho ("end parallel", gfc_match_omp_eos
, ST_OMP_END_PARALLEL
);
787 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
788 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
789 matcho ("end target data", gfc_match_omp_eos
, ST_OMP_END_TARGET_DATA
);
790 matchs ("end target teams distribute parallel do simd",
792 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
793 matcho ("end target teams distribute parallel do", gfc_match_omp_eos
,
794 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
795 matchs ("end target teams distribute simd", gfc_match_omp_eos
,
796 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
797 matcho ("end target teams distribute", gfc_match_omp_eos
,
798 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
799 matcho ("end target teams", gfc_match_omp_eos
, ST_OMP_END_TARGET_TEAMS
);
800 matcho ("end target", gfc_match_omp_eos
, ST_OMP_END_TARGET
);
801 matcho ("end taskgroup", gfc_match_omp_eos
, ST_OMP_END_TASKGROUP
);
802 matcho ("end task", gfc_match_omp_eos
, ST_OMP_END_TASK
);
803 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos
,
804 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
805 matcho ("end teams distribute parallel do", gfc_match_omp_eos
,
806 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
807 matchs ("end teams distribute simd", gfc_match_omp_eos
,
808 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
809 matcho ("end teams distribute", gfc_match_omp_eos
,
810 ST_OMP_END_TEAMS_DISTRIBUTE
);
811 matcho ("end teams", gfc_match_omp_eos
, ST_OMP_END_TEAMS
);
812 matcho ("end workshare", gfc_match_omp_end_nowait
,
813 ST_OMP_END_WORKSHARE
);
816 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
819 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
822 matcho ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
825 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
826 ST_OMP_PARALLEL_DO_SIMD
);
827 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
828 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
829 ST_OMP_PARALLEL_SECTIONS
);
830 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
831 ST_OMP_PARALLEL_WORKSHARE
);
832 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
835 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
836 matcho ("section", gfc_match_omp_eos
, ST_OMP_SECTION
);
837 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
838 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
841 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
842 matchs ("target teams distribute parallel do simd",
843 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
844 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
845 matcho ("target teams distribute parallel do",
846 gfc_match_omp_target_teams_distribute_parallel_do
,
847 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
848 matchs ("target teams distribute simd",
849 gfc_match_omp_target_teams_distribute_simd
,
850 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
851 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
852 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
853 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
854 matcho ("target update", gfc_match_omp_target_update
,
855 ST_OMP_TARGET_UPDATE
);
856 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
857 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
858 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
859 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
860 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
861 matchs ("teams distribute parallel do simd",
862 gfc_match_omp_teams_distribute_parallel_do_simd
,
863 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
864 matcho ("teams distribute parallel do",
865 gfc_match_omp_teams_distribute_parallel_do
,
866 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
867 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
868 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
869 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
870 ST_OMP_TEAMS_DISTRIBUTE
);
871 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
872 matcho ("threadprivate", gfc_match_omp_threadprivate
,
873 ST_OMP_THREADPRIVATE
);
876 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
880 /* All else has failed, so give up. See if any of the matchers has
881 stored an error message of some sort. Don't error out if
882 not -fopenmp and simd_matched is false, i.e. if a directive other
883 than one marked with match has been seen. */
885 if (flag_openmp
|| simd_matched
)
887 if (!gfc_error_check ())
888 gfc_error_now ("Unclassifiable OpenMP directive at %C");
893 gfc_error_recovery ();
899 decode_gcc_attribute (void)
903 gfc_enforce_clean_symbol_state ();
905 gfc_clear_error (); /* Clear any pending errors. */
906 gfc_clear_warning (); /* Clear any pending warnings. */
907 old_locus
= gfc_current_locus
;
909 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
911 /* All else has failed, so give up. See if any of the matchers has
912 stored an error message of some sort. */
914 if (!gfc_error_check ())
915 gfc_error_now ("Unclassifiable GCC directive at %C");
919 gfc_error_recovery ();
926 /* Assert next length characters to be equal to token in free form. */
929 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
934 c
= gfc_next_ascii_char ();
935 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
936 gcc_assert (c
== token
[i
]);
938 gcc_assert (gfc_is_whitespace(c
));
939 gfc_gobble_whitespace ();
940 if (last_was_use_stmt
)
944 /* Get the next statement in free form source. */
953 at_bol
= gfc_at_bol ();
954 gfc_gobble_whitespace ();
956 c
= gfc_peek_ascii_char ();
962 /* Found a statement label? */
963 m
= gfc_match_st_label (&gfc_statement_label
);
965 d
= gfc_peek_ascii_char ();
966 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
968 gfc_match_small_literal_int (&i
, &cnt
);
971 gfc_error_now ("Too many digits in statement label at %C");
974 gfc_error_now ("Zero is not a valid statement label at %C");
977 c
= gfc_next_ascii_char ();
980 if (!gfc_is_whitespace (c
))
981 gfc_error_now ("Non-numeric character in statement label at %C");
987 label_locus
= gfc_current_locus
;
989 gfc_gobble_whitespace ();
991 if (at_bol
&& gfc_peek_ascii_char () == ';')
993 gfc_error_now ("Semicolon at %C needs to be preceded by "
995 gfc_next_ascii_char (); /* Eat up the semicolon. */
999 if (gfc_match_eos () == MATCH_YES
)
1001 gfc_warning_now (0, "Ignoring statement label in empty statement "
1002 "at %L", &label_locus
);
1003 gfc_free_st_label (gfc_statement_label
);
1004 gfc_statement_label
= NULL
;
1011 /* Comments have already been skipped by the time we get here,
1012 except for GCC attributes and OpenMP/OpenACC directives. */
1014 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1015 c
= gfc_peek_ascii_char ();
1021 c
= gfc_next_ascii_char ();
1022 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1023 gcc_assert (c
== "gcc$"[i
]);
1025 gfc_gobble_whitespace ();
1026 return decode_gcc_attribute ();
1031 /* Since both OpenMP and OpenACC directives starts with
1032 !$ character sequence, we must check all flags combinations */
1033 if ((flag_openmp
|| flag_openmp_simd
)
1036 verify_token_free ("$omp", 4, last_was_use_stmt
);
1037 return decode_omp_directive ();
1039 else if ((flag_openmp
|| flag_openmp_simd
)
1042 gfc_next_ascii_char (); /* Eat up dollar character */
1043 c
= gfc_peek_ascii_char ();
1047 verify_token_free ("omp", 3, last_was_use_stmt
);
1048 return decode_omp_directive ();
1052 verify_token_free ("acc", 3, last_was_use_stmt
);
1053 return decode_oacc_directive ();
1056 else if (flag_openacc
)
1058 verify_token_free ("$acc", 4, last_was_use_stmt
);
1059 return decode_oacc_directive ();
1065 if (at_bol
&& c
== ';')
1067 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1068 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1070 gfc_next_ascii_char (); /* Eat up the semicolon. */
1074 return decode_statement ();
1077 /* Assert next length characters to be equal to token in fixed form. */
1080 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1083 char c
= gfc_next_char_literal (NONSTRING
);
1085 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1086 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1088 if (c
!= ' ' && c
!= '0')
1090 gfc_buffer_error (false);
1091 gfc_error ("Bad continuation line at %C");
1094 if (last_was_use_stmt
)
1100 /* Get the next statement in fixed-form source. */
1102 static gfc_statement
1105 int label
, digit_flag
, i
;
1110 return decode_statement ();
1112 /* Skip past the current label field, parsing a statement label if
1113 one is there. This is a weird number parser, since the number is
1114 contained within five columns and can have any kind of embedded
1115 spaces. We also check for characters that make the rest of the
1121 for (i
= 0; i
< 5; i
++)
1123 c
= gfc_next_char_literal (NONSTRING
);
1140 label
= label
* 10 + ((unsigned char) c
- '0');
1141 label_locus
= gfc_current_locus
;
1145 /* Comments have already been skipped by the time we get
1146 here, except for GCC attributes and OpenMP directives. */
1149 c
= gfc_next_char_literal (NONSTRING
);
1151 if (TOLOWER (c
) == 'g')
1153 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1154 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1156 return decode_gcc_attribute ();
1160 if ((flag_openmp
|| flag_openmp_simd
)
1163 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1165 return decode_omp_directive ();
1167 else if ((flag_openmp
|| flag_openmp_simd
)
1170 c
= gfc_next_char_literal(NONSTRING
);
1171 if (c
== 'o' || c
== 'O')
1173 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1175 return decode_omp_directive ();
1177 else if (c
== 'a' || c
== 'A')
1179 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1181 return decode_oacc_directive ();
1184 else if (flag_openacc
)
1186 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1188 return decode_oacc_directive ();
1193 /* Comments have already been skipped by the time we get
1194 here so don't bother checking for them. */
1197 gfc_buffer_error (false);
1198 gfc_error ("Non-numeric character in statement label at %C");
1206 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1209 /* We've found a valid statement label. */
1210 gfc_statement_label
= gfc_get_st_label (label
);
1214 /* Since this line starts a statement, it cannot be a continuation
1215 of a previous statement. If we see something here besides a
1216 space or zero, it must be a bad continuation line. */
1218 c
= gfc_next_char_literal (NONSTRING
);
1222 if (c
!= ' ' && c
!= '0')
1224 gfc_buffer_error (false);
1225 gfc_error ("Bad continuation line at %C");
1229 /* Now that we've taken care of the statement label columns, we have
1230 to make sure that the first nonblank character is not a '!'. If
1231 it is, the rest of the line is a comment. */
1235 loc
= gfc_current_locus
;
1236 c
= gfc_next_char_literal (NONSTRING
);
1238 while (gfc_is_whitespace (c
));
1242 gfc_current_locus
= loc
;
1247 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1248 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1249 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1254 if (gfc_match_eos () == MATCH_YES
)
1257 /* At this point, we've got a nonblank statement to parse. */
1258 return decode_statement ();
1262 gfc_warning_now (0, "Ignoring statement label in empty statement at %L",
1265 gfc_current_locus
.lb
->truncated
= 0;
1266 gfc_advance_line ();
1271 /* Return the next non-ST_NONE statement to the caller. We also worry
1272 about including files and the ends of include files at this stage. */
1274 static gfc_statement
1275 next_statement (void)
1280 gfc_enforce_clean_symbol_state ();
1282 gfc_new_block
= NULL
;
1284 gfc_current_ns
->old_cl_list
= gfc_current_ns
->cl_list
;
1285 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1286 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1289 gfc_statement_label
= NULL
;
1290 gfc_buffer_error (true);
1293 gfc_advance_line ();
1295 gfc_skip_comments ();
1303 if (gfc_define_undef_line ())
1306 old_locus
= gfc_current_locus
;
1308 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1314 gfc_buffer_error (false);
1316 if (st
== ST_GET_FCN_CHARACTERISTICS
&& gfc_statement_label
!= NULL
)
1318 gfc_free_st_label (gfc_statement_label
);
1319 gfc_statement_label
= NULL
;
1320 gfc_current_locus
= old_locus
;
1324 check_statement_label (st
);
1330 /****************************** Parser ***********************************/
1332 /* The parser subroutines are of type 'try' that fail if the file ends
1335 /* Macros that expand to case-labels for various classes of
1336 statements. Start with executable statements that directly do
1339 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1340 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1341 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1342 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1343 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1344 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1345 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1346 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1347 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1348 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: \
1349 case ST_OMP_TARGET_UPDATE: case ST_ERROR_STOP: case ST_SYNC_ALL: \
1350 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1351 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1352 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1354 /* Statements that mark other executable statements. */
1356 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1357 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1358 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1359 case ST_OMP_PARALLEL: \
1360 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1361 case ST_OMP_CRITICAL: case ST_OMP_MASTER: case ST_OMP_SINGLE: \
1362 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1363 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1364 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1365 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1366 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1367 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1368 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1369 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1370 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1371 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1372 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1373 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1374 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1375 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1376 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: \
1378 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1379 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1380 case ST_OACC_KERNELS_LOOP: case ST_OACC_ATOMIC
1382 /* Declaration statements */
1384 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1385 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1386 case ST_TYPE: case ST_INTERFACE: case ST_OMP_THREADPRIVATE: \
1387 case ST_PROCEDURE: case ST_OMP_DECLARE_SIMD: case ST_OMP_DECLARE_REDUCTION: \
1388 case ST_OMP_DECLARE_TARGET: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1390 /* Block end statements. Errors associated with interchanging these
1391 are detected in gfc_match_end(). */
1393 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1394 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1395 case ST_END_BLOCK: case ST_END_ASSOCIATE
1398 /* Push a new state onto the stack. */
1401 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1403 p
->state
= new_state
;
1404 p
->previous
= gfc_state_stack
;
1406 p
->head
= p
->tail
= NULL
;
1407 p
->do_variable
= NULL
;
1408 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1409 p
->ext
.oacc_declare_clauses
= NULL
;
1411 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1412 construct statement was accepted right before pushing the state. Thus,
1413 the construct's gfc_code is available as tail of the parent state. */
1414 gcc_assert (gfc_state_stack
);
1415 p
->construct
= gfc_state_stack
->tail
;
1417 gfc_state_stack
= p
;
1421 /* Pop the current state. */
1425 gfc_state_stack
= gfc_state_stack
->previous
;
1429 /* Try to find the given state in the state stack. */
1432 gfc_find_state (gfc_compile_state state
)
1436 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1437 if (p
->state
== state
)
1440 return (p
== NULL
) ? false : true;
1444 /* Starts a new level in the statement list. */
1447 new_level (gfc_code
*q
)
1451 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1453 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1459 /* Add the current new_st code structure and adds it to the current
1460 program unit. As a side-effect, it zeroes the new_st. */
1463 add_statement (void)
1467 p
= XCNEW (gfc_code
);
1470 p
->loc
= gfc_current_locus
;
1472 if (gfc_state_stack
->head
== NULL
)
1473 gfc_state_stack
->head
= p
;
1475 gfc_state_stack
->tail
->next
= p
;
1477 while (p
->next
!= NULL
)
1480 gfc_state_stack
->tail
= p
;
1482 gfc_clear_new_st ();
1488 /* Frees everything associated with the current statement. */
1491 undo_new_statement (void)
1493 gfc_free_statements (new_st
.block
);
1494 gfc_free_statements (new_st
.next
);
1495 gfc_free_statement (&new_st
);
1496 gfc_clear_new_st ();
1500 /* If the current statement has a statement label, make sure that it
1501 is allowed to, or should have one. */
1504 check_statement_label (gfc_statement st
)
1508 if (gfc_statement_label
== NULL
)
1510 if (st
== ST_FORMAT
)
1511 gfc_error ("FORMAT statement at %L does not have a statement label",
1518 case ST_END_PROGRAM
:
1519 case ST_END_FUNCTION
:
1520 case ST_END_SUBROUTINE
:
1524 case ST_END_CRITICAL
:
1526 case ST_END_ASSOCIATE
:
1529 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1530 type
= ST_LABEL_DO_TARGET
;
1532 type
= ST_LABEL_TARGET
;
1536 type
= ST_LABEL_FORMAT
;
1539 /* Statement labels are not restricted from appearing on a
1540 particular line. However, there are plenty of situations
1541 where the resulting label can't be referenced. */
1544 type
= ST_LABEL_BAD_TARGET
;
1548 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1550 new_st
.here
= gfc_statement_label
;
1554 /* Figures out what the enclosing program unit is. This will be a
1555 function, subroutine, program, block data or module. */
1558 gfc_enclosing_unit (gfc_compile_state
* result
)
1562 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1563 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1564 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1565 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1574 *result
= COMP_PROGRAM
;
1579 /* Translate a statement enum to a string. */
1582 gfc_ascii_statement (gfc_statement st
)
1588 case ST_ARITHMETIC_IF
:
1589 p
= _("arithmetic IF");
1598 p
= _("attribute declaration");
1634 p
= _("data declaration");
1642 case ST_DERIVED_DECL
:
1643 p
= _("derived type declaration");
1657 case ST_END_ASSOCIATE
:
1658 p
= "END ASSOCIATE";
1663 case ST_END_BLOCK_DATA
:
1664 p
= "END BLOCK DATA";
1666 case ST_END_CRITICAL
:
1678 case ST_END_FUNCTION
:
1684 case ST_END_INTERFACE
:
1685 p
= "END INTERFACE";
1690 case ST_END_SUBMODULE
:
1691 p
= "END SUBMODULE";
1693 case ST_END_PROGRAM
:
1699 case ST_END_SUBROUTINE
:
1700 p
= "END SUBROUTINE";
1711 case ST_EQUIVALENCE
:
1723 case ST_FORALL_BLOCK
: /* Fall through */
1745 case ST_IMPLICIT_NONE
:
1746 p
= "IMPLICIT NONE";
1748 case ST_IMPLIED_ENDDO
:
1749 p
= _("implied END DO");
1781 case ST_MODULE_PROC
:
1782 p
= "MODULE PROCEDURE";
1814 case ST_SYNC_IMAGES
:
1817 case ST_SYNC_MEMORY
:
1832 case ST_WHERE_BLOCK
: /* Fall through */
1843 p
= _("assignment");
1845 case ST_POINTER_ASSIGNMENT
:
1846 p
= _("pointer assignment");
1848 case ST_SELECT_CASE
:
1851 case ST_SELECT_TYPE
:
1866 case ST_STATEMENT_FUNCTION
:
1867 p
= "STATEMENT FUNCTION";
1869 case ST_LABEL_ASSIGNMENT
:
1870 p
= "LABEL ASSIGNMENT";
1873 p
= "ENUM DEFINITION";
1876 p
= "ENUMERATOR DEFINITION";
1881 case ST_OACC_PARALLEL_LOOP
:
1882 p
= "!$ACC PARALLEL LOOP";
1884 case ST_OACC_END_PARALLEL_LOOP
:
1885 p
= "!$ACC END PARALLEL LOOP";
1887 case ST_OACC_PARALLEL
:
1888 p
= "!$ACC PARALLEL";
1890 case ST_OACC_END_PARALLEL
:
1891 p
= "!$ACC END PARALLEL";
1893 case ST_OACC_KERNELS
:
1894 p
= "!$ACC KERNELS";
1896 case ST_OACC_END_KERNELS
:
1897 p
= "!$ACC END KERNELS";
1899 case ST_OACC_KERNELS_LOOP
:
1900 p
= "!$ACC KERNELS LOOP";
1902 case ST_OACC_END_KERNELS_LOOP
:
1903 p
= "!$ACC END KERNELS LOOP";
1908 case ST_OACC_END_DATA
:
1909 p
= "!$ACC END DATA";
1911 case ST_OACC_HOST_DATA
:
1912 p
= "!$ACC HOST_DATA";
1914 case ST_OACC_END_HOST_DATA
:
1915 p
= "!$ACC END HOST_DATA";
1920 case ST_OACC_END_LOOP
:
1921 p
= "!$ACC END LOOP";
1923 case ST_OACC_DECLARE
:
1924 p
= "!$ACC DECLARE";
1926 case ST_OACC_UPDATE
:
1935 case ST_OACC_ENTER_DATA
:
1936 p
= "!$ACC ENTER DATA";
1938 case ST_OACC_EXIT_DATA
:
1939 p
= "!$ACC EXIT DATA";
1941 case ST_OACC_ROUTINE
:
1942 p
= "!$ACC ROUTINE";
1944 case ST_OACC_ATOMIC
:
1947 case ST_OACC_END_ATOMIC
:
1948 p
= "!ACC END ATOMIC";
1953 case ST_OMP_BARRIER
:
1954 p
= "!$OMP BARRIER";
1959 case ST_OMP_CANCELLATION_POINT
:
1960 p
= "!$OMP CANCELLATION POINT";
1962 case ST_OMP_CRITICAL
:
1963 p
= "!$OMP CRITICAL";
1965 case ST_OMP_DECLARE_REDUCTION
:
1966 p
= "!$OMP DECLARE REDUCTION";
1968 case ST_OMP_DECLARE_SIMD
:
1969 p
= "!$OMP DECLARE SIMD";
1971 case ST_OMP_DECLARE_TARGET
:
1972 p
= "!$OMP DECLARE TARGET";
1974 case ST_OMP_DISTRIBUTE
:
1975 p
= "!$OMP DISTRIBUTE";
1977 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
1978 p
= "!$OMP DISTRIBUTE PARALLEL DO";
1980 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
1981 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
1983 case ST_OMP_DISTRIBUTE_SIMD
:
1984 p
= "!$OMP DISTRIBUTE SIMD";
1989 case ST_OMP_DO_SIMD
:
1990 p
= "!$OMP DO SIMD";
1992 case ST_OMP_END_ATOMIC
:
1993 p
= "!$OMP END ATOMIC";
1995 case ST_OMP_END_CRITICAL
:
1996 p
= "!$OMP END CRITICAL";
1998 case ST_OMP_END_DISTRIBUTE
:
1999 p
= "!$OMP END DISTRIBUTE";
2001 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2002 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2004 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2005 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2007 case ST_OMP_END_DISTRIBUTE_SIMD
:
2008 p
= "!$OMP END DISTRIBUTE SIMD";
2013 case ST_OMP_END_DO_SIMD
:
2014 p
= "!$OMP END DO SIMD";
2016 case ST_OMP_END_SIMD
:
2017 p
= "!$OMP END SIMD";
2019 case ST_OMP_END_MASTER
:
2020 p
= "!$OMP END MASTER";
2022 case ST_OMP_END_ORDERED
:
2023 p
= "!$OMP END ORDERED";
2025 case ST_OMP_END_PARALLEL
:
2026 p
= "!$OMP END PARALLEL";
2028 case ST_OMP_END_PARALLEL_DO
:
2029 p
= "!$OMP END PARALLEL DO";
2031 case ST_OMP_END_PARALLEL_DO_SIMD
:
2032 p
= "!$OMP END PARALLEL DO SIMD";
2034 case ST_OMP_END_PARALLEL_SECTIONS
:
2035 p
= "!$OMP END PARALLEL SECTIONS";
2037 case ST_OMP_END_PARALLEL_WORKSHARE
:
2038 p
= "!$OMP END PARALLEL WORKSHARE";
2040 case ST_OMP_END_SECTIONS
:
2041 p
= "!$OMP END SECTIONS";
2043 case ST_OMP_END_SINGLE
:
2044 p
= "!$OMP END SINGLE";
2046 case ST_OMP_END_TASK
:
2047 p
= "!$OMP END TASK";
2049 case ST_OMP_END_TARGET
:
2050 p
= "!$OMP END TARGET";
2052 case ST_OMP_END_TARGET_DATA
:
2053 p
= "!$OMP END TARGET DATA";
2055 case ST_OMP_END_TARGET_TEAMS
:
2056 p
= "!$OMP END TARGET TEAMS";
2058 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2059 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2061 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2062 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2064 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2065 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2067 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2068 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2070 case ST_OMP_END_TASKGROUP
:
2071 p
= "!$OMP END TASKGROUP";
2073 case ST_OMP_END_TEAMS
:
2074 p
= "!$OMP END TEAMS";
2076 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2077 p
= "!$OMP END TEAMS DISTRIBUTE";
2079 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2080 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2082 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2083 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2085 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2086 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2088 case ST_OMP_END_WORKSHARE
:
2089 p
= "!$OMP END WORKSHARE";
2097 case ST_OMP_ORDERED
:
2098 p
= "!$OMP ORDERED";
2100 case ST_OMP_PARALLEL
:
2101 p
= "!$OMP PARALLEL";
2103 case ST_OMP_PARALLEL_DO
:
2104 p
= "!$OMP PARALLEL DO";
2106 case ST_OMP_PARALLEL_DO_SIMD
:
2107 p
= "!$OMP PARALLEL DO SIMD";
2109 case ST_OMP_PARALLEL_SECTIONS
:
2110 p
= "!$OMP PARALLEL SECTIONS";
2112 case ST_OMP_PARALLEL_WORKSHARE
:
2113 p
= "!$OMP PARALLEL WORKSHARE";
2115 case ST_OMP_SECTIONS
:
2116 p
= "!$OMP SECTIONS";
2118 case ST_OMP_SECTION
:
2119 p
= "!$OMP SECTION";
2130 case ST_OMP_TARGET_DATA
:
2131 p
= "!$OMP TARGET DATA";
2133 case ST_OMP_TARGET_TEAMS
:
2134 p
= "!$OMP TARGET TEAMS";
2136 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2137 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2139 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2140 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2142 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2143 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2145 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2146 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2148 case ST_OMP_TARGET_UPDATE
:
2149 p
= "!$OMP TARGET UPDATE";
2154 case ST_OMP_TASKGROUP
:
2155 p
= "!$OMP TASKGROUP";
2157 case ST_OMP_TASKWAIT
:
2158 p
= "!$OMP TASKWAIT";
2160 case ST_OMP_TASKYIELD
:
2161 p
= "!$OMP TASKYIELD";
2166 case ST_OMP_TEAMS_DISTRIBUTE
:
2167 p
= "!$OMP TEAMS DISTRIBUTE";
2169 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2170 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2172 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2173 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2175 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2176 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2178 case ST_OMP_THREADPRIVATE
:
2179 p
= "!$OMP THREADPRIVATE";
2181 case ST_OMP_WORKSHARE
:
2182 p
= "!$OMP WORKSHARE";
2185 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2192 /* Create a symbol for the main program and assign it to ns->proc_name. */
2195 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2197 gfc_symbol
*main_program
;
2198 symbol_attribute attr
;
2200 gfc_get_symbol (name
, ns
, &main_program
);
2201 gfc_clear_attr (&attr
);
2202 attr
.flavor
= FL_PROGRAM
;
2203 attr
.proc
= PROC_UNKNOWN
;
2204 attr
.subroutine
= 1;
2205 attr
.access
= ACCESS_PUBLIC
;
2206 attr
.is_main_program
= 1;
2207 main_program
->attr
= attr
;
2208 main_program
->declared_at
= gfc_current_locus
;
2209 ns
->proc_name
= main_program
;
2210 gfc_commit_symbols ();
2214 /* Do whatever is necessary to accept the last statement. */
2217 accept_statement (gfc_statement st
)
2221 case ST_IMPLICIT_NONE
:
2229 gfc_current_ns
->proc_name
= gfc_new_block
;
2232 /* If the statement is the end of a block, lay down a special code
2233 that allows a branch to the end of the block from within the
2234 construct. IF and SELECT are treated differently from DO
2235 (where EXEC_NOP is added inside the loop) for two
2237 1. END DO has a meaning in the sense that after a GOTO to
2238 it, the loop counter must be increased.
2239 2. IF blocks and SELECT blocks can consist of multiple
2240 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2241 Putting the label before the END IF would make the jump
2242 from, say, the ELSE IF block to the END IF illegal. */
2246 case ST_END_CRITICAL
:
2247 if (gfc_statement_label
!= NULL
)
2249 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2254 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2255 one parallel block. Thus, we add the special code to the nested block
2256 itself, instead of the parent one. */
2258 case ST_END_ASSOCIATE
:
2259 if (gfc_statement_label
!= NULL
)
2261 new_st
.op
= EXEC_END_BLOCK
;
2266 /* The end-of-program unit statements do not get the special
2267 marker and require a statement of some sort if they are a
2270 case ST_END_PROGRAM
:
2271 case ST_END_FUNCTION
:
2272 case ST_END_SUBROUTINE
:
2273 if (gfc_statement_label
!= NULL
)
2275 new_st
.op
= EXEC_RETURN
;
2280 new_st
.op
= EXEC_END_PROCEDURE
;
2296 gfc_commit_symbols ();
2297 gfc_warning_check ();
2298 gfc_clear_new_st ();
2302 /* Undo anything tentative that has been built for the current
2306 reject_statement (void)
2308 /* Revert to the previous charlen chain. */
2309 gfc_free_charlen (gfc_current_ns
->cl_list
, gfc_current_ns
->old_cl_list
);
2310 gfc_current_ns
->cl_list
= gfc_current_ns
->old_cl_list
;
2312 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2313 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2315 gfc_reject_data (gfc_current_ns
);
2317 gfc_new_block
= NULL
;
2318 gfc_undo_symbols ();
2319 gfc_clear_warning ();
2320 undo_new_statement ();
2324 /* Generic complaint about an out of order statement. We also do
2325 whatever is necessary to clean up. */
2328 unexpected_statement (gfc_statement st
)
2330 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2332 reject_statement ();
2336 /* Given the next statement seen by the matcher, make sure that it is
2337 in proper order with the last. This subroutine is initialized by
2338 calling it with an argument of ST_NONE. If there is a problem, we
2339 issue an error and return false. Otherwise we return true.
2341 Individual parsers need to verify that the statements seen are
2342 valid before calling here, i.e., ENTRY statements are not allowed in
2343 INTERFACE blocks. The following diagram is taken from the standard:
2345 +---------------------------------------+
2346 | program subroutine function module |
2347 +---------------------------------------+
2349 +---------------------------------------+
2351 +---------------------------------------+
2353 | +-----------+------------------+
2354 | | parameter | implicit |
2355 | +-----------+------------------+
2356 | format | | derived type |
2357 | entry | parameter | interface |
2358 | | data | specification |
2359 | | | statement func |
2360 | +-----------+------------------+
2361 | | data | executable |
2362 +--------+-----------+------------------+
2364 +---------------------------------------+
2365 | internal module/subprogram |
2366 +---------------------------------------+
2368 +---------------------------------------+
2377 ORDER_IMPLICIT_NONE
,
2385 enum state_order state
;
2386 gfc_statement last_statement
;
2392 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2398 p
->state
= ORDER_START
;
2402 if (p
->state
> ORDER_USE
)
2404 p
->state
= ORDER_USE
;
2408 if (p
->state
> ORDER_IMPORT
)
2410 p
->state
= ORDER_IMPORT
;
2413 case ST_IMPLICIT_NONE
:
2414 if (p
->state
> ORDER_IMPLICIT
)
2417 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2418 statement disqualifies a USE but not an IMPLICIT NONE.
2419 Duplicate IMPLICIT NONEs are caught when the implicit types
2422 p
->state
= ORDER_IMPLICIT_NONE
;
2426 if (p
->state
> ORDER_IMPLICIT
)
2428 p
->state
= ORDER_IMPLICIT
;
2433 if (p
->state
< ORDER_IMPLICIT_NONE
)
2434 p
->state
= ORDER_IMPLICIT_NONE
;
2438 if (p
->state
>= ORDER_EXEC
)
2440 if (p
->state
< ORDER_IMPLICIT
)
2441 p
->state
= ORDER_IMPLICIT
;
2445 if (p
->state
< ORDER_SPEC
)
2446 p
->state
= ORDER_SPEC
;
2451 case ST_DERIVED_DECL
:
2453 if (p
->state
>= ORDER_EXEC
)
2455 if (p
->state
< ORDER_SPEC
)
2456 p
->state
= ORDER_SPEC
;
2461 if (p
->state
< ORDER_EXEC
)
2462 p
->state
= ORDER_EXEC
;
2469 /* All is well, record the statement in case we need it next time. */
2470 p
->where
= gfc_current_locus
;
2471 p
->last_statement
= st
;
2476 gfc_error ("%s statement at %C cannot follow %s statement at %L",
2477 gfc_ascii_statement (st
),
2478 gfc_ascii_statement (p
->last_statement
), &p
->where
);
2484 /* Handle an unexpected end of file. This is a show-stopper... */
2486 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
2489 unexpected_eof (void)
2493 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
2495 /* Memory cleanup. Move to "second to last". */
2496 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
2499 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
2502 longjmp (eof_buf
, 1);
2506 /* Parse the CONTAINS section of a derived type definition. */
2508 gfc_access gfc_typebound_default_access
;
2511 parse_derived_contains (void)
2514 bool seen_private
= false;
2515 bool seen_comps
= false;
2516 bool error_flag
= false;
2519 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2520 gcc_assert (gfc_current_block ());
2522 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
2524 if (gfc_current_block ()->attr
.sequence
)
2525 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
2526 " section at %C", gfc_current_block ()->name
);
2527 if (gfc_current_block ()->attr
.is_bind_c
)
2528 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
2529 " section at %C", gfc_current_block ()->name
);
2531 accept_statement (ST_CONTAINS
);
2532 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
2534 gfc_typebound_default_access
= ACCESS_PUBLIC
;
2540 st
= next_statement ();
2548 gfc_error ("Components in TYPE at %C must precede CONTAINS");
2552 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
2555 accept_statement (ST_PROCEDURE
);
2560 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
2563 accept_statement (ST_GENERIC
);
2568 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
2572 accept_statement (ST_FINAL
);
2580 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
2581 "at %C with empty CONTAINS section")))
2584 /* ST_END_TYPE is accepted by parse_derived after return. */
2588 if (!gfc_find_state (COMP_MODULE
))
2590 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
2597 gfc_error ("PRIVATE statement at %C must precede procedure"
2604 gfc_error ("Duplicate PRIVATE statement at %C");
2608 accept_statement (ST_PRIVATE
);
2609 gfc_typebound_default_access
= ACCESS_PRIVATE
;
2610 seen_private
= true;
2614 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
2618 gfc_error ("Already inside a CONTAINS block at %C");
2622 unexpected_statement (st
);
2630 reject_statement ();
2634 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2640 /* Parse a derived type. */
2643 parse_derived (void)
2645 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
2649 gfc_component
*c
, *lock_comp
= NULL
;
2651 accept_statement (ST_DERIVED_DECL
);
2652 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
2654 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
2661 while (compiling_type
)
2663 st
= next_statement ();
2671 accept_statement (st
);
2676 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
2683 if (!seen_component
)
2684 gfc_notify_std (GFC_STD_F2003
, "Derived type "
2685 "definition at %C without components");
2687 accept_statement (ST_END_TYPE
);
2691 if (!gfc_find_state (COMP_MODULE
))
2693 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
2700 gfc_error ("PRIVATE statement at %C must precede "
2701 "structure components");
2706 gfc_error ("Duplicate PRIVATE statement at %C");
2708 s
.sym
->component_access
= ACCESS_PRIVATE
;
2710 accept_statement (ST_PRIVATE
);
2717 gfc_error ("SEQUENCE statement at %C must precede "
2718 "structure components");
2722 if (gfc_current_block ()->attr
.sequence
)
2723 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
2728 gfc_error ("Duplicate SEQUENCE statement at %C");
2732 gfc_add_sequence (&gfc_current_block ()->attr
,
2733 gfc_current_block ()->name
, NULL
);
2737 gfc_notify_std (GFC_STD_F2003
,
2738 "CONTAINS block in derived type"
2739 " definition at %C");
2741 accept_statement (ST_CONTAINS
);
2742 parse_derived_contains ();
2746 unexpected_statement (st
);
2751 /* need to verify that all fields of the derived type are
2752 * interoperable with C if the type is declared to be bind(c)
2754 sym
= gfc_current_block ();
2755 for (c
= sym
->components
; c
; c
= c
->next
)
2757 bool coarray
, lock_type
, allocatable
, pointer
;
2758 coarray
= lock_type
= allocatable
= pointer
= false;
2760 /* Look for allocatable components. */
2761 if (c
->attr
.allocatable
2762 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2763 && CLASS_DATA (c
)->attr
.allocatable
)
2764 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
2765 && c
->ts
.u
.derived
->attr
.alloc_comp
))
2768 sym
->attr
.alloc_comp
= 1;
2771 /* Look for pointer components. */
2773 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2774 && CLASS_DATA (c
)->attr
.class_pointer
)
2775 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
2778 sym
->attr
.pointer_comp
= 1;
2781 /* Look for procedure pointer components. */
2782 if (c
->attr
.proc_pointer
2783 || (c
->ts
.type
== BT_DERIVED
2784 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
2785 sym
->attr
.proc_pointer_comp
= 1;
2787 /* Looking for coarray components. */
2788 if (c
->attr
.codimension
2789 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2790 && CLASS_DATA (c
)->attr
.codimension
))
2793 sym
->attr
.coarray_comp
= 1;
2796 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
2797 && !c
->attr
.pointer
)
2800 sym
->attr
.coarray_comp
= 1;
2803 /* Looking for lock_type components. */
2804 if ((c
->ts
.type
== BT_DERIVED
2805 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2806 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
2807 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2808 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2809 == INTMOD_ISO_FORTRAN_ENV
2810 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2811 == ISOFORTRAN_LOCK_TYPE
)
2812 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
2813 && !allocatable
&& !pointer
))
2817 sym
->attr
.lock_comp
= 1;
2820 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
2821 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
2822 unless there are nondirect [allocatable or pointer] components
2823 involved (cf. 1.3.33.1 and 1.3.33.3). */
2825 if (pointer
&& !coarray
&& lock_type
)
2826 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
2827 "codimension or be a subcomponent of a coarray, "
2828 "which is not possible as the component has the "
2829 "pointer attribute", c
->name
, &c
->loc
);
2830 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
2831 && c
->ts
.u
.derived
->attr
.lock_comp
)
2832 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
2833 "of type LOCK_TYPE, which must have a codimension or be a "
2834 "subcomponent of a coarray", c
->name
, &c
->loc
);
2836 if (lock_type
&& allocatable
&& !coarray
)
2837 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
2838 "a codimension", c
->name
, &c
->loc
);
2839 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
2840 && c
->ts
.u
.derived
->attr
.lock_comp
)
2841 gfc_error ("Allocatable component %s at %L must have a codimension as "
2842 "it has a noncoarray subcomponent of type LOCK_TYPE",
2845 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
2846 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2847 "subcomponent of type LOCK_TYPE must have a codimension or "
2848 "be a subcomponent of a coarray. (Variables of type %s may "
2849 "not have a codimension as already a coarray "
2850 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
2852 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
2853 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2854 "subcomponent of type LOCK_TYPE must have a codimension or "
2855 "be a subcomponent of a coarray. (Variables of type %s may "
2856 "not have a codimension as %s at %L has a codimension or a "
2857 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
2858 sym
->name
, c
->name
, &c
->loc
);
2860 /* Look for private components. */
2861 if (sym
->component_access
== ACCESS_PRIVATE
2862 || c
->attr
.access
== ACCESS_PRIVATE
2863 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
2864 sym
->attr
.private_comp
= 1;
2867 if (!seen_component
)
2868 sym
->attr
.zero_comp
= 1;
2874 /* Parse an ENUM. */
2882 int seen_enumerator
= 0;
2884 push_state (&s
, COMP_ENUM
, gfc_new_block
);
2888 while (compiling_enum
)
2890 st
= next_statement ();
2898 seen_enumerator
= 1;
2899 accept_statement (st
);
2904 if (!seen_enumerator
)
2905 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
2906 accept_statement (st
);
2910 gfc_free_enum_history ();
2911 unexpected_statement (st
);
2919 /* Parse an interface. We must be able to deal with the possibility
2920 of recursive interfaces. The parse_spec() subroutine is mutually
2921 recursive with parse_interface(). */
2923 static gfc_statement
parse_spec (gfc_statement
);
2926 parse_interface (void)
2928 gfc_compile_state new_state
= COMP_NONE
, current_state
;
2929 gfc_symbol
*prog_unit
, *sym
;
2930 gfc_interface_info save
;
2931 gfc_state_data s1
, s2
;
2934 accept_statement (ST_INTERFACE
);
2936 current_interface
.ns
= gfc_current_ns
;
2937 save
= current_interface
;
2939 sym
= (current_interface
.type
== INTERFACE_GENERIC
2940 || current_interface
.type
== INTERFACE_USER_OP
)
2941 ? gfc_new_block
: NULL
;
2943 push_state (&s1
, COMP_INTERFACE
, sym
);
2944 current_state
= COMP_NONE
;
2947 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
2949 st
= next_statement ();
2957 if (st
== ST_SUBROUTINE
)
2958 new_state
= COMP_SUBROUTINE
;
2959 else if (st
== ST_FUNCTION
)
2960 new_state
= COMP_FUNCTION
;
2961 if (gfc_new_block
->attr
.pointer
)
2963 gfc_new_block
->attr
.pointer
= 0;
2964 gfc_new_block
->attr
.proc_pointer
= 1;
2966 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
2967 gfc_new_block
->formal
, NULL
))
2969 reject_statement ();
2970 gfc_free_namespace (gfc_current_ns
);
2973 /* F2008 C1210 forbids the IMPORT statement in module procedure
2974 interface bodies and the flag is set to import symbols. */
2975 if (gfc_new_block
->attr
.module_procedure
)
2976 gfc_current_ns
->has_import_set
= 1;
2980 case ST_MODULE_PROC
: /* The module procedure matcher makes
2981 sure the context is correct. */
2982 accept_statement (st
);
2983 gfc_free_namespace (gfc_current_ns
);
2986 case ST_END_INTERFACE
:
2987 gfc_free_namespace (gfc_current_ns
);
2988 gfc_current_ns
= current_interface
.ns
;
2992 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
2993 gfc_ascii_statement (st
));
2994 reject_statement ();
2995 gfc_free_namespace (gfc_current_ns
);
3000 /* Make sure that the generic name has the right attribute. */
3001 if (current_interface
.type
== INTERFACE_GENERIC
3002 && current_state
== COMP_NONE
)
3004 if (new_state
== COMP_FUNCTION
&& sym
)
3005 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3006 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3007 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3009 current_state
= new_state
;
3012 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3014 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3015 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3016 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3017 "cannot be the same as an intrinsic type",
3018 gfc_new_block
->name
);
3021 push_state (&s2
, new_state
, gfc_new_block
);
3022 accept_statement (st
);
3023 prog_unit
= gfc_new_block
;
3024 prog_unit
->formal_ns
= gfc_current_ns
;
3025 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3026 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3030 /* Read data declaration statements. */
3031 st
= parse_spec (ST_NONE
);
3032 in_specification_block
= true;
3034 /* Since the interface block does not permit an IMPLICIT statement,
3035 the default type for the function or the result must be taken
3036 from the formal namespace. */
3037 if (new_state
== COMP_FUNCTION
)
3039 if (prog_unit
->result
== prog_unit
3040 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3041 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3042 else if (prog_unit
->result
!= prog_unit
3043 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3044 gfc_set_default_type (prog_unit
->result
, 1,
3045 prog_unit
->formal_ns
);
3048 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3050 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3051 gfc_ascii_statement (st
));
3052 reject_statement ();
3056 /* Add EXTERNAL attribute to function or subroutine. */
3057 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3058 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3060 current_interface
= save
;
3061 gfc_add_interface (prog_unit
);
3064 if (current_interface
.ns
3065 && current_interface
.ns
->proc_name
3066 && strcmp (current_interface
.ns
->proc_name
->name
,
3067 prog_unit
->name
) == 0)
3068 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3069 "enclosing procedure", prog_unit
->name
,
3070 ¤t_interface
.ns
->proc_name
->declared_at
);
3079 /* Associate function characteristics by going back to the function
3080 declaration and rematching the prefix. */
3083 match_deferred_characteristics (gfc_typespec
* ts
)
3086 match m
= MATCH_ERROR
;
3087 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3089 loc
= gfc_current_locus
;
3091 gfc_current_locus
= gfc_current_block ()->declared_at
;
3094 gfc_buffer_error (true);
3095 m
= gfc_match_prefix (ts
);
3096 gfc_buffer_error (false);
3098 if (ts
->type
== BT_DERIVED
)
3106 /* Only permit one go at the characteristic association. */
3110 /* Set the function locus correctly. If we have not found the
3111 function name, there is an error. */
3113 && gfc_match ("function% %n", name
) == MATCH_YES
3114 && strcmp (name
, gfc_current_block ()->name
) == 0)
3116 gfc_current_block ()->declared_at
= gfc_current_locus
;
3117 gfc_commit_symbols ();
3122 gfc_undo_symbols ();
3125 gfc_current_locus
=loc
;
3130 /* Check specification-expressions in the function result of the currently
3131 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3132 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3133 scope are not yet parsed so this has to be delayed up to parse_spec. */
3136 check_function_result_typed (void)
3140 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3142 if (!gfc_current_ns
->proc_name
->result
) return;
3144 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3146 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3147 /* TODO: Extend when KIND type parameters are implemented. */
3148 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3149 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3153 /* Parse a set of specification statements. Returns the statement
3154 that doesn't fit. */
3156 static gfc_statement
3157 parse_spec (gfc_statement st
)
3160 bool function_result_typed
= false;
3161 bool bad_characteristic
= false;
3164 in_specification_block
= true;
3166 verify_st_order (&ss
, ST_NONE
, false);
3168 st
= next_statement ();
3170 /* If we are not inside a function or don't have a result specified so far,
3171 do nothing special about it. */
3172 if (gfc_current_state () != COMP_FUNCTION
)
3173 function_result_typed
= true;
3176 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3179 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3180 function_result_typed
= true;
3185 /* If we're inside a BLOCK construct, some statements are disallowed.
3186 Check this here. Attribute declaration statements like INTENT, OPTIONAL
3187 or VALUE are also disallowed, but they don't have a particular ST_*
3188 key so we have to check for them individually in their matcher routine. */
3189 if (gfc_current_state () == COMP_BLOCK
)
3193 case ST_IMPLICIT_NONE
:
3196 case ST_EQUIVALENCE
:
3197 case ST_STATEMENT_FUNCTION
:
3198 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
3199 gfc_ascii_statement (st
));
3200 reject_statement ();
3206 else if (gfc_current_state () == COMP_BLOCK_DATA
)
3207 /* Fortran 2008, C1116. */
3214 case ST_END_BLOCK_DATA
:
3216 case ST_EQUIVALENCE
:
3219 case ST_IMPLICIT_NONE
:
3220 case ST_DERIVED_DECL
:
3228 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
3229 gfc_ascii_statement (st
));
3230 reject_statement ();
3234 /* If we find a statement that can not be followed by an IMPLICIT statement
3235 (and thus we can expect to see none any further), type the function result
3236 if it has not yet been typed. Be careful not to give the END statement
3237 to verify_st_order! */
3238 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
3240 bool verify_now
= false;
3242 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
3247 verify_st_order (&dummyss
, ST_NONE
, false);
3248 verify_st_order (&dummyss
, st
, false);
3250 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
3256 check_function_result_typed ();
3257 function_result_typed
= true;
3266 case ST_IMPLICIT_NONE
:
3268 if (!function_result_typed
)
3270 check_function_result_typed ();
3271 function_result_typed
= true;
3277 case ST_DATA
: /* Not allowed in interfaces */
3278 if (gfc_current_state () == COMP_INTERFACE
)
3288 case ST_DERIVED_DECL
:
3291 if (!verify_st_order (&ss
, st
, false))
3293 reject_statement ();
3294 st
= next_statement ();
3304 case ST_DERIVED_DECL
:
3310 if (gfc_current_state () != COMP_MODULE
)
3312 gfc_error ("%s statement must appear in a MODULE",
3313 gfc_ascii_statement (st
));
3314 reject_statement ();
3318 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
3320 gfc_error ("%s statement at %C follows another accessibility "
3321 "specification", gfc_ascii_statement (st
));
3322 reject_statement ();
3326 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
3327 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
3331 case ST_STATEMENT_FUNCTION
:
3332 if (gfc_current_state () == COMP_MODULE
3333 || gfc_current_state () == COMP_SUBMODULE
)
3335 unexpected_statement (st
);
3343 accept_statement (st
);
3344 st
= next_statement ();
3348 accept_statement (st
);
3350 st
= next_statement ();
3353 case ST_GET_FCN_CHARACTERISTICS
:
3354 /* This statement triggers the association of a function's result
3356 ts
= &gfc_current_block ()->result
->ts
;
3357 if (match_deferred_characteristics (ts
) != MATCH_YES
)
3358 bad_characteristic
= true;
3360 st
= next_statement ();
3367 /* If match_deferred_characteristics failed, then there is an error. */
3368 if (bad_characteristic
)
3370 ts
= &gfc_current_block ()->result
->ts
;
3371 if (ts
->type
!= BT_DERIVED
)
3372 gfc_error ("Bad kind expression for function %qs at %L",
3373 gfc_current_block ()->name
,
3374 &gfc_current_block ()->declared_at
);
3376 gfc_error ("The type for function %qs at %L is not accessible",
3377 gfc_current_block ()->name
,
3378 &gfc_current_block ()->declared_at
);
3380 gfc_current_block ()->ts
.kind
= 0;
3381 /* Keep the derived type; if it's bad, it will be discovered later. */
3382 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
3383 ts
->type
= BT_UNKNOWN
;
3386 in_specification_block
= false;
3392 /* Parse a WHERE block, (not a simple WHERE statement). */
3395 parse_where_block (void)
3397 int seen_empty_else
;
3402 accept_statement (ST_WHERE_BLOCK
);
3403 top
= gfc_state_stack
->tail
;
3405 push_state (&s
, COMP_WHERE
, gfc_new_block
);
3407 d
= add_statement ();
3408 d
->expr1
= top
->expr1
;
3414 seen_empty_else
= 0;
3418 st
= next_statement ();
3424 case ST_WHERE_BLOCK
:
3425 parse_where_block ();
3430 accept_statement (st
);
3434 if (seen_empty_else
)
3436 gfc_error ("ELSEWHERE statement at %C follows previous "
3437 "unmasked ELSEWHERE");
3438 reject_statement ();
3442 if (new_st
.expr1
== NULL
)
3443 seen_empty_else
= 1;
3445 d
= new_level (gfc_state_stack
->head
);
3447 d
->expr1
= new_st
.expr1
;
3449 accept_statement (st
);
3454 accept_statement (st
);
3458 gfc_error ("Unexpected %s statement in WHERE block at %C",
3459 gfc_ascii_statement (st
));
3460 reject_statement ();
3464 while (st
!= ST_END_WHERE
);
3470 /* Parse a FORALL block (not a simple FORALL statement). */
3473 parse_forall_block (void)
3479 accept_statement (ST_FORALL_BLOCK
);
3480 top
= gfc_state_stack
->tail
;
3482 push_state (&s
, COMP_FORALL
, gfc_new_block
);
3484 d
= add_statement ();
3485 d
->op
= EXEC_FORALL
;
3490 st
= next_statement ();
3495 case ST_POINTER_ASSIGNMENT
:
3498 accept_statement (st
);
3501 case ST_WHERE_BLOCK
:
3502 parse_where_block ();
3505 case ST_FORALL_BLOCK
:
3506 parse_forall_block ();
3510 accept_statement (st
);
3517 gfc_error ("Unexpected %s statement in FORALL block at %C",
3518 gfc_ascii_statement (st
));
3520 reject_statement ();
3524 while (st
!= ST_END_FORALL
);
3530 static gfc_statement
parse_executable (gfc_statement
);
3532 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
3535 parse_if_block (void)
3544 accept_statement (ST_IF_BLOCK
);
3546 top
= gfc_state_stack
->tail
;
3547 push_state (&s
, COMP_IF
, gfc_new_block
);
3549 new_st
.op
= EXEC_IF
;
3550 d
= add_statement ();
3552 d
->expr1
= top
->expr1
;
3558 st
= parse_executable (ST_NONE
);
3568 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
3569 "statement at %L", &else_locus
);
3571 reject_statement ();
3575 d
= new_level (gfc_state_stack
->head
);
3577 d
->expr1
= new_st
.expr1
;
3579 accept_statement (st
);
3586 gfc_error ("Duplicate ELSE statements at %L and %C",
3588 reject_statement ();
3593 else_locus
= gfc_current_locus
;
3595 d
= new_level (gfc_state_stack
->head
);
3598 accept_statement (st
);
3606 unexpected_statement (st
);
3610 while (st
!= ST_ENDIF
);
3613 accept_statement (st
);
3617 /* Parse a SELECT block. */
3620 parse_select_block (void)
3626 accept_statement (ST_SELECT_CASE
);
3628 cp
= gfc_state_stack
->tail
;
3629 push_state (&s
, COMP_SELECT
, gfc_new_block
);
3631 /* Make sure that the next statement is a CASE or END SELECT. */
3634 st
= next_statement ();
3637 if (st
== ST_END_SELECT
)
3639 /* Empty SELECT CASE is OK. */
3640 accept_statement (st
);
3647 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
3650 reject_statement ();
3653 /* At this point, we're got a nonempty select block. */
3654 cp
= new_level (cp
);
3657 accept_statement (st
);
3661 st
= parse_executable (ST_NONE
);
3668 cp
= new_level (gfc_state_stack
->head
);
3670 gfc_clear_new_st ();
3672 accept_statement (st
);
3678 /* Can't have an executable statement because of
3679 parse_executable(). */
3681 unexpected_statement (st
);
3685 while (st
!= ST_END_SELECT
);
3688 accept_statement (st
);
3692 /* Pop the current selector from the SELECT TYPE stack. */
3695 select_type_pop (void)
3697 gfc_select_type_stack
*old
= select_type_stack
;
3698 select_type_stack
= old
->prev
;
3703 /* Parse a SELECT TYPE construct (F03:R821). */
3706 parse_select_type_block (void)
3712 accept_statement (ST_SELECT_TYPE
);
3714 cp
= gfc_state_stack
->tail
;
3715 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
3717 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
3721 st
= next_statement ();
3724 if (st
== ST_END_SELECT
)
3725 /* Empty SELECT CASE is OK. */
3727 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
3730 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
3731 "following SELECT TYPE at %C");
3733 reject_statement ();
3736 /* At this point, we're got a nonempty select block. */
3737 cp
= new_level (cp
);
3740 accept_statement (st
);
3744 st
= parse_executable (ST_NONE
);
3752 cp
= new_level (gfc_state_stack
->head
);
3754 gfc_clear_new_st ();
3756 accept_statement (st
);
3762 /* Can't have an executable statement because of
3763 parse_executable(). */
3765 unexpected_statement (st
);
3769 while (st
!= ST_END_SELECT
);
3773 accept_statement (st
);
3774 gfc_current_ns
= gfc_current_ns
->parent
;
3779 /* Given a symbol, make sure it is not an iteration variable for a DO
3780 statement. This subroutine is called when the symbol is seen in a
3781 context that causes it to become redefined. If the symbol is an
3782 iterator, we generate an error message and return nonzero. */
3785 gfc_check_do_variable (gfc_symtree
*st
)
3789 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
3790 if (s
->do_variable
== st
)
3792 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
3793 "loop beginning at %L", st
->name
, &s
->head
->loc
);
3801 /* Checks to see if the current statement label closes an enddo.
3802 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
3803 an error) if it incorrectly closes an ENDDO. */
3806 check_do_closure (void)
3810 if (gfc_statement_label
== NULL
)
3813 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
3814 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
3818 return 0; /* No loops to close */
3820 if (p
->ext
.end_do_label
== gfc_statement_label
)
3822 if (p
== gfc_state_stack
)
3825 gfc_error ("End of nonblock DO statement at %C is within another block");
3829 /* At this point, the label doesn't terminate the innermost loop.
3830 Make sure it doesn't terminate another one. */
3831 for (; p
; p
= p
->previous
)
3832 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
3833 && p
->ext
.end_do_label
== gfc_statement_label
)
3835 gfc_error ("End of nonblock DO statement at %C is interwoven "
3836 "with another DO loop");
3844 /* Parse a series of contained program units. */
3846 static void parse_progunit (gfc_statement
);
3849 /* Parse a CRITICAL block. */
3852 parse_critical_block (void)
3855 gfc_state_data s
, *sd
;
3858 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
3859 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
3860 gfc_error_now (is_oacc (sd
)
3861 ? "CRITICAL block inside of OpenACC region at %C"
3862 : "CRITICAL block inside of OpenMP region at %C");
3864 s
.ext
.end_do_label
= new_st
.label1
;
3866 accept_statement (ST_CRITICAL
);
3867 top
= gfc_state_stack
->tail
;
3869 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
3871 d
= add_statement ();
3872 d
->op
= EXEC_CRITICAL
;
3877 st
= parse_executable (ST_NONE
);
3885 case ST_END_CRITICAL
:
3886 if (s
.ext
.end_do_label
!= NULL
3887 && s
.ext
.end_do_label
!= gfc_statement_label
)
3888 gfc_error_now ("Statement label in END CRITICAL at %C does not "
3889 "match CRITICAL label");
3891 if (gfc_statement_label
!= NULL
)
3893 new_st
.op
= EXEC_NOP
;
3899 unexpected_statement (st
);
3903 while (st
!= ST_END_CRITICAL
);
3906 accept_statement (st
);
3910 /* Set up the local namespace for a BLOCK construct. */
3913 gfc_build_block_ns (gfc_namespace
*parent_ns
)
3915 gfc_namespace
* my_ns
;
3916 static int numblock
= 1;
3918 my_ns
= gfc_get_namespace (parent_ns
, 1);
3919 my_ns
->construct_entities
= 1;
3921 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
3922 code generation (so it must not be NULL).
3923 We set its recursive argument if our container procedure is recursive, so
3924 that local variables are accordingly placed on the stack when it
3925 will be necessary. */
3927 my_ns
->proc_name
= gfc_new_block
;
3931 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
3933 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
3934 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
3935 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
3936 my_ns
->proc_name
->name
, NULL
);
3938 gfc_commit_symbol (my_ns
->proc_name
);
3941 if (parent_ns
->proc_name
)
3942 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
3948 /* Parse a BLOCK construct. */
3951 parse_block_construct (void)
3953 gfc_namespace
* my_ns
;
3954 gfc_namespace
* my_parent
;
3957 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
3959 my_ns
= gfc_build_block_ns (gfc_current_ns
);
3961 new_st
.op
= EXEC_BLOCK
;
3962 new_st
.ext
.block
.ns
= my_ns
;
3963 new_st
.ext
.block
.assoc
= NULL
;
3964 accept_statement (ST_BLOCK
);
3966 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
3967 gfc_current_ns
= my_ns
;
3968 my_parent
= my_ns
->parent
;
3970 parse_progunit (ST_NONE
);
3972 /* Don't depend on the value of gfc_current_ns; it might have been
3973 reset if the block had errors and was cleaned up. */
3974 gfc_current_ns
= my_parent
;
3980 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
3981 behind the scenes with compiler-generated variables. */
3984 parse_associate (void)
3986 gfc_namespace
* my_ns
;
3989 gfc_association_list
* a
;
3991 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
3993 my_ns
= gfc_build_block_ns (gfc_current_ns
);
3995 new_st
.op
= EXEC_BLOCK
;
3996 new_st
.ext
.block
.ns
= my_ns
;
3997 gcc_assert (new_st
.ext
.block
.assoc
);
3999 /* Add all associate-names as BLOCK variables. Creating them is enough
4000 for now, they'll get their values during trans-* phase. */
4001 gfc_current_ns
= my_ns
;
4002 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4006 gfc_array_ref
*array_ref
;
4008 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4012 sym
->attr
.flavor
= FL_VARIABLE
;
4014 sym
->declared_at
= a
->where
;
4015 gfc_set_sym_referenced (sym
);
4017 /* Initialize the typespec. It is not available in all cases,
4018 however, as it may only be set on the target during resolution.
4019 Still, sometimes it helps to have it right now -- especially
4020 for parsing component references on the associate-name
4021 in case of association to a derived-type. */
4022 sym
->ts
= a
->target
->ts
;
4024 /* Check if the target expression is array valued. This can not always
4025 be done by looking at target.rank, because that might not have been
4026 set yet. Therefore traverse the chain of refs, looking for the last
4027 array ref and evaluate that. */
4029 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4030 if (ref
->type
== REF_ARRAY
)
4031 array_ref
= &ref
->u
.ar
;
4032 if (array_ref
|| a
->target
->rank
)
4038 /* Count the dimension, that have a non-scalar extend. */
4039 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4040 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4041 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4042 && array_ref
->end
[dim
] == NULL
4043 && array_ref
->start
[dim
] != NULL
))
4047 rank
= a
->target
->rank
;
4048 /* When the rank is greater than zero then sym will be an array. */
4049 if (sym
->ts
.type
== BT_CLASS
)
4051 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4052 || (CLASS_DATA (sym
)->as
4053 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4055 /* Don't just (re-)set the attr and as in the sym.ts,
4056 because this modifies the target's attr and as. Copy the
4057 data and do a build_class_symbol. */
4058 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4059 int corank
= gfc_get_corank (a
->target
);
4064 as
= gfc_get_array_spec ();
4065 as
->type
= AS_DEFERRED
;
4067 as
->corank
= corank
;
4068 attr
.dimension
= rank
? 1 : 0;
4069 attr
.codimension
= corank
? 1 : 0;
4074 attr
.dimension
= attr
.codimension
= 0;
4077 type
= CLASS_DATA (sym
)->ts
;
4078 if (!gfc_build_class_symbol (&type
,
4082 sym
->ts
.type
= BT_CLASS
;
4083 sym
->attr
.class_ok
= 1;
4086 sym
->attr
.class_ok
= 1;
4088 else if ((!sym
->as
&& rank
!= 0)
4089 || (sym
->as
&& sym
->as
->rank
!= rank
))
4091 as
= gfc_get_array_spec ();
4092 as
->type
= AS_DEFERRED
;
4094 as
->corank
= gfc_get_corank (a
->target
);
4096 sym
->attr
.dimension
= 1;
4098 sym
->attr
.codimension
= 1;
4103 accept_statement (ST_ASSOCIATE
);
4104 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
4107 st
= parse_executable (ST_NONE
);
4114 accept_statement (st
);
4115 my_ns
->code
= gfc_state_stack
->head
;
4119 unexpected_statement (st
);
4123 gfc_current_ns
= gfc_current_ns
->parent
;
4128 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
4129 handled inside of parse_executable(), because they aren't really
4133 parse_do_block (void)
4142 s
.ext
.end_do_label
= new_st
.label1
;
4144 if (new_st
.ext
.iterator
!= NULL
)
4145 stree
= new_st
.ext
.iterator
->var
->symtree
;
4149 accept_statement (ST_DO
);
4151 top
= gfc_state_stack
->tail
;
4152 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
4155 s
.do_variable
= stree
;
4157 top
->block
= new_level (top
);
4158 top
->block
->op
= EXEC_DO
;
4161 st
= parse_executable (ST_NONE
);
4169 if (s
.ext
.end_do_label
!= NULL
4170 && s
.ext
.end_do_label
!= gfc_statement_label
)
4171 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
4174 if (gfc_statement_label
!= NULL
)
4176 new_st
.op
= EXEC_NOP
;
4181 case ST_IMPLIED_ENDDO
:
4182 /* If the do-stmt of this DO construct has a do-construct-name,
4183 the corresponding end-do must be an end-do-stmt (with a matching
4184 name, but in that case we must have seen ST_ENDDO first).
4185 We only complain about this in pedantic mode. */
4186 if (gfc_current_block () != NULL
)
4187 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
4188 &gfc_current_block()->declared_at
);
4193 unexpected_statement (st
);
4198 accept_statement (st
);
4202 /* Parse the statements of OpenMP do/parallel do. */
4204 static gfc_statement
4205 parse_omp_do (gfc_statement omp_st
)
4211 accept_statement (omp_st
);
4213 cp
= gfc_state_stack
->tail
;
4214 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4215 np
= new_level (cp
);
4221 st
= next_statement ();
4224 else if (st
== ST_DO
)
4227 unexpected_statement (st
);
4231 if (gfc_statement_label
!= NULL
4232 && gfc_state_stack
->previous
!= NULL
4233 && gfc_state_stack
->previous
->state
== COMP_DO
4234 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4242 there should be no !$OMP END DO. */
4244 return ST_IMPLIED_ENDDO
;
4247 check_do_closure ();
4250 st
= next_statement ();
4251 gfc_statement omp_end_st
= ST_OMP_END_DO
;
4254 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
4255 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4256 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4258 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4259 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4261 case ST_OMP_DISTRIBUTE_SIMD
:
4262 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4264 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
4265 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
4266 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
4267 case ST_OMP_PARALLEL_DO_SIMD
:
4268 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
4270 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
4271 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4272 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4274 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4275 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4277 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4278 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4280 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4281 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4283 case ST_OMP_TEAMS_DISTRIBUTE
:
4284 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4286 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4287 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4289 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4290 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4292 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4293 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4295 default: gcc_unreachable ();
4297 if (st
== omp_end_st
)
4299 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
4300 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4302 gcc_assert (new_st
.op
== EXEC_NOP
);
4303 gfc_clear_new_st ();
4304 gfc_commit_symbols ();
4305 gfc_warning_check ();
4306 st
= next_statement ();
4312 /* Parse the statements of OpenMP atomic directive. */
4314 static gfc_statement
4315 parse_omp_oacc_atomic (bool omp_p
)
4317 gfc_statement st
, st_atomic
, st_end_atomic
;
4324 st_atomic
= ST_OMP_ATOMIC
;
4325 st_end_atomic
= ST_OMP_END_ATOMIC
;
4329 st_atomic
= ST_OACC_ATOMIC
;
4330 st_end_atomic
= ST_OACC_END_ATOMIC
;
4332 accept_statement (st_atomic
);
4334 cp
= gfc_state_stack
->tail
;
4335 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4336 np
= new_level (cp
);
4339 count
= 1 + ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4340 == GFC_OMP_ATOMIC_CAPTURE
);
4344 st
= next_statement ();
4347 else if (st
== ST_ASSIGNMENT
)
4349 accept_statement (st
);
4353 unexpected_statement (st
);
4358 st
= next_statement ();
4359 if (st
== st_end_atomic
)
4361 gfc_clear_new_st ();
4362 gfc_commit_symbols ();
4363 gfc_warning_check ();
4364 st
= next_statement ();
4366 else if ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4367 == GFC_OMP_ATOMIC_CAPTURE
)
4368 gfc_error ("Missing !$OMP END ATOMIC after !$OMP ATOMIC CAPTURE at %C");
4373 /* Parse the statements of an OpenACC structured block. */
4376 parse_oacc_structured_block (gfc_statement acc_st
)
4378 gfc_statement st
, acc_end_st
;
4380 gfc_state_data s
, *sd
;
4382 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4383 if (sd
->state
== COMP_CRITICAL
)
4384 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4386 accept_statement (acc_st
);
4388 cp
= gfc_state_stack
->tail
;
4389 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4390 np
= new_level (cp
);
4395 case ST_OACC_PARALLEL
:
4396 acc_end_st
= ST_OACC_END_PARALLEL
;
4398 case ST_OACC_KERNELS
:
4399 acc_end_st
= ST_OACC_END_KERNELS
;
4402 acc_end_st
= ST_OACC_END_DATA
;
4404 case ST_OACC_HOST_DATA
:
4405 acc_end_st
= ST_OACC_END_HOST_DATA
;
4413 st
= parse_executable (ST_NONE
);
4416 else if (st
!= acc_end_st
)
4418 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
4419 reject_statement ();
4422 while (st
!= acc_end_st
);
4424 gcc_assert (new_st
.op
== EXEC_NOP
);
4426 gfc_clear_new_st ();
4427 gfc_commit_symbols ();
4428 gfc_warning_check ();
4432 /* Parse the statements of OpenACC loop/parallel loop/kernels loop. */
4434 static gfc_statement
4435 parse_oacc_loop (gfc_statement acc_st
)
4439 gfc_state_data s
, *sd
;
4441 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4442 if (sd
->state
== COMP_CRITICAL
)
4443 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4445 accept_statement (acc_st
);
4447 cp
= gfc_state_stack
->tail
;
4448 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4449 np
= new_level (cp
);
4455 st
= next_statement ();
4458 else if (st
== ST_DO
)
4462 gfc_error ("Expected DO loop at %C");
4463 reject_statement ();
4468 if (gfc_statement_label
!= NULL
4469 && gfc_state_stack
->previous
!= NULL
4470 && gfc_state_stack
->previous
->state
== COMP_DO
4471 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4474 return ST_IMPLIED_ENDDO
;
4477 check_do_closure ();
4480 st
= next_statement ();
4481 if (st
== ST_OACC_END_LOOP
)
4482 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
4483 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
4484 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
4485 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
4487 gcc_assert (new_st
.op
== EXEC_NOP
);
4488 gfc_clear_new_st ();
4489 gfc_commit_symbols ();
4490 gfc_warning_check ();
4491 st
= next_statement ();
4497 /* Parse the statements of an OpenMP structured block. */
4500 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
4502 gfc_statement st
, omp_end_st
;
4506 accept_statement (omp_st
);
4508 cp
= gfc_state_stack
->tail
;
4509 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4510 np
= new_level (cp
);
4516 case ST_OMP_PARALLEL
:
4517 omp_end_st
= ST_OMP_END_PARALLEL
;
4519 case ST_OMP_PARALLEL_SECTIONS
:
4520 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
4522 case ST_OMP_SECTIONS
:
4523 omp_end_st
= ST_OMP_END_SECTIONS
;
4525 case ST_OMP_ORDERED
:
4526 omp_end_st
= ST_OMP_END_ORDERED
;
4528 case ST_OMP_CRITICAL
:
4529 omp_end_st
= ST_OMP_END_CRITICAL
;
4532 omp_end_st
= ST_OMP_END_MASTER
;
4535 omp_end_st
= ST_OMP_END_SINGLE
;
4538 omp_end_st
= ST_OMP_END_TARGET
;
4540 case ST_OMP_TARGET_DATA
:
4541 omp_end_st
= ST_OMP_END_TARGET_DATA
;
4543 case ST_OMP_TARGET_TEAMS
:
4544 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
4546 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4547 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4549 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4550 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4552 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4553 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4555 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4556 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4559 omp_end_st
= ST_OMP_END_TASK
;
4561 case ST_OMP_TASKGROUP
:
4562 omp_end_st
= ST_OMP_END_TASKGROUP
;
4565 omp_end_st
= ST_OMP_END_TEAMS
;
4567 case ST_OMP_TEAMS_DISTRIBUTE
:
4568 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4570 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4571 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4573 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4574 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4576 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4577 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4579 case ST_OMP_DISTRIBUTE
:
4580 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
4582 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4583 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4585 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4586 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4588 case ST_OMP_DISTRIBUTE_SIMD
:
4589 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4591 case ST_OMP_WORKSHARE
:
4592 omp_end_st
= ST_OMP_END_WORKSHARE
;
4594 case ST_OMP_PARALLEL_WORKSHARE
:
4595 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
4603 if (workshare_stmts_only
)
4605 /* Inside of !$omp workshare, only
4608 where statements and constructs
4609 forall statements and constructs
4613 are allowed. For !$omp critical these
4614 restrictions apply recursively. */
4617 st
= next_statement ();
4628 accept_statement (st
);
4631 case ST_WHERE_BLOCK
:
4632 parse_where_block ();
4635 case ST_FORALL_BLOCK
:
4636 parse_forall_block ();
4639 case ST_OMP_PARALLEL
:
4640 case ST_OMP_PARALLEL_SECTIONS
:
4641 parse_omp_structured_block (st
, false);
4644 case ST_OMP_PARALLEL_WORKSHARE
:
4645 case ST_OMP_CRITICAL
:
4646 parse_omp_structured_block (st
, true);
4649 case ST_OMP_PARALLEL_DO
:
4650 case ST_OMP_PARALLEL_DO_SIMD
:
4651 st
= parse_omp_do (st
);
4655 st
= parse_omp_oacc_atomic (true);
4666 st
= next_statement ();
4670 st
= parse_executable (ST_NONE
);
4673 else if (st
== ST_OMP_SECTION
4674 && (omp_st
== ST_OMP_SECTIONS
4675 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
4677 np
= new_level (np
);
4681 else if (st
!= omp_end_st
)
4682 unexpected_statement (st
);
4684 while (st
!= omp_end_st
);
4688 case EXEC_OMP_END_NOWAIT
:
4689 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4691 case EXEC_OMP_CRITICAL
:
4692 if (((cp
->ext
.omp_name
== NULL
) ^ (new_st
.ext
.omp_name
== NULL
))
4693 || (new_st
.ext
.omp_name
!= NULL
4694 && strcmp (cp
->ext
.omp_name
, new_st
.ext
.omp_name
) != 0))
4695 gfc_error ("Name after !$omp critical and !$omp end critical does "
4697 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
4699 case EXEC_OMP_END_SINGLE
:
4700 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
4701 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
4702 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
4703 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
4711 gfc_clear_new_st ();
4712 gfc_commit_symbols ();
4713 gfc_warning_check ();
4718 /* Accept a series of executable statements. We return the first
4719 statement that doesn't fit to the caller. Any block statements are
4720 passed on to the correct handler, which usually passes the buck
4723 static gfc_statement
4724 parse_executable (gfc_statement st
)
4729 st
= next_statement ();
4733 close_flag
= check_do_closure ();
4738 case ST_END_PROGRAM
:
4741 case ST_END_FUNCTION
:
4746 case ST_END_SUBROUTINE
:
4751 case ST_SELECT_CASE
:
4752 gfc_error ("%s statement at %C cannot terminate a non-block "
4753 "DO loop", gfc_ascii_statement (st
));
4766 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
4767 "first executable statement");
4773 accept_statement (st
);
4774 if (close_flag
== 1)
4775 return ST_IMPLIED_ENDDO
;
4779 parse_block_construct ();
4790 case ST_SELECT_CASE
:
4791 parse_select_block ();
4794 case ST_SELECT_TYPE
:
4795 parse_select_type_block();
4800 if (check_do_closure () == 1)
4801 return ST_IMPLIED_ENDDO
;
4805 parse_critical_block ();
4808 case ST_WHERE_BLOCK
:
4809 parse_where_block ();
4812 case ST_FORALL_BLOCK
:
4813 parse_forall_block ();
4816 case ST_OACC_PARALLEL_LOOP
:
4817 case ST_OACC_KERNELS_LOOP
:
4819 st
= parse_oacc_loop (st
);
4820 if (st
== ST_IMPLIED_ENDDO
)
4824 case ST_OACC_PARALLEL
:
4825 case ST_OACC_KERNELS
:
4827 case ST_OACC_HOST_DATA
:
4828 parse_oacc_structured_block (st
);
4831 case ST_OMP_PARALLEL
:
4832 case ST_OMP_PARALLEL_SECTIONS
:
4833 case ST_OMP_SECTIONS
:
4834 case ST_OMP_ORDERED
:
4835 case ST_OMP_CRITICAL
:
4839 case ST_OMP_TARGET_DATA
:
4840 case ST_OMP_TARGET_TEAMS
:
4843 case ST_OMP_TASKGROUP
:
4844 parse_omp_structured_block (st
, false);
4847 case ST_OMP_WORKSHARE
:
4848 case ST_OMP_PARALLEL_WORKSHARE
:
4849 parse_omp_structured_block (st
, true);
4852 case ST_OMP_DISTRIBUTE
:
4853 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4854 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4855 case ST_OMP_DISTRIBUTE_SIMD
:
4857 case ST_OMP_DO_SIMD
:
4858 case ST_OMP_PARALLEL_DO
:
4859 case ST_OMP_PARALLEL_DO_SIMD
:
4861 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4862 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4863 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4864 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4865 case ST_OMP_TEAMS_DISTRIBUTE
:
4866 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4867 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4868 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4869 st
= parse_omp_do (st
);
4870 if (st
== ST_IMPLIED_ENDDO
)
4874 case ST_OACC_ATOMIC
:
4875 st
= parse_omp_oacc_atomic (false);
4879 st
= parse_omp_oacc_atomic (true);
4886 st
= next_statement ();
4891 /* Fix the symbols for sibling functions. These are incorrectly added to
4892 the child namespace as the parser didn't know about this procedure. */
4895 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
4899 gfc_symbol
*old_sym
;
4901 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
4903 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
4905 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
4906 goto fixup_contained
;
4908 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
4909 && sym
->attr
.generic
&& sym
->attr
.function
)
4910 ||(sym
->attr
.flavor
== FL_DERIVED
4911 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
4912 goto fixup_contained
;
4914 old_sym
= st
->n
.sym
;
4915 if (old_sym
->ns
== ns
4916 && !old_sym
->attr
.contained
4918 /* By 14.6.1.3, host association should be excluded
4919 for the following. */
4920 && !(old_sym
->attr
.external
4921 || (old_sym
->ts
.type
!= BT_UNKNOWN
4922 && !old_sym
->attr
.implicit_type
)
4923 || old_sym
->attr
.flavor
== FL_PARAMETER
4924 || old_sym
->attr
.use_assoc
4925 || old_sym
->attr
.in_common
4926 || old_sym
->attr
.in_equivalence
4927 || old_sym
->attr
.data
4928 || old_sym
->attr
.dummy
4929 || old_sym
->attr
.result
4930 || old_sym
->attr
.dimension
4931 || old_sym
->attr
.allocatable
4932 || old_sym
->attr
.intrinsic
4933 || old_sym
->attr
.generic
4934 || old_sym
->attr
.flavor
== FL_NAMELIST
4935 || old_sym
->attr
.flavor
== FL_LABEL
4936 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
4938 /* Replace it with the symbol from the parent namespace. */
4942 gfc_release_symbol (old_sym
);
4946 /* Do the same for any contained procedures. */
4947 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
4952 parse_contained (int module
)
4954 gfc_namespace
*ns
, *parent_ns
, *tmp
;
4955 gfc_state_data s1
, s2
;
4959 int contains_statements
= 0;
4962 push_state (&s1
, COMP_CONTAINS
, NULL
);
4963 parent_ns
= gfc_current_ns
;
4967 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
4969 gfc_current_ns
->sibling
= parent_ns
->contained
;
4970 parent_ns
->contained
= gfc_current_ns
;
4973 /* Process the next available statement. We come here if we got an error
4974 and rejected the last statement. */
4975 st
= next_statement ();
4984 contains_statements
= 1;
4985 accept_statement (st
);
4988 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
4991 /* For internal procedures, create/update the symbol in the
4992 parent namespace. */
4996 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
4997 gfc_error ("Contained procedure %qs at %C is already "
4998 "ambiguous", gfc_new_block
->name
);
5001 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
5003 &gfc_new_block
->declared_at
))
5005 if (st
== ST_FUNCTION
)
5006 gfc_add_function (&sym
->attr
, sym
->name
,
5007 &gfc_new_block
->declared_at
);
5009 gfc_add_subroutine (&sym
->attr
, sym
->name
,
5010 &gfc_new_block
->declared_at
);
5014 gfc_commit_symbols ();
5017 sym
= gfc_new_block
;
5019 /* Mark this as a contained function, so it isn't replaced
5020 by other module functions. */
5021 sym
->attr
.contained
= 1;
5023 /* Set implicit_pure so that it can be reset if any of the
5024 tests for purity fail. This is used for some optimisation
5025 during translation. */
5026 if (!sym
->attr
.pure
)
5027 sym
->attr
.implicit_pure
= 1;
5029 parse_progunit (ST_NONE
);
5031 /* Fix up any sibling functions that refer to this one. */
5032 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
5033 /* Or refer to any of its alternate entry points. */
5034 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
5035 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
5037 gfc_current_ns
->code
= s2
.head
;
5038 gfc_current_ns
= parent_ns
;
5043 /* These statements are associated with the end of the host unit. */
5044 case ST_END_FUNCTION
:
5046 case ST_END_SUBMODULE
:
5047 case ST_END_PROGRAM
:
5048 case ST_END_SUBROUTINE
:
5049 accept_statement (st
);
5050 gfc_current_ns
->code
= s1
.head
;
5054 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
5055 gfc_ascii_statement (st
));
5056 reject_statement ();
5062 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
5063 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
5064 && st
!= ST_END_PROGRAM
);
5066 /* The first namespace in the list is guaranteed to not have
5067 anything (worthwhile) in it. */
5068 tmp
= gfc_current_ns
;
5069 gfc_current_ns
= parent_ns
;
5070 if (seen_error
&& tmp
->refs
> 1)
5071 gfc_free_namespace (tmp
);
5073 ns
= gfc_current_ns
->contained
;
5074 gfc_current_ns
->contained
= ns
->sibling
;
5075 gfc_free_namespace (ns
);
5078 if (!contains_statements
)
5079 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
5080 "FUNCTION or SUBROUTINE statement at %C");
5084 /* The result variable in a MODULE PROCEDURE needs to be created and
5085 its characteristics copied from the interface since it is neither
5086 declared in the procedure declaration nor in the specification
5090 get_modproc_result (void)
5093 if (gfc_state_stack
->previous
5094 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
5095 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
5097 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
5099 && proc
->attr
.function
5100 && proc
->ts
.interface
5101 && proc
->ts
.interface
->result
5102 && proc
->ts
.interface
->result
!= proc
->ts
.interface
)
5104 gfc_copy_dummy_sym (&proc
->result
, proc
->ts
.interface
->result
, 1);
5105 gfc_set_sym_referenced (proc
->result
);
5106 proc
->result
->attr
.if_source
= IFSRC_DECL
;
5107 gfc_commit_symbol (proc
->result
);
5113 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
5116 parse_progunit (gfc_statement st
)
5122 && gfc_new_block
->abr_modproc_decl
5123 && gfc_new_block
->attr
.function
)
5124 get_modproc_result ();
5126 st
= parse_spec (st
);
5133 /* This is not allowed within BLOCK! */
5134 if (gfc_current_state () != COMP_BLOCK
)
5139 accept_statement (st
);
5146 if (gfc_current_state () == COMP_FUNCTION
)
5147 gfc_check_function_type (gfc_current_ns
);
5152 st
= parse_executable (st
);
5160 /* This is not allowed within BLOCK! */
5161 if (gfc_current_state () != COMP_BLOCK
)
5166 accept_statement (st
);
5173 unexpected_statement (st
);
5174 reject_statement ();
5175 st
= next_statement ();
5181 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
5182 if (p
->state
== COMP_CONTAINS
)
5185 if (gfc_find_state (COMP_MODULE
) == true
5186 || gfc_find_state (COMP_SUBMODULE
) == true)
5191 gfc_error ("CONTAINS statement at %C is already in a contained "
5193 reject_statement ();
5194 st
= next_statement ();
5198 parse_contained (0);
5201 gfc_current_ns
->code
= gfc_state_stack
->head
;
5205 /* Come here to complain about a global symbol already in use as
5209 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
5214 where
= &gfc_current_locus
;
5224 case GSYM_SUBROUTINE
:
5225 name
= "SUBROUTINE";
5230 case GSYM_BLOCK_DATA
:
5231 name
= "BLOCK DATA";
5237 gfc_internal_error ("gfc_global_used(): Bad type");
5241 if (sym
->binding_label
)
5242 gfc_error ("Global binding name %qs at %L is already being used as a %s "
5243 "at %L", sym
->binding_label
, where
, name
, &sym
->where
);
5245 gfc_error ("Global name %qs at %L is already being used as a %s at %L",
5246 sym
->name
, where
, name
, &sym
->where
);
5250 /* Parse a block data program unit. */
5253 parse_block_data (void)
5256 static locus blank_locus
;
5257 static int blank_block
=0;
5260 gfc_current_ns
->proc_name
= gfc_new_block
;
5261 gfc_current_ns
->is_block_data
= 1;
5263 if (gfc_new_block
== NULL
)
5266 gfc_error ("Blank BLOCK DATA at %C conflicts with "
5267 "prior BLOCK DATA at %L", &blank_locus
);
5271 blank_locus
= gfc_current_locus
;
5276 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5278 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
5279 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5282 s
->type
= GSYM_BLOCK_DATA
;
5283 s
->where
= gfc_new_block
->declared_at
;
5288 st
= parse_spec (ST_NONE
);
5290 while (st
!= ST_END_BLOCK_DATA
)
5292 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
5293 gfc_ascii_statement (st
));
5294 reject_statement ();
5295 st
= next_statement ();
5300 /* Following the association of the ancestor (sub)module symbols, they
5301 must be set host rather than use associated and all must be public.
5302 They are flagged up by 'used_in_submodule' so that they can be set
5303 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
5304 linker chokes on multiple symbol definitions. */
5307 set_syms_host_assoc (gfc_symbol
*sym
)
5314 if (sym
->attr
.module_procedure
)
5315 sym
->attr
.external
= 0;
5317 /* sym->attr.access = ACCESS_PUBLIC; */
5319 sym
->attr
.use_assoc
= 0;
5320 sym
->attr
.host_assoc
= 1;
5321 sym
->attr
.used_in_submodule
=1;
5323 if (sym
->attr
.flavor
== FL_DERIVED
)
5325 for (c
= sym
->components
; c
; c
= c
->next
)
5326 c
->attr
.access
= ACCESS_PUBLIC
;
5330 /* Parse a module subprogram. */
5339 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5340 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
5341 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5344 s
->type
= GSYM_MODULE
;
5345 s
->where
= gfc_new_block
->declared_at
;
5349 /* Something is nulling the module_list after this point. This is good
5350 since it allows us to 'USE' the parent modules that the submodule
5351 inherits and to set (most) of the symbols as host associated. */
5352 if (gfc_current_state () == COMP_SUBMODULE
)
5355 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
5358 st
= parse_spec (ST_NONE
);
5368 parse_contained (1);
5372 case ST_END_SUBMODULE
:
5373 accept_statement (st
);
5377 gfc_error ("Unexpected %s statement in MODULE at %C",
5378 gfc_ascii_statement (st
));
5381 reject_statement ();
5382 st
= next_statement ();
5386 /* Make sure not to free the namespace twice on error. */
5388 s
->ns
= gfc_current_ns
;
5392 /* Add a procedure name to the global symbol table. */
5395 add_global_procedure (bool sub
)
5399 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
5400 name is a global identifier. */
5401 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
5403 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5406 || (s
->type
!= GSYM_UNKNOWN
5407 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5409 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5410 /* Silence follow-up errors. */
5411 gfc_new_block
->binding_label
= NULL
;
5415 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5416 s
->sym_name
= gfc_new_block
->name
;
5417 s
->where
= gfc_new_block
->declared_at
;
5419 s
->ns
= gfc_current_ns
;
5423 /* Don't add the symbol multiple times. */
5424 if (gfc_new_block
->binding_label
5425 && (!gfc_notification_std (GFC_STD_F2008
)
5426 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
5428 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
);
5431 || (s
->type
!= GSYM_UNKNOWN
5432 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5434 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5435 /* Silence follow-up errors. */
5436 gfc_new_block
->binding_label
= NULL
;
5440 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5441 s
->sym_name
= gfc_new_block
->name
;
5442 s
->binding_label
= gfc_new_block
->binding_label
;
5443 s
->where
= gfc_new_block
->declared_at
;
5445 s
->ns
= gfc_current_ns
;
5451 /* Add a program to the global symbol table. */
5454 add_global_program (void)
5458 if (gfc_new_block
== NULL
)
5460 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5462 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
5463 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5466 s
->type
= GSYM_PROGRAM
;
5467 s
->where
= gfc_new_block
->declared_at
;
5469 s
->ns
= gfc_current_ns
;
5474 /* Resolve all the program units. */
5476 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
5478 gfc_free_dt_list ();
5479 gfc_current_ns
= gfc_global_ns_list
;
5480 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5482 if (gfc_current_ns
->proc_name
5483 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5484 continue; /* Already resolved. */
5486 if (gfc_current_ns
->proc_name
)
5487 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5488 gfc_resolve (gfc_current_ns
);
5489 gfc_current_ns
->derived_types
= gfc_derived_types
;
5490 gfc_derived_types
= NULL
;
5496 clean_up_modules (gfc_gsymbol
*gsym
)
5501 clean_up_modules (gsym
->left
);
5502 clean_up_modules (gsym
->right
);
5504 if (gsym
->type
!= GSYM_MODULE
|| !gsym
->ns
)
5507 gfc_current_ns
= gsym
->ns
;
5508 gfc_derived_types
= gfc_current_ns
->derived_types
;
5515 /* Translate all the program units. This could be in a different order
5516 to resolution if there are forward references in the file. */
5518 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
5522 gfc_current_ns
= gfc_global_ns_list
;
5523 gfc_get_errors (NULL
, &errors
);
5525 /* We first translate all modules to make sure that later parts
5526 of the program can use the decl. Then we translate the nonmodules. */
5528 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5530 if (!gfc_current_ns
->proc_name
5531 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
5534 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5535 gfc_derived_types
= gfc_current_ns
->derived_types
;
5536 gfc_generate_module_code (gfc_current_ns
);
5537 gfc_current_ns
->translated
= 1;
5540 gfc_current_ns
= gfc_global_ns_list
;
5541 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5543 if (gfc_current_ns
->proc_name
5544 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5547 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5548 gfc_derived_types
= gfc_current_ns
->derived_types
;
5549 gfc_generate_code (gfc_current_ns
);
5550 gfc_current_ns
->translated
= 1;
5553 /* Clean up all the namespaces after translation. */
5554 gfc_current_ns
= gfc_global_ns_list
;
5555 for (;gfc_current_ns
;)
5559 if (gfc_current_ns
->proc_name
5560 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5562 gfc_current_ns
= gfc_current_ns
->sibling
;
5566 ns
= gfc_current_ns
->sibling
;
5567 gfc_derived_types
= gfc_current_ns
->derived_types
;
5569 gfc_current_ns
= ns
;
5572 clean_up_modules (gfc_gsym_root
);
5576 /* Top level parser. */
5579 gfc_parse_file (void)
5581 int seen_program
, errors_before
, errors
;
5582 gfc_state_data top
, s
;
5585 gfc_namespace
*next
;
5587 gfc_start_source_files ();
5589 top
.state
= COMP_NONE
;
5591 top
.previous
= NULL
;
5592 top
.head
= top
.tail
= NULL
;
5593 top
.do_variable
= NULL
;
5595 gfc_state_stack
= &top
;
5597 gfc_clear_new_st ();
5599 gfc_statement_label
= NULL
;
5601 if (setjmp (eof_buf
))
5602 return false; /* Come here on unexpected EOF */
5604 /* Prepare the global namespace that will contain the
5606 gfc_global_ns_list
= next
= NULL
;
5611 /* Exit early for empty files. */
5615 in_specification_block
= true;
5618 st
= next_statement ();
5627 goto duplicate_main
;
5629 prog_locus
= gfc_current_locus
;
5631 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
5632 main_program_symbol(gfc_current_ns
, gfc_new_block
->name
);
5633 accept_statement (st
);
5634 add_global_program ();
5635 parse_progunit (ST_NONE
);
5640 add_global_procedure (true);
5641 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
5642 accept_statement (st
);
5643 parse_progunit (ST_NONE
);
5648 add_global_procedure (false);
5649 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
5650 accept_statement (st
);
5651 parse_progunit (ST_NONE
);
5656 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
5657 accept_statement (st
);
5658 parse_block_data ();
5662 push_state (&s
, COMP_MODULE
, gfc_new_block
);
5663 accept_statement (st
);
5665 gfc_get_errors (NULL
, &errors_before
);
5670 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
5671 accept_statement (st
);
5673 gfc_get_errors (NULL
, &errors_before
);
5677 /* Anything else starts a nameless main program block. */
5680 goto duplicate_main
;
5682 prog_locus
= gfc_current_locus
;
5684 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
5685 main_program_symbol (gfc_current_ns
, "MAIN__");
5686 parse_progunit (st
);
5691 /* Handle the non-program units. */
5692 gfc_current_ns
->code
= s
.head
;
5694 gfc_resolve (gfc_current_ns
);
5696 /* Dump the parse tree if requested. */
5697 if (flag_dump_fortran_original
)
5698 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
5700 gfc_get_errors (NULL
, &errors
);
5701 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
5703 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
5704 gfc_current_ns
->derived_types
= gfc_derived_types
;
5705 gfc_derived_types
= NULL
;
5711 gfc_generate_code (gfc_current_ns
);
5719 /* The main program and non-contained procedures are put
5720 in the global namespace list, so that they can be processed
5721 later and all their interfaces resolved. */
5722 gfc_current_ns
->code
= s
.head
;
5725 for (; next
->sibling
; next
= next
->sibling
)
5727 next
->sibling
= gfc_current_ns
;
5730 gfc_global_ns_list
= gfc_current_ns
;
5732 next
= gfc_current_ns
;
5739 /* Do the resolution. */
5740 resolve_all_program_units (gfc_global_ns_list
);
5742 /* Do the parse tree dump. */
5744 = flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
5746 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5747 if (!gfc_current_ns
->proc_name
5748 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
5750 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
5751 fputs ("------------------------------------------\n\n", stdout
);
5754 /* Do the translation. */
5755 translate_all_program_units (gfc_global_ns_list
);
5757 gfc_end_source_files ();
5761 /* If we see a duplicate main program, shut down. If the second
5762 instance is an implied main program, i.e. data decls or executable
5763 statements, we're in for lots of errors. */
5764 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
5765 reject_statement ();
5770 /* Return true if this state data represents an OpenACC region. */
5772 is_oacc (gfc_state_data
*sd
)
5774 switch (sd
->construct
->op
)
5776 case EXEC_OACC_PARALLEL_LOOP
:
5777 case EXEC_OACC_PARALLEL
:
5778 case EXEC_OACC_KERNELS_LOOP
:
5779 case EXEC_OACC_KERNELS
:
5780 case EXEC_OACC_DATA
:
5781 case EXEC_OACC_HOST_DATA
:
5782 case EXEC_OACC_LOOP
:
5783 case EXEC_OACC_UPDATE
:
5784 case EXEC_OACC_WAIT
:
5785 case EXEC_OACC_CACHE
:
5786 case EXEC_OACC_ENTER_DATA
:
5787 case EXEC_OACC_EXIT_DATA
:
5788 case EXEC_OACC_ATOMIC
: