2 Copyright (C) 2000-2016 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 /* Current statement label. Zero means no statement label. Because new_st
31 can get wiped during statement matching, we have to keep it separate. */
33 gfc_st_label
*gfc_statement_label
;
35 static locus label_locus
;
36 static jmp_buf eof_buf
;
38 gfc_state_data
*gfc_state_stack
;
39 static bool last_was_use_stmt
= false;
41 /* TODO: Re-order functions to kill these forward decls. */
42 static void check_statement_label (gfc_statement
);
43 static void undo_new_statement (void);
44 static void reject_statement (void);
47 /* A sort of half-matching function. We try to match the word on the
48 input with the passed string. If this succeeds, we call the
49 keyword-dependent matching function that will match the rest of the
50 statement. For single keywords, the matching subroutine is
54 match_word (const char *str
, match (*subr
) (void), locus
*old_locus
)
69 gfc_current_locus
= *old_locus
;
77 /* Like match_word, but if str is matched, set a flag that it
80 match_word_omp_simd (const char *str
, match (*subr
) (void), locus
*old_locus
,
97 gfc_current_locus
= *old_locus
;
105 /* Load symbols from all USE statements encountered in this scoping unit. */
110 gfc_error_buffer old_error
;
112 gfc_push_error (&old_error
);
113 gfc_buffer_error (false);
115 gfc_buffer_error (true);
116 gfc_pop_error (&old_error
);
117 gfc_commit_symbols ();
118 gfc_warning_check ();
119 gfc_current_ns
->old_cl_list
= gfc_current_ns
->cl_list
;
120 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
121 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
122 last_was_use_stmt
= false;
126 /* Figure out what the next statement is, (mostly) regardless of
127 proper ordering. The do...while(0) is there to prevent if/else
130 #define match(keyword, subr, st) \
132 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
135 undo_new_statement (); \
139 /* This is a specialist version of decode_statement that is used
140 for the specification statements in a function, whose
141 characteristics are deferred into the specification statements.
142 eg.: INTEGER (king = mykind) foo ()
143 USE mymodule, ONLY mykind.....
144 The KIND parameter needs a return after USE or IMPORT, whereas
145 derived type declarations can occur anywhere, up the executable
146 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
147 out of the correct kind of specification statements. */
149 decode_specification_statement (void)
155 if (gfc_match_eos () == MATCH_YES
)
158 old_locus
= gfc_current_locus
;
160 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
162 last_was_use_stmt
= true;
167 undo_new_statement ();
168 if (last_was_use_stmt
)
172 match ("import", gfc_match_import
, ST_IMPORT
);
174 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
177 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
178 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
179 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
181 /* General statement matching: Instead of testing every possible
182 statement, we eliminate most possibilities by peeking at the
185 c
= gfc_peek_ascii_char ();
190 match ("abstract% interface", gfc_match_abstract_interface
,
192 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
193 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
197 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
201 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
202 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
206 match ("data", gfc_match_data
, ST_DATA
);
207 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
211 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
212 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
213 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
214 match ("external", gfc_match_external
, ST_ATTR_DECL
);
218 match ("format", gfc_match_format
, ST_FORMAT
);
225 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
226 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
227 match ("interface", gfc_match_interface
, ST_INTERFACE
);
228 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
229 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
236 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
240 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
244 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
245 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
246 if (gfc_match_private (&st
) == MATCH_YES
)
248 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
249 if (gfc_match_public (&st
) == MATCH_YES
)
251 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
258 match ("save", gfc_match_save
, ST_ATTR_DECL
);
259 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
263 match ("target", gfc_match_target
, ST_ATTR_DECL
);
264 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
271 match ("value", gfc_match_value
, ST_ATTR_DECL
);
272 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
279 /* This is not a specification statement. See if any of the matchers
280 has stored an error message of some sort. */
284 gfc_buffer_error (false);
285 gfc_current_locus
= old_locus
;
287 return ST_GET_FCN_CHARACTERISTICS
;
290 static bool in_specification_block
;
292 /* This is the primary 'decode_statement'. */
294 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;
355 /* Match statements whose error messages are meant to be overwritten
356 by something better. */
358 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
359 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
361 if (in_specification_block
)
363 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
365 return ST_STATEMENT_FUNCTION
;
368 if (!(in_specification_block
&& m
== MATCH_ERROR
))
370 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
373 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
374 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
376 /* Try to match a subroutine statement, which has the same optional
377 prefixes that functions can have. */
379 if (gfc_match_subroutine () == MATCH_YES
)
380 return ST_SUBROUTINE
;
382 gfc_current_locus
= old_locus
;
384 if (gfc_match_submod_proc () == MATCH_YES
)
386 if (gfc_new_block
->attr
.subroutine
)
387 return ST_SUBROUTINE
;
388 else if (gfc_new_block
->attr
.function
)
392 gfc_current_locus
= old_locus
;
394 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
395 statements, which might begin with a block label. The match functions for
396 these statements are unusual in that their keyword is not seen before
397 the matcher is called. */
399 if (gfc_match_if (&st
) == MATCH_YES
)
402 gfc_current_locus
= old_locus
;
404 if (gfc_match_where (&st
) == MATCH_YES
)
407 gfc_current_locus
= old_locus
;
409 if (gfc_match_forall (&st
) == MATCH_YES
)
412 gfc_current_locus
= old_locus
;
414 match (NULL
, gfc_match_do
, ST_DO
);
415 match (NULL
, gfc_match_block
, ST_BLOCK
);
416 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
417 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
418 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
420 gfc_current_ns
= gfc_build_block_ns (gfc_current_ns
);
421 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
423 gfc_current_ns
= gfc_current_ns
->parent
;
424 gfc_free_namespace (ns
);
426 /* General statement matching: Instead of testing every possible
427 statement, we eliminate most possibilities by peeking at the
433 match ("abstract% interface", gfc_match_abstract_interface
,
435 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
436 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
437 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
438 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
442 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
443 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
444 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
448 match ("call", gfc_match_call
, ST_CALL
);
449 match ("close", gfc_match_close
, ST_CLOSE
);
450 match ("continue", gfc_match_continue
, ST_CONTINUE
);
451 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
452 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
453 match ("case", gfc_match_case
, ST_CASE
);
454 match ("common", gfc_match_common
, ST_COMMON
);
455 match ("contains", gfc_match_eos
, ST_CONTAINS
);
456 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
457 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
461 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
462 match ("data", gfc_match_data
, ST_DATA
);
463 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
467 match ("end file", gfc_match_endfile
, ST_END_FILE
);
468 match ("exit", gfc_match_exit
, ST_EXIT
);
469 match ("else", gfc_match_else
, ST_ELSE
);
470 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
471 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
472 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
);
473 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
475 if (gfc_match_end (&st
) == MATCH_YES
)
478 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
479 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
480 match ("external", gfc_match_external
, ST_ATTR_DECL
);
481 match ("event post", gfc_match_event_post
, ST_EVENT_POST
);
482 match ("event wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
486 match ("final", gfc_match_final_decl
, ST_FINAL
);
487 match ("flush", gfc_match_flush
, ST_FLUSH
);
488 match ("format", gfc_match_format
, ST_FORMAT
);
492 match ("generic", gfc_match_generic
, ST_GENERIC
);
493 match ("go to", gfc_match_goto
, ST_GOTO
);
497 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
498 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
499 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
500 match ("import", gfc_match_import
, ST_IMPORT
);
501 match ("interface", gfc_match_interface
, ST_INTERFACE
);
502 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
503 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
507 match ("lock", gfc_match_lock
, ST_LOCK
);
511 match ("map", gfc_match_map
, ST_MAP
);
512 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
513 match ("module", gfc_match_module
, ST_MODULE
);
517 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
518 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
522 match ("open", gfc_match_open
, ST_OPEN
);
523 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
527 match ("print", gfc_match_print
, ST_WRITE
);
528 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
529 match ("pause", gfc_match_pause
, ST_PAUSE
);
530 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
531 if (gfc_match_private (&st
) == MATCH_YES
)
533 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
534 match ("program", gfc_match_program
, ST_PROGRAM
);
535 if (gfc_match_public (&st
) == MATCH_YES
)
537 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
541 match ("read", gfc_match_read
, ST_READ
);
542 match ("return", gfc_match_return
, ST_RETURN
);
543 match ("rewind", gfc_match_rewind
, ST_REWIND
);
547 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
548 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
549 match ("stop", gfc_match_stop
, ST_STOP
);
550 match ("save", gfc_match_save
, ST_ATTR_DECL
);
551 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
552 match ("sync all", gfc_match_sync_all
, ST_SYNC_ALL
);
553 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
554 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
558 match ("target", gfc_match_target
, ST_ATTR_DECL
);
559 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
560 match ("type is", gfc_match_type_is
, ST_TYPE_IS
);
564 match ("union", gfc_match_union
, ST_UNION
);
565 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
569 match ("value", gfc_match_value
, ST_ATTR_DECL
);
570 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
574 match ("wait", gfc_match_wait
, ST_WAIT
);
575 match ("write", gfc_match_write
, ST_WRITE
);
579 /* All else has failed, so give up. See if any of the matchers has
580 stored an error message of some sort. */
582 if (!gfc_error_check ())
583 gfc_error_now ("Unclassifiable statement at %C");
587 gfc_error_recovery ();
592 /* Like match, but set a flag simd_matched if keyword matched. */
593 #define matchs(keyword, subr, st) \
595 if (match_word_omp_simd (keyword, subr, &old_locus, \
596 &simd_matched) == MATCH_YES) \
599 undo_new_statement (); \
602 /* Like match, but don't match anything if not -fopenmp. */
603 #define matcho(keyword, subr, st) \
607 else if (match_word (keyword, subr, &old_locus) \
611 undo_new_statement (); \
615 decode_oacc_directive (void)
620 gfc_enforce_clean_symbol_state ();
622 gfc_clear_error (); /* Clear any pending errors. */
623 gfc_clear_warning (); /* Clear any pending warnings. */
627 gfc_error_now ("OpenACC directives at %C may not appear in PURE "
629 gfc_error_recovery ();
633 gfc_unset_implicit_pure (NULL
);
635 old_locus
= gfc_current_locus
;
637 /* General OpenACC directive matching: Instead of testing every possible
638 statement, we eliminate most possibilities by peeking at the
641 c
= gfc_peek_ascii_char ();
646 match ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
649 match ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
652 match ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
653 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
656 match ("end atomic", gfc_match_omp_eos
, ST_OACC_END_ATOMIC
);
657 match ("end data", gfc_match_omp_eos
, ST_OACC_END_DATA
);
658 match ("end host_data", gfc_match_omp_eos
, ST_OACC_END_HOST_DATA
);
659 match ("end kernels loop", gfc_match_omp_eos
, ST_OACC_END_KERNELS_LOOP
);
660 match ("end kernels", gfc_match_omp_eos
, ST_OACC_END_KERNELS
);
661 match ("end loop", gfc_match_omp_eos
, ST_OACC_END_LOOP
);
662 match ("end parallel loop", gfc_match_omp_eos
, ST_OACC_END_PARALLEL_LOOP
);
663 match ("end parallel", gfc_match_omp_eos
, ST_OACC_END_PARALLEL
);
664 match ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
665 match ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
668 match ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
671 match ("parallel loop", gfc_match_oacc_parallel_loop
, ST_OACC_PARALLEL_LOOP
);
672 match ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
675 match ("kernels loop", gfc_match_oacc_kernels_loop
, ST_OACC_KERNELS_LOOP
);
676 match ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
679 match ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
682 match ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
685 match ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
688 match ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
692 /* Directive not found or stored an error message.
693 Check and give up. */
695 if (gfc_error_check () == 0)
696 gfc_error_now ("Unclassifiable OpenACC directive at %C");
700 gfc_error_recovery ();
706 decode_omp_directive (void)
710 bool simd_matched
= false;
712 gfc_enforce_clean_symbol_state ();
714 gfc_clear_error (); /* Clear any pending errors. */
715 gfc_clear_warning (); /* Clear any pending warnings. */
719 gfc_error_now ("OpenMP directives at %C may not appear in PURE "
720 "or ELEMENTAL procedures");
721 gfc_error_recovery ();
725 gfc_unset_implicit_pure (NULL
);
727 old_locus
= gfc_current_locus
;
729 /* General OpenMP directive matching: Instead of testing every possible
730 statement, we eliminate most possibilities by peeking at the
733 c
= gfc_peek_ascii_char ();
735 /* match is for directives that should be recognized only if
736 -fopenmp, matchs for directives that should be recognized
737 if either -fopenmp or -fopenmp-simd. */
741 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
744 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
747 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
748 ST_OMP_CANCELLATION_POINT
);
749 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
750 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
753 matchs ("declare reduction", gfc_match_omp_declare_reduction
,
754 ST_OMP_DECLARE_REDUCTION
);
755 matchs ("declare simd", gfc_match_omp_declare_simd
,
756 ST_OMP_DECLARE_SIMD
);
757 matcho ("declare target", gfc_match_omp_declare_target
,
758 ST_OMP_DECLARE_TARGET
);
759 matchs ("distribute parallel do simd",
760 gfc_match_omp_distribute_parallel_do_simd
,
761 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
762 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
763 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
764 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
765 ST_OMP_DISTRIBUTE_SIMD
);
766 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
767 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
768 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
771 matcho ("end atomic", gfc_match_omp_eos
, ST_OMP_END_ATOMIC
);
772 matcho ("end critical", gfc_match_omp_critical
, ST_OMP_END_CRITICAL
);
773 matchs ("end distribute parallel do simd", gfc_match_omp_eos
,
774 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
775 matcho ("end distribute parallel do", gfc_match_omp_eos
,
776 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
777 matchs ("end distribute simd", gfc_match_omp_eos
,
778 ST_OMP_END_DISTRIBUTE_SIMD
);
779 matcho ("end distribute", gfc_match_omp_eos
, ST_OMP_END_DISTRIBUTE
);
780 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
781 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
782 matchs ("end simd", gfc_match_omp_eos
, ST_OMP_END_SIMD
);
783 matcho ("end master", gfc_match_omp_eos
, ST_OMP_END_MASTER
);
784 matcho ("end ordered", gfc_match_omp_eos
, ST_OMP_END_ORDERED
);
785 matchs ("end parallel do simd", gfc_match_omp_eos
,
786 ST_OMP_END_PARALLEL_DO_SIMD
);
787 matcho ("end parallel do", gfc_match_omp_eos
, ST_OMP_END_PARALLEL_DO
);
788 matcho ("end parallel sections", gfc_match_omp_eos
,
789 ST_OMP_END_PARALLEL_SECTIONS
);
790 matcho ("end parallel workshare", gfc_match_omp_eos
,
791 ST_OMP_END_PARALLEL_WORKSHARE
);
792 matcho ("end parallel", gfc_match_omp_eos
, ST_OMP_END_PARALLEL
);
793 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
794 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
795 matcho ("end target data", gfc_match_omp_eos
, ST_OMP_END_TARGET_DATA
);
796 matchs ("end target teams distribute parallel do simd",
798 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
799 matcho ("end target teams distribute parallel do", gfc_match_omp_eos
,
800 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
801 matchs ("end target teams distribute simd", gfc_match_omp_eos
,
802 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
803 matcho ("end target teams distribute", gfc_match_omp_eos
,
804 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
805 matcho ("end target teams", gfc_match_omp_eos
, ST_OMP_END_TARGET_TEAMS
);
806 matcho ("end target", gfc_match_omp_eos
, ST_OMP_END_TARGET
);
807 matcho ("end taskgroup", gfc_match_omp_eos
, ST_OMP_END_TASKGROUP
);
808 matcho ("end task", gfc_match_omp_eos
, ST_OMP_END_TASK
);
809 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos
,
810 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
811 matcho ("end teams distribute parallel do", gfc_match_omp_eos
,
812 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
813 matchs ("end teams distribute simd", gfc_match_omp_eos
,
814 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
815 matcho ("end teams distribute", gfc_match_omp_eos
,
816 ST_OMP_END_TEAMS_DISTRIBUTE
);
817 matcho ("end teams", gfc_match_omp_eos
, ST_OMP_END_TEAMS
);
818 matcho ("end workshare", gfc_match_omp_end_nowait
,
819 ST_OMP_END_WORKSHARE
);
822 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
825 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
828 matcho ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
831 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
832 ST_OMP_PARALLEL_DO_SIMD
);
833 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
834 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
835 ST_OMP_PARALLEL_SECTIONS
);
836 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
837 ST_OMP_PARALLEL_WORKSHARE
);
838 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
841 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
842 matcho ("section", gfc_match_omp_eos
, ST_OMP_SECTION
);
843 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
844 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
847 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
848 matchs ("target teams distribute parallel do simd",
849 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
850 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
851 matcho ("target teams distribute parallel do",
852 gfc_match_omp_target_teams_distribute_parallel_do
,
853 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
854 matchs ("target teams distribute simd",
855 gfc_match_omp_target_teams_distribute_simd
,
856 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
857 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
858 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
859 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
860 matcho ("target update", gfc_match_omp_target_update
,
861 ST_OMP_TARGET_UPDATE
);
862 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
863 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
864 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
865 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
866 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
867 matchs ("teams distribute parallel do simd",
868 gfc_match_omp_teams_distribute_parallel_do_simd
,
869 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
870 matcho ("teams distribute parallel do",
871 gfc_match_omp_teams_distribute_parallel_do
,
872 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
873 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
874 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
875 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
876 ST_OMP_TEAMS_DISTRIBUTE
);
877 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
878 matcho ("threadprivate", gfc_match_omp_threadprivate
,
879 ST_OMP_THREADPRIVATE
);
882 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
886 /* All else has failed, so give up. See if any of the matchers has
887 stored an error message of some sort. Don't error out if
888 not -fopenmp and simd_matched is false, i.e. if a directive other
889 than one marked with match has been seen. */
891 if (flag_openmp
|| simd_matched
)
893 if (!gfc_error_check ())
894 gfc_error_now ("Unclassifiable OpenMP directive at %C");
899 gfc_error_recovery ();
905 decode_gcc_attribute (void)
909 gfc_enforce_clean_symbol_state ();
911 gfc_clear_error (); /* Clear any pending errors. */
912 gfc_clear_warning (); /* Clear any pending warnings. */
913 old_locus
= gfc_current_locus
;
915 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
917 /* All else has failed, so give up. See if any of the matchers has
918 stored an error message of some sort. */
920 if (!gfc_error_check ())
921 gfc_error_now ("Unclassifiable GCC directive at %C");
925 gfc_error_recovery ();
932 /* Assert next length characters to be equal to token in free form. */
935 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
940 c
= gfc_next_ascii_char ();
941 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
942 gcc_assert (c
== token
[i
]);
944 gcc_assert (gfc_is_whitespace(c
));
945 gfc_gobble_whitespace ();
946 if (last_was_use_stmt
)
950 /* Get the next statement in free form source. */
959 at_bol
= gfc_at_bol ();
960 gfc_gobble_whitespace ();
962 c
= gfc_peek_ascii_char ();
968 /* Found a statement label? */
969 m
= gfc_match_st_label (&gfc_statement_label
);
971 d
= gfc_peek_ascii_char ();
972 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
974 gfc_match_small_literal_int (&i
, &cnt
);
977 gfc_error_now ("Too many digits in statement label at %C");
980 gfc_error_now ("Zero is not a valid statement label at %C");
983 c
= gfc_next_ascii_char ();
986 if (!gfc_is_whitespace (c
))
987 gfc_error_now ("Non-numeric character in statement label at %C");
993 label_locus
= gfc_current_locus
;
995 gfc_gobble_whitespace ();
997 if (at_bol
&& gfc_peek_ascii_char () == ';')
999 gfc_error_now ("Semicolon at %C needs to be preceded by "
1001 gfc_next_ascii_char (); /* Eat up the semicolon. */
1005 if (gfc_match_eos () == MATCH_YES
)
1007 gfc_warning_now (0, "Ignoring statement label in empty statement "
1008 "at %L", &label_locus
);
1009 gfc_free_st_label (gfc_statement_label
);
1010 gfc_statement_label
= NULL
;
1017 /* Comments have already been skipped by the time we get here,
1018 except for GCC attributes and OpenMP/OpenACC directives. */
1020 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1021 c
= gfc_peek_ascii_char ();
1027 c
= gfc_next_ascii_char ();
1028 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1029 gcc_assert (c
== "gcc$"[i
]);
1031 gfc_gobble_whitespace ();
1032 return decode_gcc_attribute ();
1037 /* Since both OpenMP and OpenACC directives starts with
1038 !$ character sequence, we must check all flags combinations */
1039 if ((flag_openmp
|| flag_openmp_simd
)
1042 verify_token_free ("$omp", 4, last_was_use_stmt
);
1043 return decode_omp_directive ();
1045 else if ((flag_openmp
|| flag_openmp_simd
)
1048 gfc_next_ascii_char (); /* Eat up dollar character */
1049 c
= gfc_peek_ascii_char ();
1053 verify_token_free ("omp", 3, last_was_use_stmt
);
1054 return decode_omp_directive ();
1058 verify_token_free ("acc", 3, last_was_use_stmt
);
1059 return decode_oacc_directive ();
1062 else if (flag_openacc
)
1064 verify_token_free ("$acc", 4, last_was_use_stmt
);
1065 return decode_oacc_directive ();
1071 if (at_bol
&& c
== ';')
1073 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1074 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1076 gfc_next_ascii_char (); /* Eat up the semicolon. */
1080 return decode_statement ();
1083 /* Assert next length characters to be equal to token in fixed form. */
1086 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1089 char c
= gfc_next_char_literal (NONSTRING
);
1091 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1092 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1094 if (c
!= ' ' && c
!= '0')
1096 gfc_buffer_error (false);
1097 gfc_error ("Bad continuation line at %C");
1100 if (last_was_use_stmt
)
1106 /* Get the next statement in fixed-form source. */
1108 static gfc_statement
1111 int label
, digit_flag
, i
;
1116 return decode_statement ();
1118 /* Skip past the current label field, parsing a statement label if
1119 one is there. This is a weird number parser, since the number is
1120 contained within five columns and can have any kind of embedded
1121 spaces. We also check for characters that make the rest of the
1127 for (i
= 0; i
< 5; i
++)
1129 c
= gfc_next_char_literal (NONSTRING
);
1146 label
= label
* 10 + ((unsigned char) c
- '0');
1147 label_locus
= gfc_current_locus
;
1151 /* Comments have already been skipped by the time we get
1152 here, except for GCC attributes and OpenMP directives. */
1155 c
= gfc_next_char_literal (NONSTRING
);
1157 if (TOLOWER (c
) == 'g')
1159 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1160 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1162 return decode_gcc_attribute ();
1166 if ((flag_openmp
|| flag_openmp_simd
)
1169 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1171 return decode_omp_directive ();
1173 else if ((flag_openmp
|| flag_openmp_simd
)
1176 c
= gfc_next_char_literal(NONSTRING
);
1177 if (c
== 'o' || c
== 'O')
1179 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1181 return decode_omp_directive ();
1183 else if (c
== 'a' || c
== 'A')
1185 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1187 return decode_oacc_directive ();
1190 else if (flag_openacc
)
1192 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1194 return decode_oacc_directive ();
1199 /* Comments have already been skipped by the time we get
1200 here so don't bother checking for them. */
1203 gfc_buffer_error (false);
1204 gfc_error ("Non-numeric character in statement label at %C");
1212 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1215 /* We've found a valid statement label. */
1216 gfc_statement_label
= gfc_get_st_label (label
);
1220 /* Since this line starts a statement, it cannot be a continuation
1221 of a previous statement. If we see something here besides a
1222 space or zero, it must be a bad continuation line. */
1224 c
= gfc_next_char_literal (NONSTRING
);
1228 if (c
!= ' ' && c
!= '0')
1230 gfc_buffer_error (false);
1231 gfc_error ("Bad continuation line at %C");
1235 /* Now that we've taken care of the statement label columns, we have
1236 to make sure that the first nonblank character is not a '!'. If
1237 it is, the rest of the line is a comment. */
1241 loc
= gfc_current_locus
;
1242 c
= gfc_next_char_literal (NONSTRING
);
1244 while (gfc_is_whitespace (c
));
1248 gfc_current_locus
= loc
;
1253 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1254 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1255 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1260 if (gfc_match_eos () == MATCH_YES
)
1263 /* At this point, we've got a nonblank statement to parse. */
1264 return decode_statement ();
1268 gfc_warning_now (0, "Ignoring statement label in empty statement at %L",
1271 gfc_current_locus
.lb
->truncated
= 0;
1272 gfc_advance_line ();
1277 /* Return the next non-ST_NONE statement to the caller. We also worry
1278 about including files and the ends of include files at this stage. */
1280 static gfc_statement
1281 next_statement (void)
1286 gfc_enforce_clean_symbol_state ();
1288 gfc_new_block
= NULL
;
1290 gfc_current_ns
->old_cl_list
= gfc_current_ns
->cl_list
;
1291 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1292 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1295 gfc_statement_label
= NULL
;
1296 gfc_buffer_error (true);
1299 gfc_advance_line ();
1301 gfc_skip_comments ();
1309 if (gfc_define_undef_line ())
1312 old_locus
= gfc_current_locus
;
1314 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1320 gfc_buffer_error (false);
1322 if (st
== ST_GET_FCN_CHARACTERISTICS
&& gfc_statement_label
!= NULL
)
1324 gfc_free_st_label (gfc_statement_label
);
1325 gfc_statement_label
= NULL
;
1326 gfc_current_locus
= old_locus
;
1330 check_statement_label (st
);
1336 /****************************** Parser ***********************************/
1338 /* The parser subroutines are of type 'try' that fail if the file ends
1341 /* Macros that expand to case-labels for various classes of
1342 statements. Start with executable statements that directly do
1345 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1346 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1347 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1348 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1349 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1350 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1351 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1352 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1353 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1354 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: \
1355 case ST_OMP_TARGET_UPDATE: case ST_ERROR_STOP: case ST_SYNC_ALL: \
1356 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1357 case ST_EVENT_POST: case ST_EVENT_WAIT: \
1358 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1359 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1361 /* Statements that mark other executable statements. */
1363 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1364 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1365 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1366 case ST_OMP_PARALLEL: \
1367 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1368 case ST_OMP_CRITICAL: case ST_OMP_MASTER: case ST_OMP_SINGLE: \
1369 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1370 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1371 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1372 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1373 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1374 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1375 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1376 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1377 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1378 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1379 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1380 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1381 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1382 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1383 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: \
1385 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1386 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1387 case ST_OACC_KERNELS_LOOP: case ST_OACC_ATOMIC
1389 /* Declaration statements */
1391 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1392 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1393 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE: case ST_OACC_ROUTINE: \
1394 case ST_OACC_DECLARE
1396 /* OpenMP declaration statements. */
1398 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1399 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION
1401 /* Block end statements. Errors associated with interchanging these
1402 are detected in gfc_match_end(). */
1404 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1405 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1406 case ST_END_BLOCK: case ST_END_ASSOCIATE
1409 /* Push a new state onto the stack. */
1412 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1414 p
->state
= new_state
;
1415 p
->previous
= gfc_state_stack
;
1417 p
->head
= p
->tail
= NULL
;
1418 p
->do_variable
= NULL
;
1419 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1420 p
->ext
.oacc_declare_clauses
= NULL
;
1422 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1423 construct statement was accepted right before pushing the state. Thus,
1424 the construct's gfc_code is available as tail of the parent state. */
1425 gcc_assert (gfc_state_stack
);
1426 p
->construct
= gfc_state_stack
->tail
;
1428 gfc_state_stack
= p
;
1432 /* Pop the current state. */
1436 gfc_state_stack
= gfc_state_stack
->previous
;
1440 /* Try to find the given state in the state stack. */
1443 gfc_find_state (gfc_compile_state state
)
1447 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1448 if (p
->state
== state
)
1451 return (p
== NULL
) ? false : true;
1455 /* Starts a new level in the statement list. */
1458 new_level (gfc_code
*q
)
1462 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1464 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1470 /* Add the current new_st code structure and adds it to the current
1471 program unit. As a side-effect, it zeroes the new_st. */
1474 add_statement (void)
1478 p
= XCNEW (gfc_code
);
1481 p
->loc
= gfc_current_locus
;
1483 if (gfc_state_stack
->head
== NULL
)
1484 gfc_state_stack
->head
= p
;
1486 gfc_state_stack
->tail
->next
= p
;
1488 while (p
->next
!= NULL
)
1491 gfc_state_stack
->tail
= p
;
1493 gfc_clear_new_st ();
1499 /* Frees everything associated with the current statement. */
1502 undo_new_statement (void)
1504 gfc_free_statements (new_st
.block
);
1505 gfc_free_statements (new_st
.next
);
1506 gfc_free_statement (&new_st
);
1507 gfc_clear_new_st ();
1511 /* If the current statement has a statement label, make sure that it
1512 is allowed to, or should have one. */
1515 check_statement_label (gfc_statement st
)
1519 if (gfc_statement_label
== NULL
)
1521 if (st
== ST_FORMAT
)
1522 gfc_error ("FORMAT statement at %L does not have a statement label",
1529 case ST_END_PROGRAM
:
1530 case ST_END_FUNCTION
:
1531 case ST_END_SUBROUTINE
:
1535 case ST_END_CRITICAL
:
1537 case ST_END_ASSOCIATE
:
1540 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1541 type
= ST_LABEL_DO_TARGET
;
1543 type
= ST_LABEL_TARGET
;
1547 type
= ST_LABEL_FORMAT
;
1550 /* Statement labels are not restricted from appearing on a
1551 particular line. However, there are plenty of situations
1552 where the resulting label can't be referenced. */
1555 type
= ST_LABEL_BAD_TARGET
;
1559 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1561 new_st
.here
= gfc_statement_label
;
1565 /* Figures out what the enclosing program unit is. This will be a
1566 function, subroutine, program, block data or module. */
1569 gfc_enclosing_unit (gfc_compile_state
* result
)
1573 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1574 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1575 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1576 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1585 *result
= COMP_PROGRAM
;
1590 /* Translate a statement enum to a string. */
1593 gfc_ascii_statement (gfc_statement st
)
1599 case ST_ARITHMETIC_IF
:
1600 p
= _("arithmetic IF");
1609 p
= _("attribute declaration");
1645 p
= _("data declaration");
1659 case ST_STRUCTURE_DECL
:
1662 case ST_DERIVED_DECL
:
1663 p
= _("derived type declaration");
1683 case ST_END_ASSOCIATE
:
1684 p
= "END ASSOCIATE";
1689 case ST_END_BLOCK_DATA
:
1690 p
= "END BLOCK DATA";
1692 case ST_END_CRITICAL
:
1704 case ST_END_FUNCTION
:
1710 case ST_END_INTERFACE
:
1711 p
= "END INTERFACE";
1716 case ST_END_SUBMODULE
:
1717 p
= "END SUBMODULE";
1719 case ST_END_PROGRAM
:
1725 case ST_END_SUBROUTINE
:
1726 p
= "END SUBROUTINE";
1731 case ST_END_STRUCTURE
:
1732 p
= "END STRUCTURE";
1746 case ST_EQUIVALENCE
:
1758 case ST_FORALL_BLOCK
: /* Fall through */
1780 case ST_IMPLICIT_NONE
:
1781 p
= "IMPLICIT NONE";
1783 case ST_IMPLIED_ENDDO
:
1784 p
= _("implied END DO");
1816 case ST_MODULE_PROC
:
1817 p
= "MODULE PROCEDURE";
1849 case ST_SYNC_IMAGES
:
1852 case ST_SYNC_MEMORY
:
1867 case ST_WHERE_BLOCK
: /* Fall through */
1878 p
= _("assignment");
1880 case ST_POINTER_ASSIGNMENT
:
1881 p
= _("pointer assignment");
1883 case ST_SELECT_CASE
:
1886 case ST_SELECT_TYPE
:
1901 case ST_STATEMENT_FUNCTION
:
1902 p
= "STATEMENT FUNCTION";
1904 case ST_LABEL_ASSIGNMENT
:
1905 p
= "LABEL ASSIGNMENT";
1908 p
= "ENUM DEFINITION";
1911 p
= "ENUMERATOR DEFINITION";
1916 case ST_OACC_PARALLEL_LOOP
:
1917 p
= "!$ACC PARALLEL LOOP";
1919 case ST_OACC_END_PARALLEL_LOOP
:
1920 p
= "!$ACC END PARALLEL LOOP";
1922 case ST_OACC_PARALLEL
:
1923 p
= "!$ACC PARALLEL";
1925 case ST_OACC_END_PARALLEL
:
1926 p
= "!$ACC END PARALLEL";
1928 case ST_OACC_KERNELS
:
1929 p
= "!$ACC KERNELS";
1931 case ST_OACC_END_KERNELS
:
1932 p
= "!$ACC END KERNELS";
1934 case ST_OACC_KERNELS_LOOP
:
1935 p
= "!$ACC KERNELS LOOP";
1937 case ST_OACC_END_KERNELS_LOOP
:
1938 p
= "!$ACC END KERNELS LOOP";
1943 case ST_OACC_END_DATA
:
1944 p
= "!$ACC END DATA";
1946 case ST_OACC_HOST_DATA
:
1947 p
= "!$ACC HOST_DATA";
1949 case ST_OACC_END_HOST_DATA
:
1950 p
= "!$ACC END HOST_DATA";
1955 case ST_OACC_END_LOOP
:
1956 p
= "!$ACC END LOOP";
1958 case ST_OACC_DECLARE
:
1959 p
= "!$ACC DECLARE";
1961 case ST_OACC_UPDATE
:
1970 case ST_OACC_ENTER_DATA
:
1971 p
= "!$ACC ENTER DATA";
1973 case ST_OACC_EXIT_DATA
:
1974 p
= "!$ACC EXIT DATA";
1976 case ST_OACC_ROUTINE
:
1977 p
= "!$ACC ROUTINE";
1979 case ST_OACC_ATOMIC
:
1982 case ST_OACC_END_ATOMIC
:
1983 p
= "!ACC END ATOMIC";
1988 case ST_OMP_BARRIER
:
1989 p
= "!$OMP BARRIER";
1994 case ST_OMP_CANCELLATION_POINT
:
1995 p
= "!$OMP CANCELLATION POINT";
1997 case ST_OMP_CRITICAL
:
1998 p
= "!$OMP CRITICAL";
2000 case ST_OMP_DECLARE_REDUCTION
:
2001 p
= "!$OMP DECLARE REDUCTION";
2003 case ST_OMP_DECLARE_SIMD
:
2004 p
= "!$OMP DECLARE SIMD";
2006 case ST_OMP_DECLARE_TARGET
:
2007 p
= "!$OMP DECLARE TARGET";
2009 case ST_OMP_DISTRIBUTE
:
2010 p
= "!$OMP DISTRIBUTE";
2012 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2013 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2015 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2016 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2018 case ST_OMP_DISTRIBUTE_SIMD
:
2019 p
= "!$OMP DISTRIBUTE SIMD";
2024 case ST_OMP_DO_SIMD
:
2025 p
= "!$OMP DO SIMD";
2027 case ST_OMP_END_ATOMIC
:
2028 p
= "!$OMP END ATOMIC";
2030 case ST_OMP_END_CRITICAL
:
2031 p
= "!$OMP END CRITICAL";
2033 case ST_OMP_END_DISTRIBUTE
:
2034 p
= "!$OMP END DISTRIBUTE";
2036 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2037 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2039 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2040 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2042 case ST_OMP_END_DISTRIBUTE_SIMD
:
2043 p
= "!$OMP END DISTRIBUTE SIMD";
2048 case ST_OMP_END_DO_SIMD
:
2049 p
= "!$OMP END DO SIMD";
2051 case ST_OMP_END_SIMD
:
2052 p
= "!$OMP END SIMD";
2054 case ST_OMP_END_MASTER
:
2055 p
= "!$OMP END MASTER";
2057 case ST_OMP_END_ORDERED
:
2058 p
= "!$OMP END ORDERED";
2060 case ST_OMP_END_PARALLEL
:
2061 p
= "!$OMP END PARALLEL";
2063 case ST_OMP_END_PARALLEL_DO
:
2064 p
= "!$OMP END PARALLEL DO";
2066 case ST_OMP_END_PARALLEL_DO_SIMD
:
2067 p
= "!$OMP END PARALLEL DO SIMD";
2069 case ST_OMP_END_PARALLEL_SECTIONS
:
2070 p
= "!$OMP END PARALLEL SECTIONS";
2072 case ST_OMP_END_PARALLEL_WORKSHARE
:
2073 p
= "!$OMP END PARALLEL WORKSHARE";
2075 case ST_OMP_END_SECTIONS
:
2076 p
= "!$OMP END SECTIONS";
2078 case ST_OMP_END_SINGLE
:
2079 p
= "!$OMP END SINGLE";
2081 case ST_OMP_END_TASK
:
2082 p
= "!$OMP END TASK";
2084 case ST_OMP_END_TARGET
:
2085 p
= "!$OMP END TARGET";
2087 case ST_OMP_END_TARGET_DATA
:
2088 p
= "!$OMP END TARGET DATA";
2090 case ST_OMP_END_TARGET_TEAMS
:
2091 p
= "!$OMP END TARGET TEAMS";
2093 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2094 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2096 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2097 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2099 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2100 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2102 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2103 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2105 case ST_OMP_END_TASKGROUP
:
2106 p
= "!$OMP END TASKGROUP";
2108 case ST_OMP_END_TEAMS
:
2109 p
= "!$OMP END TEAMS";
2111 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2112 p
= "!$OMP END TEAMS DISTRIBUTE";
2114 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2115 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2117 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2118 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2120 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2121 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2123 case ST_OMP_END_WORKSHARE
:
2124 p
= "!$OMP END WORKSHARE";
2132 case ST_OMP_ORDERED
:
2133 p
= "!$OMP ORDERED";
2135 case ST_OMP_PARALLEL
:
2136 p
= "!$OMP PARALLEL";
2138 case ST_OMP_PARALLEL_DO
:
2139 p
= "!$OMP PARALLEL DO";
2141 case ST_OMP_PARALLEL_DO_SIMD
:
2142 p
= "!$OMP PARALLEL DO SIMD";
2144 case ST_OMP_PARALLEL_SECTIONS
:
2145 p
= "!$OMP PARALLEL SECTIONS";
2147 case ST_OMP_PARALLEL_WORKSHARE
:
2148 p
= "!$OMP PARALLEL WORKSHARE";
2150 case ST_OMP_SECTIONS
:
2151 p
= "!$OMP SECTIONS";
2153 case ST_OMP_SECTION
:
2154 p
= "!$OMP SECTION";
2165 case ST_OMP_TARGET_DATA
:
2166 p
= "!$OMP TARGET DATA";
2168 case ST_OMP_TARGET_TEAMS
:
2169 p
= "!$OMP TARGET TEAMS";
2171 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2172 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2174 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2175 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2177 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2178 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2180 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2181 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2183 case ST_OMP_TARGET_UPDATE
:
2184 p
= "!$OMP TARGET UPDATE";
2189 case ST_OMP_TASKGROUP
:
2190 p
= "!$OMP TASKGROUP";
2192 case ST_OMP_TASKWAIT
:
2193 p
= "!$OMP TASKWAIT";
2195 case ST_OMP_TASKYIELD
:
2196 p
= "!$OMP TASKYIELD";
2201 case ST_OMP_TEAMS_DISTRIBUTE
:
2202 p
= "!$OMP TEAMS DISTRIBUTE";
2204 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2205 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2207 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2208 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2210 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2211 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2213 case ST_OMP_THREADPRIVATE
:
2214 p
= "!$OMP THREADPRIVATE";
2216 case ST_OMP_WORKSHARE
:
2217 p
= "!$OMP WORKSHARE";
2220 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2227 /* Create a symbol for the main program and assign it to ns->proc_name. */
2230 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2232 gfc_symbol
*main_program
;
2233 symbol_attribute attr
;
2235 gfc_get_symbol (name
, ns
, &main_program
);
2236 gfc_clear_attr (&attr
);
2237 attr
.flavor
= FL_PROGRAM
;
2238 attr
.proc
= PROC_UNKNOWN
;
2239 attr
.subroutine
= 1;
2240 attr
.access
= ACCESS_PUBLIC
;
2241 attr
.is_main_program
= 1;
2242 main_program
->attr
= attr
;
2243 main_program
->declared_at
= gfc_current_locus
;
2244 ns
->proc_name
= main_program
;
2245 gfc_commit_symbols ();
2249 /* Do whatever is necessary to accept the last statement. */
2252 accept_statement (gfc_statement st
)
2256 case ST_IMPLICIT_NONE
:
2264 gfc_current_ns
->proc_name
= gfc_new_block
;
2267 /* If the statement is the end of a block, lay down a special code
2268 that allows a branch to the end of the block from within the
2269 construct. IF and SELECT are treated differently from DO
2270 (where EXEC_NOP is added inside the loop) for two
2272 1. END DO has a meaning in the sense that after a GOTO to
2273 it, the loop counter must be increased.
2274 2. IF blocks and SELECT blocks can consist of multiple
2275 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2276 Putting the label before the END IF would make the jump
2277 from, say, the ELSE IF block to the END IF illegal. */
2281 case ST_END_CRITICAL
:
2282 if (gfc_statement_label
!= NULL
)
2284 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2289 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2290 one parallel block. Thus, we add the special code to the nested block
2291 itself, instead of the parent one. */
2293 case ST_END_ASSOCIATE
:
2294 if (gfc_statement_label
!= NULL
)
2296 new_st
.op
= EXEC_END_BLOCK
;
2301 /* The end-of-program unit statements do not get the special
2302 marker and require a statement of some sort if they are a
2305 case ST_END_PROGRAM
:
2306 case ST_END_FUNCTION
:
2307 case ST_END_SUBROUTINE
:
2308 if (gfc_statement_label
!= NULL
)
2310 new_st
.op
= EXEC_RETURN
;
2315 new_st
.op
= EXEC_END_PROCEDURE
;
2331 gfc_commit_symbols ();
2332 gfc_warning_check ();
2333 gfc_clear_new_st ();
2337 /* Undo anything tentative that has been built for the current
2341 reject_statement (void)
2343 /* Revert to the previous charlen chain. */
2344 gfc_free_charlen (gfc_current_ns
->cl_list
, gfc_current_ns
->old_cl_list
);
2345 gfc_current_ns
->cl_list
= gfc_current_ns
->old_cl_list
;
2347 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2348 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2350 gfc_reject_data (gfc_current_ns
);
2352 gfc_new_block
= NULL
;
2353 gfc_undo_symbols ();
2354 gfc_clear_warning ();
2355 undo_new_statement ();
2359 /* Generic complaint about an out of order statement. We also do
2360 whatever is necessary to clean up. */
2363 unexpected_statement (gfc_statement st
)
2365 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2367 reject_statement ();
2371 /* Given the next statement seen by the matcher, make sure that it is
2372 in proper order with the last. This subroutine is initialized by
2373 calling it with an argument of ST_NONE. If there is a problem, we
2374 issue an error and return false. Otherwise we return true.
2376 Individual parsers need to verify that the statements seen are
2377 valid before calling here, i.e., ENTRY statements are not allowed in
2378 INTERFACE blocks. The following diagram is taken from the standard:
2380 +---------------------------------------+
2381 | program subroutine function module |
2382 +---------------------------------------+
2384 +---------------------------------------+
2386 +---------------------------------------+
2388 | +-----------+------------------+
2389 | | parameter | implicit |
2390 | +-----------+------------------+
2391 | format | | derived type |
2392 | entry | parameter | interface |
2393 | | data | specification |
2394 | | | statement func |
2395 | +-----------+------------------+
2396 | | data | executable |
2397 +--------+-----------+------------------+
2399 +---------------------------------------+
2400 | internal module/subprogram |
2401 +---------------------------------------+
2403 +---------------------------------------+
2412 ORDER_IMPLICIT_NONE
,
2420 enum state_order state
;
2421 gfc_statement last_statement
;
2427 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2433 p
->state
= ORDER_START
;
2437 if (p
->state
> ORDER_USE
)
2439 p
->state
= ORDER_USE
;
2443 if (p
->state
> ORDER_IMPORT
)
2445 p
->state
= ORDER_IMPORT
;
2448 case ST_IMPLICIT_NONE
:
2449 if (p
->state
> ORDER_IMPLICIT
)
2452 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2453 statement disqualifies a USE but not an IMPLICIT NONE.
2454 Duplicate IMPLICIT NONEs are caught when the implicit types
2457 p
->state
= ORDER_IMPLICIT_NONE
;
2461 if (p
->state
> ORDER_IMPLICIT
)
2463 p
->state
= ORDER_IMPLICIT
;
2468 if (p
->state
< ORDER_IMPLICIT_NONE
)
2469 p
->state
= ORDER_IMPLICIT_NONE
;
2473 if (p
->state
>= ORDER_EXEC
)
2475 if (p
->state
< ORDER_IMPLICIT
)
2476 p
->state
= ORDER_IMPLICIT
;
2480 if (p
->state
< ORDER_SPEC
)
2481 p
->state
= ORDER_SPEC
;
2486 case ST_STRUCTURE_DECL
:
2487 case ST_DERIVED_DECL
:
2489 if (p
->state
>= ORDER_EXEC
)
2491 if (p
->state
< ORDER_SPEC
)
2492 p
->state
= ORDER_SPEC
;
2496 /* The OpenMP directives have to be somewhere in the specification
2497 part, but there are no further requirements on their ordering.
2498 Thus don't adjust p->state, just ignore them. */
2499 if (p
->state
>= ORDER_EXEC
)
2505 if (p
->state
< ORDER_EXEC
)
2506 p
->state
= ORDER_EXEC
;
2513 /* All is well, record the statement in case we need it next time. */
2514 p
->where
= gfc_current_locus
;
2515 p
->last_statement
= st
;
2520 gfc_error ("%s statement at %C cannot follow %s statement at %L",
2521 gfc_ascii_statement (st
),
2522 gfc_ascii_statement (p
->last_statement
), &p
->where
);
2528 /* Handle an unexpected end of file. This is a show-stopper... */
2530 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
2533 unexpected_eof (void)
2537 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
2539 /* Memory cleanup. Move to "second to last". */
2540 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
2543 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
2546 longjmp (eof_buf
, 1);
2550 /* Parse the CONTAINS section of a derived type definition. */
2552 gfc_access gfc_typebound_default_access
;
2555 parse_derived_contains (void)
2558 bool seen_private
= false;
2559 bool seen_comps
= false;
2560 bool error_flag
= false;
2563 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2564 gcc_assert (gfc_current_block ());
2566 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
2568 if (gfc_current_block ()->attr
.sequence
)
2569 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
2570 " section at %C", gfc_current_block ()->name
);
2571 if (gfc_current_block ()->attr
.is_bind_c
)
2572 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
2573 " section at %C", gfc_current_block ()->name
);
2575 accept_statement (ST_CONTAINS
);
2576 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
2578 gfc_typebound_default_access
= ACCESS_PUBLIC
;
2584 st
= next_statement ();
2592 gfc_error ("Components in TYPE at %C must precede CONTAINS");
2596 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
2599 accept_statement (ST_PROCEDURE
);
2604 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
2607 accept_statement (ST_GENERIC
);
2612 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
2616 accept_statement (ST_FINAL
);
2624 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
2625 "at %C with empty CONTAINS section")))
2628 /* ST_END_TYPE is accepted by parse_derived after return. */
2632 if (!gfc_find_state (COMP_MODULE
))
2634 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
2641 gfc_error ("PRIVATE statement at %C must precede procedure"
2648 gfc_error ("Duplicate PRIVATE statement at %C");
2652 accept_statement (ST_PRIVATE
);
2653 gfc_typebound_default_access
= ACCESS_PRIVATE
;
2654 seen_private
= true;
2658 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
2662 gfc_error ("Already inside a CONTAINS block at %C");
2666 unexpected_statement (st
);
2674 reject_statement ();
2678 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2684 /* Set attributes for the parent symbol based on the attributes of a component
2685 and raise errors if conflicting attributes are found for the component. */
2688 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
2689 gfc_component
**eventp
)
2691 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
2692 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
2693 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
2695 if (lockp
) lock_comp
= *lockp
;
2696 if (eventp
) event_comp
= *eventp
;
2698 /* Look for allocatable components. */
2699 if (c
->attr
.allocatable
2700 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2701 && CLASS_DATA (c
)->attr
.allocatable
)
2702 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
2703 && c
->ts
.u
.derived
->attr
.alloc_comp
))
2706 sym
->attr
.alloc_comp
= 1;
2709 /* Look for pointer components. */
2711 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2712 && CLASS_DATA (c
)->attr
.class_pointer
)
2713 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
2716 sym
->attr
.pointer_comp
= 1;
2719 /* Look for procedure pointer components. */
2720 if (c
->attr
.proc_pointer
2721 || (c
->ts
.type
== BT_DERIVED
2722 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
2723 sym
->attr
.proc_pointer_comp
= 1;
2725 /* Looking for coarray components. */
2726 if (c
->attr
.codimension
2727 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2728 && CLASS_DATA (c
)->attr
.codimension
))
2731 sym
->attr
.coarray_comp
= 1;
2734 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
2735 && !c
->attr
.pointer
)
2738 sym
->attr
.coarray_comp
= 1;
2741 /* Looking for lock_type components. */
2742 if ((c
->ts
.type
== BT_DERIVED
2743 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2744 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
2745 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2746 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2747 == INTMOD_ISO_FORTRAN_ENV
2748 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2749 == ISOFORTRAN_LOCK_TYPE
)
2750 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
2751 && !allocatable
&& !pointer
))
2755 sym
->attr
.lock_comp
= 1;
2758 /* Looking for event_type components. */
2759 if ((c
->ts
.type
== BT_DERIVED
2760 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2761 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2762 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2763 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2764 == INTMOD_ISO_FORTRAN_ENV
2765 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2766 == ISOFORTRAN_EVENT_TYPE
)
2767 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
2768 && !allocatable
&& !pointer
))
2772 sym
->attr
.event_comp
= 1;
2775 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
2776 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
2777 unless there are nondirect [allocatable or pointer] components
2778 involved (cf. 1.3.33.1 and 1.3.33.3). */
2780 if (pointer
&& !coarray
&& lock_type
)
2781 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
2782 "codimension or be a subcomponent of a coarray, "
2783 "which is not possible as the component has the "
2784 "pointer attribute", c
->name
, &c
->loc
);
2785 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
2786 && c
->ts
.u
.derived
->attr
.lock_comp
)
2787 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
2788 "of type LOCK_TYPE, which must have a codimension or be a "
2789 "subcomponent of a coarray", c
->name
, &c
->loc
);
2791 if (lock_type
&& allocatable
&& !coarray
)
2792 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
2793 "a codimension", c
->name
, &c
->loc
);
2794 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
2795 && c
->ts
.u
.derived
->attr
.lock_comp
)
2796 gfc_error ("Allocatable component %s at %L must have a codimension as "
2797 "it has a noncoarray subcomponent of type LOCK_TYPE",
2800 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
2801 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2802 "subcomponent of type LOCK_TYPE must have a codimension or "
2803 "be a subcomponent of a coarray. (Variables of type %s may "
2804 "not have a codimension as already a coarray "
2805 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
2807 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
2808 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2809 "subcomponent of type LOCK_TYPE must have a codimension or "
2810 "be a subcomponent of a coarray. (Variables of type %s may "
2811 "not have a codimension as %s at %L has a codimension or a "
2812 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
2813 sym
->name
, c
->name
, &c
->loc
);
2815 /* Similarly for EVENT TYPE. */
2817 if (pointer
&& !coarray
&& event_type
)
2818 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
2819 "codimension or be a subcomponent of a coarray, "
2820 "which is not possible as the component has the "
2821 "pointer attribute", c
->name
, &c
->loc
);
2822 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
2823 && c
->ts
.u
.derived
->attr
.event_comp
)
2824 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
2825 "of type EVENT_TYPE, which must have a codimension or be a "
2826 "subcomponent of a coarray", c
->name
, &c
->loc
);
2828 if (event_type
&& allocatable
&& !coarray
)
2829 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
2830 "a codimension", c
->name
, &c
->loc
);
2831 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
2832 && c
->ts
.u
.derived
->attr
.event_comp
)
2833 gfc_error ("Allocatable component %s at %L must have a codimension as "
2834 "it has a noncoarray subcomponent of type EVENT_TYPE",
2837 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
2838 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
2839 "subcomponent of type EVENT_TYPE must have a codimension or "
2840 "be a subcomponent of a coarray. (Variables of type %s may "
2841 "not have a codimension as already a coarray "
2842 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
2844 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
2845 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
2846 "subcomponent of type EVENT_TYPE must have a codimension or "
2847 "be a subcomponent of a coarray. (Variables of type %s may "
2848 "not have a codimension as %s at %L has a codimension or a "
2849 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
2850 sym
->name
, c
->name
, &c
->loc
);
2852 /* Look for private components. */
2853 if (sym
->component_access
== ACCESS_PRIVATE
2854 || c
->attr
.access
== ACCESS_PRIVATE
2855 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
2856 sym
->attr
.private_comp
= 1;
2858 if (lockp
) *lockp
= lock_comp
;
2859 if (eventp
) *eventp
= event_comp
;
2863 static void parse_struct_map (gfc_statement
);
2865 /* Parse a union component definition within a structure definition. */
2873 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
2876 accept_statement(ST_UNION
);
2877 push_state (&s
, COMP_UNION
, gfc_new_block
);
2884 st
= next_statement ();
2885 /* Only MAP declarations valid within a union. */
2892 accept_statement (ST_MAP
);
2893 parse_struct_map (ST_MAP
);
2894 /* Add a component to the union for each map. */
2895 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
2897 gfc_internal_error ("failed to create map component '%s'",
2898 gfc_new_block
->name
);
2899 reject_statement ();
2902 c
->ts
.type
= BT_DERIVED
;
2903 c
->ts
.u
.derived
= gfc_new_block
;
2904 /* Normally components get their initialization expressions when they
2905 are created in decl.c (build_struct) so we can look through the
2906 flat component list for initializers during resolution. Unions and
2907 maps create components along with their type definitions so we
2908 have to generate initializers here. */
2909 c
->initializer
= gfc_default_initializer (&c
->ts
);
2914 accept_statement (ST_END_UNION
);
2918 unexpected_statement (st
);
2923 for (c
= un
->components
; c
; c
= c
->next
)
2924 check_component (un
, c
, &lock_comp
, &event_comp
);
2926 /* Add the union as a component in its parent structure. */
2928 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
2930 gfc_internal_error ("failed to create union component '%s'", un
->name
);
2931 reject_statement ();
2934 c
->ts
.type
= BT_UNION
;
2935 c
->ts
.u
.derived
= un
;
2936 c
->initializer
= gfc_default_initializer (&c
->ts
);
2938 un
->attr
.zero_comp
= un
->components
== NULL
;
2942 /* Parse a STRUCTURE or MAP. */
2945 parse_struct_map (gfc_statement block
)
2951 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
2952 gfc_compile_state comp
;
2955 if (block
== ST_STRUCTURE_DECL
)
2957 comp
= COMP_STRUCTURE
;
2958 ends
= ST_END_STRUCTURE
;
2962 gcc_assert (block
== ST_MAP
);
2967 accept_statement(block
);
2968 push_state (&s
, comp
, gfc_new_block
);
2970 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
2973 while (compiling_type
)
2975 st
= next_statement ();
2981 /* Nested structure declarations will be captured as ST_DATA_DECL. */
2982 case ST_STRUCTURE_DECL
:
2983 /* Let a more specific error make it to decode_statement(). */
2984 if (gfc_error_check () == 0)
2985 gfc_error ("Syntax error in nested structure declaration at %C");
2986 reject_statement ();
2987 /* Skip the rest of this statement. */
2988 gfc_error_recovery ();
2992 accept_statement (ST_UNION
);
2997 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
2998 accept_statement (ST_DATA_DECL
);
2999 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3000 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3001 parse_struct_map (ST_STRUCTURE_DECL
);
3004 case ST_END_STRUCTURE
:
3008 accept_statement (st
);
3012 unexpected_statement (st
);
3016 unexpected_statement (st
);
3021 /* Validate each component. */
3022 sym
= gfc_current_block ();
3023 for (c
= sym
->components
; c
; c
= c
->next
)
3024 check_component (sym
, c
, &lock_comp
, &event_comp
);
3026 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3028 /* Allow parse_union to find this structure to add to its list of maps. */
3029 if (block
== ST_MAP
)
3030 gfc_new_block
= gfc_current_block ();
3036 /* Parse a derived type. */
3039 parse_derived (void)
3041 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3045 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3047 accept_statement (ST_DERIVED_DECL
);
3048 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3050 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3057 while (compiling_type
)
3059 st
= next_statement ();
3067 accept_statement (st
);
3072 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3079 if (!seen_component
)
3080 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3081 "definition at %C without components");
3083 accept_statement (ST_END_TYPE
);
3087 if (!gfc_find_state (COMP_MODULE
))
3089 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3096 gfc_error ("PRIVATE statement at %C must precede "
3097 "structure components");
3102 gfc_error ("Duplicate PRIVATE statement at %C");
3104 s
.sym
->component_access
= ACCESS_PRIVATE
;
3106 accept_statement (ST_PRIVATE
);
3113 gfc_error ("SEQUENCE statement at %C must precede "
3114 "structure components");
3118 if (gfc_current_block ()->attr
.sequence
)
3119 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3124 gfc_error ("Duplicate SEQUENCE statement at %C");
3128 gfc_add_sequence (&gfc_current_block ()->attr
,
3129 gfc_current_block ()->name
, NULL
);
3133 gfc_notify_std (GFC_STD_F2003
,
3134 "CONTAINS block in derived type"
3135 " definition at %C");
3137 accept_statement (ST_CONTAINS
);
3138 parse_derived_contains ();
3142 unexpected_statement (st
);
3147 /* need to verify that all fields of the derived type are
3148 * interoperable with C if the type is declared to be bind(c)
3150 sym
= gfc_current_block ();
3151 for (c
= sym
->components
; c
; c
= c
->next
)
3152 check_component (sym
, c
, &lock_comp
, &event_comp
);
3154 if (!seen_component
)
3155 sym
->attr
.zero_comp
= 1;
3161 /* Parse an ENUM. */
3169 int seen_enumerator
= 0;
3171 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3175 while (compiling_enum
)
3177 st
= next_statement ();
3185 seen_enumerator
= 1;
3186 accept_statement (st
);
3191 if (!seen_enumerator
)
3192 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3193 accept_statement (st
);
3197 gfc_free_enum_history ();
3198 unexpected_statement (st
);
3206 /* Parse an interface. We must be able to deal with the possibility
3207 of recursive interfaces. The parse_spec() subroutine is mutually
3208 recursive with parse_interface(). */
3210 static gfc_statement
parse_spec (gfc_statement
);
3213 parse_interface (void)
3215 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3216 gfc_symbol
*prog_unit
, *sym
;
3217 gfc_interface_info save
;
3218 gfc_state_data s1
, s2
;
3221 accept_statement (ST_INTERFACE
);
3223 current_interface
.ns
= gfc_current_ns
;
3224 save
= current_interface
;
3226 sym
= (current_interface
.type
== INTERFACE_GENERIC
3227 || current_interface
.type
== INTERFACE_USER_OP
)
3228 ? gfc_new_block
: NULL
;
3230 push_state (&s1
, COMP_INTERFACE
, sym
);
3231 current_state
= COMP_NONE
;
3234 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3236 st
= next_statement ();
3244 if (st
== ST_SUBROUTINE
)
3245 new_state
= COMP_SUBROUTINE
;
3246 else if (st
== ST_FUNCTION
)
3247 new_state
= COMP_FUNCTION
;
3248 if (gfc_new_block
->attr
.pointer
)
3250 gfc_new_block
->attr
.pointer
= 0;
3251 gfc_new_block
->attr
.proc_pointer
= 1;
3253 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3254 gfc_new_block
->formal
, NULL
))
3256 reject_statement ();
3257 gfc_free_namespace (gfc_current_ns
);
3260 /* F2008 C1210 forbids the IMPORT statement in module procedure
3261 interface bodies and the flag is set to import symbols. */
3262 if (gfc_new_block
->attr
.module_procedure
)
3263 gfc_current_ns
->has_import_set
= 1;
3267 case ST_MODULE_PROC
: /* The module procedure matcher makes
3268 sure the context is correct. */
3269 accept_statement (st
);
3270 gfc_free_namespace (gfc_current_ns
);
3273 case ST_END_INTERFACE
:
3274 gfc_free_namespace (gfc_current_ns
);
3275 gfc_current_ns
= current_interface
.ns
;
3279 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3280 gfc_ascii_statement (st
));
3281 reject_statement ();
3282 gfc_free_namespace (gfc_current_ns
);
3287 /* Make sure that the generic name has the right attribute. */
3288 if (current_interface
.type
== INTERFACE_GENERIC
3289 && current_state
== COMP_NONE
)
3291 if (new_state
== COMP_FUNCTION
&& sym
)
3292 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3293 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3294 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3296 current_state
= new_state
;
3299 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3301 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3302 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3303 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3304 "cannot be the same as an intrinsic type",
3305 gfc_new_block
->name
);
3308 push_state (&s2
, new_state
, gfc_new_block
);
3309 accept_statement (st
);
3310 prog_unit
= gfc_new_block
;
3311 prog_unit
->formal_ns
= gfc_current_ns
;
3312 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3313 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3317 /* Read data declaration statements. */
3318 st
= parse_spec (ST_NONE
);
3319 in_specification_block
= true;
3321 /* Since the interface block does not permit an IMPLICIT statement,
3322 the default type for the function or the result must be taken
3323 from the formal namespace. */
3324 if (new_state
== COMP_FUNCTION
)
3326 if (prog_unit
->result
== prog_unit
3327 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3328 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3329 else if (prog_unit
->result
!= prog_unit
3330 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3331 gfc_set_default_type (prog_unit
->result
, 1,
3332 prog_unit
->formal_ns
);
3335 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3337 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3338 gfc_ascii_statement (st
));
3339 reject_statement ();
3343 /* Add EXTERNAL attribute to function or subroutine. */
3344 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3345 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3347 current_interface
= save
;
3348 gfc_add_interface (prog_unit
);
3351 if (current_interface
.ns
3352 && current_interface
.ns
->proc_name
3353 && strcmp (current_interface
.ns
->proc_name
->name
,
3354 prog_unit
->name
) == 0)
3355 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3356 "enclosing procedure", prog_unit
->name
,
3357 ¤t_interface
.ns
->proc_name
->declared_at
);
3366 /* Associate function characteristics by going back to the function
3367 declaration and rematching the prefix. */
3370 match_deferred_characteristics (gfc_typespec
* ts
)
3373 match m
= MATCH_ERROR
;
3374 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3376 loc
= gfc_current_locus
;
3378 gfc_current_locus
= gfc_current_block ()->declared_at
;
3381 gfc_buffer_error (true);
3382 m
= gfc_match_prefix (ts
);
3383 gfc_buffer_error (false);
3385 if (ts
->type
== BT_DERIVED
)
3393 /* Only permit one go at the characteristic association. */
3397 /* Set the function locus correctly. If we have not found the
3398 function name, there is an error. */
3400 && gfc_match ("function% %n", name
) == MATCH_YES
3401 && strcmp (name
, gfc_current_block ()->name
) == 0)
3403 gfc_current_block ()->declared_at
= gfc_current_locus
;
3404 gfc_commit_symbols ();
3409 gfc_undo_symbols ();
3412 gfc_current_locus
=loc
;
3417 /* Check specification-expressions in the function result of the currently
3418 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3419 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3420 scope are not yet parsed so this has to be delayed up to parse_spec. */
3423 check_function_result_typed (void)
3427 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3429 if (!gfc_current_ns
->proc_name
->result
) return;
3431 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3433 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3434 /* TODO: Extend when KIND type parameters are implemented. */
3435 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3436 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3440 /* Parse a set of specification statements. Returns the statement
3441 that doesn't fit. */
3443 static gfc_statement
3444 parse_spec (gfc_statement st
)
3447 bool function_result_typed
= false;
3448 bool bad_characteristic
= false;
3451 in_specification_block
= true;
3453 verify_st_order (&ss
, ST_NONE
, false);
3455 st
= next_statement ();
3457 /* If we are not inside a function or don't have a result specified so far,
3458 do nothing special about it. */
3459 if (gfc_current_state () != COMP_FUNCTION
)
3460 function_result_typed
= true;
3463 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3466 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3467 function_result_typed
= true;
3472 /* If we're inside a BLOCK construct, some statements are disallowed.
3473 Check this here. Attribute declaration statements like INTENT, OPTIONAL
3474 or VALUE are also disallowed, but they don't have a particular ST_*
3475 key so we have to check for them individually in their matcher routine. */
3476 if (gfc_current_state () == COMP_BLOCK
)
3480 case ST_IMPLICIT_NONE
:
3483 case ST_EQUIVALENCE
:
3484 case ST_STATEMENT_FUNCTION
:
3485 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
3486 gfc_ascii_statement (st
));
3487 reject_statement ();
3493 else if (gfc_current_state () == COMP_BLOCK_DATA
)
3494 /* Fortran 2008, C1116. */
3501 case ST_END_BLOCK_DATA
:
3503 case ST_EQUIVALENCE
:
3506 case ST_IMPLICIT_NONE
:
3507 case ST_DERIVED_DECL
:
3515 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
3516 gfc_ascii_statement (st
));
3517 reject_statement ();
3521 /* If we find a statement that can not be followed by an IMPLICIT statement
3522 (and thus we can expect to see none any further), type the function result
3523 if it has not yet been typed. Be careful not to give the END statement
3524 to verify_st_order! */
3525 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
3527 bool verify_now
= false;
3529 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
3534 verify_st_order (&dummyss
, ST_NONE
, false);
3535 verify_st_order (&dummyss
, st
, false);
3537 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
3543 check_function_result_typed ();
3544 function_result_typed
= true;
3553 case ST_IMPLICIT_NONE
:
3555 if (!function_result_typed
)
3557 check_function_result_typed ();
3558 function_result_typed
= true;
3564 case ST_DATA
: /* Not allowed in interfaces */
3565 if (gfc_current_state () == COMP_INTERFACE
)
3575 case ST_STRUCTURE_DECL
:
3576 case ST_DERIVED_DECL
:
3580 if (!verify_st_order (&ss
, st
, false))
3582 reject_statement ();
3583 st
= next_statement ();
3593 case ST_STRUCTURE_DECL
:
3594 parse_struct_map (ST_STRUCTURE_DECL
);
3597 case ST_DERIVED_DECL
:
3603 if (gfc_current_state () != COMP_MODULE
)
3605 gfc_error ("%s statement must appear in a MODULE",
3606 gfc_ascii_statement (st
));
3607 reject_statement ();
3611 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
3613 gfc_error ("%s statement at %C follows another accessibility "
3614 "specification", gfc_ascii_statement (st
));
3615 reject_statement ();
3619 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
3620 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
3624 case ST_STATEMENT_FUNCTION
:
3625 if (gfc_current_state () == COMP_MODULE
3626 || gfc_current_state () == COMP_SUBMODULE
)
3628 unexpected_statement (st
);
3636 accept_statement (st
);
3637 st
= next_statement ();
3641 accept_statement (st
);
3643 st
= next_statement ();
3646 case ST_GET_FCN_CHARACTERISTICS
:
3647 /* This statement triggers the association of a function's result
3649 ts
= &gfc_current_block ()->result
->ts
;
3650 if (match_deferred_characteristics (ts
) != MATCH_YES
)
3651 bad_characteristic
= true;
3653 st
= next_statement ();
3660 /* If match_deferred_characteristics failed, then there is an error. */
3661 if (bad_characteristic
)
3663 ts
= &gfc_current_block ()->result
->ts
;
3664 if (ts
->type
!= BT_DERIVED
)
3665 gfc_error ("Bad kind expression for function %qs at %L",
3666 gfc_current_block ()->name
,
3667 &gfc_current_block ()->declared_at
);
3669 gfc_error ("The type for function %qs at %L is not accessible",
3670 gfc_current_block ()->name
,
3671 &gfc_current_block ()->declared_at
);
3673 gfc_current_block ()->ts
.kind
= 0;
3674 /* Keep the derived type; if it's bad, it will be discovered later. */
3675 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
3676 ts
->type
= BT_UNKNOWN
;
3679 in_specification_block
= false;
3685 /* Parse a WHERE block, (not a simple WHERE statement). */
3688 parse_where_block (void)
3690 int seen_empty_else
;
3695 accept_statement (ST_WHERE_BLOCK
);
3696 top
= gfc_state_stack
->tail
;
3698 push_state (&s
, COMP_WHERE
, gfc_new_block
);
3700 d
= add_statement ();
3701 d
->expr1
= top
->expr1
;
3707 seen_empty_else
= 0;
3711 st
= next_statement ();
3717 case ST_WHERE_BLOCK
:
3718 parse_where_block ();
3723 accept_statement (st
);
3727 if (seen_empty_else
)
3729 gfc_error ("ELSEWHERE statement at %C follows previous "
3730 "unmasked ELSEWHERE");
3731 reject_statement ();
3735 if (new_st
.expr1
== NULL
)
3736 seen_empty_else
= 1;
3738 d
= new_level (gfc_state_stack
->head
);
3740 d
->expr1
= new_st
.expr1
;
3742 accept_statement (st
);
3747 accept_statement (st
);
3751 gfc_error ("Unexpected %s statement in WHERE block at %C",
3752 gfc_ascii_statement (st
));
3753 reject_statement ();
3757 while (st
!= ST_END_WHERE
);
3763 /* Parse a FORALL block (not a simple FORALL statement). */
3766 parse_forall_block (void)
3772 accept_statement (ST_FORALL_BLOCK
);
3773 top
= gfc_state_stack
->tail
;
3775 push_state (&s
, COMP_FORALL
, gfc_new_block
);
3777 d
= add_statement ();
3778 d
->op
= EXEC_FORALL
;
3783 st
= next_statement ();
3788 case ST_POINTER_ASSIGNMENT
:
3791 accept_statement (st
);
3794 case ST_WHERE_BLOCK
:
3795 parse_where_block ();
3798 case ST_FORALL_BLOCK
:
3799 parse_forall_block ();
3803 accept_statement (st
);
3810 gfc_error ("Unexpected %s statement in FORALL block at %C",
3811 gfc_ascii_statement (st
));
3813 reject_statement ();
3817 while (st
!= ST_END_FORALL
);
3823 static gfc_statement
parse_executable (gfc_statement
);
3825 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
3828 parse_if_block (void)
3837 accept_statement (ST_IF_BLOCK
);
3839 top
= gfc_state_stack
->tail
;
3840 push_state (&s
, COMP_IF
, gfc_new_block
);
3842 new_st
.op
= EXEC_IF
;
3843 d
= add_statement ();
3845 d
->expr1
= top
->expr1
;
3851 st
= parse_executable (ST_NONE
);
3861 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
3862 "statement at %L", &else_locus
);
3864 reject_statement ();
3868 d
= new_level (gfc_state_stack
->head
);
3870 d
->expr1
= new_st
.expr1
;
3872 accept_statement (st
);
3879 gfc_error ("Duplicate ELSE statements at %L and %C",
3881 reject_statement ();
3886 else_locus
= gfc_current_locus
;
3888 d
= new_level (gfc_state_stack
->head
);
3891 accept_statement (st
);
3899 unexpected_statement (st
);
3903 while (st
!= ST_ENDIF
);
3906 accept_statement (st
);
3910 /* Parse a SELECT block. */
3913 parse_select_block (void)
3919 accept_statement (ST_SELECT_CASE
);
3921 cp
= gfc_state_stack
->tail
;
3922 push_state (&s
, COMP_SELECT
, gfc_new_block
);
3924 /* Make sure that the next statement is a CASE or END SELECT. */
3927 st
= next_statement ();
3930 if (st
== ST_END_SELECT
)
3932 /* Empty SELECT CASE is OK. */
3933 accept_statement (st
);
3940 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
3943 reject_statement ();
3946 /* At this point, we're got a nonempty select block. */
3947 cp
= new_level (cp
);
3950 accept_statement (st
);
3954 st
= parse_executable (ST_NONE
);
3961 cp
= new_level (gfc_state_stack
->head
);
3963 gfc_clear_new_st ();
3965 accept_statement (st
);
3971 /* Can't have an executable statement because of
3972 parse_executable(). */
3974 unexpected_statement (st
);
3978 while (st
!= ST_END_SELECT
);
3981 accept_statement (st
);
3985 /* Pop the current selector from the SELECT TYPE stack. */
3988 select_type_pop (void)
3990 gfc_select_type_stack
*old
= select_type_stack
;
3991 select_type_stack
= old
->prev
;
3996 /* Parse a SELECT TYPE construct (F03:R821). */
3999 parse_select_type_block (void)
4005 accept_statement (ST_SELECT_TYPE
);
4007 cp
= gfc_state_stack
->tail
;
4008 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4010 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4014 st
= next_statement ();
4017 if (st
== ST_END_SELECT
)
4018 /* Empty SELECT CASE is OK. */
4020 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4023 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4024 "following SELECT TYPE at %C");
4026 reject_statement ();
4029 /* At this point, we're got a nonempty select block. */
4030 cp
= new_level (cp
);
4033 accept_statement (st
);
4037 st
= parse_executable (ST_NONE
);
4045 cp
= new_level (gfc_state_stack
->head
);
4047 gfc_clear_new_st ();
4049 accept_statement (st
);
4055 /* Can't have an executable statement because of
4056 parse_executable(). */
4058 unexpected_statement (st
);
4062 while (st
!= ST_END_SELECT
);
4066 accept_statement (st
);
4067 gfc_current_ns
= gfc_current_ns
->parent
;
4072 /* Given a symbol, make sure it is not an iteration variable for a DO
4073 statement. This subroutine is called when the symbol is seen in a
4074 context that causes it to become redefined. If the symbol is an
4075 iterator, we generate an error message and return nonzero. */
4078 gfc_check_do_variable (gfc_symtree
*st
)
4082 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4083 if (s
->do_variable
== st
)
4085 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4086 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4094 /* Checks to see if the current statement label closes an enddo.
4095 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4096 an error) if it incorrectly closes an ENDDO. */
4099 check_do_closure (void)
4103 if (gfc_statement_label
== NULL
)
4106 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4107 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4111 return 0; /* No loops to close */
4113 if (p
->ext
.end_do_label
== gfc_statement_label
)
4115 if (p
== gfc_state_stack
)
4118 gfc_error ("End of nonblock DO statement at %C is within another block");
4122 /* At this point, the label doesn't terminate the innermost loop.
4123 Make sure it doesn't terminate another one. */
4124 for (; p
; p
= p
->previous
)
4125 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4126 && p
->ext
.end_do_label
== gfc_statement_label
)
4128 gfc_error ("End of nonblock DO statement at %C is interwoven "
4129 "with another DO loop");
4137 /* Parse a series of contained program units. */
4139 static void parse_progunit (gfc_statement
);
4142 /* Parse a CRITICAL block. */
4145 parse_critical_block (void)
4148 gfc_state_data s
, *sd
;
4151 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4152 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4153 gfc_error_now (is_oacc (sd
)
4154 ? "CRITICAL block inside of OpenACC region at %C"
4155 : "CRITICAL block inside of OpenMP region at %C");
4157 s
.ext
.end_do_label
= new_st
.label1
;
4159 accept_statement (ST_CRITICAL
);
4160 top
= gfc_state_stack
->tail
;
4162 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4164 d
= add_statement ();
4165 d
->op
= EXEC_CRITICAL
;
4170 st
= parse_executable (ST_NONE
);
4178 case ST_END_CRITICAL
:
4179 if (s
.ext
.end_do_label
!= NULL
4180 && s
.ext
.end_do_label
!= gfc_statement_label
)
4181 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4182 "match CRITICAL label");
4184 if (gfc_statement_label
!= NULL
)
4186 new_st
.op
= EXEC_NOP
;
4192 unexpected_statement (st
);
4196 while (st
!= ST_END_CRITICAL
);
4199 accept_statement (st
);
4203 /* Set up the local namespace for a BLOCK construct. */
4206 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4208 gfc_namespace
* my_ns
;
4209 static int numblock
= 1;
4211 my_ns
= gfc_get_namespace (parent_ns
, 1);
4212 my_ns
->construct_entities
= 1;
4214 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4215 code generation (so it must not be NULL).
4216 We set its recursive argument if our container procedure is recursive, so
4217 that local variables are accordingly placed on the stack when it
4218 will be necessary. */
4220 my_ns
->proc_name
= gfc_new_block
;
4224 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4226 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4227 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4228 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4229 my_ns
->proc_name
->name
, NULL
);
4231 gfc_commit_symbol (my_ns
->proc_name
);
4234 if (parent_ns
->proc_name
)
4235 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4241 /* Parse a BLOCK construct. */
4244 parse_block_construct (void)
4246 gfc_namespace
* my_ns
;
4247 gfc_namespace
* my_parent
;
4250 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4252 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4254 new_st
.op
= EXEC_BLOCK
;
4255 new_st
.ext
.block
.ns
= my_ns
;
4256 new_st
.ext
.block
.assoc
= NULL
;
4257 accept_statement (ST_BLOCK
);
4259 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4260 gfc_current_ns
= my_ns
;
4261 my_parent
= my_ns
->parent
;
4263 parse_progunit (ST_NONE
);
4265 /* Don't depend on the value of gfc_current_ns; it might have been
4266 reset if the block had errors and was cleaned up. */
4267 gfc_current_ns
= my_parent
;
4273 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4274 behind the scenes with compiler-generated variables. */
4277 parse_associate (void)
4279 gfc_namespace
* my_ns
;
4282 gfc_association_list
* a
;
4284 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4286 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4288 new_st
.op
= EXEC_BLOCK
;
4289 new_st
.ext
.block
.ns
= my_ns
;
4290 gcc_assert (new_st
.ext
.block
.assoc
);
4292 /* Add all associate-names as BLOCK variables. Creating them is enough
4293 for now, they'll get their values during trans-* phase. */
4294 gfc_current_ns
= my_ns
;
4295 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4299 gfc_array_ref
*array_ref
;
4301 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4305 sym
->attr
.flavor
= FL_VARIABLE
;
4307 sym
->declared_at
= a
->where
;
4308 gfc_set_sym_referenced (sym
);
4310 /* Initialize the typespec. It is not available in all cases,
4311 however, as it may only be set on the target during resolution.
4312 Still, sometimes it helps to have it right now -- especially
4313 for parsing component references on the associate-name
4314 in case of association to a derived-type. */
4315 sym
->ts
= a
->target
->ts
;
4317 /* Check if the target expression is array valued. This can not always
4318 be done by looking at target.rank, because that might not have been
4319 set yet. Therefore traverse the chain of refs, looking for the last
4320 array ref and evaluate that. */
4322 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4323 if (ref
->type
== REF_ARRAY
)
4324 array_ref
= &ref
->u
.ar
;
4325 if (array_ref
|| a
->target
->rank
)
4332 /* Count the dimension, that have a non-scalar extend. */
4333 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4334 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4335 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4336 && array_ref
->end
[dim
] == NULL
4337 && array_ref
->start
[dim
] != NULL
))
4341 rank
= a
->target
->rank
;
4342 /* When the rank is greater than zero then sym will be an array. */
4343 if (sym
->ts
.type
== BT_CLASS
)
4345 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4346 || (CLASS_DATA (sym
)->as
4347 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4349 /* Don't just (re-)set the attr and as in the sym.ts,
4350 because this modifies the target's attr and as. Copy the
4351 data and do a build_class_symbol. */
4352 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4353 int corank
= gfc_get_corank (a
->target
);
4358 as
= gfc_get_array_spec ();
4359 as
->type
= AS_DEFERRED
;
4361 as
->corank
= corank
;
4362 attr
.dimension
= rank
? 1 : 0;
4363 attr
.codimension
= corank
? 1 : 0;
4368 attr
.dimension
= attr
.codimension
= 0;
4371 type
= CLASS_DATA (sym
)->ts
;
4372 if (!gfc_build_class_symbol (&type
,
4376 sym
->ts
.type
= BT_CLASS
;
4377 sym
->attr
.class_ok
= 1;
4380 sym
->attr
.class_ok
= 1;
4382 else if ((!sym
->as
&& rank
!= 0)
4383 || (sym
->as
&& sym
->as
->rank
!= rank
))
4385 as
= gfc_get_array_spec ();
4386 as
->type
= AS_DEFERRED
;
4388 as
->corank
= gfc_get_corank (a
->target
);
4390 sym
->attr
.dimension
= 1;
4392 sym
->attr
.codimension
= 1;
4397 accept_statement (ST_ASSOCIATE
);
4398 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
4401 st
= parse_executable (ST_NONE
);
4408 accept_statement (st
);
4409 my_ns
->code
= gfc_state_stack
->head
;
4413 unexpected_statement (st
);
4417 gfc_current_ns
= gfc_current_ns
->parent
;
4422 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
4423 handled inside of parse_executable(), because they aren't really
4427 parse_do_block (void)
4436 s
.ext
.end_do_label
= new_st
.label1
;
4438 if (new_st
.ext
.iterator
!= NULL
)
4439 stree
= new_st
.ext
.iterator
->var
->symtree
;
4443 accept_statement (ST_DO
);
4445 top
= gfc_state_stack
->tail
;
4446 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
4449 s
.do_variable
= stree
;
4451 top
->block
= new_level (top
);
4452 top
->block
->op
= EXEC_DO
;
4455 st
= parse_executable (ST_NONE
);
4463 if (s
.ext
.end_do_label
!= NULL
4464 && s
.ext
.end_do_label
!= gfc_statement_label
)
4465 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
4468 if (gfc_statement_label
!= NULL
)
4470 new_st
.op
= EXEC_NOP
;
4475 case ST_IMPLIED_ENDDO
:
4476 /* If the do-stmt of this DO construct has a do-construct-name,
4477 the corresponding end-do must be an end-do-stmt (with a matching
4478 name, but in that case we must have seen ST_ENDDO first).
4479 We only complain about this in pedantic mode. */
4480 if (gfc_current_block () != NULL
)
4481 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
4482 &gfc_current_block()->declared_at
);
4487 unexpected_statement (st
);
4492 accept_statement (st
);
4496 /* Parse the statements of OpenMP do/parallel do. */
4498 static gfc_statement
4499 parse_omp_do (gfc_statement omp_st
)
4505 accept_statement (omp_st
);
4507 cp
= gfc_state_stack
->tail
;
4508 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4509 np
= new_level (cp
);
4515 st
= next_statement ();
4518 else if (st
== ST_DO
)
4521 unexpected_statement (st
);
4525 if (gfc_statement_label
!= NULL
4526 && gfc_state_stack
->previous
!= NULL
4527 && gfc_state_stack
->previous
->state
== COMP_DO
4528 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4536 there should be no !$OMP END DO. */
4538 return ST_IMPLIED_ENDDO
;
4541 check_do_closure ();
4544 st
= next_statement ();
4545 gfc_statement omp_end_st
= ST_OMP_END_DO
;
4548 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
4549 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4550 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4552 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4553 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4555 case ST_OMP_DISTRIBUTE_SIMD
:
4556 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4558 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
4559 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
4560 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
4561 case ST_OMP_PARALLEL_DO_SIMD
:
4562 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
4564 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
4565 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4566 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4568 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4569 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4571 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4572 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4574 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4575 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4577 case ST_OMP_TEAMS_DISTRIBUTE
:
4578 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4580 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4581 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4583 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4584 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4586 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4587 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4589 default: gcc_unreachable ();
4591 if (st
== omp_end_st
)
4593 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
4594 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4596 gcc_assert (new_st
.op
== EXEC_NOP
);
4597 gfc_clear_new_st ();
4598 gfc_commit_symbols ();
4599 gfc_warning_check ();
4600 st
= next_statement ();
4606 /* Parse the statements of OpenMP atomic directive. */
4608 static gfc_statement
4609 parse_omp_oacc_atomic (bool omp_p
)
4611 gfc_statement st
, st_atomic
, st_end_atomic
;
4618 st_atomic
= ST_OMP_ATOMIC
;
4619 st_end_atomic
= ST_OMP_END_ATOMIC
;
4623 st_atomic
= ST_OACC_ATOMIC
;
4624 st_end_atomic
= ST_OACC_END_ATOMIC
;
4626 accept_statement (st_atomic
);
4628 cp
= gfc_state_stack
->tail
;
4629 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4630 np
= new_level (cp
);
4633 count
= 1 + ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4634 == GFC_OMP_ATOMIC_CAPTURE
);
4638 st
= next_statement ();
4641 else if (st
== ST_ASSIGNMENT
)
4643 accept_statement (st
);
4647 unexpected_statement (st
);
4652 st
= next_statement ();
4653 if (st
== st_end_atomic
)
4655 gfc_clear_new_st ();
4656 gfc_commit_symbols ();
4657 gfc_warning_check ();
4658 st
= next_statement ();
4660 else if ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4661 == GFC_OMP_ATOMIC_CAPTURE
)
4662 gfc_error ("Missing !$OMP END ATOMIC after !$OMP ATOMIC CAPTURE at %C");
4667 /* Parse the statements of an OpenACC structured block. */
4670 parse_oacc_structured_block (gfc_statement acc_st
)
4672 gfc_statement st
, acc_end_st
;
4674 gfc_state_data s
, *sd
;
4676 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4677 if (sd
->state
== COMP_CRITICAL
)
4678 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4680 accept_statement (acc_st
);
4682 cp
= gfc_state_stack
->tail
;
4683 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4684 np
= new_level (cp
);
4689 case ST_OACC_PARALLEL
:
4690 acc_end_st
= ST_OACC_END_PARALLEL
;
4692 case ST_OACC_KERNELS
:
4693 acc_end_st
= ST_OACC_END_KERNELS
;
4696 acc_end_st
= ST_OACC_END_DATA
;
4698 case ST_OACC_HOST_DATA
:
4699 acc_end_st
= ST_OACC_END_HOST_DATA
;
4707 st
= parse_executable (ST_NONE
);
4710 else if (st
!= acc_end_st
)
4712 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
4713 reject_statement ();
4716 while (st
!= acc_end_st
);
4718 gcc_assert (new_st
.op
== EXEC_NOP
);
4720 gfc_clear_new_st ();
4721 gfc_commit_symbols ();
4722 gfc_warning_check ();
4726 /* Parse the statements of OpenACC loop/parallel loop/kernels loop. */
4728 static gfc_statement
4729 parse_oacc_loop (gfc_statement acc_st
)
4733 gfc_state_data s
, *sd
;
4735 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4736 if (sd
->state
== COMP_CRITICAL
)
4737 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4739 accept_statement (acc_st
);
4741 cp
= gfc_state_stack
->tail
;
4742 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4743 np
= new_level (cp
);
4749 st
= next_statement ();
4752 else if (st
== ST_DO
)
4756 gfc_error ("Expected DO loop at %C");
4757 reject_statement ();
4762 if (gfc_statement_label
!= NULL
4763 && gfc_state_stack
->previous
!= NULL
4764 && gfc_state_stack
->previous
->state
== COMP_DO
4765 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4768 return ST_IMPLIED_ENDDO
;
4771 check_do_closure ();
4774 st
= next_statement ();
4775 if (st
== ST_OACC_END_LOOP
)
4776 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
4777 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
4778 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
4779 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
4781 gcc_assert (new_st
.op
== EXEC_NOP
);
4782 gfc_clear_new_st ();
4783 gfc_commit_symbols ();
4784 gfc_warning_check ();
4785 st
= next_statement ();
4791 /* Parse the statements of an OpenMP structured block. */
4794 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
4796 gfc_statement st
, omp_end_st
;
4800 accept_statement (omp_st
);
4802 cp
= gfc_state_stack
->tail
;
4803 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4804 np
= new_level (cp
);
4810 case ST_OMP_PARALLEL
:
4811 omp_end_st
= ST_OMP_END_PARALLEL
;
4813 case ST_OMP_PARALLEL_SECTIONS
:
4814 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
4816 case ST_OMP_SECTIONS
:
4817 omp_end_st
= ST_OMP_END_SECTIONS
;
4819 case ST_OMP_ORDERED
:
4820 omp_end_st
= ST_OMP_END_ORDERED
;
4822 case ST_OMP_CRITICAL
:
4823 omp_end_st
= ST_OMP_END_CRITICAL
;
4826 omp_end_st
= ST_OMP_END_MASTER
;
4829 omp_end_st
= ST_OMP_END_SINGLE
;
4832 omp_end_st
= ST_OMP_END_TARGET
;
4834 case ST_OMP_TARGET_DATA
:
4835 omp_end_st
= ST_OMP_END_TARGET_DATA
;
4837 case ST_OMP_TARGET_TEAMS
:
4838 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
4840 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4841 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4843 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4844 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4846 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4847 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4849 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4850 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4853 omp_end_st
= ST_OMP_END_TASK
;
4855 case ST_OMP_TASKGROUP
:
4856 omp_end_st
= ST_OMP_END_TASKGROUP
;
4859 omp_end_st
= ST_OMP_END_TEAMS
;
4861 case ST_OMP_TEAMS_DISTRIBUTE
:
4862 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4864 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4865 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4867 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4868 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4870 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4871 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4873 case ST_OMP_DISTRIBUTE
:
4874 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
4876 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4877 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4879 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4880 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4882 case ST_OMP_DISTRIBUTE_SIMD
:
4883 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4885 case ST_OMP_WORKSHARE
:
4886 omp_end_st
= ST_OMP_END_WORKSHARE
;
4888 case ST_OMP_PARALLEL_WORKSHARE
:
4889 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
4897 if (workshare_stmts_only
)
4899 /* Inside of !$omp workshare, only
4902 where statements and constructs
4903 forall statements and constructs
4907 are allowed. For !$omp critical these
4908 restrictions apply recursively. */
4911 st
= next_statement ();
4922 accept_statement (st
);
4925 case ST_WHERE_BLOCK
:
4926 parse_where_block ();
4929 case ST_FORALL_BLOCK
:
4930 parse_forall_block ();
4933 case ST_OMP_PARALLEL
:
4934 case ST_OMP_PARALLEL_SECTIONS
:
4935 parse_omp_structured_block (st
, false);
4938 case ST_OMP_PARALLEL_WORKSHARE
:
4939 case ST_OMP_CRITICAL
:
4940 parse_omp_structured_block (st
, true);
4943 case ST_OMP_PARALLEL_DO
:
4944 case ST_OMP_PARALLEL_DO_SIMD
:
4945 st
= parse_omp_do (st
);
4949 st
= parse_omp_oacc_atomic (true);
4960 st
= next_statement ();
4964 st
= parse_executable (ST_NONE
);
4967 else if (st
== ST_OMP_SECTION
4968 && (omp_st
== ST_OMP_SECTIONS
4969 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
4971 np
= new_level (np
);
4975 else if (st
!= omp_end_st
)
4976 unexpected_statement (st
);
4978 while (st
!= omp_end_st
);
4982 case EXEC_OMP_END_NOWAIT
:
4983 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4985 case EXEC_OMP_CRITICAL
:
4986 if (((cp
->ext
.omp_name
== NULL
) ^ (new_st
.ext
.omp_name
== NULL
))
4987 || (new_st
.ext
.omp_name
!= NULL
4988 && strcmp (cp
->ext
.omp_name
, new_st
.ext
.omp_name
) != 0))
4989 gfc_error ("Name after !$omp critical and !$omp end critical does "
4991 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
4993 case EXEC_OMP_END_SINGLE
:
4994 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
4995 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
4996 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
4997 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5005 gfc_clear_new_st ();
5006 gfc_commit_symbols ();
5007 gfc_warning_check ();
5012 /* Accept a series of executable statements. We return the first
5013 statement that doesn't fit to the caller. Any block statements are
5014 passed on to the correct handler, which usually passes the buck
5017 static gfc_statement
5018 parse_executable (gfc_statement st
)
5023 st
= next_statement ();
5027 close_flag
= check_do_closure ();
5032 case ST_END_PROGRAM
:
5035 case ST_END_FUNCTION
:
5040 case ST_END_SUBROUTINE
:
5045 case ST_SELECT_CASE
:
5046 gfc_error ("%s statement at %C cannot terminate a non-block "
5047 "DO loop", gfc_ascii_statement (st
));
5060 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5061 "first executable statement");
5067 accept_statement (st
);
5068 if (close_flag
== 1)
5069 return ST_IMPLIED_ENDDO
;
5073 parse_block_construct ();
5084 case ST_SELECT_CASE
:
5085 parse_select_block ();
5088 case ST_SELECT_TYPE
:
5089 parse_select_type_block();
5094 if (check_do_closure () == 1)
5095 return ST_IMPLIED_ENDDO
;
5099 parse_critical_block ();
5102 case ST_WHERE_BLOCK
:
5103 parse_where_block ();
5106 case ST_FORALL_BLOCK
:
5107 parse_forall_block ();
5110 case ST_OACC_PARALLEL_LOOP
:
5111 case ST_OACC_KERNELS_LOOP
:
5113 st
= parse_oacc_loop (st
);
5114 if (st
== ST_IMPLIED_ENDDO
)
5118 case ST_OACC_PARALLEL
:
5119 case ST_OACC_KERNELS
:
5121 case ST_OACC_HOST_DATA
:
5122 parse_oacc_structured_block (st
);
5125 case ST_OMP_PARALLEL
:
5126 case ST_OMP_PARALLEL_SECTIONS
:
5127 case ST_OMP_SECTIONS
:
5128 case ST_OMP_ORDERED
:
5129 case ST_OMP_CRITICAL
:
5133 case ST_OMP_TARGET_DATA
:
5134 case ST_OMP_TARGET_TEAMS
:
5137 case ST_OMP_TASKGROUP
:
5138 parse_omp_structured_block (st
, false);
5141 case ST_OMP_WORKSHARE
:
5142 case ST_OMP_PARALLEL_WORKSHARE
:
5143 parse_omp_structured_block (st
, true);
5146 case ST_OMP_DISTRIBUTE
:
5147 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5148 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5149 case ST_OMP_DISTRIBUTE_SIMD
:
5151 case ST_OMP_DO_SIMD
:
5152 case ST_OMP_PARALLEL_DO
:
5153 case ST_OMP_PARALLEL_DO_SIMD
:
5155 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5156 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5157 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5158 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5159 case ST_OMP_TEAMS_DISTRIBUTE
:
5160 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5161 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5162 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5163 st
= parse_omp_do (st
);
5164 if (st
== ST_IMPLIED_ENDDO
)
5168 case ST_OACC_ATOMIC
:
5169 st
= parse_omp_oacc_atomic (false);
5173 st
= parse_omp_oacc_atomic (true);
5180 st
= next_statement ();
5185 /* Fix the symbols for sibling functions. These are incorrectly added to
5186 the child namespace as the parser didn't know about this procedure. */
5189 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5193 gfc_symbol
*old_sym
;
5195 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5197 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5199 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5200 goto fixup_contained
;
5202 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5203 && sym
->attr
.generic
&& sym
->attr
.function
)
5204 ||(sym
->attr
.flavor
== FL_DERIVED
5205 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5206 goto fixup_contained
;
5208 old_sym
= st
->n
.sym
;
5209 if (old_sym
->ns
== ns
5210 && !old_sym
->attr
.contained
5212 /* By 14.6.1.3, host association should be excluded
5213 for the following. */
5214 && !(old_sym
->attr
.external
5215 || (old_sym
->ts
.type
!= BT_UNKNOWN
5216 && !old_sym
->attr
.implicit_type
)
5217 || old_sym
->attr
.flavor
== FL_PARAMETER
5218 || old_sym
->attr
.use_assoc
5219 || old_sym
->attr
.in_common
5220 || old_sym
->attr
.in_equivalence
5221 || old_sym
->attr
.data
5222 || old_sym
->attr
.dummy
5223 || old_sym
->attr
.result
5224 || old_sym
->attr
.dimension
5225 || old_sym
->attr
.allocatable
5226 || old_sym
->attr
.intrinsic
5227 || old_sym
->attr
.generic
5228 || old_sym
->attr
.flavor
== FL_NAMELIST
5229 || old_sym
->attr
.flavor
== FL_LABEL
5230 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
5232 /* Replace it with the symbol from the parent namespace. */
5236 gfc_release_symbol (old_sym
);
5240 /* Do the same for any contained procedures. */
5241 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
5246 parse_contained (int module
)
5248 gfc_namespace
*ns
, *parent_ns
, *tmp
;
5249 gfc_state_data s1
, s2
;
5253 int contains_statements
= 0;
5256 push_state (&s1
, COMP_CONTAINS
, NULL
);
5257 parent_ns
= gfc_current_ns
;
5261 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
5263 gfc_current_ns
->sibling
= parent_ns
->contained
;
5264 parent_ns
->contained
= gfc_current_ns
;
5267 /* Process the next available statement. We come here if we got an error
5268 and rejected the last statement. */
5269 st
= next_statement ();
5278 contains_statements
= 1;
5279 accept_statement (st
);
5282 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
5285 /* For internal procedures, create/update the symbol in the
5286 parent namespace. */
5290 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
5291 gfc_error ("Contained procedure %qs at %C is already "
5292 "ambiguous", gfc_new_block
->name
);
5295 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
5297 &gfc_new_block
->declared_at
))
5299 if (st
== ST_FUNCTION
)
5300 gfc_add_function (&sym
->attr
, sym
->name
,
5301 &gfc_new_block
->declared_at
);
5303 gfc_add_subroutine (&sym
->attr
, sym
->name
,
5304 &gfc_new_block
->declared_at
);
5308 gfc_commit_symbols ();
5311 sym
= gfc_new_block
;
5313 /* Mark this as a contained function, so it isn't replaced
5314 by other module functions. */
5315 sym
->attr
.contained
= 1;
5317 /* Set implicit_pure so that it can be reset if any of the
5318 tests for purity fail. This is used for some optimisation
5319 during translation. */
5320 if (!sym
->attr
.pure
)
5321 sym
->attr
.implicit_pure
= 1;
5323 parse_progunit (ST_NONE
);
5325 /* Fix up any sibling functions that refer to this one. */
5326 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
5327 /* Or refer to any of its alternate entry points. */
5328 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
5329 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
5331 gfc_current_ns
->code
= s2
.head
;
5332 gfc_current_ns
= parent_ns
;
5337 /* These statements are associated with the end of the host unit. */
5338 case ST_END_FUNCTION
:
5340 case ST_END_SUBMODULE
:
5341 case ST_END_PROGRAM
:
5342 case ST_END_SUBROUTINE
:
5343 accept_statement (st
);
5344 gfc_current_ns
->code
= s1
.head
;
5348 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
5349 gfc_ascii_statement (st
));
5350 reject_statement ();
5356 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
5357 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
5358 && st
!= ST_END_PROGRAM
);
5360 /* The first namespace in the list is guaranteed to not have
5361 anything (worthwhile) in it. */
5362 tmp
= gfc_current_ns
;
5363 gfc_current_ns
= parent_ns
;
5364 if (seen_error
&& tmp
->refs
> 1)
5365 gfc_free_namespace (tmp
);
5367 ns
= gfc_current_ns
->contained
;
5368 gfc_current_ns
->contained
= ns
->sibling
;
5369 gfc_free_namespace (ns
);
5372 if (!contains_statements
)
5373 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
5374 "FUNCTION or SUBROUTINE statement at %C");
5378 /* The result variable in a MODULE PROCEDURE needs to be created and
5379 its characteristics copied from the interface since it is neither
5380 declared in the procedure declaration nor in the specification
5384 get_modproc_result (void)
5387 if (gfc_state_stack
->previous
5388 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
5389 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
5391 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
5393 && proc
->attr
.function
5394 && proc
->ts
.interface
5395 && proc
->ts
.interface
->result
5396 && proc
->ts
.interface
->result
!= proc
->ts
.interface
)
5398 gfc_copy_dummy_sym (&proc
->result
, proc
->ts
.interface
->result
, 1);
5399 gfc_set_sym_referenced (proc
->result
);
5400 proc
->result
->attr
.if_source
= IFSRC_DECL
;
5401 gfc_commit_symbol (proc
->result
);
5407 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
5410 parse_progunit (gfc_statement st
)
5416 && gfc_new_block
->abr_modproc_decl
5417 && gfc_new_block
->attr
.function
)
5418 get_modproc_result ();
5420 st
= parse_spec (st
);
5427 /* This is not allowed within BLOCK! */
5428 if (gfc_current_state () != COMP_BLOCK
)
5433 accept_statement (st
);
5440 if (gfc_current_state () == COMP_FUNCTION
)
5441 gfc_check_function_type (gfc_current_ns
);
5446 st
= parse_executable (st
);
5454 /* This is not allowed within BLOCK! */
5455 if (gfc_current_state () != COMP_BLOCK
)
5460 accept_statement (st
);
5467 unexpected_statement (st
);
5468 reject_statement ();
5469 st
= next_statement ();
5475 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
5476 if (p
->state
== COMP_CONTAINS
)
5479 if (gfc_find_state (COMP_MODULE
) == true
5480 || gfc_find_state (COMP_SUBMODULE
) == true)
5485 gfc_error ("CONTAINS statement at %C is already in a contained "
5487 reject_statement ();
5488 st
= next_statement ();
5492 parse_contained (0);
5495 gfc_current_ns
->code
= gfc_state_stack
->head
;
5499 /* Come here to complain about a global symbol already in use as
5503 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
5508 where
= &gfc_current_locus
;
5518 case GSYM_SUBROUTINE
:
5519 name
= "SUBROUTINE";
5524 case GSYM_BLOCK_DATA
:
5525 name
= "BLOCK DATA";
5531 gfc_internal_error ("gfc_global_used(): Bad type");
5535 if (sym
->binding_label
)
5536 gfc_error ("Global binding name %qs at %L is already being used as a %s "
5537 "at %L", sym
->binding_label
, where
, name
, &sym
->where
);
5539 gfc_error ("Global name %qs at %L is already being used as a %s at %L",
5540 sym
->name
, where
, name
, &sym
->where
);
5544 /* Parse a block data program unit. */
5547 parse_block_data (void)
5550 static locus blank_locus
;
5551 static int blank_block
=0;
5554 gfc_current_ns
->proc_name
= gfc_new_block
;
5555 gfc_current_ns
->is_block_data
= 1;
5557 if (gfc_new_block
== NULL
)
5560 gfc_error ("Blank BLOCK DATA at %C conflicts with "
5561 "prior BLOCK DATA at %L", &blank_locus
);
5565 blank_locus
= gfc_current_locus
;
5570 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5572 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
5573 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5576 s
->type
= GSYM_BLOCK_DATA
;
5577 s
->where
= gfc_new_block
->declared_at
;
5582 st
= parse_spec (ST_NONE
);
5584 while (st
!= ST_END_BLOCK_DATA
)
5586 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
5587 gfc_ascii_statement (st
));
5588 reject_statement ();
5589 st
= next_statement ();
5594 /* Following the association of the ancestor (sub)module symbols, they
5595 must be set host rather than use associated and all must be public.
5596 They are flagged up by 'used_in_submodule' so that they can be set
5597 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
5598 linker chokes on multiple symbol definitions. */
5601 set_syms_host_assoc (gfc_symbol
*sym
)
5608 if (sym
->attr
.module_procedure
)
5609 sym
->attr
.external
= 0;
5611 /* sym->attr.access = ACCESS_PUBLIC; */
5613 sym
->attr
.use_assoc
= 0;
5614 sym
->attr
.host_assoc
= 1;
5615 sym
->attr
.used_in_submodule
=1;
5617 if (sym
->attr
.flavor
== FL_DERIVED
)
5619 for (c
= sym
->components
; c
; c
= c
->next
)
5620 c
->attr
.access
= ACCESS_PUBLIC
;
5624 /* Parse a module subprogram. */
5633 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5634 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
5635 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5638 s
->type
= GSYM_MODULE
;
5639 s
->where
= gfc_new_block
->declared_at
;
5643 /* Something is nulling the module_list after this point. This is good
5644 since it allows us to 'USE' the parent modules that the submodule
5645 inherits and to set (most) of the symbols as host associated. */
5646 if (gfc_current_state () == COMP_SUBMODULE
)
5649 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
5652 st
= parse_spec (ST_NONE
);
5662 parse_contained (1);
5666 case ST_END_SUBMODULE
:
5667 accept_statement (st
);
5671 gfc_error ("Unexpected %s statement in MODULE at %C",
5672 gfc_ascii_statement (st
));
5675 reject_statement ();
5676 st
= next_statement ();
5680 /* Make sure not to free the namespace twice on error. */
5682 s
->ns
= gfc_current_ns
;
5686 /* Add a procedure name to the global symbol table. */
5689 add_global_procedure (bool sub
)
5693 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
5694 name is a global identifier. */
5695 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
5697 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5700 || (s
->type
!= GSYM_UNKNOWN
5701 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5703 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5704 /* Silence follow-up errors. */
5705 gfc_new_block
->binding_label
= NULL
;
5709 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5710 s
->sym_name
= gfc_new_block
->name
;
5711 s
->where
= gfc_new_block
->declared_at
;
5713 s
->ns
= gfc_current_ns
;
5717 /* Don't add the symbol multiple times. */
5718 if (gfc_new_block
->binding_label
5719 && (!gfc_notification_std (GFC_STD_F2008
)
5720 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
5722 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
);
5725 || (s
->type
!= GSYM_UNKNOWN
5726 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5728 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5729 /* Silence follow-up errors. */
5730 gfc_new_block
->binding_label
= NULL
;
5734 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5735 s
->sym_name
= gfc_new_block
->name
;
5736 s
->binding_label
= gfc_new_block
->binding_label
;
5737 s
->where
= gfc_new_block
->declared_at
;
5739 s
->ns
= gfc_current_ns
;
5745 /* Add a program to the global symbol table. */
5748 add_global_program (void)
5752 if (gfc_new_block
== NULL
)
5754 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5756 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
5757 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5760 s
->type
= GSYM_PROGRAM
;
5761 s
->where
= gfc_new_block
->declared_at
;
5763 s
->ns
= gfc_current_ns
;
5768 /* Resolve all the program units. */
5770 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
5772 gfc_free_dt_list ();
5773 gfc_current_ns
= gfc_global_ns_list
;
5774 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5776 if (gfc_current_ns
->proc_name
5777 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5778 continue; /* Already resolved. */
5780 if (gfc_current_ns
->proc_name
)
5781 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5782 gfc_resolve (gfc_current_ns
);
5783 gfc_current_ns
->derived_types
= gfc_derived_types
;
5784 gfc_derived_types
= NULL
;
5790 clean_up_modules (gfc_gsymbol
*gsym
)
5795 clean_up_modules (gsym
->left
);
5796 clean_up_modules (gsym
->right
);
5798 if (gsym
->type
!= GSYM_MODULE
|| !gsym
->ns
)
5801 gfc_current_ns
= gsym
->ns
;
5802 gfc_derived_types
= gfc_current_ns
->derived_types
;
5809 /* Translate all the program units. This could be in a different order
5810 to resolution if there are forward references in the file. */
5812 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
5816 gfc_current_ns
= gfc_global_ns_list
;
5817 gfc_get_errors (NULL
, &errors
);
5819 /* We first translate all modules to make sure that later parts
5820 of the program can use the decl. Then we translate the nonmodules. */
5822 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5824 if (!gfc_current_ns
->proc_name
5825 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
5828 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5829 gfc_derived_types
= gfc_current_ns
->derived_types
;
5830 gfc_generate_module_code (gfc_current_ns
);
5831 gfc_current_ns
->translated
= 1;
5834 gfc_current_ns
= gfc_global_ns_list
;
5835 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5837 if (gfc_current_ns
->proc_name
5838 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5841 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5842 gfc_derived_types
= gfc_current_ns
->derived_types
;
5843 gfc_generate_code (gfc_current_ns
);
5844 gfc_current_ns
->translated
= 1;
5847 /* Clean up all the namespaces after translation. */
5848 gfc_current_ns
= gfc_global_ns_list
;
5849 for (;gfc_current_ns
;)
5853 if (gfc_current_ns
->proc_name
5854 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5856 gfc_current_ns
= gfc_current_ns
->sibling
;
5860 ns
= gfc_current_ns
->sibling
;
5861 gfc_derived_types
= gfc_current_ns
->derived_types
;
5863 gfc_current_ns
= ns
;
5866 clean_up_modules (gfc_gsym_root
);
5870 /* Top level parser. */
5873 gfc_parse_file (void)
5875 int seen_program
, errors_before
, errors
;
5876 gfc_state_data top
, s
;
5879 gfc_namespace
*next
;
5881 gfc_start_source_files ();
5883 top
.state
= COMP_NONE
;
5885 top
.previous
= NULL
;
5886 top
.head
= top
.tail
= NULL
;
5887 top
.do_variable
= NULL
;
5889 gfc_state_stack
= &top
;
5891 gfc_clear_new_st ();
5893 gfc_statement_label
= NULL
;
5895 if (setjmp (eof_buf
))
5896 return false; /* Come here on unexpected EOF */
5898 /* Prepare the global namespace that will contain the
5900 gfc_global_ns_list
= next
= NULL
;
5905 /* Exit early for empty files. */
5909 in_specification_block
= true;
5912 st
= next_statement ();
5921 goto duplicate_main
;
5923 prog_locus
= gfc_current_locus
;
5925 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
5926 main_program_symbol(gfc_current_ns
, gfc_new_block
->name
);
5927 accept_statement (st
);
5928 add_global_program ();
5929 parse_progunit (ST_NONE
);
5934 add_global_procedure (true);
5935 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
5936 accept_statement (st
);
5937 parse_progunit (ST_NONE
);
5942 add_global_procedure (false);
5943 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
5944 accept_statement (st
);
5945 parse_progunit (ST_NONE
);
5950 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
5951 accept_statement (st
);
5952 parse_block_data ();
5956 push_state (&s
, COMP_MODULE
, gfc_new_block
);
5957 accept_statement (st
);
5959 gfc_get_errors (NULL
, &errors_before
);
5964 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
5965 accept_statement (st
);
5967 gfc_get_errors (NULL
, &errors_before
);
5971 /* Anything else starts a nameless main program block. */
5974 goto duplicate_main
;
5976 prog_locus
= gfc_current_locus
;
5978 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
5979 main_program_symbol (gfc_current_ns
, "MAIN__");
5980 parse_progunit (st
);
5985 /* Handle the non-program units. */
5986 gfc_current_ns
->code
= s
.head
;
5988 gfc_resolve (gfc_current_ns
);
5990 /* Dump the parse tree if requested. */
5991 if (flag_dump_fortran_original
)
5992 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
5994 gfc_get_errors (NULL
, &errors
);
5995 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
5997 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
5998 gfc_current_ns
->derived_types
= gfc_derived_types
;
5999 gfc_derived_types
= NULL
;
6005 gfc_generate_code (gfc_current_ns
);
6013 /* The main program and non-contained procedures are put
6014 in the global namespace list, so that they can be processed
6015 later and all their interfaces resolved. */
6016 gfc_current_ns
->code
= s
.head
;
6019 for (; next
->sibling
; next
= next
->sibling
)
6021 next
->sibling
= gfc_current_ns
;
6024 gfc_global_ns_list
= gfc_current_ns
;
6026 next
= gfc_current_ns
;
6033 /* Do the resolution. */
6034 resolve_all_program_units (gfc_global_ns_list
);
6036 /* Do the parse tree dump. */
6038 = flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6040 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6041 if (!gfc_current_ns
->proc_name
6042 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6044 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6045 fputs ("------------------------------------------\n\n", stdout
);
6048 /* Do the translation. */
6049 translate_all_program_units (gfc_global_ns_list
);
6051 gfc_end_source_files ();
6055 /* If we see a duplicate main program, shut down. If the second
6056 instance is an implied main program, i.e. data decls or executable
6057 statements, we're in for lots of errors. */
6058 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6059 reject_statement ();
6064 /* Return true if this state data represents an OpenACC region. */
6066 is_oacc (gfc_state_data
*sd
)
6068 switch (sd
->construct
->op
)
6070 case EXEC_OACC_PARALLEL_LOOP
:
6071 case EXEC_OACC_PARALLEL
:
6072 case EXEC_OACC_KERNELS_LOOP
:
6073 case EXEC_OACC_KERNELS
:
6074 case EXEC_OACC_DATA
:
6075 case EXEC_OACC_HOST_DATA
:
6076 case EXEC_OACC_LOOP
:
6077 case EXEC_OACC_UPDATE
:
6078 case EXEC_OACC_WAIT
:
6079 case EXEC_OACC_CACHE
:
6080 case EXEC_OACC_ENTER_DATA
:
6081 case EXEC_OACC_EXIT_DATA
:
6082 case EXEC_OACC_ATOMIC
:
6083 case EXEC_OACC_ROUTINE
: