2 Copyright (C) 2000-2018 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_equiv
= gfc_current_ns
->equiv
;
120 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
121 last_was_use_stmt
= false;
125 /* Figure out what the next statement is, (mostly) regardless of
126 proper ordering. The do...while(0) is there to prevent if/else
129 #define match(keyword, subr, st) \
131 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
134 undo_new_statement (); \
138 /* This is a specialist version of decode_statement that is used
139 for the specification statements in a function, whose
140 characteristics are deferred into the specification statements.
141 eg.: INTEGER (king = mykind) foo ()
142 USE mymodule, ONLY mykind.....
143 The KIND parameter needs a return after USE or IMPORT, whereas
144 derived type declarations can occur anywhere, up the executable
145 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
146 out of the correct kind of specification statements. */
148 decode_specification_statement (void)
154 if (gfc_match_eos () == MATCH_YES
)
157 old_locus
= gfc_current_locus
;
159 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
161 last_was_use_stmt
= true;
166 undo_new_statement ();
167 if (last_was_use_stmt
)
171 match ("import", gfc_match_import
, ST_IMPORT
);
173 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
176 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
177 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
178 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
180 /* General statement matching: Instead of testing every possible
181 statement, we eliminate most possibilities by peeking at the
184 c
= gfc_peek_ascii_char ();
189 match ("abstract% interface", gfc_match_abstract_interface
,
191 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
192 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
193 match ("automatic", gfc_match_automatic
, 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
);
259 match ("static", gfc_match_static
, ST_ATTR_DECL
);
260 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
264 match ("target", gfc_match_target
, ST_ATTR_DECL
);
265 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
272 match ("value", gfc_match_value
, ST_ATTR_DECL
);
273 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
280 /* This is not a specification statement. See if any of the matchers
281 has stored an error message of some sort. */
285 gfc_buffer_error (false);
286 gfc_current_locus
= old_locus
;
288 return ST_GET_FCN_CHARACTERISTICS
;
291 static bool in_specification_block
;
293 /* This is the primary 'decode_statement'. */
295 decode_statement (void)
302 gfc_enforce_clean_symbol_state ();
304 gfc_clear_error (); /* Clear any pending errors. */
305 gfc_clear_warning (); /* Clear any pending warnings. */
307 gfc_matching_function
= false;
309 if (gfc_match_eos () == MATCH_YES
)
312 if (gfc_current_state () == COMP_FUNCTION
313 && gfc_current_block ()->result
->ts
.kind
== -1)
314 return decode_specification_statement ();
316 old_locus
= gfc_current_locus
;
318 c
= gfc_peek_ascii_char ();
322 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
324 last_was_use_stmt
= true;
328 undo_new_statement ();
331 if (last_was_use_stmt
)
334 /* Try matching a data declaration or function declaration. The
335 input "REALFUNCTIONA(N)" can mean several things in different
336 contexts, so it (and its relatives) get special treatment. */
338 if (gfc_current_state () == COMP_NONE
339 || gfc_current_state () == COMP_INTERFACE
340 || gfc_current_state () == COMP_CONTAINS
)
342 gfc_matching_function
= true;
343 m
= gfc_match_function_decl ();
346 else if (m
== MATCH_ERROR
)
350 gfc_current_locus
= old_locus
;
352 gfc_matching_function
= false;
354 /* Legacy parameter statements are ambiguous with assignments so try parameter
356 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
358 /* Match statements whose error messages are meant to be overwritten
359 by something better. */
361 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
362 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
364 if (in_specification_block
)
366 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
368 return ST_STATEMENT_FUNCTION
;
371 if (!(in_specification_block
&& m
== MATCH_ERROR
))
373 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
376 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
377 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
379 /* Try to match a subroutine statement, which has the same optional
380 prefixes that functions can have. */
382 if (gfc_match_subroutine () == MATCH_YES
)
383 return ST_SUBROUTINE
;
385 gfc_current_locus
= old_locus
;
387 if (gfc_match_submod_proc () == MATCH_YES
)
389 if (gfc_new_block
->attr
.subroutine
)
390 return ST_SUBROUTINE
;
391 else if (gfc_new_block
->attr
.function
)
395 gfc_current_locus
= old_locus
;
397 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
398 statements, which might begin with a block label. The match functions for
399 these statements are unusual in that their keyword is not seen before
400 the matcher is called. */
402 if (gfc_match_if (&st
) == MATCH_YES
)
405 gfc_current_locus
= old_locus
;
407 if (gfc_match_where (&st
) == MATCH_YES
)
410 gfc_current_locus
= old_locus
;
412 if (gfc_match_forall (&st
) == MATCH_YES
)
415 gfc_current_locus
= old_locus
;
417 /* Try to match TYPE as an alias for PRINT. */
418 if (gfc_match_type (&st
) == MATCH_YES
)
421 gfc_current_locus
= old_locus
;
423 match (NULL
, gfc_match_do
, ST_DO
);
424 match (NULL
, gfc_match_block
, ST_BLOCK
);
425 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
426 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
427 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
428 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
430 /* General statement matching: Instead of testing every possible
431 statement, we eliminate most possibilities by peeking at the
437 match ("abstract% interface", gfc_match_abstract_interface
,
439 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
440 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
441 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
442 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
443 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
447 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
448 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
449 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
453 match ("call", gfc_match_call
, ST_CALL
);
454 match ("change team", gfc_match_change_team
, ST_CHANGE_TEAM
);
455 match ("close", gfc_match_close
, ST_CLOSE
);
456 match ("continue", gfc_match_continue
, ST_CONTINUE
);
457 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
458 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
459 match ("case", gfc_match_case
, ST_CASE
);
460 match ("common", gfc_match_common
, ST_COMMON
);
461 match ("contains", gfc_match_eos
, ST_CONTAINS
);
462 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
463 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
467 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
468 match ("data", gfc_match_data
, ST_DATA
);
469 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
473 match ("end file", gfc_match_endfile
, ST_END_FILE
);
474 match ("end team", gfc_match_end_team
, ST_END_TEAM
);
475 match ("exit", gfc_match_exit
, ST_EXIT
);
476 match ("else", gfc_match_else
, ST_ELSE
);
477 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
478 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
479 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
);
480 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
482 if (gfc_match_end (&st
) == MATCH_YES
)
485 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
486 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
487 match ("external", gfc_match_external
, ST_ATTR_DECL
);
488 match ("event post", gfc_match_event_post
, ST_EVENT_POST
);
489 match ("event wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
493 match ("fail image", gfc_match_fail_image
, ST_FAIL_IMAGE
);
494 match ("final", gfc_match_final_decl
, ST_FINAL
);
495 match ("flush", gfc_match_flush
, ST_FLUSH
);
496 match ("form team", gfc_match_form_team
, ST_FORM_TEAM
);
497 match ("format", gfc_match_format
, ST_FORMAT
);
501 match ("generic", gfc_match_generic
, ST_GENERIC
);
502 match ("go to", gfc_match_goto
, ST_GOTO
);
506 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
507 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
508 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
509 match ("import", gfc_match_import
, ST_IMPORT
);
510 match ("interface", gfc_match_interface
, ST_INTERFACE
);
511 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
512 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
516 match ("lock", gfc_match_lock
, ST_LOCK
);
520 match ("map", gfc_match_map
, ST_MAP
);
521 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
522 match ("module", gfc_match_module
, ST_MODULE
);
526 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
527 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
531 match ("open", gfc_match_open
, ST_OPEN
);
532 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
536 match ("print", gfc_match_print
, ST_WRITE
);
537 match ("pause", gfc_match_pause
, ST_PAUSE
);
538 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
539 if (gfc_match_private (&st
) == MATCH_YES
)
541 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
542 match ("program", gfc_match_program
, ST_PROGRAM
);
543 if (gfc_match_public (&st
) == MATCH_YES
)
545 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
549 match ("read", gfc_match_read
, ST_READ
);
550 match ("return", gfc_match_return
, ST_RETURN
);
551 match ("rewind", gfc_match_rewind
, ST_REWIND
);
555 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
556 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
557 match ("stop", gfc_match_stop
, ST_STOP
);
558 match ("save", gfc_match_save
, ST_ATTR_DECL
);
559 match ("static", gfc_match_static
, ST_ATTR_DECL
);
560 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
561 match ("sync all", gfc_match_sync_all
, ST_SYNC_ALL
);
562 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
563 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
564 match ("sync team", gfc_match_sync_team
, ST_SYNC_TEAM
);
568 match ("target", gfc_match_target
, ST_ATTR_DECL
);
569 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
570 match ("type is", gfc_match_type_is
, ST_TYPE_IS
);
574 match ("union", gfc_match_union
, ST_UNION
);
575 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
579 match ("value", gfc_match_value
, ST_ATTR_DECL
);
580 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
584 match ("wait", gfc_match_wait
, ST_WAIT
);
585 match ("write", gfc_match_write
, ST_WRITE
);
589 /* All else has failed, so give up. See if any of the matchers has
590 stored an error message of some sort. */
592 if (!gfc_error_check ())
593 gfc_error_now ("Unclassifiable statement at %C");
597 gfc_error_recovery ();
602 /* Like match and if spec_only, goto do_spec_only without actually
604 #define matcha(keyword, subr, st) \
606 if (spec_only && gfc_match (keyword) == MATCH_YES) \
608 else if (match_word (keyword, subr, &old_locus) \
612 undo_new_statement (); \
616 decode_oacc_directive (void)
620 bool spec_only
= false;
622 gfc_enforce_clean_symbol_state ();
624 gfc_clear_error (); /* Clear any pending errors. */
625 gfc_clear_warning (); /* Clear any pending warnings. */
627 gfc_matching_function
= false;
631 gfc_error_now ("OpenACC directives at %C may not appear in PURE "
633 gfc_error_recovery ();
637 if (gfc_current_state () == COMP_FUNCTION
638 && gfc_current_block ()->result
->ts
.kind
== -1)
641 gfc_unset_implicit_pure (NULL
);
643 old_locus
= gfc_current_locus
;
645 /* General OpenACC directive matching: Instead of testing every possible
646 statement, we eliminate most possibilities by peeking at the
649 c
= gfc_peek_ascii_char ();
654 matcha ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
657 matcha ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
660 matcha ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
661 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
664 matcha ("end atomic", gfc_match_omp_eos
, ST_OACC_END_ATOMIC
);
665 matcha ("end data", gfc_match_omp_eos
, ST_OACC_END_DATA
);
666 matcha ("end host_data", gfc_match_omp_eos
, ST_OACC_END_HOST_DATA
);
667 matcha ("end kernels loop", gfc_match_omp_eos
, ST_OACC_END_KERNELS_LOOP
);
668 matcha ("end kernels", gfc_match_omp_eos
, ST_OACC_END_KERNELS
);
669 matcha ("end loop", gfc_match_omp_eos
, ST_OACC_END_LOOP
);
670 matcha ("end parallel loop", gfc_match_omp_eos
,
671 ST_OACC_END_PARALLEL_LOOP
);
672 matcha ("end parallel", gfc_match_omp_eos
, ST_OACC_END_PARALLEL
);
673 matcha ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
674 matcha ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
677 matcha ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
680 matcha ("parallel loop", gfc_match_oacc_parallel_loop
,
681 ST_OACC_PARALLEL_LOOP
);
682 matcha ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
685 matcha ("kernels loop", gfc_match_oacc_kernels_loop
,
686 ST_OACC_KERNELS_LOOP
);
687 matcha ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
690 matcha ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
693 match ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
696 matcha ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
699 matcha ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
703 /* Directive not found or stored an error message.
704 Check and give up. */
706 if (gfc_error_check () == 0)
707 gfc_error_now ("Unclassifiable OpenACC directive at %C");
711 gfc_error_recovery ();
718 gfc_buffer_error (false);
719 gfc_current_locus
= old_locus
;
720 return ST_GET_FCN_CHARACTERISTICS
;
723 /* Like match, but set a flag simd_matched if keyword matched
724 and if spec_only, goto do_spec_only without actually matching. */
725 #define matchs(keyword, subr, st) \
727 if (spec_only && gfc_match (keyword) == MATCH_YES) \
729 if (match_word_omp_simd (keyword, subr, &old_locus, \
730 &simd_matched) == MATCH_YES) \
736 undo_new_statement (); \
739 /* Like match, but don't match anything if not -fopenmp
740 and if spec_only, goto do_spec_only without actually matching. */
741 #define matcho(keyword, subr, st) \
745 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
747 else if (match_word (keyword, subr, &old_locus) \
754 undo_new_statement (); \
757 /* Like match, but set a flag simd_matched if keyword matched. */
758 #define matchds(keyword, subr, st) \
760 if (match_word_omp_simd (keyword, subr, &old_locus, \
761 &simd_matched) == MATCH_YES) \
767 undo_new_statement (); \
770 /* Like match, but don't match anything if not -fopenmp. */
771 #define matchdo(keyword, subr, st) \
775 else if (match_word (keyword, subr, &old_locus) \
782 undo_new_statement (); \
786 decode_omp_directive (void)
790 bool simd_matched
= false;
791 bool spec_only
= false;
792 gfc_statement ret
= ST_NONE
;
795 gfc_enforce_clean_symbol_state ();
797 gfc_clear_error (); /* Clear any pending errors. */
798 gfc_clear_warning (); /* Clear any pending warnings. */
800 gfc_matching_function
= false;
802 if (gfc_current_state () == COMP_FUNCTION
803 && gfc_current_block ()->result
->ts
.kind
== -1)
806 old_locus
= gfc_current_locus
;
808 /* General OpenMP directive matching: Instead of testing every possible
809 statement, we eliminate most possibilities by peeking at the
812 c
= gfc_peek_ascii_char ();
814 /* match is for directives that should be recognized only if
815 -fopenmp, matchs for directives that should be recognized
816 if either -fopenmp or -fopenmp-simd.
817 Handle only the directives allowed in PURE/ELEMENTAL procedures
818 first (those also shall not turn off implicit pure). */
822 matchds ("declare simd", gfc_match_omp_declare_simd
,
823 ST_OMP_DECLARE_SIMD
);
824 matchdo ("declare target", gfc_match_omp_declare_target
,
825 ST_OMP_DECLARE_TARGET
);
828 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
833 if (flag_openmp
&& gfc_pure (NULL
))
835 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
836 "at %C may not appear in PURE or ELEMENTAL procedures");
837 gfc_error_recovery ();
841 /* match is for directives that should be recognized only if
842 -fopenmp, matchs for directives that should be recognized
843 if either -fopenmp or -fopenmp-simd. */
847 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
850 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
853 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
854 ST_OMP_CANCELLATION_POINT
);
855 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
856 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
859 matchds ("declare reduction", gfc_match_omp_declare_reduction
,
860 ST_OMP_DECLARE_REDUCTION
);
861 matchs ("distribute parallel do simd",
862 gfc_match_omp_distribute_parallel_do_simd
,
863 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
864 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
865 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
866 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
867 ST_OMP_DISTRIBUTE_SIMD
);
868 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
869 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
870 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
873 matcho ("end atomic", gfc_match_omp_eos
, ST_OMP_END_ATOMIC
);
874 matcho ("end critical", gfc_match_omp_end_critical
, ST_OMP_END_CRITICAL
);
875 matchs ("end distribute parallel do simd", gfc_match_omp_eos
,
876 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
877 matcho ("end distribute parallel do", gfc_match_omp_eos
,
878 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
879 matchs ("end distribute simd", gfc_match_omp_eos
,
880 ST_OMP_END_DISTRIBUTE_SIMD
);
881 matcho ("end distribute", gfc_match_omp_eos
, ST_OMP_END_DISTRIBUTE
);
882 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
883 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
884 matchs ("end simd", gfc_match_omp_eos
, ST_OMP_END_SIMD
);
885 matcho ("end master", gfc_match_omp_eos
, ST_OMP_END_MASTER
);
886 matchs ("end ordered", gfc_match_omp_eos
, ST_OMP_END_ORDERED
);
887 matchs ("end parallel do simd", gfc_match_omp_eos
,
888 ST_OMP_END_PARALLEL_DO_SIMD
);
889 matcho ("end parallel do", gfc_match_omp_eos
, ST_OMP_END_PARALLEL_DO
);
890 matcho ("end parallel sections", gfc_match_omp_eos
,
891 ST_OMP_END_PARALLEL_SECTIONS
);
892 matcho ("end parallel workshare", gfc_match_omp_eos
,
893 ST_OMP_END_PARALLEL_WORKSHARE
);
894 matcho ("end parallel", gfc_match_omp_eos
, ST_OMP_END_PARALLEL
);
895 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
896 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
897 matcho ("end target data", gfc_match_omp_eos
, ST_OMP_END_TARGET_DATA
);
898 matchs ("end target parallel do simd", gfc_match_omp_eos
,
899 ST_OMP_END_TARGET_PARALLEL_DO_SIMD
);
900 matcho ("end target parallel do", gfc_match_omp_eos
,
901 ST_OMP_END_TARGET_PARALLEL_DO
);
902 matcho ("end target parallel", gfc_match_omp_eos
,
903 ST_OMP_END_TARGET_PARALLEL
);
904 matchs ("end target simd", gfc_match_omp_eos
, ST_OMP_END_TARGET_SIMD
);
905 matchs ("end target teams distribute parallel do simd",
907 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
908 matcho ("end target teams distribute parallel do", gfc_match_omp_eos
,
909 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
910 matchs ("end target teams distribute simd", gfc_match_omp_eos
,
911 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
912 matcho ("end target teams distribute", gfc_match_omp_eos
,
913 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
914 matcho ("end target teams", gfc_match_omp_eos
, ST_OMP_END_TARGET_TEAMS
);
915 matcho ("end target", gfc_match_omp_eos
, ST_OMP_END_TARGET
);
916 matcho ("end taskgroup", gfc_match_omp_eos
, ST_OMP_END_TASKGROUP
);
917 matchs ("end taskloop simd", gfc_match_omp_eos
,
918 ST_OMP_END_TASKLOOP_SIMD
);
919 matcho ("end taskloop", gfc_match_omp_eos
, ST_OMP_END_TASKLOOP
);
920 matcho ("end task", gfc_match_omp_eos
, ST_OMP_END_TASK
);
921 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos
,
922 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
923 matcho ("end teams distribute parallel do", gfc_match_omp_eos
,
924 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
925 matchs ("end teams distribute simd", gfc_match_omp_eos
,
926 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
927 matcho ("end teams distribute", gfc_match_omp_eos
,
928 ST_OMP_END_TEAMS_DISTRIBUTE
);
929 matcho ("end teams", gfc_match_omp_eos
, ST_OMP_END_TEAMS
);
930 matcho ("end workshare", gfc_match_omp_end_nowait
,
931 ST_OMP_END_WORKSHARE
);
934 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
937 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
940 if (gfc_match ("ordered depend (") == MATCH_YES
)
942 gfc_current_locus
= old_locus
;
945 matcho ("ordered", gfc_match_omp_ordered_depend
,
946 ST_OMP_ORDERED_DEPEND
);
949 matchs ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
952 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
953 ST_OMP_PARALLEL_DO_SIMD
);
954 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
955 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
956 ST_OMP_PARALLEL_SECTIONS
);
957 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
958 ST_OMP_PARALLEL_WORKSHARE
);
959 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
962 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
963 matcho ("section", gfc_match_omp_eos
, ST_OMP_SECTION
);
964 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
967 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
968 matcho ("target enter data", gfc_match_omp_target_enter_data
,
969 ST_OMP_TARGET_ENTER_DATA
);
970 matcho ("target exit data", gfc_match_omp_target_exit_data
,
971 ST_OMP_TARGET_EXIT_DATA
);
972 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd
,
973 ST_OMP_TARGET_PARALLEL_DO_SIMD
);
974 matcho ("target parallel do", gfc_match_omp_target_parallel_do
,
975 ST_OMP_TARGET_PARALLEL_DO
);
976 matcho ("target parallel", gfc_match_omp_target_parallel
,
977 ST_OMP_TARGET_PARALLEL
);
978 matchs ("target simd", gfc_match_omp_target_simd
, ST_OMP_TARGET_SIMD
);
979 matchs ("target teams distribute parallel do simd",
980 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
981 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
982 matcho ("target teams distribute parallel do",
983 gfc_match_omp_target_teams_distribute_parallel_do
,
984 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
985 matchs ("target teams distribute simd",
986 gfc_match_omp_target_teams_distribute_simd
,
987 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
988 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
989 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
990 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
991 matcho ("target update", gfc_match_omp_target_update
,
992 ST_OMP_TARGET_UPDATE
);
993 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
994 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
995 matchs ("taskloop simd", gfc_match_omp_taskloop_simd
,
996 ST_OMP_TASKLOOP_SIMD
);
997 matcho ("taskloop", gfc_match_omp_taskloop
, ST_OMP_TASKLOOP
);
998 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
999 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
1000 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
1001 matchs ("teams distribute parallel do simd",
1002 gfc_match_omp_teams_distribute_parallel_do_simd
,
1003 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1004 matcho ("teams distribute parallel do",
1005 gfc_match_omp_teams_distribute_parallel_do
,
1006 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1007 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
1008 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
1009 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
1010 ST_OMP_TEAMS_DISTRIBUTE
);
1011 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
1012 matchdo ("threadprivate", gfc_match_omp_threadprivate
,
1013 ST_OMP_THREADPRIVATE
);
1016 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
1020 /* All else has failed, so give up. See if any of the matchers has
1021 stored an error message of some sort. Don't error out if
1022 not -fopenmp and simd_matched is false, i.e. if a directive other
1023 than one marked with match has been seen. */
1025 if (flag_openmp
|| simd_matched
)
1027 if (!gfc_error_check ())
1028 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1031 reject_statement ();
1033 gfc_error_recovery ();
1040 gfc_unset_implicit_pure (NULL
);
1042 if (!flag_openmp
&& gfc_pure (NULL
))
1044 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
1045 "at %C may not appear in PURE or ELEMENTAL "
1047 reject_statement ();
1048 gfc_error_recovery ();
1055 reject_statement ();
1057 gfc_buffer_error (false);
1058 gfc_current_locus
= old_locus
;
1059 return ST_GET_FCN_CHARACTERISTICS
;
1062 static gfc_statement
1063 decode_gcc_attribute (void)
1067 gfc_enforce_clean_symbol_state ();
1069 gfc_clear_error (); /* Clear any pending errors. */
1070 gfc_clear_warning (); /* Clear any pending warnings. */
1071 old_locus
= gfc_current_locus
;
1073 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1074 match ("unroll", gfc_match_gcc_unroll
, ST_NONE
);
1076 /* All else has failed, so give up. See if any of the matchers has
1077 stored an error message of some sort. */
1079 if (!gfc_error_check ())
1080 gfc_error_now ("Unclassifiable GCC directive at %C");
1082 reject_statement ();
1084 gfc_error_recovery ();
1091 /* Assert next length characters to be equal to token in free form. */
1094 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1099 c
= gfc_next_ascii_char ();
1100 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1101 gcc_assert (c
== token
[i
]);
1103 gcc_assert (gfc_is_whitespace(c
));
1104 gfc_gobble_whitespace ();
1105 if (last_was_use_stmt
)
1109 /* Get the next statement in free form source. */
1111 static gfc_statement
1118 at_bol
= gfc_at_bol ();
1119 gfc_gobble_whitespace ();
1121 c
= gfc_peek_ascii_char ();
1127 /* Found a statement label? */
1128 m
= gfc_match_st_label (&gfc_statement_label
);
1130 d
= gfc_peek_ascii_char ();
1131 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1133 gfc_match_small_literal_int (&i
, &cnt
);
1136 gfc_error_now ("Too many digits in statement label at %C");
1139 gfc_error_now ("Zero is not a valid statement label at %C");
1142 c
= gfc_next_ascii_char ();
1145 if (!gfc_is_whitespace (c
))
1146 gfc_error_now ("Non-numeric character in statement label at %C");
1152 label_locus
= gfc_current_locus
;
1154 gfc_gobble_whitespace ();
1156 if (at_bol
&& gfc_peek_ascii_char () == ';')
1158 gfc_error_now ("Semicolon at %C needs to be preceded by "
1160 gfc_next_ascii_char (); /* Eat up the semicolon. */
1164 if (gfc_match_eos () == MATCH_YES
)
1165 gfc_error_now ("Statement label without statement at %L",
1171 /* Comments have already been skipped by the time we get here,
1172 except for GCC attributes and OpenMP/OpenACC directives. */
1174 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1175 c
= gfc_peek_ascii_char ();
1181 c
= gfc_next_ascii_char ();
1182 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1183 gcc_assert (c
== "gcc$"[i
]);
1185 gfc_gobble_whitespace ();
1186 return decode_gcc_attribute ();
1191 /* Since both OpenMP and OpenACC directives starts with
1192 !$ character sequence, we must check all flags combinations */
1193 if ((flag_openmp
|| flag_openmp_simd
)
1196 verify_token_free ("$omp", 4, last_was_use_stmt
);
1197 return decode_omp_directive ();
1199 else if ((flag_openmp
|| flag_openmp_simd
)
1202 gfc_next_ascii_char (); /* Eat up dollar character */
1203 c
= gfc_peek_ascii_char ();
1207 verify_token_free ("omp", 3, last_was_use_stmt
);
1208 return decode_omp_directive ();
1212 verify_token_free ("acc", 3, last_was_use_stmt
);
1213 return decode_oacc_directive ();
1216 else if (flag_openacc
)
1218 verify_token_free ("$acc", 4, last_was_use_stmt
);
1219 return decode_oacc_directive ();
1225 if (at_bol
&& c
== ';')
1227 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1228 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1230 gfc_next_ascii_char (); /* Eat up the semicolon. */
1234 return decode_statement ();
1237 /* Assert next length characters to be equal to token in fixed form. */
1240 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1243 char c
= gfc_next_char_literal (NONSTRING
);
1245 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1246 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1248 if (c
!= ' ' && c
!= '0')
1250 gfc_buffer_error (false);
1251 gfc_error ("Bad continuation line at %C");
1254 if (last_was_use_stmt
)
1260 /* Get the next statement in fixed-form source. */
1262 static gfc_statement
1265 int label
, digit_flag
, i
;
1270 return decode_statement ();
1272 /* Skip past the current label field, parsing a statement label if
1273 one is there. This is a weird number parser, since the number is
1274 contained within five columns and can have any kind of embedded
1275 spaces. We also check for characters that make the rest of the
1281 for (i
= 0; i
< 5; i
++)
1283 c
= gfc_next_char_literal (NONSTRING
);
1300 label
= label
* 10 + ((unsigned char) c
- '0');
1301 label_locus
= gfc_current_locus
;
1305 /* Comments have already been skipped by the time we get
1306 here, except for GCC attributes and OpenMP directives. */
1309 c
= gfc_next_char_literal (NONSTRING
);
1311 if (TOLOWER (c
) == 'g')
1313 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1314 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1316 return decode_gcc_attribute ();
1320 if ((flag_openmp
|| flag_openmp_simd
)
1323 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1325 return decode_omp_directive ();
1327 else if ((flag_openmp
|| flag_openmp_simd
)
1330 c
= gfc_next_char_literal(NONSTRING
);
1331 if (c
== 'o' || c
== 'O')
1333 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1335 return decode_omp_directive ();
1337 else if (c
== 'a' || c
== 'A')
1339 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1341 return decode_oacc_directive ();
1344 else if (flag_openacc
)
1346 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1348 return decode_oacc_directive ();
1353 /* Comments have already been skipped by the time we get
1354 here so don't bother checking for them. */
1357 gfc_buffer_error (false);
1358 gfc_error ("Non-numeric character in statement label at %C");
1366 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1369 /* We've found a valid statement label. */
1370 gfc_statement_label
= gfc_get_st_label (label
);
1374 /* Since this line starts a statement, it cannot be a continuation
1375 of a previous statement. If we see something here besides a
1376 space or zero, it must be a bad continuation line. */
1378 c
= gfc_next_char_literal (NONSTRING
);
1382 if (c
!= ' ' && c
!= '0')
1384 gfc_buffer_error (false);
1385 gfc_error ("Bad continuation line at %C");
1389 /* Now that we've taken care of the statement label columns, we have
1390 to make sure that the first nonblank character is not a '!'. If
1391 it is, the rest of the line is a comment. */
1395 loc
= gfc_current_locus
;
1396 c
= gfc_next_char_literal (NONSTRING
);
1398 while (gfc_is_whitespace (c
));
1402 gfc_current_locus
= loc
;
1407 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1408 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1409 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1414 if (gfc_match_eos () == MATCH_YES
)
1417 /* At this point, we've got a nonblank statement to parse. */
1418 return decode_statement ();
1422 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1424 gfc_current_locus
.lb
->truncated
= 0;
1425 gfc_advance_line ();
1430 /* Return the next non-ST_NONE statement to the caller. We also worry
1431 about including files and the ends of include files at this stage. */
1433 static gfc_statement
1434 next_statement (void)
1439 gfc_enforce_clean_symbol_state ();
1441 gfc_new_block
= NULL
;
1443 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1444 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1447 gfc_statement_label
= NULL
;
1448 gfc_buffer_error (true);
1451 gfc_advance_line ();
1453 gfc_skip_comments ();
1461 if (gfc_define_undef_line ())
1464 old_locus
= gfc_current_locus
;
1466 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1472 gfc_buffer_error (false);
1474 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1476 if (gfc_statement_label
!= NULL
)
1478 gfc_free_st_label (gfc_statement_label
);
1479 gfc_statement_label
= NULL
;
1481 gfc_current_locus
= old_locus
;
1485 check_statement_label (st
);
1491 /****************************** Parser ***********************************/
1493 /* The parser subroutines are of type 'try' that fail if the file ends
1496 /* Macros that expand to case-labels for various classes of
1497 statements. Start with executable statements that directly do
1500 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1501 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1502 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1503 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1504 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1505 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1506 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1507 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1508 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1509 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: \
1510 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1511 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: \
1512 case ST_ERROR_STOP: case ST_SYNC_ALL: \
1513 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1514 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1515 case ST_END_TEAM: case ST_SYNC_TEAM: \
1516 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1517 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1518 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1520 /* Statements that mark other executable statements. */
1522 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1523 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1524 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1525 case ST_OMP_PARALLEL: \
1526 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1527 case ST_OMP_CRITICAL: case ST_OMP_MASTER: case ST_OMP_SINGLE: \
1528 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1529 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1530 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1531 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1532 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1533 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1534 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1535 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1536 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1537 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1538 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1539 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1540 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1541 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1542 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1543 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1544 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1546 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1547 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1548 case ST_OACC_KERNELS_LOOP: case ST_OACC_ATOMIC
1550 /* Declaration statements */
1552 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1553 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1554 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE: case ST_OACC_ROUTINE: \
1555 case ST_OACC_DECLARE
1557 /* OpenMP declaration statements. */
1559 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1560 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION
1562 /* Block end statements. Errors associated with interchanging these
1563 are detected in gfc_match_end(). */
1565 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1566 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1567 case ST_END_BLOCK: case ST_END_ASSOCIATE
1570 /* Push a new state onto the stack. */
1573 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1575 p
->state
= new_state
;
1576 p
->previous
= gfc_state_stack
;
1578 p
->head
= p
->tail
= NULL
;
1579 p
->do_variable
= NULL
;
1580 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1581 p
->ext
.oacc_declare_clauses
= NULL
;
1583 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1584 construct statement was accepted right before pushing the state. Thus,
1585 the construct's gfc_code is available as tail of the parent state. */
1586 gcc_assert (gfc_state_stack
);
1587 p
->construct
= gfc_state_stack
->tail
;
1589 gfc_state_stack
= p
;
1593 /* Pop the current state. */
1597 gfc_state_stack
= gfc_state_stack
->previous
;
1601 /* Try to find the given state in the state stack. */
1604 gfc_find_state (gfc_compile_state state
)
1608 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1609 if (p
->state
== state
)
1612 return (p
== NULL
) ? false : true;
1616 /* Starts a new level in the statement list. */
1619 new_level (gfc_code
*q
)
1623 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1625 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1631 /* Add the current new_st code structure and adds it to the current
1632 program unit. As a side-effect, it zeroes the new_st. */
1635 add_statement (void)
1639 p
= XCNEW (gfc_code
);
1642 p
->loc
= gfc_current_locus
;
1644 if (gfc_state_stack
->head
== NULL
)
1645 gfc_state_stack
->head
= p
;
1647 gfc_state_stack
->tail
->next
= p
;
1649 while (p
->next
!= NULL
)
1652 gfc_state_stack
->tail
= p
;
1654 gfc_clear_new_st ();
1660 /* Frees everything associated with the current statement. */
1663 undo_new_statement (void)
1665 gfc_free_statements (new_st
.block
);
1666 gfc_free_statements (new_st
.next
);
1667 gfc_free_statement (&new_st
);
1668 gfc_clear_new_st ();
1672 /* If the current statement has a statement label, make sure that it
1673 is allowed to, or should have one. */
1676 check_statement_label (gfc_statement st
)
1680 if (gfc_statement_label
== NULL
)
1682 if (st
== ST_FORMAT
)
1683 gfc_error ("FORMAT statement at %L does not have a statement label",
1690 case ST_END_PROGRAM
:
1691 case ST_END_FUNCTION
:
1692 case ST_END_SUBROUTINE
:
1696 case ST_END_CRITICAL
:
1698 case ST_END_ASSOCIATE
:
1701 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1702 type
= ST_LABEL_DO_TARGET
;
1704 type
= ST_LABEL_TARGET
;
1708 type
= ST_LABEL_FORMAT
;
1711 /* Statement labels are not restricted from appearing on a
1712 particular line. However, there are plenty of situations
1713 where the resulting label can't be referenced. */
1716 type
= ST_LABEL_BAD_TARGET
;
1720 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1722 new_st
.here
= gfc_statement_label
;
1726 /* Figures out what the enclosing program unit is. This will be a
1727 function, subroutine, program, block data or module. */
1730 gfc_enclosing_unit (gfc_compile_state
* result
)
1734 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1735 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1736 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1737 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1746 *result
= COMP_PROGRAM
;
1751 /* Translate a statement enum to a string. */
1754 gfc_ascii_statement (gfc_statement st
)
1760 case ST_ARITHMETIC_IF
:
1761 p
= _("arithmetic IF");
1770 p
= _("attribute declaration");
1806 p
= _("data declaration");
1820 case ST_STRUCTURE_DECL
:
1823 case ST_DERIVED_DECL
:
1824 p
= _("derived type declaration");
1847 case ST_CHANGE_TEAM
:
1859 case ST_END_ASSOCIATE
:
1860 p
= "END ASSOCIATE";
1865 case ST_END_BLOCK_DATA
:
1866 p
= "END BLOCK DATA";
1868 case ST_END_CRITICAL
:
1880 case ST_END_FUNCTION
:
1886 case ST_END_INTERFACE
:
1887 p
= "END INTERFACE";
1892 case ST_END_SUBMODULE
:
1893 p
= "END SUBMODULE";
1895 case ST_END_PROGRAM
:
1901 case ST_END_SUBROUTINE
:
1902 p
= "END SUBROUTINE";
1907 case ST_END_STRUCTURE
:
1908 p
= "END STRUCTURE";
1922 case ST_EQUIVALENCE
:
1934 case ST_FORALL_BLOCK
: /* Fall through */
1956 case ST_IMPLICIT_NONE
:
1957 p
= "IMPLICIT NONE";
1959 case ST_IMPLIED_ENDDO
:
1960 p
= _("implied END DO");
1992 case ST_MODULE_PROC
:
1993 p
= "MODULE PROCEDURE";
2025 case ST_SYNC_IMAGES
:
2028 case ST_SYNC_MEMORY
:
2043 case ST_WHERE_BLOCK
: /* Fall through */
2054 p
= _("assignment");
2056 case ST_POINTER_ASSIGNMENT
:
2057 p
= _("pointer assignment");
2059 case ST_SELECT_CASE
:
2062 case ST_SELECT_TYPE
:
2077 case ST_STATEMENT_FUNCTION
:
2078 p
= "STATEMENT FUNCTION";
2080 case ST_LABEL_ASSIGNMENT
:
2081 p
= "LABEL ASSIGNMENT";
2084 p
= "ENUM DEFINITION";
2087 p
= "ENUMERATOR DEFINITION";
2092 case ST_OACC_PARALLEL_LOOP
:
2093 p
= "!$ACC PARALLEL LOOP";
2095 case ST_OACC_END_PARALLEL_LOOP
:
2096 p
= "!$ACC END PARALLEL LOOP";
2098 case ST_OACC_PARALLEL
:
2099 p
= "!$ACC PARALLEL";
2101 case ST_OACC_END_PARALLEL
:
2102 p
= "!$ACC END PARALLEL";
2104 case ST_OACC_KERNELS
:
2105 p
= "!$ACC KERNELS";
2107 case ST_OACC_END_KERNELS
:
2108 p
= "!$ACC END KERNELS";
2110 case ST_OACC_KERNELS_LOOP
:
2111 p
= "!$ACC KERNELS LOOP";
2113 case ST_OACC_END_KERNELS_LOOP
:
2114 p
= "!$ACC END KERNELS LOOP";
2119 case ST_OACC_END_DATA
:
2120 p
= "!$ACC END DATA";
2122 case ST_OACC_HOST_DATA
:
2123 p
= "!$ACC HOST_DATA";
2125 case ST_OACC_END_HOST_DATA
:
2126 p
= "!$ACC END HOST_DATA";
2131 case ST_OACC_END_LOOP
:
2132 p
= "!$ACC END LOOP";
2134 case ST_OACC_DECLARE
:
2135 p
= "!$ACC DECLARE";
2137 case ST_OACC_UPDATE
:
2146 case ST_OACC_ENTER_DATA
:
2147 p
= "!$ACC ENTER DATA";
2149 case ST_OACC_EXIT_DATA
:
2150 p
= "!$ACC EXIT DATA";
2152 case ST_OACC_ROUTINE
:
2153 p
= "!$ACC ROUTINE";
2155 case ST_OACC_ATOMIC
:
2158 case ST_OACC_END_ATOMIC
:
2159 p
= "!$ACC END ATOMIC";
2164 case ST_OMP_BARRIER
:
2165 p
= "!$OMP BARRIER";
2170 case ST_OMP_CANCELLATION_POINT
:
2171 p
= "!$OMP CANCELLATION POINT";
2173 case ST_OMP_CRITICAL
:
2174 p
= "!$OMP CRITICAL";
2176 case ST_OMP_DECLARE_REDUCTION
:
2177 p
= "!$OMP DECLARE REDUCTION";
2179 case ST_OMP_DECLARE_SIMD
:
2180 p
= "!$OMP DECLARE SIMD";
2182 case ST_OMP_DECLARE_TARGET
:
2183 p
= "!$OMP DECLARE TARGET";
2185 case ST_OMP_DISTRIBUTE
:
2186 p
= "!$OMP DISTRIBUTE";
2188 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2189 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2191 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2192 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2194 case ST_OMP_DISTRIBUTE_SIMD
:
2195 p
= "!$OMP DISTRIBUTE SIMD";
2200 case ST_OMP_DO_SIMD
:
2201 p
= "!$OMP DO SIMD";
2203 case ST_OMP_END_ATOMIC
:
2204 p
= "!$OMP END ATOMIC";
2206 case ST_OMP_END_CRITICAL
:
2207 p
= "!$OMP END CRITICAL";
2209 case ST_OMP_END_DISTRIBUTE
:
2210 p
= "!$OMP END DISTRIBUTE";
2212 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2213 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2215 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2216 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2218 case ST_OMP_END_DISTRIBUTE_SIMD
:
2219 p
= "!$OMP END DISTRIBUTE SIMD";
2224 case ST_OMP_END_DO_SIMD
:
2225 p
= "!$OMP END DO SIMD";
2227 case ST_OMP_END_SIMD
:
2228 p
= "!$OMP END SIMD";
2230 case ST_OMP_END_MASTER
:
2231 p
= "!$OMP END MASTER";
2233 case ST_OMP_END_ORDERED
:
2234 p
= "!$OMP END ORDERED";
2236 case ST_OMP_END_PARALLEL
:
2237 p
= "!$OMP END PARALLEL";
2239 case ST_OMP_END_PARALLEL_DO
:
2240 p
= "!$OMP END PARALLEL DO";
2242 case ST_OMP_END_PARALLEL_DO_SIMD
:
2243 p
= "!$OMP END PARALLEL DO SIMD";
2245 case ST_OMP_END_PARALLEL_SECTIONS
:
2246 p
= "!$OMP END PARALLEL SECTIONS";
2248 case ST_OMP_END_PARALLEL_WORKSHARE
:
2249 p
= "!$OMP END PARALLEL WORKSHARE";
2251 case ST_OMP_END_SECTIONS
:
2252 p
= "!$OMP END SECTIONS";
2254 case ST_OMP_END_SINGLE
:
2255 p
= "!$OMP END SINGLE";
2257 case ST_OMP_END_TASK
:
2258 p
= "!$OMP END TASK";
2260 case ST_OMP_END_TARGET
:
2261 p
= "!$OMP END TARGET";
2263 case ST_OMP_END_TARGET_DATA
:
2264 p
= "!$OMP END TARGET DATA";
2266 case ST_OMP_END_TARGET_PARALLEL
:
2267 p
= "!$OMP END TARGET PARALLEL";
2269 case ST_OMP_END_TARGET_PARALLEL_DO
:
2270 p
= "!$OMP END TARGET PARALLEL DO";
2272 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2273 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2275 case ST_OMP_END_TARGET_SIMD
:
2276 p
= "!$OMP END TARGET SIMD";
2278 case ST_OMP_END_TARGET_TEAMS
:
2279 p
= "!$OMP END TARGET TEAMS";
2281 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2282 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2284 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2285 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2287 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2288 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2290 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2291 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2293 case ST_OMP_END_TASKGROUP
:
2294 p
= "!$OMP END TASKGROUP";
2296 case ST_OMP_END_TASKLOOP
:
2297 p
= "!$OMP END TASKLOOP";
2299 case ST_OMP_END_TASKLOOP_SIMD
:
2300 p
= "!$OMP END TASKLOOP SIMD";
2302 case ST_OMP_END_TEAMS
:
2303 p
= "!$OMP END TEAMS";
2305 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2306 p
= "!$OMP END TEAMS DISTRIBUTE";
2308 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2309 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2311 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2312 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2314 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2315 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2317 case ST_OMP_END_WORKSHARE
:
2318 p
= "!$OMP END WORKSHARE";
2326 case ST_OMP_ORDERED
:
2327 case ST_OMP_ORDERED_DEPEND
:
2328 p
= "!$OMP ORDERED";
2330 case ST_OMP_PARALLEL
:
2331 p
= "!$OMP PARALLEL";
2333 case ST_OMP_PARALLEL_DO
:
2334 p
= "!$OMP PARALLEL DO";
2336 case ST_OMP_PARALLEL_DO_SIMD
:
2337 p
= "!$OMP PARALLEL DO SIMD";
2339 case ST_OMP_PARALLEL_SECTIONS
:
2340 p
= "!$OMP PARALLEL SECTIONS";
2342 case ST_OMP_PARALLEL_WORKSHARE
:
2343 p
= "!$OMP PARALLEL WORKSHARE";
2345 case ST_OMP_SECTIONS
:
2346 p
= "!$OMP SECTIONS";
2348 case ST_OMP_SECTION
:
2349 p
= "!$OMP SECTION";
2360 case ST_OMP_TARGET_DATA
:
2361 p
= "!$OMP TARGET DATA";
2363 case ST_OMP_TARGET_ENTER_DATA
:
2364 p
= "!$OMP TARGET ENTER DATA";
2366 case ST_OMP_TARGET_EXIT_DATA
:
2367 p
= "!$OMP TARGET EXIT DATA";
2369 case ST_OMP_TARGET_PARALLEL
:
2370 p
= "!$OMP TARGET PARALLEL";
2372 case ST_OMP_TARGET_PARALLEL_DO
:
2373 p
= "!$OMP TARGET PARALLEL DO";
2375 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
2376 p
= "!$OMP TARGET PARALLEL DO SIMD";
2378 case ST_OMP_TARGET_SIMD
:
2379 p
= "!$OMP TARGET SIMD";
2381 case ST_OMP_TARGET_TEAMS
:
2382 p
= "!$OMP TARGET TEAMS";
2384 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2385 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2387 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2388 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2390 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2391 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2393 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2394 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2396 case ST_OMP_TARGET_UPDATE
:
2397 p
= "!$OMP TARGET UPDATE";
2402 case ST_OMP_TASKGROUP
:
2403 p
= "!$OMP TASKGROUP";
2405 case ST_OMP_TASKLOOP
:
2406 p
= "!$OMP TASKLOOP";
2408 case ST_OMP_TASKLOOP_SIMD
:
2409 p
= "!$OMP TASKLOOP SIMD";
2411 case ST_OMP_TASKWAIT
:
2412 p
= "!$OMP TASKWAIT";
2414 case ST_OMP_TASKYIELD
:
2415 p
= "!$OMP TASKYIELD";
2420 case ST_OMP_TEAMS_DISTRIBUTE
:
2421 p
= "!$OMP TEAMS DISTRIBUTE";
2423 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2424 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2426 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2427 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2429 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2430 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2432 case ST_OMP_THREADPRIVATE
:
2433 p
= "!$OMP THREADPRIVATE";
2435 case ST_OMP_WORKSHARE
:
2436 p
= "!$OMP WORKSHARE";
2439 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2446 /* Create a symbol for the main program and assign it to ns->proc_name. */
2449 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2451 gfc_symbol
*main_program
;
2452 symbol_attribute attr
;
2454 gfc_get_symbol (name
, ns
, &main_program
);
2455 gfc_clear_attr (&attr
);
2456 attr
.flavor
= FL_PROGRAM
;
2457 attr
.proc
= PROC_UNKNOWN
;
2458 attr
.subroutine
= 1;
2459 attr
.access
= ACCESS_PUBLIC
;
2460 attr
.is_main_program
= 1;
2461 main_program
->attr
= attr
;
2462 main_program
->declared_at
= gfc_current_locus
;
2463 ns
->proc_name
= main_program
;
2464 gfc_commit_symbols ();
2468 /* Do whatever is necessary to accept the last statement. */
2471 accept_statement (gfc_statement st
)
2475 case ST_IMPLICIT_NONE
:
2483 gfc_current_ns
->proc_name
= gfc_new_block
;
2486 /* If the statement is the end of a block, lay down a special code
2487 that allows a branch to the end of the block from within the
2488 construct. IF and SELECT are treated differently from DO
2489 (where EXEC_NOP is added inside the loop) for two
2491 1. END DO has a meaning in the sense that after a GOTO to
2492 it, the loop counter must be increased.
2493 2. IF blocks and SELECT blocks can consist of multiple
2494 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2495 Putting the label before the END IF would make the jump
2496 from, say, the ELSE IF block to the END IF illegal. */
2500 case ST_END_CRITICAL
:
2501 if (gfc_statement_label
!= NULL
)
2503 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2508 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2509 one parallel block. Thus, we add the special code to the nested block
2510 itself, instead of the parent one. */
2512 case ST_END_ASSOCIATE
:
2513 if (gfc_statement_label
!= NULL
)
2515 new_st
.op
= EXEC_END_BLOCK
;
2520 /* The end-of-program unit statements do not get the special
2521 marker and require a statement of some sort if they are a
2524 case ST_END_PROGRAM
:
2525 case ST_END_FUNCTION
:
2526 case ST_END_SUBROUTINE
:
2527 if (gfc_statement_label
!= NULL
)
2529 new_st
.op
= EXEC_RETURN
;
2534 new_st
.op
= EXEC_END_PROCEDURE
;
2550 gfc_commit_symbols ();
2551 gfc_warning_check ();
2552 gfc_clear_new_st ();
2556 /* Undo anything tentative that has been built for the current statement,
2557 except if a gfc_charlen structure has been added to current namespace's
2558 list of gfc_charlen structure. */
2561 reject_statement (void)
2563 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2564 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2566 gfc_reject_data (gfc_current_ns
);
2568 gfc_new_block
= NULL
;
2569 gfc_undo_symbols ();
2570 gfc_clear_warning ();
2571 undo_new_statement ();
2575 /* Generic complaint about an out of order statement. We also do
2576 whatever is necessary to clean up. */
2579 unexpected_statement (gfc_statement st
)
2581 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2583 reject_statement ();
2587 /* Given the next statement seen by the matcher, make sure that it is
2588 in proper order with the last. This subroutine is initialized by
2589 calling it with an argument of ST_NONE. If there is a problem, we
2590 issue an error and return false. Otherwise we return true.
2592 Individual parsers need to verify that the statements seen are
2593 valid before calling here, i.e., ENTRY statements are not allowed in
2594 INTERFACE blocks. The following diagram is taken from the standard:
2596 +---------------------------------------+
2597 | program subroutine function module |
2598 +---------------------------------------+
2600 +---------------------------------------+
2602 +---------------------------------------+
2604 | +-----------+------------------+
2605 | | parameter | implicit |
2606 | +-----------+------------------+
2607 | format | | derived type |
2608 | entry | parameter | interface |
2609 | | data | specification |
2610 | | | statement func |
2611 | +-----------+------------------+
2612 | | data | executable |
2613 +--------+-----------+------------------+
2615 +---------------------------------------+
2616 | internal module/subprogram |
2617 +---------------------------------------+
2619 +---------------------------------------+
2628 ORDER_IMPLICIT_NONE
,
2636 enum state_order state
;
2637 gfc_statement last_statement
;
2643 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2649 p
->state
= ORDER_START
;
2653 if (p
->state
> ORDER_USE
)
2655 p
->state
= ORDER_USE
;
2659 if (p
->state
> ORDER_IMPORT
)
2661 p
->state
= ORDER_IMPORT
;
2664 case ST_IMPLICIT_NONE
:
2665 if (p
->state
> ORDER_IMPLICIT
)
2668 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2669 statement disqualifies a USE but not an IMPLICIT NONE.
2670 Duplicate IMPLICIT NONEs are caught when the implicit types
2673 p
->state
= ORDER_IMPLICIT_NONE
;
2677 if (p
->state
> ORDER_IMPLICIT
)
2679 p
->state
= ORDER_IMPLICIT
;
2684 if (p
->state
< ORDER_IMPLICIT_NONE
)
2685 p
->state
= ORDER_IMPLICIT_NONE
;
2689 if (p
->state
>= ORDER_EXEC
)
2691 if (p
->state
< ORDER_IMPLICIT
)
2692 p
->state
= ORDER_IMPLICIT
;
2696 if (p
->state
< ORDER_SPEC
)
2697 p
->state
= ORDER_SPEC
;
2702 case ST_STRUCTURE_DECL
:
2703 case ST_DERIVED_DECL
:
2705 if (p
->state
>= ORDER_EXEC
)
2707 if (p
->state
< ORDER_SPEC
)
2708 p
->state
= ORDER_SPEC
;
2712 /* The OpenMP directives have to be somewhere in the specification
2713 part, but there are no further requirements on their ordering.
2714 Thus don't adjust p->state, just ignore them. */
2715 if (p
->state
>= ORDER_EXEC
)
2721 if (p
->state
< ORDER_EXEC
)
2722 p
->state
= ORDER_EXEC
;
2729 /* All is well, record the statement in case we need it next time. */
2730 p
->where
= gfc_current_locus
;
2731 p
->last_statement
= st
;
2736 gfc_error ("%s statement at %C cannot follow %s statement at %L",
2737 gfc_ascii_statement (st
),
2738 gfc_ascii_statement (p
->last_statement
), &p
->where
);
2744 /* Handle an unexpected end of file. This is a show-stopper... */
2746 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
2749 unexpected_eof (void)
2753 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
2755 /* Memory cleanup. Move to "second to last". */
2756 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
2759 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
2762 longjmp (eof_buf
, 1);
2764 /* Avoids build error on systems where longjmp is not declared noreturn. */
2769 /* Parse the CONTAINS section of a derived type definition. */
2771 gfc_access gfc_typebound_default_access
;
2774 parse_derived_contains (void)
2777 bool seen_private
= false;
2778 bool seen_comps
= false;
2779 bool error_flag
= false;
2782 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2783 gcc_assert (gfc_current_block ());
2785 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
2787 if (gfc_current_block ()->attr
.sequence
)
2788 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
2789 " section at %C", gfc_current_block ()->name
);
2790 if (gfc_current_block ()->attr
.is_bind_c
)
2791 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
2792 " section at %C", gfc_current_block ()->name
);
2794 accept_statement (ST_CONTAINS
);
2795 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
2797 gfc_typebound_default_access
= ACCESS_PUBLIC
;
2803 st
= next_statement ();
2811 gfc_error ("Components in TYPE at %C must precede CONTAINS");
2815 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
2818 accept_statement (ST_PROCEDURE
);
2823 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
2826 accept_statement (ST_GENERIC
);
2831 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
2835 accept_statement (ST_FINAL
);
2843 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
2844 "at %C with empty CONTAINS section")))
2847 /* ST_END_TYPE is accepted by parse_derived after return. */
2851 if (!gfc_find_state (COMP_MODULE
))
2853 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
2860 gfc_error ("PRIVATE statement at %C must precede procedure"
2867 gfc_error ("Duplicate PRIVATE statement at %C");
2871 accept_statement (ST_PRIVATE
);
2872 gfc_typebound_default_access
= ACCESS_PRIVATE
;
2873 seen_private
= true;
2877 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
2881 gfc_error ("Already inside a CONTAINS block at %C");
2885 unexpected_statement (st
);
2893 reject_statement ();
2897 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2903 /* Set attributes for the parent symbol based on the attributes of a component
2904 and raise errors if conflicting attributes are found for the component. */
2907 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
2908 gfc_component
**eventp
)
2910 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
2911 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
2912 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
2914 if (lockp
) lock_comp
= *lockp
;
2915 if (eventp
) event_comp
= *eventp
;
2917 /* Look for allocatable components. */
2918 if (c
->attr
.allocatable
2919 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2920 && CLASS_DATA (c
)->attr
.allocatable
)
2921 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
2922 && c
->ts
.u
.derived
->attr
.alloc_comp
))
2925 sym
->attr
.alloc_comp
= 1;
2928 /* Look for pointer components. */
2930 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2931 && CLASS_DATA (c
)->attr
.class_pointer
)
2932 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
2935 sym
->attr
.pointer_comp
= 1;
2938 /* Look for procedure pointer components. */
2939 if (c
->attr
.proc_pointer
2940 || (c
->ts
.type
== BT_DERIVED
2941 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
2942 sym
->attr
.proc_pointer_comp
= 1;
2944 /* Looking for coarray components. */
2945 if (c
->attr
.codimension
2946 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2947 && CLASS_DATA (c
)->attr
.codimension
))
2950 sym
->attr
.coarray_comp
= 1;
2953 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
2954 && !c
->attr
.pointer
)
2957 sym
->attr
.coarray_comp
= 1;
2960 /* Looking for lock_type components. */
2961 if ((c
->ts
.type
== BT_DERIVED
2962 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2963 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
2964 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2965 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2966 == INTMOD_ISO_FORTRAN_ENV
2967 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2968 == ISOFORTRAN_LOCK_TYPE
)
2969 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
2970 && !allocatable
&& !pointer
))
2974 sym
->attr
.lock_comp
= 1;
2977 /* Looking for event_type components. */
2978 if ((c
->ts
.type
== BT_DERIVED
2979 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2980 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2981 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2982 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2983 == INTMOD_ISO_FORTRAN_ENV
2984 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2985 == ISOFORTRAN_EVENT_TYPE
)
2986 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
2987 && !allocatable
&& !pointer
))
2991 sym
->attr
.event_comp
= 1;
2994 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
2995 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
2996 unless there are nondirect [allocatable or pointer] components
2997 involved (cf. 1.3.33.1 and 1.3.33.3). */
2999 if (pointer
&& !coarray
&& lock_type
)
3000 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3001 "codimension or be a subcomponent of a coarray, "
3002 "which is not possible as the component has the "
3003 "pointer attribute", c
->name
, &c
->loc
);
3004 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3005 && c
->ts
.u
.derived
->attr
.lock_comp
)
3006 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3007 "of type LOCK_TYPE, which must have a codimension or be a "
3008 "subcomponent of a coarray", c
->name
, &c
->loc
);
3010 if (lock_type
&& allocatable
&& !coarray
)
3011 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3012 "a codimension", c
->name
, &c
->loc
);
3013 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3014 && c
->ts
.u
.derived
->attr
.lock_comp
)
3015 gfc_error ("Allocatable component %s at %L must have a codimension as "
3016 "it has a noncoarray subcomponent of type LOCK_TYPE",
3019 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
3020 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3021 "subcomponent of type LOCK_TYPE must have a codimension or "
3022 "be a subcomponent of a coarray. (Variables of type %s may "
3023 "not have a codimension as already a coarray "
3024 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3026 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
3027 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3028 "subcomponent of type LOCK_TYPE must have a codimension or "
3029 "be a subcomponent of a coarray. (Variables of type %s may "
3030 "not have a codimension as %s at %L has a codimension or a "
3031 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3032 sym
->name
, c
->name
, &c
->loc
);
3034 /* Similarly for EVENT TYPE. */
3036 if (pointer
&& !coarray
&& event_type
)
3037 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3038 "codimension or be a subcomponent of a coarray, "
3039 "which is not possible as the component has the "
3040 "pointer attribute", c
->name
, &c
->loc
);
3041 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3042 && c
->ts
.u
.derived
->attr
.event_comp
)
3043 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3044 "of type EVENT_TYPE, which must have a codimension or be a "
3045 "subcomponent of a coarray", c
->name
, &c
->loc
);
3047 if (event_type
&& allocatable
&& !coarray
)
3048 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3049 "a codimension", c
->name
, &c
->loc
);
3050 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3051 && c
->ts
.u
.derived
->attr
.event_comp
)
3052 gfc_error ("Allocatable component %s at %L must have a codimension as "
3053 "it has a noncoarray subcomponent of type EVENT_TYPE",
3056 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3057 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3058 "subcomponent of type EVENT_TYPE must have a codimension or "
3059 "be a subcomponent of a coarray. (Variables of type %s may "
3060 "not have a codimension as already a coarray "
3061 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3063 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3064 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3065 "subcomponent of type EVENT_TYPE must have a codimension or "
3066 "be a subcomponent of a coarray. (Variables of type %s may "
3067 "not have a codimension as %s at %L has a codimension or a "
3068 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3069 sym
->name
, c
->name
, &c
->loc
);
3071 /* Look for private components. */
3072 if (sym
->component_access
== ACCESS_PRIVATE
3073 || c
->attr
.access
== ACCESS_PRIVATE
3074 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3075 sym
->attr
.private_comp
= 1;
3077 if (lockp
) *lockp
= lock_comp
;
3078 if (eventp
) *eventp
= event_comp
;
3082 static void parse_struct_map (gfc_statement
);
3084 /* Parse a union component definition within a structure definition. */
3092 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3095 accept_statement(ST_UNION
);
3096 push_state (&s
, COMP_UNION
, gfc_new_block
);
3103 st
= next_statement ();
3104 /* Only MAP declarations valid within a union. */
3111 accept_statement (ST_MAP
);
3112 parse_struct_map (ST_MAP
);
3113 /* Add a component to the union for each map. */
3114 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3116 gfc_internal_error ("failed to create map component '%s'",
3117 gfc_new_block
->name
);
3118 reject_statement ();
3121 c
->ts
.type
= BT_DERIVED
;
3122 c
->ts
.u
.derived
= gfc_new_block
;
3123 /* Normally components get their initialization expressions when they
3124 are created in decl.c (build_struct) so we can look through the
3125 flat component list for initializers during resolution. Unions and
3126 maps create components along with their type definitions so we
3127 have to generate initializers here. */
3128 c
->initializer
= gfc_default_initializer (&c
->ts
);
3133 accept_statement (ST_END_UNION
);
3137 unexpected_statement (st
);
3142 for (c
= un
->components
; c
; c
= c
->next
)
3143 check_component (un
, c
, &lock_comp
, &event_comp
);
3145 /* Add the union as a component in its parent structure. */
3147 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3149 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3150 reject_statement ();
3153 c
->ts
.type
= BT_UNION
;
3154 c
->ts
.u
.derived
= un
;
3155 c
->initializer
= gfc_default_initializer (&c
->ts
);
3157 un
->attr
.zero_comp
= un
->components
== NULL
;
3161 /* Parse a STRUCTURE or MAP. */
3164 parse_struct_map (gfc_statement block
)
3170 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3171 gfc_compile_state comp
;
3174 if (block
== ST_STRUCTURE_DECL
)
3176 comp
= COMP_STRUCTURE
;
3177 ends
= ST_END_STRUCTURE
;
3181 gcc_assert (block
== ST_MAP
);
3186 accept_statement(block
);
3187 push_state (&s
, comp
, gfc_new_block
);
3189 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3192 while (compiling_type
)
3194 st
= next_statement ();
3200 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3201 case ST_STRUCTURE_DECL
:
3202 /* Let a more specific error make it to decode_statement(). */
3203 if (gfc_error_check () == 0)
3204 gfc_error ("Syntax error in nested structure declaration at %C");
3205 reject_statement ();
3206 /* Skip the rest of this statement. */
3207 gfc_error_recovery ();
3211 accept_statement (ST_UNION
);
3216 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3217 accept_statement (ST_DATA_DECL
);
3218 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3219 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3220 parse_struct_map (ST_STRUCTURE_DECL
);
3223 case ST_END_STRUCTURE
:
3227 accept_statement (st
);
3231 unexpected_statement (st
);
3235 unexpected_statement (st
);
3240 /* Validate each component. */
3241 sym
= gfc_current_block ();
3242 for (c
= sym
->components
; c
; c
= c
->next
)
3243 check_component (sym
, c
, &lock_comp
, &event_comp
);
3245 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3247 /* Allow parse_union to find this structure to add to its list of maps. */
3248 if (block
== ST_MAP
)
3249 gfc_new_block
= gfc_current_block ();
3255 /* Parse a derived type. */
3258 parse_derived (void)
3260 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3264 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3266 accept_statement (ST_DERIVED_DECL
);
3267 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3269 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3276 while (compiling_type
)
3278 st
= next_statement ();
3286 accept_statement (st
);
3291 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3298 if (!seen_component
)
3299 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3300 "definition at %C without components");
3302 accept_statement (ST_END_TYPE
);
3306 if (!gfc_find_state (COMP_MODULE
))
3308 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3315 gfc_error ("PRIVATE statement at %C must precede "
3316 "structure components");
3321 gfc_error ("Duplicate PRIVATE statement at %C");
3323 s
.sym
->component_access
= ACCESS_PRIVATE
;
3325 accept_statement (ST_PRIVATE
);
3332 gfc_error ("SEQUENCE statement at %C must precede "
3333 "structure components");
3337 if (gfc_current_block ()->attr
.sequence
)
3338 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3343 gfc_error ("Duplicate SEQUENCE statement at %C");
3347 gfc_add_sequence (&gfc_current_block ()->attr
,
3348 gfc_current_block ()->name
, NULL
);
3352 gfc_notify_std (GFC_STD_F2003
,
3353 "CONTAINS block in derived type"
3354 " definition at %C");
3356 accept_statement (ST_CONTAINS
);
3357 parse_derived_contains ();
3361 unexpected_statement (st
);
3366 /* need to verify that all fields of the derived type are
3367 * interoperable with C if the type is declared to be bind(c)
3369 sym
= gfc_current_block ();
3370 for (c
= sym
->components
; c
; c
= c
->next
)
3371 check_component (sym
, c
, &lock_comp
, &event_comp
);
3373 if (!seen_component
)
3374 sym
->attr
.zero_comp
= 1;
3380 /* Parse an ENUM. */
3388 int seen_enumerator
= 0;
3390 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3394 while (compiling_enum
)
3396 st
= next_statement ();
3404 seen_enumerator
= 1;
3405 accept_statement (st
);
3410 if (!seen_enumerator
)
3411 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3412 accept_statement (st
);
3416 gfc_free_enum_history ();
3417 unexpected_statement (st
);
3425 /* Parse an interface. We must be able to deal with the possibility
3426 of recursive interfaces. The parse_spec() subroutine is mutually
3427 recursive with parse_interface(). */
3429 static gfc_statement
parse_spec (gfc_statement
);
3432 parse_interface (void)
3434 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3435 gfc_symbol
*prog_unit
, *sym
;
3436 gfc_interface_info save
;
3437 gfc_state_data s1
, s2
;
3440 accept_statement (ST_INTERFACE
);
3442 current_interface
.ns
= gfc_current_ns
;
3443 save
= current_interface
;
3445 sym
= (current_interface
.type
== INTERFACE_GENERIC
3446 || current_interface
.type
== INTERFACE_USER_OP
)
3447 ? gfc_new_block
: NULL
;
3449 push_state (&s1
, COMP_INTERFACE
, sym
);
3450 current_state
= COMP_NONE
;
3453 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3455 st
= next_statement ();
3463 if (st
== ST_SUBROUTINE
)
3464 new_state
= COMP_SUBROUTINE
;
3465 else if (st
== ST_FUNCTION
)
3466 new_state
= COMP_FUNCTION
;
3467 if (gfc_new_block
->attr
.pointer
)
3469 gfc_new_block
->attr
.pointer
= 0;
3470 gfc_new_block
->attr
.proc_pointer
= 1;
3472 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3473 gfc_new_block
->formal
, NULL
))
3475 reject_statement ();
3476 gfc_free_namespace (gfc_current_ns
);
3479 /* F2008 C1210 forbids the IMPORT statement in module procedure
3480 interface bodies and the flag is set to import symbols. */
3481 if (gfc_new_block
->attr
.module_procedure
)
3482 gfc_current_ns
->has_import_set
= 1;
3486 case ST_MODULE_PROC
: /* The module procedure matcher makes
3487 sure the context is correct. */
3488 accept_statement (st
);
3489 gfc_free_namespace (gfc_current_ns
);
3492 case ST_END_INTERFACE
:
3493 gfc_free_namespace (gfc_current_ns
);
3494 gfc_current_ns
= current_interface
.ns
;
3498 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3499 gfc_ascii_statement (st
));
3500 reject_statement ();
3501 gfc_free_namespace (gfc_current_ns
);
3506 /* Make sure that the generic name has the right attribute. */
3507 if (current_interface
.type
== INTERFACE_GENERIC
3508 && current_state
== COMP_NONE
)
3510 if (new_state
== COMP_FUNCTION
&& sym
)
3511 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3512 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3513 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3515 current_state
= new_state
;
3518 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3520 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3521 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3522 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3523 "cannot be the same as an intrinsic type",
3524 gfc_new_block
->name
);
3527 push_state (&s2
, new_state
, gfc_new_block
);
3528 accept_statement (st
);
3529 prog_unit
= gfc_new_block
;
3530 prog_unit
->formal_ns
= gfc_current_ns
;
3531 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3532 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3536 /* Read data declaration statements. */
3537 st
= parse_spec (ST_NONE
);
3538 in_specification_block
= true;
3540 /* Since the interface block does not permit an IMPLICIT statement,
3541 the default type for the function or the result must be taken
3542 from the formal namespace. */
3543 if (new_state
== COMP_FUNCTION
)
3545 if (prog_unit
->result
== prog_unit
3546 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3547 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3548 else if (prog_unit
->result
!= prog_unit
3549 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3550 gfc_set_default_type (prog_unit
->result
, 1,
3551 prog_unit
->formal_ns
);
3554 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3556 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3557 gfc_ascii_statement (st
));
3558 reject_statement ();
3562 /* Add EXTERNAL attribute to function or subroutine. */
3563 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3564 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3566 current_interface
= save
;
3567 gfc_add_interface (prog_unit
);
3570 if (current_interface
.ns
3571 && current_interface
.ns
->proc_name
3572 && strcmp (current_interface
.ns
->proc_name
->name
,
3573 prog_unit
->name
) == 0)
3574 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3575 "enclosing procedure", prog_unit
->name
,
3576 ¤t_interface
.ns
->proc_name
->declared_at
);
3585 /* Associate function characteristics by going back to the function
3586 declaration and rematching the prefix. */
3589 match_deferred_characteristics (gfc_typespec
* ts
)
3592 match m
= MATCH_ERROR
;
3593 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3595 loc
= gfc_current_locus
;
3597 gfc_current_locus
= gfc_current_block ()->declared_at
;
3600 gfc_buffer_error (true);
3601 m
= gfc_match_prefix (ts
);
3602 gfc_buffer_error (false);
3604 if (ts
->type
== BT_DERIVED
)
3612 /* Only permit one go at the characteristic association. */
3616 /* Set the function locus correctly. If we have not found the
3617 function name, there is an error. */
3619 && gfc_match ("function% %n", name
) == MATCH_YES
3620 && strcmp (name
, gfc_current_block ()->name
) == 0)
3622 gfc_current_block ()->declared_at
= gfc_current_locus
;
3623 gfc_commit_symbols ();
3628 gfc_undo_symbols ();
3631 gfc_current_locus
=loc
;
3636 /* Check specification-expressions in the function result of the currently
3637 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3638 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3639 scope are not yet parsed so this has to be delayed up to parse_spec. */
3642 check_function_result_typed (void)
3646 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3648 if (!gfc_current_ns
->proc_name
->result
) return;
3650 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3652 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3653 /* TODO: Extend when KIND type parameters are implemented. */
3654 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3655 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3659 /* Parse a set of specification statements. Returns the statement
3660 that doesn't fit. */
3662 static gfc_statement
3663 parse_spec (gfc_statement st
)
3666 bool function_result_typed
= false;
3667 bool bad_characteristic
= false;
3670 in_specification_block
= true;
3672 verify_st_order (&ss
, ST_NONE
, false);
3674 st
= next_statement ();
3676 /* If we are not inside a function or don't have a result specified so far,
3677 do nothing special about it. */
3678 if (gfc_current_state () != COMP_FUNCTION
)
3679 function_result_typed
= true;
3682 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3685 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3686 function_result_typed
= true;
3691 /* If we're inside a BLOCK construct, some statements are disallowed.
3692 Check this here. Attribute declaration statements like INTENT, OPTIONAL
3693 or VALUE are also disallowed, but they don't have a particular ST_*
3694 key so we have to check for them individually in their matcher routine. */
3695 if (gfc_current_state () == COMP_BLOCK
)
3699 case ST_IMPLICIT_NONE
:
3702 case ST_EQUIVALENCE
:
3703 case ST_STATEMENT_FUNCTION
:
3704 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
3705 gfc_ascii_statement (st
));
3706 reject_statement ();
3712 else if (gfc_current_state () == COMP_BLOCK_DATA
)
3713 /* Fortran 2008, C1116. */
3720 case ST_DERIVED_DECL
:
3721 case ST_END_BLOCK_DATA
:
3722 case ST_EQUIVALENCE
:
3724 case ST_IMPLICIT_NONE
:
3725 case ST_OMP_THREADPRIVATE
:
3727 case ST_STRUCTURE_DECL
:
3736 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
3737 gfc_ascii_statement (st
));
3738 reject_statement ();
3742 /* If we find a statement that can not be followed by an IMPLICIT statement
3743 (and thus we can expect to see none any further), type the function result
3744 if it has not yet been typed. Be careful not to give the END statement
3745 to verify_st_order! */
3746 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
3748 bool verify_now
= false;
3750 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
3755 verify_st_order (&dummyss
, ST_NONE
, false);
3756 verify_st_order (&dummyss
, st
, false);
3758 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
3764 check_function_result_typed ();
3765 function_result_typed
= true;
3774 case ST_IMPLICIT_NONE
:
3776 if (!function_result_typed
)
3778 check_function_result_typed ();
3779 function_result_typed
= true;
3785 case ST_DATA
: /* Not allowed in interfaces */
3786 if (gfc_current_state () == COMP_INTERFACE
)
3796 case ST_STRUCTURE_DECL
:
3797 case ST_DERIVED_DECL
:
3801 if (!verify_st_order (&ss
, st
, false))
3803 reject_statement ();
3804 st
= next_statement ();
3814 case ST_STRUCTURE_DECL
:
3815 parse_struct_map (ST_STRUCTURE_DECL
);
3818 case ST_DERIVED_DECL
:
3824 if (gfc_current_state () != COMP_MODULE
)
3826 gfc_error ("%s statement must appear in a MODULE",
3827 gfc_ascii_statement (st
));
3828 reject_statement ();
3832 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
3834 gfc_error ("%s statement at %C follows another accessibility "
3835 "specification", gfc_ascii_statement (st
));
3836 reject_statement ();
3840 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
3841 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
3845 case ST_STATEMENT_FUNCTION
:
3846 if (gfc_current_state () == COMP_MODULE
3847 || gfc_current_state () == COMP_SUBMODULE
)
3849 unexpected_statement (st
);
3857 accept_statement (st
);
3858 st
= next_statement ();
3862 accept_statement (st
);
3864 st
= next_statement ();
3867 case ST_GET_FCN_CHARACTERISTICS
:
3868 /* This statement triggers the association of a function's result
3870 ts
= &gfc_current_block ()->result
->ts
;
3871 if (match_deferred_characteristics (ts
) != MATCH_YES
)
3872 bad_characteristic
= true;
3874 st
= next_statement ();
3881 /* If match_deferred_characteristics failed, then there is an error. */
3882 if (bad_characteristic
)
3884 ts
= &gfc_current_block ()->result
->ts
;
3885 if (ts
->type
!= BT_DERIVED
)
3886 gfc_error ("Bad kind expression for function %qs at %L",
3887 gfc_current_block ()->name
,
3888 &gfc_current_block ()->declared_at
);
3890 gfc_error ("The type for function %qs at %L is not accessible",
3891 gfc_current_block ()->name
,
3892 &gfc_current_block ()->declared_at
);
3894 gfc_current_block ()->ts
.kind
= 0;
3895 /* Keep the derived type; if it's bad, it will be discovered later. */
3896 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
3897 ts
->type
= BT_UNKNOWN
;
3900 in_specification_block
= false;
3906 /* Parse a WHERE block, (not a simple WHERE statement). */
3909 parse_where_block (void)
3911 int seen_empty_else
;
3916 accept_statement (ST_WHERE_BLOCK
);
3917 top
= gfc_state_stack
->tail
;
3919 push_state (&s
, COMP_WHERE
, gfc_new_block
);
3921 d
= add_statement ();
3922 d
->expr1
= top
->expr1
;
3928 seen_empty_else
= 0;
3932 st
= next_statement ();
3938 case ST_WHERE_BLOCK
:
3939 parse_where_block ();
3944 accept_statement (st
);
3948 if (seen_empty_else
)
3950 gfc_error ("ELSEWHERE statement at %C follows previous "
3951 "unmasked ELSEWHERE");
3952 reject_statement ();
3956 if (new_st
.expr1
== NULL
)
3957 seen_empty_else
= 1;
3959 d
= new_level (gfc_state_stack
->head
);
3961 d
->expr1
= new_st
.expr1
;
3963 accept_statement (st
);
3968 accept_statement (st
);
3972 gfc_error ("Unexpected %s statement in WHERE block at %C",
3973 gfc_ascii_statement (st
));
3974 reject_statement ();
3978 while (st
!= ST_END_WHERE
);
3984 /* Parse a FORALL block (not a simple FORALL statement). */
3987 parse_forall_block (void)
3993 accept_statement (ST_FORALL_BLOCK
);
3994 top
= gfc_state_stack
->tail
;
3996 push_state (&s
, COMP_FORALL
, gfc_new_block
);
3998 d
= add_statement ();
3999 d
->op
= EXEC_FORALL
;
4004 st
= next_statement ();
4009 case ST_POINTER_ASSIGNMENT
:
4012 accept_statement (st
);
4015 case ST_WHERE_BLOCK
:
4016 parse_where_block ();
4019 case ST_FORALL_BLOCK
:
4020 parse_forall_block ();
4024 accept_statement (st
);
4031 gfc_error ("Unexpected %s statement in FORALL block at %C",
4032 gfc_ascii_statement (st
));
4034 reject_statement ();
4038 while (st
!= ST_END_FORALL
);
4044 static gfc_statement
parse_executable (gfc_statement
);
4046 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4049 parse_if_block (void)
4058 accept_statement (ST_IF_BLOCK
);
4060 top
= gfc_state_stack
->tail
;
4061 push_state (&s
, COMP_IF
, gfc_new_block
);
4063 new_st
.op
= EXEC_IF
;
4064 d
= add_statement ();
4066 d
->expr1
= top
->expr1
;
4072 st
= parse_executable (ST_NONE
);
4082 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4083 "statement at %L", &else_locus
);
4085 reject_statement ();
4089 d
= new_level (gfc_state_stack
->head
);
4091 d
->expr1
= new_st
.expr1
;
4093 accept_statement (st
);
4100 gfc_error ("Duplicate ELSE statements at %L and %C",
4102 reject_statement ();
4107 else_locus
= gfc_current_locus
;
4109 d
= new_level (gfc_state_stack
->head
);
4112 accept_statement (st
);
4120 unexpected_statement (st
);
4124 while (st
!= ST_ENDIF
);
4127 accept_statement (st
);
4131 /* Parse a SELECT block. */
4134 parse_select_block (void)
4140 accept_statement (ST_SELECT_CASE
);
4142 cp
= gfc_state_stack
->tail
;
4143 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4145 /* Make sure that the next statement is a CASE or END SELECT. */
4148 st
= next_statement ();
4151 if (st
== ST_END_SELECT
)
4153 /* Empty SELECT CASE is OK. */
4154 accept_statement (st
);
4161 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4164 reject_statement ();
4167 /* At this point, we're got a nonempty select block. */
4168 cp
= new_level (cp
);
4171 accept_statement (st
);
4175 st
= parse_executable (ST_NONE
);
4182 cp
= new_level (gfc_state_stack
->head
);
4184 gfc_clear_new_st ();
4186 accept_statement (st
);
4192 /* Can't have an executable statement because of
4193 parse_executable(). */
4195 unexpected_statement (st
);
4199 while (st
!= ST_END_SELECT
);
4202 accept_statement (st
);
4206 /* Pop the current selector from the SELECT TYPE stack. */
4209 select_type_pop (void)
4211 gfc_select_type_stack
*old
= select_type_stack
;
4212 select_type_stack
= old
->prev
;
4217 /* Parse a SELECT TYPE construct (F03:R821). */
4220 parse_select_type_block (void)
4226 gfc_current_ns
= new_st
.ext
.block
.ns
;
4227 accept_statement (ST_SELECT_TYPE
);
4229 cp
= gfc_state_stack
->tail
;
4230 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4232 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4236 st
= next_statement ();
4239 if (st
== ST_END_SELECT
)
4240 /* Empty SELECT CASE is OK. */
4242 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4245 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4246 "following SELECT TYPE at %C");
4248 reject_statement ();
4251 /* At this point, we're got a nonempty select block. */
4252 cp
= new_level (cp
);
4255 accept_statement (st
);
4259 st
= parse_executable (ST_NONE
);
4267 cp
= new_level (gfc_state_stack
->head
);
4269 gfc_clear_new_st ();
4271 accept_statement (st
);
4277 /* Can't have an executable statement because of
4278 parse_executable(). */
4280 unexpected_statement (st
);
4284 while (st
!= ST_END_SELECT
);
4288 accept_statement (st
);
4289 gfc_current_ns
= gfc_current_ns
->parent
;
4294 /* Given a symbol, make sure it is not an iteration variable for a DO
4295 statement. This subroutine is called when the symbol is seen in a
4296 context that causes it to become redefined. If the symbol is an
4297 iterator, we generate an error message and return nonzero. */
4300 gfc_check_do_variable (gfc_symtree
*st
)
4304 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4305 if (s
->do_variable
== st
)
4307 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4308 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4316 /* Checks to see if the current statement label closes an enddo.
4317 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4318 an error) if it incorrectly closes an ENDDO. */
4321 check_do_closure (void)
4325 if (gfc_statement_label
== NULL
)
4328 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4329 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4333 return 0; /* No loops to close */
4335 if (p
->ext
.end_do_label
== gfc_statement_label
)
4337 if (p
== gfc_state_stack
)
4340 gfc_error ("End of nonblock DO statement at %C is within another block");
4344 /* At this point, the label doesn't terminate the innermost loop.
4345 Make sure it doesn't terminate another one. */
4346 for (; p
; p
= p
->previous
)
4347 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4348 && p
->ext
.end_do_label
== gfc_statement_label
)
4350 gfc_error ("End of nonblock DO statement at %C is interwoven "
4351 "with another DO loop");
4359 /* Parse a series of contained program units. */
4361 static void parse_progunit (gfc_statement
);
4364 /* Parse a CRITICAL block. */
4367 parse_critical_block (void)
4370 gfc_state_data s
, *sd
;
4373 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4374 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4375 gfc_error_now (is_oacc (sd
)
4376 ? G_("CRITICAL block inside of OpenACC region at %C")
4377 : G_("CRITICAL block inside of OpenMP region at %C"));
4379 s
.ext
.end_do_label
= new_st
.label1
;
4381 accept_statement (ST_CRITICAL
);
4382 top
= gfc_state_stack
->tail
;
4384 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4386 d
= add_statement ();
4387 d
->op
= EXEC_CRITICAL
;
4392 st
= parse_executable (ST_NONE
);
4400 case ST_END_CRITICAL
:
4401 if (s
.ext
.end_do_label
!= NULL
4402 && s
.ext
.end_do_label
!= gfc_statement_label
)
4403 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4404 "match CRITICAL label");
4406 if (gfc_statement_label
!= NULL
)
4408 new_st
.op
= EXEC_NOP
;
4414 unexpected_statement (st
);
4418 while (st
!= ST_END_CRITICAL
);
4421 accept_statement (st
);
4425 /* Set up the local namespace for a BLOCK construct. */
4428 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4430 gfc_namespace
* my_ns
;
4431 static int numblock
= 1;
4433 my_ns
= gfc_get_namespace (parent_ns
, 1);
4434 my_ns
->construct_entities
= 1;
4436 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4437 code generation (so it must not be NULL).
4438 We set its recursive argument if our container procedure is recursive, so
4439 that local variables are accordingly placed on the stack when it
4440 will be necessary. */
4442 my_ns
->proc_name
= gfc_new_block
;
4446 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4448 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4449 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4450 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4451 my_ns
->proc_name
->name
, NULL
);
4453 gfc_commit_symbol (my_ns
->proc_name
);
4456 if (parent_ns
->proc_name
)
4457 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4463 /* Parse a BLOCK construct. */
4466 parse_block_construct (void)
4468 gfc_namespace
* my_ns
;
4469 gfc_namespace
* my_parent
;
4472 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4474 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4476 new_st
.op
= EXEC_BLOCK
;
4477 new_st
.ext
.block
.ns
= my_ns
;
4478 new_st
.ext
.block
.assoc
= NULL
;
4479 accept_statement (ST_BLOCK
);
4481 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4482 gfc_current_ns
= my_ns
;
4483 my_parent
= my_ns
->parent
;
4485 parse_progunit (ST_NONE
);
4487 /* Don't depend on the value of gfc_current_ns; it might have been
4488 reset if the block had errors and was cleaned up. */
4489 gfc_current_ns
= my_parent
;
4495 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4496 behind the scenes with compiler-generated variables. */
4499 parse_associate (void)
4501 gfc_namespace
* my_ns
;
4504 gfc_association_list
* a
;
4506 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4508 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4510 new_st
.op
= EXEC_BLOCK
;
4511 new_st
.ext
.block
.ns
= my_ns
;
4512 gcc_assert (new_st
.ext
.block
.assoc
);
4514 /* Add all associate-names as BLOCK variables. Creating them is enough
4515 for now, they'll get their values during trans-* phase. */
4516 gfc_current_ns
= my_ns
;
4517 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4521 gfc_array_ref
*array_ref
;
4523 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4527 sym
->attr
.flavor
= FL_VARIABLE
;
4529 sym
->declared_at
= a
->where
;
4530 gfc_set_sym_referenced (sym
);
4532 /* Initialize the typespec. It is not available in all cases,
4533 however, as it may only be set on the target during resolution.
4534 Still, sometimes it helps to have it right now -- especially
4535 for parsing component references on the associate-name
4536 in case of association to a derived-type. */
4537 sym
->ts
= a
->target
->ts
;
4539 /* Check if the target expression is array valued. This can not always
4540 be done by looking at target.rank, because that might not have been
4541 set yet. Therefore traverse the chain of refs, looking for the last
4542 array ref and evaluate that. */
4544 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4545 if (ref
->type
== REF_ARRAY
)
4546 array_ref
= &ref
->u
.ar
;
4547 if (array_ref
|| a
->target
->rank
)
4554 /* Count the dimension, that have a non-scalar extend. */
4555 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4556 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4557 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4558 && array_ref
->end
[dim
] == NULL
4559 && array_ref
->start
[dim
] != NULL
))
4563 rank
= a
->target
->rank
;
4564 /* When the rank is greater than zero then sym will be an array. */
4565 if (sym
->ts
.type
== BT_CLASS
)
4567 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4568 || (CLASS_DATA (sym
)->as
4569 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4571 /* Don't just (re-)set the attr and as in the sym.ts,
4572 because this modifies the target's attr and as. Copy the
4573 data and do a build_class_symbol. */
4574 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4575 int corank
= gfc_get_corank (a
->target
);
4580 as
= gfc_get_array_spec ();
4581 as
->type
= AS_DEFERRED
;
4583 as
->corank
= corank
;
4584 attr
.dimension
= rank
? 1 : 0;
4585 attr
.codimension
= corank
? 1 : 0;
4590 attr
.dimension
= attr
.codimension
= 0;
4593 type
= CLASS_DATA (sym
)->ts
;
4594 if (!gfc_build_class_symbol (&type
,
4598 sym
->ts
.type
= BT_CLASS
;
4599 sym
->attr
.class_ok
= 1;
4602 sym
->attr
.class_ok
= 1;
4604 else if ((!sym
->as
&& rank
!= 0)
4605 || (sym
->as
&& sym
->as
->rank
!= rank
))
4607 as
= gfc_get_array_spec ();
4608 as
->type
= AS_DEFERRED
;
4610 as
->corank
= gfc_get_corank (a
->target
);
4612 sym
->attr
.dimension
= 1;
4614 sym
->attr
.codimension
= 1;
4619 accept_statement (ST_ASSOCIATE
);
4620 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
4623 st
= parse_executable (ST_NONE
);
4630 accept_statement (st
);
4631 my_ns
->code
= gfc_state_stack
->head
;
4635 unexpected_statement (st
);
4639 gfc_current_ns
= gfc_current_ns
->parent
;
4644 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
4645 handled inside of parse_executable(), because they aren't really
4649 parse_do_block (void)
4658 s
.ext
.end_do_label
= new_st
.label1
;
4660 if (new_st
.ext
.iterator
!= NULL
)
4662 stree
= new_st
.ext
.iterator
->var
->symtree
;
4663 if (directive_unroll
!= -1)
4665 new_st
.ext
.iterator
->unroll
= directive_unroll
;
4666 directive_unroll
= -1;
4672 accept_statement (ST_DO
);
4674 top
= gfc_state_stack
->tail
;
4675 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
4678 s
.do_variable
= stree
;
4680 top
->block
= new_level (top
);
4681 top
->block
->op
= EXEC_DO
;
4684 st
= parse_executable (ST_NONE
);
4692 if (s
.ext
.end_do_label
!= NULL
4693 && s
.ext
.end_do_label
!= gfc_statement_label
)
4694 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
4697 if (gfc_statement_label
!= NULL
)
4699 new_st
.op
= EXEC_NOP
;
4704 case ST_IMPLIED_ENDDO
:
4705 /* If the do-stmt of this DO construct has a do-construct-name,
4706 the corresponding end-do must be an end-do-stmt (with a matching
4707 name, but in that case we must have seen ST_ENDDO first).
4708 We only complain about this in pedantic mode. */
4709 if (gfc_current_block () != NULL
)
4710 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
4711 &gfc_current_block()->declared_at
);
4716 unexpected_statement (st
);
4721 accept_statement (st
);
4725 /* Parse the statements of OpenMP do/parallel do. */
4727 static gfc_statement
4728 parse_omp_do (gfc_statement omp_st
)
4734 accept_statement (omp_st
);
4736 cp
= gfc_state_stack
->tail
;
4737 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4738 np
= new_level (cp
);
4744 st
= next_statement ();
4747 else if (st
== ST_DO
)
4750 unexpected_statement (st
);
4754 if (gfc_statement_label
!= NULL
4755 && gfc_state_stack
->previous
!= NULL
4756 && gfc_state_stack
->previous
->state
== COMP_DO
4757 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4765 there should be no !$OMP END DO. */
4767 return ST_IMPLIED_ENDDO
;
4770 check_do_closure ();
4773 st
= next_statement ();
4774 gfc_statement omp_end_st
= ST_OMP_END_DO
;
4777 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
4778 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4779 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4781 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4782 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4784 case ST_OMP_DISTRIBUTE_SIMD
:
4785 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4787 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
4788 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
4789 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
4790 case ST_OMP_PARALLEL_DO_SIMD
:
4791 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
4793 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
4794 case ST_OMP_TARGET_PARALLEL_DO
:
4795 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO
;
4797 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
4798 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
4800 case ST_OMP_TARGET_SIMD
: omp_end_st
= ST_OMP_END_TARGET_SIMD
; break;
4801 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4802 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4804 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4805 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4807 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4808 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4810 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4811 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4813 case ST_OMP_TASKLOOP
: omp_end_st
= ST_OMP_END_TASKLOOP
; break;
4814 case ST_OMP_TASKLOOP_SIMD
: omp_end_st
= ST_OMP_END_TASKLOOP_SIMD
; break;
4815 case ST_OMP_TEAMS_DISTRIBUTE
:
4816 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4818 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4819 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4821 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4822 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4824 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4825 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4827 default: gcc_unreachable ();
4829 if (st
== omp_end_st
)
4831 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
4832 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4834 gcc_assert (new_st
.op
== EXEC_NOP
);
4835 gfc_clear_new_st ();
4836 gfc_commit_symbols ();
4837 gfc_warning_check ();
4838 st
= next_statement ();
4844 /* Parse the statements of OpenMP atomic directive. */
4846 static gfc_statement
4847 parse_omp_oacc_atomic (bool omp_p
)
4849 gfc_statement st
, st_atomic
, st_end_atomic
;
4856 st_atomic
= ST_OMP_ATOMIC
;
4857 st_end_atomic
= ST_OMP_END_ATOMIC
;
4861 st_atomic
= ST_OACC_ATOMIC
;
4862 st_end_atomic
= ST_OACC_END_ATOMIC
;
4864 accept_statement (st_atomic
);
4866 cp
= gfc_state_stack
->tail
;
4867 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4868 np
= new_level (cp
);
4871 np
->ext
.omp_atomic
= cp
->ext
.omp_atomic
;
4872 count
= 1 + ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4873 == GFC_OMP_ATOMIC_CAPTURE
);
4877 st
= next_statement ();
4880 else if (st
== ST_ASSIGNMENT
)
4882 accept_statement (st
);
4886 unexpected_statement (st
);
4891 st
= next_statement ();
4892 if (st
== st_end_atomic
)
4894 gfc_clear_new_st ();
4895 gfc_commit_symbols ();
4896 gfc_warning_check ();
4897 st
= next_statement ();
4899 else if ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4900 == GFC_OMP_ATOMIC_CAPTURE
)
4901 gfc_error ("Missing !$OMP END ATOMIC after !$OMP ATOMIC CAPTURE at %C");
4906 /* Parse the statements of an OpenACC structured block. */
4909 parse_oacc_structured_block (gfc_statement acc_st
)
4911 gfc_statement st
, acc_end_st
;
4913 gfc_state_data s
, *sd
;
4915 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4916 if (sd
->state
== COMP_CRITICAL
)
4917 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4919 accept_statement (acc_st
);
4921 cp
= gfc_state_stack
->tail
;
4922 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4923 np
= new_level (cp
);
4928 case ST_OACC_PARALLEL
:
4929 acc_end_st
= ST_OACC_END_PARALLEL
;
4931 case ST_OACC_KERNELS
:
4932 acc_end_st
= ST_OACC_END_KERNELS
;
4935 acc_end_st
= ST_OACC_END_DATA
;
4937 case ST_OACC_HOST_DATA
:
4938 acc_end_st
= ST_OACC_END_HOST_DATA
;
4946 st
= parse_executable (ST_NONE
);
4949 else if (st
!= acc_end_st
)
4951 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
4952 reject_statement ();
4955 while (st
!= acc_end_st
);
4957 gcc_assert (new_st
.op
== EXEC_NOP
);
4959 gfc_clear_new_st ();
4960 gfc_commit_symbols ();
4961 gfc_warning_check ();
4965 /* Parse the statements of OpenACC loop/parallel loop/kernels loop. */
4967 static gfc_statement
4968 parse_oacc_loop (gfc_statement acc_st
)
4972 gfc_state_data s
, *sd
;
4974 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4975 if (sd
->state
== COMP_CRITICAL
)
4976 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4978 accept_statement (acc_st
);
4980 cp
= gfc_state_stack
->tail
;
4981 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4982 np
= new_level (cp
);
4988 st
= next_statement ();
4991 else if (st
== ST_DO
)
4995 gfc_error ("Expected DO loop at %C");
4996 reject_statement ();
5001 if (gfc_statement_label
!= NULL
5002 && gfc_state_stack
->previous
!= NULL
5003 && gfc_state_stack
->previous
->state
== COMP_DO
5004 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5007 return ST_IMPLIED_ENDDO
;
5010 check_do_closure ();
5013 st
= next_statement ();
5014 if (st
== ST_OACC_END_LOOP
)
5015 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
5016 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
5017 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
5018 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
5020 gcc_assert (new_st
.op
== EXEC_NOP
);
5021 gfc_clear_new_st ();
5022 gfc_commit_symbols ();
5023 gfc_warning_check ();
5024 st
= next_statement ();
5030 /* Parse the statements of an OpenMP structured block. */
5033 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
5035 gfc_statement st
, omp_end_st
;
5039 accept_statement (omp_st
);
5041 cp
= gfc_state_stack
->tail
;
5042 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5043 np
= new_level (cp
);
5049 case ST_OMP_PARALLEL
:
5050 omp_end_st
= ST_OMP_END_PARALLEL
;
5052 case ST_OMP_PARALLEL_SECTIONS
:
5053 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
5055 case ST_OMP_SECTIONS
:
5056 omp_end_st
= ST_OMP_END_SECTIONS
;
5058 case ST_OMP_ORDERED
:
5059 omp_end_st
= ST_OMP_END_ORDERED
;
5061 case ST_OMP_CRITICAL
:
5062 omp_end_st
= ST_OMP_END_CRITICAL
;
5065 omp_end_st
= ST_OMP_END_MASTER
;
5068 omp_end_st
= ST_OMP_END_SINGLE
;
5071 omp_end_st
= ST_OMP_END_TARGET
;
5073 case ST_OMP_TARGET_DATA
:
5074 omp_end_st
= ST_OMP_END_TARGET_DATA
;
5076 case ST_OMP_TARGET_TEAMS
:
5077 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
5079 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5080 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5082 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5083 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5085 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5086 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5088 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5089 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5092 omp_end_st
= ST_OMP_END_TASK
;
5094 case ST_OMP_TASKGROUP
:
5095 omp_end_st
= ST_OMP_END_TASKGROUP
;
5098 omp_end_st
= ST_OMP_END_TEAMS
;
5100 case ST_OMP_TEAMS_DISTRIBUTE
:
5101 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5103 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5104 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5106 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5107 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5109 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5110 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5112 case ST_OMP_DISTRIBUTE
:
5113 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
5115 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5116 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5118 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5119 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5121 case ST_OMP_DISTRIBUTE_SIMD
:
5122 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
5124 case ST_OMP_WORKSHARE
:
5125 omp_end_st
= ST_OMP_END_WORKSHARE
;
5127 case ST_OMP_PARALLEL_WORKSHARE
:
5128 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
5136 if (workshare_stmts_only
)
5138 /* Inside of !$omp workshare, only
5141 where statements and constructs
5142 forall statements and constructs
5146 are allowed. For !$omp critical these
5147 restrictions apply recursively. */
5150 st
= next_statement ();
5161 accept_statement (st
);
5164 case ST_WHERE_BLOCK
:
5165 parse_where_block ();
5168 case ST_FORALL_BLOCK
:
5169 parse_forall_block ();
5172 case ST_OMP_PARALLEL
:
5173 case ST_OMP_PARALLEL_SECTIONS
:
5174 parse_omp_structured_block (st
, false);
5177 case ST_OMP_PARALLEL_WORKSHARE
:
5178 case ST_OMP_CRITICAL
:
5179 parse_omp_structured_block (st
, true);
5182 case ST_OMP_PARALLEL_DO
:
5183 case ST_OMP_PARALLEL_DO_SIMD
:
5184 st
= parse_omp_do (st
);
5188 st
= parse_omp_oacc_atomic (true);
5199 st
= next_statement ();
5203 st
= parse_executable (ST_NONE
);
5206 else if (st
== ST_OMP_SECTION
5207 && (omp_st
== ST_OMP_SECTIONS
5208 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
5210 np
= new_level (np
);
5214 else if (st
!= omp_end_st
)
5215 unexpected_statement (st
);
5217 while (st
!= omp_end_st
);
5221 case EXEC_OMP_END_NOWAIT
:
5222 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5224 case EXEC_OMP_END_CRITICAL
:
5225 if (((cp
->ext
.omp_clauses
== NULL
) ^ (new_st
.ext
.omp_name
== NULL
))
5226 || (new_st
.ext
.omp_name
!= NULL
5227 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
5228 new_st
.ext
.omp_name
) != 0))
5229 gfc_error ("Name after !$omp critical and !$omp end critical does "
5231 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
5232 new_st
.ext
.omp_name
= NULL
;
5234 case EXEC_OMP_END_SINGLE
:
5235 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
5236 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
5237 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
5238 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5246 gfc_clear_new_st ();
5247 gfc_commit_symbols ();
5248 gfc_warning_check ();
5253 /* Accept a series of executable statements. We return the first
5254 statement that doesn't fit to the caller. Any block statements are
5255 passed on to the correct handler, which usually passes the buck
5258 static gfc_statement
5259 parse_executable (gfc_statement st
)
5264 st
= next_statement ();
5268 close_flag
= check_do_closure ();
5273 case ST_END_PROGRAM
:
5276 case ST_END_FUNCTION
:
5281 case ST_END_SUBROUTINE
:
5286 case ST_SELECT_CASE
:
5287 gfc_error ("%s statement at %C cannot terminate a non-block "
5288 "DO loop", gfc_ascii_statement (st
));
5301 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5302 "first executable statement");
5308 accept_statement (st
);
5309 if (close_flag
== 1)
5310 return ST_IMPLIED_ENDDO
;
5314 parse_block_construct ();
5325 case ST_SELECT_CASE
:
5326 parse_select_block ();
5329 case ST_SELECT_TYPE
:
5330 parse_select_type_block ();
5335 if (check_do_closure () == 1)
5336 return ST_IMPLIED_ENDDO
;
5340 parse_critical_block ();
5343 case ST_WHERE_BLOCK
:
5344 parse_where_block ();
5347 case ST_FORALL_BLOCK
:
5348 parse_forall_block ();
5351 case ST_OACC_PARALLEL_LOOP
:
5352 case ST_OACC_KERNELS_LOOP
:
5354 st
= parse_oacc_loop (st
);
5355 if (st
== ST_IMPLIED_ENDDO
)
5359 case ST_OACC_PARALLEL
:
5360 case ST_OACC_KERNELS
:
5362 case ST_OACC_HOST_DATA
:
5363 parse_oacc_structured_block (st
);
5366 case ST_OMP_PARALLEL
:
5367 case ST_OMP_PARALLEL_SECTIONS
:
5368 case ST_OMP_SECTIONS
:
5369 case ST_OMP_ORDERED
:
5370 case ST_OMP_CRITICAL
:
5374 case ST_OMP_TARGET_DATA
:
5375 case ST_OMP_TARGET_PARALLEL
:
5376 case ST_OMP_TARGET_TEAMS
:
5379 case ST_OMP_TASKGROUP
:
5380 parse_omp_structured_block (st
, false);
5383 case ST_OMP_WORKSHARE
:
5384 case ST_OMP_PARALLEL_WORKSHARE
:
5385 parse_omp_structured_block (st
, true);
5388 case ST_OMP_DISTRIBUTE
:
5389 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5390 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5391 case ST_OMP_DISTRIBUTE_SIMD
:
5393 case ST_OMP_DO_SIMD
:
5394 case ST_OMP_PARALLEL_DO
:
5395 case ST_OMP_PARALLEL_DO_SIMD
:
5397 case ST_OMP_TARGET_PARALLEL_DO
:
5398 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5399 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5400 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5401 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5402 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5403 case ST_OMP_TASKLOOP
:
5404 case ST_OMP_TASKLOOP_SIMD
:
5405 case ST_OMP_TEAMS_DISTRIBUTE
:
5406 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5407 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5408 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5409 st
= parse_omp_do (st
);
5410 if (st
== ST_IMPLIED_ENDDO
)
5414 case ST_OACC_ATOMIC
:
5415 st
= parse_omp_oacc_atomic (false);
5419 st
= parse_omp_oacc_atomic (true);
5426 if (directive_unroll
!= -1)
5427 gfc_error ("%<GCC unroll%> directive does not commence a loop at %C");
5429 st
= next_statement ();
5434 /* Fix the symbols for sibling functions. These are incorrectly added to
5435 the child namespace as the parser didn't know about this procedure. */
5438 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5442 gfc_symbol
*old_sym
;
5444 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5446 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5448 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5449 goto fixup_contained
;
5451 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5452 && sym
->attr
.generic
&& sym
->attr
.function
)
5453 ||(sym
->attr
.flavor
== FL_DERIVED
5454 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5455 goto fixup_contained
;
5457 old_sym
= st
->n
.sym
;
5458 if (old_sym
->ns
== ns
5459 && !old_sym
->attr
.contained
5461 /* By 14.6.1.3, host association should be excluded
5462 for the following. */
5463 && !(old_sym
->attr
.external
5464 || (old_sym
->ts
.type
!= BT_UNKNOWN
5465 && !old_sym
->attr
.implicit_type
)
5466 || old_sym
->attr
.flavor
== FL_PARAMETER
5467 || old_sym
->attr
.use_assoc
5468 || old_sym
->attr
.in_common
5469 || old_sym
->attr
.in_equivalence
5470 || old_sym
->attr
.data
5471 || old_sym
->attr
.dummy
5472 || old_sym
->attr
.result
5473 || old_sym
->attr
.dimension
5474 || old_sym
->attr
.allocatable
5475 || old_sym
->attr
.intrinsic
5476 || old_sym
->attr
.generic
5477 || old_sym
->attr
.flavor
== FL_NAMELIST
5478 || old_sym
->attr
.flavor
== FL_LABEL
5479 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
5481 /* Replace it with the symbol from the parent namespace. */
5485 gfc_release_symbol (old_sym
);
5489 /* Do the same for any contained procedures. */
5490 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
5495 parse_contained (int module
)
5497 gfc_namespace
*ns
, *parent_ns
, *tmp
;
5498 gfc_state_data s1
, s2
;
5503 int contains_statements
= 0;
5506 push_state (&s1
, COMP_CONTAINS
, NULL
);
5507 parent_ns
= gfc_current_ns
;
5511 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
5513 gfc_current_ns
->sibling
= parent_ns
->contained
;
5514 parent_ns
->contained
= gfc_current_ns
;
5517 /* Process the next available statement. We come here if we got an error
5518 and rejected the last statement. */
5519 old_loc
= gfc_current_locus
;
5520 st
= next_statement ();
5529 contains_statements
= 1;
5530 accept_statement (st
);
5533 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
5536 /* For internal procedures, create/update the symbol in the
5537 parent namespace. */
5541 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
5542 gfc_error ("Contained procedure %qs at %C is already "
5543 "ambiguous", gfc_new_block
->name
);
5546 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
5548 &gfc_new_block
->declared_at
))
5550 if (st
== ST_FUNCTION
)
5551 gfc_add_function (&sym
->attr
, sym
->name
,
5552 &gfc_new_block
->declared_at
);
5554 gfc_add_subroutine (&sym
->attr
, sym
->name
,
5555 &gfc_new_block
->declared_at
);
5559 gfc_commit_symbols ();
5562 sym
= gfc_new_block
;
5564 /* Mark this as a contained function, so it isn't replaced
5565 by other module functions. */
5566 sym
->attr
.contained
= 1;
5568 /* Set implicit_pure so that it can be reset if any of the
5569 tests for purity fail. This is used for some optimisation
5570 during translation. */
5571 if (!sym
->attr
.pure
)
5572 sym
->attr
.implicit_pure
= 1;
5574 parse_progunit (ST_NONE
);
5576 /* Fix up any sibling functions that refer to this one. */
5577 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
5578 /* Or refer to any of its alternate entry points. */
5579 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
5580 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
5582 gfc_current_ns
->code
= s2
.head
;
5583 gfc_current_ns
= parent_ns
;
5588 /* These statements are associated with the end of the host unit. */
5589 case ST_END_FUNCTION
:
5591 case ST_END_SUBMODULE
:
5592 case ST_END_PROGRAM
:
5593 case ST_END_SUBROUTINE
:
5594 accept_statement (st
);
5595 gfc_current_ns
->code
= s1
.head
;
5599 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
5600 gfc_ascii_statement (st
));
5601 reject_statement ();
5607 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
5608 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
5609 && st
!= ST_END_PROGRAM
);
5611 /* The first namespace in the list is guaranteed to not have
5612 anything (worthwhile) in it. */
5613 tmp
= gfc_current_ns
;
5614 gfc_current_ns
= parent_ns
;
5615 if (seen_error
&& tmp
->refs
> 1)
5616 gfc_free_namespace (tmp
);
5618 ns
= gfc_current_ns
->contained
;
5619 gfc_current_ns
->contained
= ns
->sibling
;
5620 gfc_free_namespace (ns
);
5623 if (!contains_statements
)
5624 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
5625 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
5629 /* The result variable in a MODULE PROCEDURE needs to be created and
5630 its characteristics copied from the interface since it is neither
5631 declared in the procedure declaration nor in the specification
5635 get_modproc_result (void)
5638 if (gfc_state_stack
->previous
5639 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
5640 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
5642 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
5644 && proc
->attr
.function
5646 && proc
->tlink
->result
5647 && proc
->tlink
->result
!= proc
->tlink
)
5649 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
5650 gfc_set_sym_referenced (proc
->result
);
5651 proc
->result
->attr
.if_source
= IFSRC_DECL
;
5652 gfc_commit_symbol (proc
->result
);
5658 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
5661 parse_progunit (gfc_statement st
)
5667 && gfc_new_block
->abr_modproc_decl
5668 && gfc_new_block
->attr
.function
)
5669 get_modproc_result ();
5671 st
= parse_spec (st
);
5678 /* This is not allowed within BLOCK! */
5679 if (gfc_current_state () != COMP_BLOCK
)
5684 accept_statement (st
);
5691 if (gfc_current_state () == COMP_FUNCTION
)
5692 gfc_check_function_type (gfc_current_ns
);
5697 st
= parse_executable (st
);
5705 /* This is not allowed within BLOCK! */
5706 if (gfc_current_state () != COMP_BLOCK
)
5711 accept_statement (st
);
5718 unexpected_statement (st
);
5719 reject_statement ();
5720 st
= next_statement ();
5726 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
5727 if (p
->state
== COMP_CONTAINS
)
5730 if (gfc_find_state (COMP_MODULE
) == true
5731 || gfc_find_state (COMP_SUBMODULE
) == true)
5736 gfc_error ("CONTAINS statement at %C is already in a contained "
5738 reject_statement ();
5739 st
= next_statement ();
5743 parse_contained (0);
5746 gfc_current_ns
->code
= gfc_state_stack
->head
;
5750 /* Come here to complain about a global symbol already in use as
5754 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
5759 where
= &gfc_current_locus
;
5769 case GSYM_SUBROUTINE
:
5770 name
= "SUBROUTINE";
5775 case GSYM_BLOCK_DATA
:
5776 name
= "BLOCK DATA";
5787 if (sym
->binding_label
)
5788 gfc_error ("Global binding name %qs at %L is already being used "
5789 "as a %s at %L", sym
->binding_label
, where
, name
,
5792 gfc_error ("Global name %qs at %L is already being used as "
5793 "a %s at %L", sym
->name
, where
, name
, &sym
->where
);
5797 if (sym
->binding_label
)
5798 gfc_error ("Global binding name %qs at %L is already being used "
5799 "at %L", sym
->binding_label
, where
, &sym
->where
);
5801 gfc_error ("Global name %qs at %L is already being used at %L",
5802 sym
->name
, where
, &sym
->where
);
5807 /* Parse a block data program unit. */
5810 parse_block_data (void)
5813 static locus blank_locus
;
5814 static int blank_block
=0;
5817 gfc_current_ns
->proc_name
= gfc_new_block
;
5818 gfc_current_ns
->is_block_data
= 1;
5820 if (gfc_new_block
== NULL
)
5823 gfc_error ("Blank BLOCK DATA at %C conflicts with "
5824 "prior BLOCK DATA at %L", &blank_locus
);
5828 blank_locus
= gfc_current_locus
;
5833 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5835 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
5836 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5839 s
->type
= GSYM_BLOCK_DATA
;
5840 s
->where
= gfc_new_block
->declared_at
;
5845 st
= parse_spec (ST_NONE
);
5847 while (st
!= ST_END_BLOCK_DATA
)
5849 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
5850 gfc_ascii_statement (st
));
5851 reject_statement ();
5852 st
= next_statement ();
5857 /* Following the association of the ancestor (sub)module symbols, they
5858 must be set host rather than use associated and all must be public.
5859 They are flagged up by 'used_in_submodule' so that they can be set
5860 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
5861 linker chokes on multiple symbol definitions. */
5864 set_syms_host_assoc (gfc_symbol
*sym
)
5867 const char dot
[2] = ".";
5868 char parent1
[GFC_MAX_SYMBOL_LEN
+ 1];
5869 char parent2
[GFC_MAX_SYMBOL_LEN
+ 1];
5874 if (sym
->attr
.module_procedure
)
5875 sym
->attr
.external
= 0;
5877 sym
->attr
.use_assoc
= 0;
5878 sym
->attr
.host_assoc
= 1;
5879 sym
->attr
.used_in_submodule
=1;
5881 if (sym
->attr
.flavor
== FL_DERIVED
)
5883 /* Derived types with PRIVATE components that are declared in
5884 modules other than the parent module must not be changed to be
5885 PUBLIC. The 'use-assoc' attribute must be reset so that the
5886 test in symbol.c(gfc_find_component) works correctly. This is
5887 not necessary for PRIVATE symbols since they are not read from
5889 memset(parent1
, '\0', sizeof(parent1
));
5890 memset(parent2
, '\0', sizeof(parent2
));
5891 strcpy (parent1
, gfc_new_block
->name
);
5892 strcpy (parent2
, sym
->module
);
5893 if (strcmp (strtok (parent1
, dot
), strtok (parent2
, dot
)) == 0)
5895 for (c
= sym
->components
; c
; c
= c
->next
)
5896 c
->attr
.access
= ACCESS_PUBLIC
;
5900 sym
->attr
.use_assoc
= 1;
5901 sym
->attr
.host_assoc
= 0;
5906 /* Parse a module subprogram. */
5915 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5916 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
5917 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5920 s
->type
= GSYM_MODULE
;
5921 s
->where
= gfc_new_block
->declared_at
;
5925 /* Something is nulling the module_list after this point. This is good
5926 since it allows us to 'USE' the parent modules that the submodule
5927 inherits and to set (most) of the symbols as host associated. */
5928 if (gfc_current_state () == COMP_SUBMODULE
)
5931 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
5934 st
= parse_spec (ST_NONE
);
5944 parse_contained (1);
5948 case ST_END_SUBMODULE
:
5949 accept_statement (st
);
5953 gfc_error ("Unexpected %s statement in MODULE at %C",
5954 gfc_ascii_statement (st
));
5957 reject_statement ();
5958 st
= next_statement ();
5962 /* Make sure not to free the namespace twice on error. */
5964 s
->ns
= gfc_current_ns
;
5968 /* Add a procedure name to the global symbol table. */
5971 add_global_procedure (bool sub
)
5975 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
5976 name is a global identifier. */
5977 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
5979 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5982 || (s
->type
!= GSYM_UNKNOWN
5983 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5985 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5986 /* Silence follow-up errors. */
5987 gfc_new_block
->binding_label
= NULL
;
5991 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5992 s
->sym_name
= gfc_new_block
->name
;
5993 s
->where
= gfc_new_block
->declared_at
;
5995 s
->ns
= gfc_current_ns
;
5999 /* Don't add the symbol multiple times. */
6000 if (gfc_new_block
->binding_label
6001 && (!gfc_notification_std (GFC_STD_F2008
)
6002 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
6004 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
);
6007 || (s
->type
!= GSYM_UNKNOWN
6008 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6010 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6011 /* Silence follow-up errors. */
6012 gfc_new_block
->binding_label
= NULL
;
6016 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6017 s
->sym_name
= gfc_new_block
->name
;
6018 s
->binding_label
= gfc_new_block
->binding_label
;
6019 s
->where
= gfc_new_block
->declared_at
;
6021 s
->ns
= gfc_current_ns
;
6027 /* Add a program to the global symbol table. */
6030 add_global_program (void)
6034 if (gfc_new_block
== NULL
)
6036 s
= gfc_get_gsymbol (gfc_new_block
->name
);
6038 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
6039 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6042 s
->type
= GSYM_PROGRAM
;
6043 s
->where
= gfc_new_block
->declared_at
;
6045 s
->ns
= gfc_current_ns
;
6050 /* Resolve all the program units. */
6052 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6054 gfc_free_dt_list ();
6055 gfc_current_ns
= gfc_global_ns_list
;
6056 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6058 if (gfc_current_ns
->proc_name
6059 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6060 continue; /* Already resolved. */
6062 if (gfc_current_ns
->proc_name
)
6063 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6064 gfc_resolve (gfc_current_ns
);
6065 gfc_current_ns
->derived_types
= gfc_derived_types
;
6066 gfc_derived_types
= NULL
;
6072 clean_up_modules (gfc_gsymbol
*gsym
)
6077 clean_up_modules (gsym
->left
);
6078 clean_up_modules (gsym
->right
);
6080 if (gsym
->type
!= GSYM_MODULE
|| !gsym
->ns
)
6083 gfc_current_ns
= gsym
->ns
;
6084 gfc_derived_types
= gfc_current_ns
->derived_types
;
6091 /* Translate all the program units. This could be in a different order
6092 to resolution if there are forward references in the file. */
6094 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6098 gfc_current_ns
= gfc_global_ns_list
;
6099 gfc_get_errors (NULL
, &errors
);
6101 /* We first translate all modules to make sure that later parts
6102 of the program can use the decl. Then we translate the nonmodules. */
6104 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6106 if (!gfc_current_ns
->proc_name
6107 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6110 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6111 gfc_derived_types
= gfc_current_ns
->derived_types
;
6112 gfc_generate_module_code (gfc_current_ns
);
6113 gfc_current_ns
->translated
= 1;
6116 gfc_current_ns
= gfc_global_ns_list
;
6117 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6119 if (gfc_current_ns
->proc_name
6120 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6123 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6124 gfc_derived_types
= gfc_current_ns
->derived_types
;
6125 gfc_generate_code (gfc_current_ns
);
6126 gfc_current_ns
->translated
= 1;
6129 /* Clean up all the namespaces after translation. */
6130 gfc_current_ns
= gfc_global_ns_list
;
6131 for (;gfc_current_ns
;)
6135 if (gfc_current_ns
->proc_name
6136 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6138 gfc_current_ns
= gfc_current_ns
->sibling
;
6142 ns
= gfc_current_ns
->sibling
;
6143 gfc_derived_types
= gfc_current_ns
->derived_types
;
6145 gfc_current_ns
= ns
;
6148 clean_up_modules (gfc_gsym_root
);
6152 /* Top level parser. */
6155 gfc_parse_file (void)
6157 int seen_program
, errors_before
, errors
;
6158 gfc_state_data top
, s
;
6161 gfc_namespace
*next
;
6163 gfc_start_source_files ();
6165 top
.state
= COMP_NONE
;
6167 top
.previous
= NULL
;
6168 top
.head
= top
.tail
= NULL
;
6169 top
.do_variable
= NULL
;
6171 gfc_state_stack
= &top
;
6173 gfc_clear_new_st ();
6175 gfc_statement_label
= NULL
;
6177 if (setjmp (eof_buf
))
6178 return false; /* Come here on unexpected EOF */
6180 /* Prepare the global namespace that will contain the
6182 gfc_global_ns_list
= next
= NULL
;
6187 /* Exit early for empty files. */
6191 in_specification_block
= true;
6194 st
= next_statement ();
6203 goto duplicate_main
;
6205 prog_locus
= gfc_current_locus
;
6207 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6208 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
6209 accept_statement (st
);
6210 add_global_program ();
6211 parse_progunit (ST_NONE
);
6215 add_global_procedure (true);
6216 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
6217 accept_statement (st
);
6218 parse_progunit (ST_NONE
);
6222 add_global_procedure (false);
6223 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
6224 accept_statement (st
);
6225 parse_progunit (ST_NONE
);
6229 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
6230 accept_statement (st
);
6231 parse_block_data ();
6235 push_state (&s
, COMP_MODULE
, gfc_new_block
);
6236 accept_statement (st
);
6238 gfc_get_errors (NULL
, &errors_before
);
6243 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
6244 accept_statement (st
);
6246 gfc_get_errors (NULL
, &errors_before
);
6250 /* Anything else starts a nameless main program block. */
6253 goto duplicate_main
;
6255 prog_locus
= gfc_current_locus
;
6257 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6258 main_program_symbol (gfc_current_ns
, "MAIN__");
6259 parse_progunit (st
);
6263 /* Handle the non-program units. */
6264 gfc_current_ns
->code
= s
.head
;
6266 gfc_resolve (gfc_current_ns
);
6268 /* Dump the parse tree if requested. */
6269 if (flag_dump_fortran_original
)
6270 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6272 if (flag_c_prototypes
)
6273 gfc_dump_c_prototypes (gfc_current_ns
, stdout
);
6275 gfc_get_errors (NULL
, &errors
);
6276 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
6278 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
6279 gfc_current_ns
->derived_types
= gfc_derived_types
;
6280 gfc_derived_types
= NULL
;
6286 gfc_generate_code (gfc_current_ns
);
6294 /* The main program and non-contained procedures are put
6295 in the global namespace list, so that they can be processed
6296 later and all their interfaces resolved. */
6297 gfc_current_ns
->code
= s
.head
;
6300 for (; next
->sibling
; next
= next
->sibling
)
6302 next
->sibling
= gfc_current_ns
;
6305 gfc_global_ns_list
= gfc_current_ns
;
6307 next
= gfc_current_ns
;
6313 /* Do the resolution. */
6314 resolve_all_program_units (gfc_global_ns_list
);
6316 /* Do the parse tree dump. */
6317 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6319 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6320 if (!gfc_current_ns
->proc_name
6321 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6323 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6324 fputs ("------------------------------------------\n\n", stdout
);
6327 /* Do the translation. */
6328 translate_all_program_units (gfc_global_ns_list
);
6330 gfc_end_source_files ();
6334 /* If we see a duplicate main program, shut down. If the second
6335 instance is an implied main program, i.e. data decls or executable
6336 statements, we're in for lots of errors. */
6337 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6338 reject_statement ();
6343 /* Return true if this state data represents an OpenACC region. */
6345 is_oacc (gfc_state_data
*sd
)
6347 switch (sd
->construct
->op
)
6349 case EXEC_OACC_PARALLEL_LOOP
:
6350 case EXEC_OACC_PARALLEL
:
6351 case EXEC_OACC_KERNELS_LOOP
:
6352 case EXEC_OACC_KERNELS
:
6353 case EXEC_OACC_DATA
:
6354 case EXEC_OACC_HOST_DATA
:
6355 case EXEC_OACC_LOOP
:
6356 case EXEC_OACC_UPDATE
:
6357 case EXEC_OACC_WAIT
:
6358 case EXEC_OACC_CACHE
:
6359 case EXEC_OACC_ENTER_DATA
:
6360 case EXEC_OACC_EXIT_DATA
:
6361 case EXEC_OACC_ATOMIC
:
6362 case EXEC_OACC_ROUTINE
: