2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 /* Current statement label. Zero means no statement label. Because new_st
31 can get wiped during statement matching, we have to keep it separate. */
33 gfc_st_label
*gfc_statement_label
;
35 static locus label_locus
;
36 static jmp_buf eof_buf
;
38 gfc_state_data
*gfc_state_stack
;
39 static bool last_was_use_stmt
= false;
41 /* TODO: Re-order functions to kill these forward decls. */
42 static void check_statement_label (gfc_statement
);
43 static void undo_new_statement (void);
44 static void reject_statement (void);
47 /* A sort of half-matching function. We try to match the word on the
48 input with the passed string. If this succeeds, we call the
49 keyword-dependent matching function that will match the rest of the
50 statement. For single keywords, the matching subroutine is
54 match_word (const char *str
, match (*subr
) (void), locus
*old_locus
)
69 gfc_current_locus
= *old_locus
;
77 /* Like match_word, but if str is matched, set a flag that it
80 match_word_omp_simd (const char *str
, match (*subr
) (void), locus
*old_locus
,
97 gfc_current_locus
= *old_locus
;
105 /* Load symbols from all USE statements encountered in this scoping unit. */
110 gfc_error_buffer old_error
;
112 gfc_push_error (&old_error
);
113 gfc_buffer_error (false);
115 gfc_buffer_error (true);
116 gfc_pop_error (&old_error
);
117 gfc_commit_symbols ();
118 gfc_warning_check ();
119 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
120 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
121 last_was_use_stmt
= false;
125 /* Figure out what the next statement is, (mostly) regardless of
126 proper ordering. The do...while(0) is there to prevent if/else
129 #define match(keyword, subr, st) \
131 if (match_word (keyword, subr, &old_locus) == MATCH_YES) \
134 undo_new_statement (); \
138 /* This is a specialist version of decode_statement that is used
139 for the specification statements in a function, whose
140 characteristics are deferred into the specification statements.
141 eg.: INTEGER (king = mykind) foo ()
142 USE mymodule, ONLY mykind.....
143 The KIND parameter needs a return after USE or IMPORT, whereas
144 derived type declarations can occur anywhere, up the executable
145 block. ST_GET_FCN_CHARACTERISTICS is returned when we have run
146 out of the correct kind of specification statements. */
148 decode_specification_statement (void)
154 if (gfc_match_eos () == MATCH_YES
)
157 old_locus
= gfc_current_locus
;
159 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
161 last_was_use_stmt
= true;
166 undo_new_statement ();
167 if (last_was_use_stmt
)
171 match ("import", gfc_match_import
, ST_IMPORT
);
173 if (gfc_current_block ()->result
->ts
.type
!= BT_DERIVED
)
176 match (NULL
, gfc_match_st_function
, ST_STATEMENT_FUNCTION
);
177 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
178 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
180 /* General statement matching: Instead of testing every possible
181 statement, we eliminate most possibilities by peeking at the
184 c
= gfc_peek_ascii_char ();
189 match ("abstract% interface", gfc_match_abstract_interface
,
191 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
192 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
193 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
197 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
201 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
202 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
206 match ("data", gfc_match_data
, ST_DATA
);
207 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
211 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
212 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
213 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
214 match ("external", gfc_match_external
, ST_ATTR_DECL
);
218 match ("format", gfc_match_format
, ST_FORMAT
);
225 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
226 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
227 match ("interface", gfc_match_interface
, ST_INTERFACE
);
228 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
229 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
236 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
240 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
244 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
245 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
246 if (gfc_match_private (&st
) == MATCH_YES
)
248 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
249 if (gfc_match_public (&st
) == MATCH_YES
)
251 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
258 match ("save", gfc_match_save
, ST_ATTR_DECL
);
259 match ("static", gfc_match_static
, ST_ATTR_DECL
);
260 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
264 match ("target", gfc_match_target
, ST_ATTR_DECL
);
265 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
272 match ("value", gfc_match_value
, ST_ATTR_DECL
);
273 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
280 /* This is not a specification statement. See if any of the matchers
281 has stored an error message of some sort. */
285 gfc_buffer_error (false);
286 gfc_current_locus
= old_locus
;
288 return ST_GET_FCN_CHARACTERISTICS
;
291 static bool in_specification_block
;
293 /* This is the primary 'decode_statement'. */
295 decode_statement (void)
302 gfc_enforce_clean_symbol_state ();
304 gfc_clear_error (); /* Clear any pending errors. */
305 gfc_clear_warning (); /* Clear any pending warnings. */
307 gfc_matching_function
= false;
309 if (gfc_match_eos () == MATCH_YES
)
312 if (gfc_current_state () == COMP_FUNCTION
313 && gfc_current_block ()->result
->ts
.kind
== -1)
314 return decode_specification_statement ();
316 old_locus
= gfc_current_locus
;
318 c
= gfc_peek_ascii_char ();
322 if (match_word ("use", gfc_match_use
, &old_locus
) == MATCH_YES
)
324 last_was_use_stmt
= true;
328 undo_new_statement ();
331 if (last_was_use_stmt
)
334 /* Try matching a data declaration or function declaration. The
335 input "REALFUNCTIONA(N)" can mean several things in different
336 contexts, so it (and its relatives) get special treatment. */
338 if (gfc_current_state () == COMP_NONE
339 || gfc_current_state () == COMP_INTERFACE
340 || gfc_current_state () == COMP_CONTAINS
)
342 gfc_matching_function
= true;
343 m
= gfc_match_function_decl ();
346 else if (m
== MATCH_ERROR
)
350 gfc_current_locus
= old_locus
;
352 gfc_matching_function
= false;
354 /* Legacy parameter statements are ambiguous with assignments so try parameter
356 match ("parameter", gfc_match_parameter
, ST_PARAMETER
);
358 /* Match statements whose error messages are meant to be overwritten
359 by something better. */
361 match (NULL
, gfc_match_assignment
, ST_ASSIGNMENT
);
362 match (NULL
, gfc_match_pointer_assignment
, ST_POINTER_ASSIGNMENT
);
364 if (in_specification_block
)
366 m
= match_word (NULL
, gfc_match_st_function
, &old_locus
);
368 return ST_STATEMENT_FUNCTION
;
371 if (!(in_specification_block
&& m
== MATCH_ERROR
))
373 match (NULL
, gfc_match_ptr_fcn_assign
, ST_ASSIGNMENT
);
376 match (NULL
, gfc_match_data_decl
, ST_DATA_DECL
);
377 match (NULL
, gfc_match_enumerator_def
, ST_ENUMERATOR
);
379 /* Try to match a subroutine statement, which has the same optional
380 prefixes that functions can have. */
382 if (gfc_match_subroutine () == MATCH_YES
)
383 return ST_SUBROUTINE
;
385 gfc_current_locus
= old_locus
;
387 if (gfc_match_submod_proc () == MATCH_YES
)
389 if (gfc_new_block
->attr
.subroutine
)
390 return ST_SUBROUTINE
;
391 else if (gfc_new_block
->attr
.function
)
395 gfc_current_locus
= old_locus
;
397 /* Check for the IF, DO, SELECT, WHERE, FORALL, CRITICAL, BLOCK and ASSOCIATE
398 statements, which might begin with a block label. The match functions for
399 these statements are unusual in that their keyword is not seen before
400 the matcher is called. */
402 if (gfc_match_if (&st
) == MATCH_YES
)
405 gfc_current_locus
= old_locus
;
407 if (gfc_match_where (&st
) == MATCH_YES
)
410 gfc_current_locus
= old_locus
;
412 if (gfc_match_forall (&st
) == MATCH_YES
)
415 gfc_current_locus
= old_locus
;
417 /* Try to match TYPE as an alias for PRINT. */
418 if (gfc_match_type (&st
) == MATCH_YES
)
421 gfc_current_locus
= old_locus
;
423 match (NULL
, gfc_match_do
, ST_DO
);
424 match (NULL
, gfc_match_block
, ST_BLOCK
);
425 match (NULL
, gfc_match_associate
, ST_ASSOCIATE
);
426 match (NULL
, gfc_match_critical
, ST_CRITICAL
);
427 match (NULL
, gfc_match_select
, ST_SELECT_CASE
);
428 match (NULL
, gfc_match_select_type
, ST_SELECT_TYPE
);
430 /* General statement matching: Instead of testing every possible
431 statement, we eliminate most possibilities by peeking at the
437 match ("abstract% interface", gfc_match_abstract_interface
,
439 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
440 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
441 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
442 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
443 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
447 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
448 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
449 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
453 match ("call", gfc_match_call
, ST_CALL
);
454 match ("close", gfc_match_close
, ST_CLOSE
);
455 match ("continue", gfc_match_continue
, ST_CONTINUE
);
456 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
457 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
458 match ("case", gfc_match_case
, ST_CASE
);
459 match ("common", gfc_match_common
, ST_COMMON
);
460 match ("contains", gfc_match_eos
, ST_CONTAINS
);
461 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
462 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
466 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
467 match ("data", gfc_match_data
, ST_DATA
);
468 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
472 match ("end file", gfc_match_endfile
, ST_END_FILE
);
473 match ("exit", gfc_match_exit
, ST_EXIT
);
474 match ("else", gfc_match_else
, ST_ELSE
);
475 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
476 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
477 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
);
478 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
480 if (gfc_match_end (&st
) == MATCH_YES
)
483 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
484 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
485 match ("external", gfc_match_external
, ST_ATTR_DECL
);
486 match ("event post", gfc_match_event_post
, ST_EVENT_POST
);
487 match ("event wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
491 match ("final", gfc_match_final_decl
, ST_FINAL
);
492 match ("flush", gfc_match_flush
, ST_FLUSH
);
493 match ("format", gfc_match_format
, ST_FORMAT
);
497 match ("generic", gfc_match_generic
, ST_GENERIC
);
498 match ("go to", gfc_match_goto
, ST_GOTO
);
502 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
503 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
504 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
505 match ("import", gfc_match_import
, ST_IMPORT
);
506 match ("interface", gfc_match_interface
, ST_INTERFACE
);
507 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
508 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
512 match ("lock", gfc_match_lock
, ST_LOCK
);
516 match ("map", gfc_match_map
, ST_MAP
);
517 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
518 match ("module", gfc_match_module
, ST_MODULE
);
522 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
523 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
527 match ("open", gfc_match_open
, ST_OPEN
);
528 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
532 match ("print", gfc_match_print
, ST_WRITE
);
533 match ("pause", gfc_match_pause
, ST_PAUSE
);
534 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
535 if (gfc_match_private (&st
) == MATCH_YES
)
537 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
538 match ("program", gfc_match_program
, ST_PROGRAM
);
539 if (gfc_match_public (&st
) == MATCH_YES
)
541 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
545 match ("read", gfc_match_read
, ST_READ
);
546 match ("return", gfc_match_return
, ST_RETURN
);
547 match ("rewind", gfc_match_rewind
, ST_REWIND
);
551 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
552 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
553 match ("stop", gfc_match_stop
, ST_STOP
);
554 match ("save", gfc_match_save
, ST_ATTR_DECL
);
555 match ("static", gfc_match_static
, ST_ATTR_DECL
);
556 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
557 match ("sync all", gfc_match_sync_all
, ST_SYNC_ALL
);
558 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
559 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
563 match ("target", gfc_match_target
, ST_ATTR_DECL
);
564 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
565 match ("type is", gfc_match_type_is
, ST_TYPE_IS
);
569 match ("union", gfc_match_union
, ST_UNION
);
570 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
574 match ("value", gfc_match_value
, ST_ATTR_DECL
);
575 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
579 match ("wait", gfc_match_wait
, ST_WAIT
);
580 match ("write", gfc_match_write
, ST_WRITE
);
584 /* All else has failed, so give up. See if any of the matchers has
585 stored an error message of some sort. */
587 if (!gfc_error_check ())
588 gfc_error_now ("Unclassifiable statement at %C");
592 gfc_error_recovery ();
597 /* Like match and if spec_only, goto do_spec_only without actually
599 #define matcha(keyword, subr, st) \
601 if (spec_only && gfc_match (keyword) == MATCH_YES) \
603 else if (match_word (keyword, subr, &old_locus) \
607 undo_new_statement (); \
611 decode_oacc_directive (void)
615 bool spec_only
= false;
617 gfc_enforce_clean_symbol_state ();
619 gfc_clear_error (); /* Clear any pending errors. */
620 gfc_clear_warning (); /* Clear any pending warnings. */
624 gfc_error_now ("OpenACC directives at %C may not appear in PURE "
626 gfc_error_recovery ();
630 if (gfc_current_state () == COMP_FUNCTION
631 && gfc_current_block ()->result
->ts
.kind
== -1)
634 gfc_unset_implicit_pure (NULL
);
636 old_locus
= gfc_current_locus
;
638 /* General OpenACC directive matching: Instead of testing every possible
639 statement, we eliminate most possibilities by peeking at the
642 c
= gfc_peek_ascii_char ();
647 matcha ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
650 matcha ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
653 matcha ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
654 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
657 matcha ("end atomic", gfc_match_omp_eos
, ST_OACC_END_ATOMIC
);
658 matcha ("end data", gfc_match_omp_eos
, ST_OACC_END_DATA
);
659 matcha ("end host_data", gfc_match_omp_eos
, ST_OACC_END_HOST_DATA
);
660 matcha ("end kernels loop", gfc_match_omp_eos
, ST_OACC_END_KERNELS_LOOP
);
661 matcha ("end kernels", gfc_match_omp_eos
, ST_OACC_END_KERNELS
);
662 matcha ("end loop", gfc_match_omp_eos
, ST_OACC_END_LOOP
);
663 matcha ("end parallel loop", gfc_match_omp_eos
,
664 ST_OACC_END_PARALLEL_LOOP
);
665 matcha ("end parallel", gfc_match_omp_eos
, ST_OACC_END_PARALLEL
);
666 matcha ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
667 matcha ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
670 matcha ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
673 matcha ("parallel loop", gfc_match_oacc_parallel_loop
,
674 ST_OACC_PARALLEL_LOOP
);
675 matcha ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
678 matcha ("kernels loop", gfc_match_oacc_kernels_loop
,
679 ST_OACC_KERNELS_LOOP
);
680 matcha ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
683 matcha ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
686 match ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
689 matcha ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
692 matcha ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
696 /* Directive not found or stored an error message.
697 Check and give up. */
699 if (gfc_error_check () == 0)
700 gfc_error_now ("Unclassifiable OpenACC directive at %C");
704 gfc_error_recovery ();
711 gfc_buffer_error (false);
712 gfc_current_locus
= old_locus
;
713 return ST_GET_FCN_CHARACTERISTICS
;
716 /* Like match, but set a flag simd_matched if keyword matched
717 and if spec_only, goto do_spec_only without actually matching. */
718 #define matchs(keyword, subr, st) \
720 if (spec_only && gfc_match (keyword) == MATCH_YES) \
722 if (match_word_omp_simd (keyword, subr, &old_locus, \
723 &simd_matched) == MATCH_YES) \
729 undo_new_statement (); \
732 /* Like match, but don't match anything if not -fopenmp
733 and if spec_only, goto do_spec_only without actually matching. */
734 #define matcho(keyword, subr, st) \
738 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
740 else if (match_word (keyword, subr, &old_locus) \
747 undo_new_statement (); \
750 /* Like match, but set a flag simd_matched if keyword matched. */
751 #define matchds(keyword, subr, st) \
753 if (match_word_omp_simd (keyword, subr, &old_locus, \
754 &simd_matched) == MATCH_YES) \
760 undo_new_statement (); \
763 /* Like match, but don't match anything if not -fopenmp. */
764 #define matchdo(keyword, subr, st) \
768 else if (match_word (keyword, subr, &old_locus) \
775 undo_new_statement (); \
779 decode_omp_directive (void)
783 bool simd_matched
= false;
784 bool spec_only
= false;
785 gfc_statement ret
= ST_NONE
;
788 gfc_enforce_clean_symbol_state ();
790 gfc_clear_error (); /* Clear any pending errors. */
791 gfc_clear_warning (); /* Clear any pending warnings. */
793 if (gfc_current_state () == COMP_FUNCTION
794 && gfc_current_block ()->result
->ts
.kind
== -1)
797 old_locus
= gfc_current_locus
;
799 /* General OpenMP directive matching: Instead of testing every possible
800 statement, we eliminate most possibilities by peeking at the
803 c
= gfc_peek_ascii_char ();
805 /* match is for directives that should be recognized only if
806 -fopenmp, matchs for directives that should be recognized
807 if either -fopenmp or -fopenmp-simd.
808 Handle only the directives allowed in PURE/ELEMENTAL procedures
809 first (those also shall not turn off implicit pure). */
813 matchds ("declare simd", gfc_match_omp_declare_simd
,
814 ST_OMP_DECLARE_SIMD
);
815 matchdo ("declare target", gfc_match_omp_declare_target
,
816 ST_OMP_DECLARE_TARGET
);
819 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
824 if (flag_openmp
&& gfc_pure (NULL
))
826 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
827 "at %C may not appear in PURE or ELEMENTAL procedures");
828 gfc_error_recovery ();
832 /* match is for directives that should be recognized only if
833 -fopenmp, matchs for directives that should be recognized
834 if either -fopenmp or -fopenmp-simd. */
838 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
841 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
844 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
845 ST_OMP_CANCELLATION_POINT
);
846 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
847 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
850 matchds ("declare reduction", gfc_match_omp_declare_reduction
,
851 ST_OMP_DECLARE_REDUCTION
);
852 matchs ("distribute parallel do simd",
853 gfc_match_omp_distribute_parallel_do_simd
,
854 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
855 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
856 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
857 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
858 ST_OMP_DISTRIBUTE_SIMD
);
859 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
860 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
861 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
864 matcho ("end atomic", gfc_match_omp_eos
, ST_OMP_END_ATOMIC
);
865 matcho ("end critical", gfc_match_omp_end_critical
, ST_OMP_END_CRITICAL
);
866 matchs ("end distribute parallel do simd", gfc_match_omp_eos
,
867 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
868 matcho ("end distribute parallel do", gfc_match_omp_eos
,
869 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
870 matchs ("end distribute simd", gfc_match_omp_eos
,
871 ST_OMP_END_DISTRIBUTE_SIMD
);
872 matcho ("end distribute", gfc_match_omp_eos
, ST_OMP_END_DISTRIBUTE
);
873 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
874 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
875 matchs ("end simd", gfc_match_omp_eos
, ST_OMP_END_SIMD
);
876 matcho ("end master", gfc_match_omp_eos
, ST_OMP_END_MASTER
);
877 matcho ("end ordered", gfc_match_omp_eos
, ST_OMP_END_ORDERED
);
878 matchs ("end parallel do simd", gfc_match_omp_eos
,
879 ST_OMP_END_PARALLEL_DO_SIMD
);
880 matcho ("end parallel do", gfc_match_omp_eos
, ST_OMP_END_PARALLEL_DO
);
881 matcho ("end parallel sections", gfc_match_omp_eos
,
882 ST_OMP_END_PARALLEL_SECTIONS
);
883 matcho ("end parallel workshare", gfc_match_omp_eos
,
884 ST_OMP_END_PARALLEL_WORKSHARE
);
885 matcho ("end parallel", gfc_match_omp_eos
, ST_OMP_END_PARALLEL
);
886 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
887 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
888 matcho ("end target data", gfc_match_omp_eos
, ST_OMP_END_TARGET_DATA
);
889 matchs ("end target parallel do simd", gfc_match_omp_eos
,
890 ST_OMP_END_TARGET_PARALLEL_DO_SIMD
);
891 matcho ("end target parallel do", gfc_match_omp_eos
,
892 ST_OMP_END_TARGET_PARALLEL_DO
);
893 matcho ("end target parallel", gfc_match_omp_eos
,
894 ST_OMP_END_TARGET_PARALLEL
);
895 matchs ("end target simd", gfc_match_omp_eos
, ST_OMP_END_TARGET_SIMD
);
896 matchs ("end target teams distribute parallel do simd",
898 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
899 matcho ("end target teams distribute parallel do", gfc_match_omp_eos
,
900 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
901 matchs ("end target teams distribute simd", gfc_match_omp_eos
,
902 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
903 matcho ("end target teams distribute", gfc_match_omp_eos
,
904 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
905 matcho ("end target teams", gfc_match_omp_eos
, ST_OMP_END_TARGET_TEAMS
);
906 matcho ("end target", gfc_match_omp_eos
, ST_OMP_END_TARGET
);
907 matcho ("end taskgroup", gfc_match_omp_eos
, ST_OMP_END_TASKGROUP
);
908 matchs ("end taskloop simd", gfc_match_omp_eos
,
909 ST_OMP_END_TASKLOOP_SIMD
);
910 matcho ("end taskloop", gfc_match_omp_eos
, ST_OMP_END_TASKLOOP
);
911 matcho ("end task", gfc_match_omp_eos
, ST_OMP_END_TASK
);
912 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos
,
913 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
914 matcho ("end teams distribute parallel do", gfc_match_omp_eos
,
915 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
916 matchs ("end teams distribute simd", gfc_match_omp_eos
,
917 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
918 matcho ("end teams distribute", gfc_match_omp_eos
,
919 ST_OMP_END_TEAMS_DISTRIBUTE
);
920 matcho ("end teams", gfc_match_omp_eos
, ST_OMP_END_TEAMS
);
921 matcho ("end workshare", gfc_match_omp_end_nowait
,
922 ST_OMP_END_WORKSHARE
);
925 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
928 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
931 if (flag_openmp
&& gfc_match ("ordered depend (") == MATCH_YES
)
933 gfc_current_locus
= old_locus
;
934 matcho ("ordered", gfc_match_omp_ordered_depend
,
935 ST_OMP_ORDERED_DEPEND
);
938 matcho ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
941 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
942 ST_OMP_PARALLEL_DO_SIMD
);
943 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
944 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
945 ST_OMP_PARALLEL_SECTIONS
);
946 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
947 ST_OMP_PARALLEL_WORKSHARE
);
948 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
951 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
952 matcho ("section", gfc_match_omp_eos
, ST_OMP_SECTION
);
953 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
956 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
957 matcho ("target enter data", gfc_match_omp_target_enter_data
,
958 ST_OMP_TARGET_ENTER_DATA
);
959 matcho ("target exit data", gfc_match_omp_target_exit_data
,
960 ST_OMP_TARGET_EXIT_DATA
);
961 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd
,
962 ST_OMP_TARGET_PARALLEL_DO_SIMD
);
963 matcho ("target parallel do", gfc_match_omp_target_parallel_do
,
964 ST_OMP_TARGET_PARALLEL_DO
);
965 matcho ("target parallel", gfc_match_omp_target_parallel
,
966 ST_OMP_TARGET_PARALLEL
);
967 matchs ("target simd", gfc_match_omp_target_simd
, ST_OMP_TARGET_SIMD
);
968 matchs ("target teams distribute parallel do simd",
969 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
970 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
971 matcho ("target teams distribute parallel do",
972 gfc_match_omp_target_teams_distribute_parallel_do
,
973 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
974 matchs ("target teams distribute simd",
975 gfc_match_omp_target_teams_distribute_simd
,
976 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
977 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
978 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
979 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
980 matcho ("target update", gfc_match_omp_target_update
,
981 ST_OMP_TARGET_UPDATE
);
982 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
983 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
984 matchs ("taskloop simd", gfc_match_omp_taskloop_simd
,
985 ST_OMP_TASKLOOP_SIMD
);
986 matcho ("taskloop", gfc_match_omp_taskloop
, ST_OMP_TASKLOOP
);
987 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
988 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
989 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
990 matchs ("teams distribute parallel do simd",
991 gfc_match_omp_teams_distribute_parallel_do_simd
,
992 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
993 matcho ("teams distribute parallel do",
994 gfc_match_omp_teams_distribute_parallel_do
,
995 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
996 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
997 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
998 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
999 ST_OMP_TEAMS_DISTRIBUTE
);
1000 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
1001 matchdo ("threadprivate", gfc_match_omp_threadprivate
,
1002 ST_OMP_THREADPRIVATE
);
1005 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
1009 /* All else has failed, so give up. See if any of the matchers has
1010 stored an error message of some sort. Don't error out if
1011 not -fopenmp and simd_matched is false, i.e. if a directive other
1012 than one marked with match has been seen. */
1014 if (flag_openmp
|| simd_matched
)
1016 if (!gfc_error_check ())
1017 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1020 reject_statement ();
1022 gfc_error_recovery ();
1029 gfc_unset_implicit_pure (NULL
);
1031 if (!flag_openmp
&& gfc_pure (NULL
))
1033 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
1034 "at %C may not appear in PURE or ELEMENTAL "
1036 reject_statement ();
1037 gfc_error_recovery ();
1044 reject_statement ();
1046 gfc_buffer_error (false);
1047 gfc_current_locus
= old_locus
;
1048 return ST_GET_FCN_CHARACTERISTICS
;
1051 static gfc_statement
1052 decode_gcc_attribute (void)
1056 gfc_enforce_clean_symbol_state ();
1058 gfc_clear_error (); /* Clear any pending errors. */
1059 gfc_clear_warning (); /* Clear any pending warnings. */
1060 old_locus
= gfc_current_locus
;
1062 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1064 /* All else has failed, so give up. See if any of the matchers has
1065 stored an error message of some sort. */
1067 if (!gfc_error_check ())
1068 gfc_error_now ("Unclassifiable GCC directive at %C");
1070 reject_statement ();
1072 gfc_error_recovery ();
1079 /* Assert next length characters to be equal to token in free form. */
1082 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1087 c
= gfc_next_ascii_char ();
1088 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1089 gcc_assert (c
== token
[i
]);
1091 gcc_assert (gfc_is_whitespace(c
));
1092 gfc_gobble_whitespace ();
1093 if (last_was_use_stmt
)
1097 /* Get the next statement in free form source. */
1099 static gfc_statement
1106 at_bol
= gfc_at_bol ();
1107 gfc_gobble_whitespace ();
1109 c
= gfc_peek_ascii_char ();
1115 /* Found a statement label? */
1116 m
= gfc_match_st_label (&gfc_statement_label
);
1118 d
= gfc_peek_ascii_char ();
1119 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1121 gfc_match_small_literal_int (&i
, &cnt
);
1124 gfc_error_now ("Too many digits in statement label at %C");
1127 gfc_error_now ("Zero is not a valid statement label at %C");
1130 c
= gfc_next_ascii_char ();
1133 if (!gfc_is_whitespace (c
))
1134 gfc_error_now ("Non-numeric character in statement label at %C");
1140 label_locus
= gfc_current_locus
;
1142 gfc_gobble_whitespace ();
1144 if (at_bol
&& gfc_peek_ascii_char () == ';')
1146 gfc_error_now ("Semicolon at %C needs to be preceded by "
1148 gfc_next_ascii_char (); /* Eat up the semicolon. */
1152 if (gfc_match_eos () == MATCH_YES
)
1153 gfc_error_now ("Statement label without statement at %L",
1159 /* Comments have already been skipped by the time we get here,
1160 except for GCC attributes and OpenMP/OpenACC directives. */
1162 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1163 c
= gfc_peek_ascii_char ();
1169 c
= gfc_next_ascii_char ();
1170 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1171 gcc_assert (c
== "gcc$"[i
]);
1173 gfc_gobble_whitespace ();
1174 return decode_gcc_attribute ();
1179 /* Since both OpenMP and OpenACC directives starts with
1180 !$ character sequence, we must check all flags combinations */
1181 if ((flag_openmp
|| flag_openmp_simd
)
1184 verify_token_free ("$omp", 4, last_was_use_stmt
);
1185 return decode_omp_directive ();
1187 else if ((flag_openmp
|| flag_openmp_simd
)
1190 gfc_next_ascii_char (); /* Eat up dollar character */
1191 c
= gfc_peek_ascii_char ();
1195 verify_token_free ("omp", 3, last_was_use_stmt
);
1196 return decode_omp_directive ();
1200 verify_token_free ("acc", 3, last_was_use_stmt
);
1201 return decode_oacc_directive ();
1204 else if (flag_openacc
)
1206 verify_token_free ("$acc", 4, last_was_use_stmt
);
1207 return decode_oacc_directive ();
1213 if (at_bol
&& c
== ';')
1215 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1216 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1218 gfc_next_ascii_char (); /* Eat up the semicolon. */
1222 return decode_statement ();
1225 /* Assert next length characters to be equal to token in fixed form. */
1228 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1231 char c
= gfc_next_char_literal (NONSTRING
);
1233 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1234 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1236 if (c
!= ' ' && c
!= '0')
1238 gfc_buffer_error (false);
1239 gfc_error ("Bad continuation line at %C");
1242 if (last_was_use_stmt
)
1248 /* Get the next statement in fixed-form source. */
1250 static gfc_statement
1253 int label
, digit_flag
, i
;
1258 return decode_statement ();
1260 /* Skip past the current label field, parsing a statement label if
1261 one is there. This is a weird number parser, since the number is
1262 contained within five columns and can have any kind of embedded
1263 spaces. We also check for characters that make the rest of the
1269 for (i
= 0; i
< 5; i
++)
1271 c
= gfc_next_char_literal (NONSTRING
);
1288 label
= label
* 10 + ((unsigned char) c
- '0');
1289 label_locus
= gfc_current_locus
;
1293 /* Comments have already been skipped by the time we get
1294 here, except for GCC attributes and OpenMP directives. */
1297 c
= gfc_next_char_literal (NONSTRING
);
1299 if (TOLOWER (c
) == 'g')
1301 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1302 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1304 return decode_gcc_attribute ();
1308 if ((flag_openmp
|| flag_openmp_simd
)
1311 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1313 return decode_omp_directive ();
1315 else if ((flag_openmp
|| flag_openmp_simd
)
1318 c
= gfc_next_char_literal(NONSTRING
);
1319 if (c
== 'o' || c
== 'O')
1321 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1323 return decode_omp_directive ();
1325 else if (c
== 'a' || c
== 'A')
1327 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1329 return decode_oacc_directive ();
1332 else if (flag_openacc
)
1334 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1336 return decode_oacc_directive ();
1341 /* Comments have already been skipped by the time we get
1342 here so don't bother checking for them. */
1345 gfc_buffer_error (false);
1346 gfc_error ("Non-numeric character in statement label at %C");
1354 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1357 /* We've found a valid statement label. */
1358 gfc_statement_label
= gfc_get_st_label (label
);
1362 /* Since this line starts a statement, it cannot be a continuation
1363 of a previous statement. If we see something here besides a
1364 space or zero, it must be a bad continuation line. */
1366 c
= gfc_next_char_literal (NONSTRING
);
1370 if (c
!= ' ' && c
!= '0')
1372 gfc_buffer_error (false);
1373 gfc_error ("Bad continuation line at %C");
1377 /* Now that we've taken care of the statement label columns, we have
1378 to make sure that the first nonblank character is not a '!'. If
1379 it is, the rest of the line is a comment. */
1383 loc
= gfc_current_locus
;
1384 c
= gfc_next_char_literal (NONSTRING
);
1386 while (gfc_is_whitespace (c
));
1390 gfc_current_locus
= loc
;
1395 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1396 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1397 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1402 if (gfc_match_eos () == MATCH_YES
)
1405 /* At this point, we've got a nonblank statement to parse. */
1406 return decode_statement ();
1410 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1412 gfc_current_locus
.lb
->truncated
= 0;
1413 gfc_advance_line ();
1418 /* Return the next non-ST_NONE statement to the caller. We also worry
1419 about including files and the ends of include files at this stage. */
1421 static gfc_statement
1422 next_statement (void)
1427 gfc_enforce_clean_symbol_state ();
1429 gfc_new_block
= NULL
;
1431 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1432 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1435 gfc_statement_label
= NULL
;
1436 gfc_buffer_error (true);
1439 gfc_advance_line ();
1441 gfc_skip_comments ();
1449 if (gfc_define_undef_line ())
1452 old_locus
= gfc_current_locus
;
1454 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1460 gfc_buffer_error (false);
1462 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1464 if (gfc_statement_label
!= NULL
)
1466 gfc_free_st_label (gfc_statement_label
);
1467 gfc_statement_label
= NULL
;
1469 gfc_current_locus
= old_locus
;
1473 check_statement_label (st
);
1479 /****************************** Parser ***********************************/
1481 /* The parser subroutines are of type 'try' that fail if the file ends
1484 /* Macros that expand to case-labels for various classes of
1485 statements. Start with executable statements that directly do
1488 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1489 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1490 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1491 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1492 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1493 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1494 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1495 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1496 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1497 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: \
1498 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1499 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: \
1500 case ST_ERROR_STOP: case ST_SYNC_ALL: \
1501 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1502 case ST_EVENT_POST: case ST_EVENT_WAIT: \
1503 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1504 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1506 /* Statements that mark other executable statements. */
1508 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1509 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1510 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1511 case ST_OMP_PARALLEL: \
1512 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1513 case ST_OMP_CRITICAL: case ST_OMP_MASTER: case ST_OMP_SINGLE: \
1514 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1515 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1516 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1517 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1518 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1519 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1520 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1521 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1522 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1523 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1524 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1525 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1526 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1527 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1528 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1529 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1530 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1532 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1533 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1534 case ST_OACC_KERNELS_LOOP: case ST_OACC_ATOMIC
1536 /* Declaration statements */
1538 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1539 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1540 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE: case ST_OACC_ROUTINE: \
1541 case ST_OACC_DECLARE
1543 /* OpenMP declaration statements. */
1545 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1546 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION
1548 /* Block end statements. Errors associated with interchanging these
1549 are detected in gfc_match_end(). */
1551 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1552 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1553 case ST_END_BLOCK: case ST_END_ASSOCIATE
1556 /* Push a new state onto the stack. */
1559 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1561 p
->state
= new_state
;
1562 p
->previous
= gfc_state_stack
;
1564 p
->head
= p
->tail
= NULL
;
1565 p
->do_variable
= NULL
;
1566 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1567 p
->ext
.oacc_declare_clauses
= NULL
;
1569 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1570 construct statement was accepted right before pushing the state. Thus,
1571 the construct's gfc_code is available as tail of the parent state. */
1572 gcc_assert (gfc_state_stack
);
1573 p
->construct
= gfc_state_stack
->tail
;
1575 gfc_state_stack
= p
;
1579 /* Pop the current state. */
1583 gfc_state_stack
= gfc_state_stack
->previous
;
1587 /* Try to find the given state in the state stack. */
1590 gfc_find_state (gfc_compile_state state
)
1594 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1595 if (p
->state
== state
)
1598 return (p
== NULL
) ? false : true;
1602 /* Starts a new level in the statement list. */
1605 new_level (gfc_code
*q
)
1609 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1611 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1617 /* Add the current new_st code structure and adds it to the current
1618 program unit. As a side-effect, it zeroes the new_st. */
1621 add_statement (void)
1625 p
= XCNEW (gfc_code
);
1628 p
->loc
= gfc_current_locus
;
1630 if (gfc_state_stack
->head
== NULL
)
1631 gfc_state_stack
->head
= p
;
1633 gfc_state_stack
->tail
->next
= p
;
1635 while (p
->next
!= NULL
)
1638 gfc_state_stack
->tail
= p
;
1640 gfc_clear_new_st ();
1646 /* Frees everything associated with the current statement. */
1649 undo_new_statement (void)
1651 gfc_free_statements (new_st
.block
);
1652 gfc_free_statements (new_st
.next
);
1653 gfc_free_statement (&new_st
);
1654 gfc_clear_new_st ();
1658 /* If the current statement has a statement label, make sure that it
1659 is allowed to, or should have one. */
1662 check_statement_label (gfc_statement st
)
1666 if (gfc_statement_label
== NULL
)
1668 if (st
== ST_FORMAT
)
1669 gfc_error ("FORMAT statement at %L does not have a statement label",
1676 case ST_END_PROGRAM
:
1677 case ST_END_FUNCTION
:
1678 case ST_END_SUBROUTINE
:
1682 case ST_END_CRITICAL
:
1684 case ST_END_ASSOCIATE
:
1687 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1688 type
= ST_LABEL_DO_TARGET
;
1690 type
= ST_LABEL_TARGET
;
1694 type
= ST_LABEL_FORMAT
;
1697 /* Statement labels are not restricted from appearing on a
1698 particular line. However, there are plenty of situations
1699 where the resulting label can't be referenced. */
1702 type
= ST_LABEL_BAD_TARGET
;
1706 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1708 new_st
.here
= gfc_statement_label
;
1712 /* Figures out what the enclosing program unit is. This will be a
1713 function, subroutine, program, block data or module. */
1716 gfc_enclosing_unit (gfc_compile_state
* result
)
1720 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1721 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1722 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1723 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1732 *result
= COMP_PROGRAM
;
1737 /* Translate a statement enum to a string. */
1740 gfc_ascii_statement (gfc_statement st
)
1746 case ST_ARITHMETIC_IF
:
1747 p
= _("arithmetic IF");
1756 p
= _("attribute declaration");
1792 p
= _("data declaration");
1806 case ST_STRUCTURE_DECL
:
1809 case ST_DERIVED_DECL
:
1810 p
= _("derived type declaration");
1830 case ST_END_ASSOCIATE
:
1831 p
= "END ASSOCIATE";
1836 case ST_END_BLOCK_DATA
:
1837 p
= "END BLOCK DATA";
1839 case ST_END_CRITICAL
:
1851 case ST_END_FUNCTION
:
1857 case ST_END_INTERFACE
:
1858 p
= "END INTERFACE";
1863 case ST_END_SUBMODULE
:
1864 p
= "END SUBMODULE";
1866 case ST_END_PROGRAM
:
1872 case ST_END_SUBROUTINE
:
1873 p
= "END SUBROUTINE";
1878 case ST_END_STRUCTURE
:
1879 p
= "END STRUCTURE";
1893 case ST_EQUIVALENCE
:
1905 case ST_FORALL_BLOCK
: /* Fall through */
1927 case ST_IMPLICIT_NONE
:
1928 p
= "IMPLICIT NONE";
1930 case ST_IMPLIED_ENDDO
:
1931 p
= _("implied END DO");
1963 case ST_MODULE_PROC
:
1964 p
= "MODULE PROCEDURE";
1996 case ST_SYNC_IMAGES
:
1999 case ST_SYNC_MEMORY
:
2014 case ST_WHERE_BLOCK
: /* Fall through */
2025 p
= _("assignment");
2027 case ST_POINTER_ASSIGNMENT
:
2028 p
= _("pointer assignment");
2030 case ST_SELECT_CASE
:
2033 case ST_SELECT_TYPE
:
2048 case ST_STATEMENT_FUNCTION
:
2049 p
= "STATEMENT FUNCTION";
2051 case ST_LABEL_ASSIGNMENT
:
2052 p
= "LABEL ASSIGNMENT";
2055 p
= "ENUM DEFINITION";
2058 p
= "ENUMERATOR DEFINITION";
2063 case ST_OACC_PARALLEL_LOOP
:
2064 p
= "!$ACC PARALLEL LOOP";
2066 case ST_OACC_END_PARALLEL_LOOP
:
2067 p
= "!$ACC END PARALLEL LOOP";
2069 case ST_OACC_PARALLEL
:
2070 p
= "!$ACC PARALLEL";
2072 case ST_OACC_END_PARALLEL
:
2073 p
= "!$ACC END PARALLEL";
2075 case ST_OACC_KERNELS
:
2076 p
= "!$ACC KERNELS";
2078 case ST_OACC_END_KERNELS
:
2079 p
= "!$ACC END KERNELS";
2081 case ST_OACC_KERNELS_LOOP
:
2082 p
= "!$ACC KERNELS LOOP";
2084 case ST_OACC_END_KERNELS_LOOP
:
2085 p
= "!$ACC END KERNELS LOOP";
2090 case ST_OACC_END_DATA
:
2091 p
= "!$ACC END DATA";
2093 case ST_OACC_HOST_DATA
:
2094 p
= "!$ACC HOST_DATA";
2096 case ST_OACC_END_HOST_DATA
:
2097 p
= "!$ACC END HOST_DATA";
2102 case ST_OACC_END_LOOP
:
2103 p
= "!$ACC END LOOP";
2105 case ST_OACC_DECLARE
:
2106 p
= "!$ACC DECLARE";
2108 case ST_OACC_UPDATE
:
2117 case ST_OACC_ENTER_DATA
:
2118 p
= "!$ACC ENTER DATA";
2120 case ST_OACC_EXIT_DATA
:
2121 p
= "!$ACC EXIT DATA";
2123 case ST_OACC_ROUTINE
:
2124 p
= "!$ACC ROUTINE";
2126 case ST_OACC_ATOMIC
:
2129 case ST_OACC_END_ATOMIC
:
2130 p
= "!ACC END ATOMIC";
2135 case ST_OMP_BARRIER
:
2136 p
= "!$OMP BARRIER";
2141 case ST_OMP_CANCELLATION_POINT
:
2142 p
= "!$OMP CANCELLATION POINT";
2144 case ST_OMP_CRITICAL
:
2145 p
= "!$OMP CRITICAL";
2147 case ST_OMP_DECLARE_REDUCTION
:
2148 p
= "!$OMP DECLARE REDUCTION";
2150 case ST_OMP_DECLARE_SIMD
:
2151 p
= "!$OMP DECLARE SIMD";
2153 case ST_OMP_DECLARE_TARGET
:
2154 p
= "!$OMP DECLARE TARGET";
2156 case ST_OMP_DISTRIBUTE
:
2157 p
= "!$OMP DISTRIBUTE";
2159 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2160 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2162 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2163 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2165 case ST_OMP_DISTRIBUTE_SIMD
:
2166 p
= "!$OMP DISTRIBUTE SIMD";
2171 case ST_OMP_DO_SIMD
:
2172 p
= "!$OMP DO SIMD";
2174 case ST_OMP_END_ATOMIC
:
2175 p
= "!$OMP END ATOMIC";
2177 case ST_OMP_END_CRITICAL
:
2178 p
= "!$OMP END CRITICAL";
2180 case ST_OMP_END_DISTRIBUTE
:
2181 p
= "!$OMP END DISTRIBUTE";
2183 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2184 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2186 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2187 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2189 case ST_OMP_END_DISTRIBUTE_SIMD
:
2190 p
= "!$OMP END DISTRIBUTE SIMD";
2195 case ST_OMP_END_DO_SIMD
:
2196 p
= "!$OMP END DO SIMD";
2198 case ST_OMP_END_SIMD
:
2199 p
= "!$OMP END SIMD";
2201 case ST_OMP_END_MASTER
:
2202 p
= "!$OMP END MASTER";
2204 case ST_OMP_END_ORDERED
:
2205 p
= "!$OMP END ORDERED";
2207 case ST_OMP_END_PARALLEL
:
2208 p
= "!$OMP END PARALLEL";
2210 case ST_OMP_END_PARALLEL_DO
:
2211 p
= "!$OMP END PARALLEL DO";
2213 case ST_OMP_END_PARALLEL_DO_SIMD
:
2214 p
= "!$OMP END PARALLEL DO SIMD";
2216 case ST_OMP_END_PARALLEL_SECTIONS
:
2217 p
= "!$OMP END PARALLEL SECTIONS";
2219 case ST_OMP_END_PARALLEL_WORKSHARE
:
2220 p
= "!$OMP END PARALLEL WORKSHARE";
2222 case ST_OMP_END_SECTIONS
:
2223 p
= "!$OMP END SECTIONS";
2225 case ST_OMP_END_SINGLE
:
2226 p
= "!$OMP END SINGLE";
2228 case ST_OMP_END_TASK
:
2229 p
= "!$OMP END TASK";
2231 case ST_OMP_END_TARGET
:
2232 p
= "!$OMP END TARGET";
2234 case ST_OMP_END_TARGET_DATA
:
2235 p
= "!$OMP END TARGET DATA";
2237 case ST_OMP_END_TARGET_PARALLEL
:
2238 p
= "!$OMP END TARGET PARALLEL";
2240 case ST_OMP_END_TARGET_PARALLEL_DO
:
2241 p
= "!$OMP END TARGET PARALLEL DO";
2243 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2244 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2246 case ST_OMP_END_TARGET_SIMD
:
2247 p
= "!$OMP END TARGET SIMD";
2249 case ST_OMP_END_TARGET_TEAMS
:
2250 p
= "!$OMP END TARGET TEAMS";
2252 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2253 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2255 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2256 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2258 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2259 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2261 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2262 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2264 case ST_OMP_END_TASKGROUP
:
2265 p
= "!$OMP END TASKGROUP";
2267 case ST_OMP_END_TASKLOOP
:
2268 p
= "!$OMP END TASKLOOP";
2270 case ST_OMP_END_TASKLOOP_SIMD
:
2271 p
= "!$OMP END TASKLOOP SIMD";
2273 case ST_OMP_END_TEAMS
:
2274 p
= "!$OMP END TEAMS";
2276 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2277 p
= "!$OMP END TEAMS DISTRIBUTE";
2279 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2280 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2282 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2283 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2285 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2286 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2288 case ST_OMP_END_WORKSHARE
:
2289 p
= "!$OMP END WORKSHARE";
2297 case ST_OMP_ORDERED
:
2298 case ST_OMP_ORDERED_DEPEND
:
2299 p
= "!$OMP ORDERED";
2301 case ST_OMP_PARALLEL
:
2302 p
= "!$OMP PARALLEL";
2304 case ST_OMP_PARALLEL_DO
:
2305 p
= "!$OMP PARALLEL DO";
2307 case ST_OMP_PARALLEL_DO_SIMD
:
2308 p
= "!$OMP PARALLEL DO SIMD";
2310 case ST_OMP_PARALLEL_SECTIONS
:
2311 p
= "!$OMP PARALLEL SECTIONS";
2313 case ST_OMP_PARALLEL_WORKSHARE
:
2314 p
= "!$OMP PARALLEL WORKSHARE";
2316 case ST_OMP_SECTIONS
:
2317 p
= "!$OMP SECTIONS";
2319 case ST_OMP_SECTION
:
2320 p
= "!$OMP SECTION";
2331 case ST_OMP_TARGET_DATA
:
2332 p
= "!$OMP TARGET DATA";
2334 case ST_OMP_TARGET_ENTER_DATA
:
2335 p
= "!$OMP TARGET ENTER DATA";
2337 case ST_OMP_TARGET_EXIT_DATA
:
2338 p
= "!$OMP TARGET EXIT DATA";
2340 case ST_OMP_TARGET_PARALLEL
:
2341 p
= "!$OMP TARGET PARALLEL";
2343 case ST_OMP_TARGET_PARALLEL_DO
:
2344 p
= "!$OMP TARGET PARALLEL DO";
2346 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
2347 p
= "!$OMP TARGET PARALLEL DO SIMD";
2349 case ST_OMP_TARGET_SIMD
:
2350 p
= "!$OMP TARGET SIMD";
2352 case ST_OMP_TARGET_TEAMS
:
2353 p
= "!$OMP TARGET TEAMS";
2355 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2356 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2358 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2359 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2361 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2362 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2364 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2365 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2367 case ST_OMP_TARGET_UPDATE
:
2368 p
= "!$OMP TARGET UPDATE";
2373 case ST_OMP_TASKGROUP
:
2374 p
= "!$OMP TASKGROUP";
2376 case ST_OMP_TASKLOOP
:
2377 p
= "!$OMP TASKLOOP";
2379 case ST_OMP_TASKLOOP_SIMD
:
2380 p
= "!$OMP TASKLOOP SIMD";
2382 case ST_OMP_TASKWAIT
:
2383 p
= "!$OMP TASKWAIT";
2385 case ST_OMP_TASKYIELD
:
2386 p
= "!$OMP TASKYIELD";
2391 case ST_OMP_TEAMS_DISTRIBUTE
:
2392 p
= "!$OMP TEAMS DISTRIBUTE";
2394 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2395 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2397 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2398 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2400 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2401 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2403 case ST_OMP_THREADPRIVATE
:
2404 p
= "!$OMP THREADPRIVATE";
2406 case ST_OMP_WORKSHARE
:
2407 p
= "!$OMP WORKSHARE";
2410 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2417 /* Create a symbol for the main program and assign it to ns->proc_name. */
2420 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2422 gfc_symbol
*main_program
;
2423 symbol_attribute attr
;
2425 gfc_get_symbol (name
, ns
, &main_program
);
2426 gfc_clear_attr (&attr
);
2427 attr
.flavor
= FL_PROGRAM
;
2428 attr
.proc
= PROC_UNKNOWN
;
2429 attr
.subroutine
= 1;
2430 attr
.access
= ACCESS_PUBLIC
;
2431 attr
.is_main_program
= 1;
2432 main_program
->attr
= attr
;
2433 main_program
->declared_at
= gfc_current_locus
;
2434 ns
->proc_name
= main_program
;
2435 gfc_commit_symbols ();
2439 /* Do whatever is necessary to accept the last statement. */
2442 accept_statement (gfc_statement st
)
2446 case ST_IMPLICIT_NONE
:
2454 gfc_current_ns
->proc_name
= gfc_new_block
;
2457 /* If the statement is the end of a block, lay down a special code
2458 that allows a branch to the end of the block from within the
2459 construct. IF and SELECT are treated differently from DO
2460 (where EXEC_NOP is added inside the loop) for two
2462 1. END DO has a meaning in the sense that after a GOTO to
2463 it, the loop counter must be increased.
2464 2. IF blocks and SELECT blocks can consist of multiple
2465 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2466 Putting the label before the END IF would make the jump
2467 from, say, the ELSE IF block to the END IF illegal. */
2471 case ST_END_CRITICAL
:
2472 if (gfc_statement_label
!= NULL
)
2474 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2479 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2480 one parallel block. Thus, we add the special code to the nested block
2481 itself, instead of the parent one. */
2483 case ST_END_ASSOCIATE
:
2484 if (gfc_statement_label
!= NULL
)
2486 new_st
.op
= EXEC_END_BLOCK
;
2491 /* The end-of-program unit statements do not get the special
2492 marker and require a statement of some sort if they are a
2495 case ST_END_PROGRAM
:
2496 case ST_END_FUNCTION
:
2497 case ST_END_SUBROUTINE
:
2498 if (gfc_statement_label
!= NULL
)
2500 new_st
.op
= EXEC_RETURN
;
2505 new_st
.op
= EXEC_END_PROCEDURE
;
2521 gfc_commit_symbols ();
2522 gfc_warning_check ();
2523 gfc_clear_new_st ();
2527 /* Undo anything tentative that has been built for the current statement,
2528 except if a gfc_charlen structure has been added to current namespace's
2529 list of gfc_charlen structure. */
2532 reject_statement (void)
2534 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2535 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2537 gfc_reject_data (gfc_current_ns
);
2539 gfc_new_block
= NULL
;
2540 gfc_undo_symbols ();
2541 gfc_clear_warning ();
2542 undo_new_statement ();
2546 /* Generic complaint about an out of order statement. We also do
2547 whatever is necessary to clean up. */
2550 unexpected_statement (gfc_statement st
)
2552 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2554 reject_statement ();
2558 /* Given the next statement seen by the matcher, make sure that it is
2559 in proper order with the last. This subroutine is initialized by
2560 calling it with an argument of ST_NONE. If there is a problem, we
2561 issue an error and return false. Otherwise we return true.
2563 Individual parsers need to verify that the statements seen are
2564 valid before calling here, i.e., ENTRY statements are not allowed in
2565 INTERFACE blocks. The following diagram is taken from the standard:
2567 +---------------------------------------+
2568 | program subroutine function module |
2569 +---------------------------------------+
2571 +---------------------------------------+
2573 +---------------------------------------+
2575 | +-----------+------------------+
2576 | | parameter | implicit |
2577 | +-----------+------------------+
2578 | format | | derived type |
2579 | entry | parameter | interface |
2580 | | data | specification |
2581 | | | statement func |
2582 | +-----------+------------------+
2583 | | data | executable |
2584 +--------+-----------+------------------+
2586 +---------------------------------------+
2587 | internal module/subprogram |
2588 +---------------------------------------+
2590 +---------------------------------------+
2599 ORDER_IMPLICIT_NONE
,
2607 enum state_order state
;
2608 gfc_statement last_statement
;
2614 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2620 p
->state
= ORDER_START
;
2624 if (p
->state
> ORDER_USE
)
2626 p
->state
= ORDER_USE
;
2630 if (p
->state
> ORDER_IMPORT
)
2632 p
->state
= ORDER_IMPORT
;
2635 case ST_IMPLICIT_NONE
:
2636 if (p
->state
> ORDER_IMPLICIT
)
2639 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2640 statement disqualifies a USE but not an IMPLICIT NONE.
2641 Duplicate IMPLICIT NONEs are caught when the implicit types
2644 p
->state
= ORDER_IMPLICIT_NONE
;
2648 if (p
->state
> ORDER_IMPLICIT
)
2650 p
->state
= ORDER_IMPLICIT
;
2655 if (p
->state
< ORDER_IMPLICIT_NONE
)
2656 p
->state
= ORDER_IMPLICIT_NONE
;
2660 if (p
->state
>= ORDER_EXEC
)
2662 if (p
->state
< ORDER_IMPLICIT
)
2663 p
->state
= ORDER_IMPLICIT
;
2667 if (p
->state
< ORDER_SPEC
)
2668 p
->state
= ORDER_SPEC
;
2673 case ST_STRUCTURE_DECL
:
2674 case ST_DERIVED_DECL
:
2676 if (p
->state
>= ORDER_EXEC
)
2678 if (p
->state
< ORDER_SPEC
)
2679 p
->state
= ORDER_SPEC
;
2683 /* The OpenMP directives have to be somewhere in the specification
2684 part, but there are no further requirements on their ordering.
2685 Thus don't adjust p->state, just ignore them. */
2686 if (p
->state
>= ORDER_EXEC
)
2692 if (p
->state
< ORDER_EXEC
)
2693 p
->state
= ORDER_EXEC
;
2700 /* All is well, record the statement in case we need it next time. */
2701 p
->where
= gfc_current_locus
;
2702 p
->last_statement
= st
;
2707 gfc_error ("%s statement at %C cannot follow %s statement at %L",
2708 gfc_ascii_statement (st
),
2709 gfc_ascii_statement (p
->last_statement
), &p
->where
);
2715 /* Handle an unexpected end of file. This is a show-stopper... */
2717 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
2720 unexpected_eof (void)
2724 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
2726 /* Memory cleanup. Move to "second to last". */
2727 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
2730 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
2733 longjmp (eof_buf
, 1);
2737 /* Parse the CONTAINS section of a derived type definition. */
2739 gfc_access gfc_typebound_default_access
;
2742 parse_derived_contains (void)
2745 bool seen_private
= false;
2746 bool seen_comps
= false;
2747 bool error_flag
= false;
2750 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2751 gcc_assert (gfc_current_block ());
2753 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
2755 if (gfc_current_block ()->attr
.sequence
)
2756 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
2757 " section at %C", gfc_current_block ()->name
);
2758 if (gfc_current_block ()->attr
.is_bind_c
)
2759 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
2760 " section at %C", gfc_current_block ()->name
);
2762 accept_statement (ST_CONTAINS
);
2763 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
2765 gfc_typebound_default_access
= ACCESS_PUBLIC
;
2771 st
= next_statement ();
2779 gfc_error ("Components in TYPE at %C must precede CONTAINS");
2783 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
2786 accept_statement (ST_PROCEDURE
);
2791 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
2794 accept_statement (ST_GENERIC
);
2799 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
2803 accept_statement (ST_FINAL
);
2811 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
2812 "at %C with empty CONTAINS section")))
2815 /* ST_END_TYPE is accepted by parse_derived after return. */
2819 if (!gfc_find_state (COMP_MODULE
))
2821 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
2828 gfc_error ("PRIVATE statement at %C must precede procedure"
2835 gfc_error ("Duplicate PRIVATE statement at %C");
2839 accept_statement (ST_PRIVATE
);
2840 gfc_typebound_default_access
= ACCESS_PRIVATE
;
2841 seen_private
= true;
2845 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
2849 gfc_error ("Already inside a CONTAINS block at %C");
2853 unexpected_statement (st
);
2861 reject_statement ();
2865 gcc_assert (gfc_current_state () == COMP_DERIVED
);
2871 /* Set attributes for the parent symbol based on the attributes of a component
2872 and raise errors if conflicting attributes are found for the component. */
2875 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
2876 gfc_component
**eventp
)
2878 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
2879 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
2880 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
2882 if (lockp
) lock_comp
= *lockp
;
2883 if (eventp
) event_comp
= *eventp
;
2885 /* Look for allocatable components. */
2886 if (c
->attr
.allocatable
2887 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2888 && CLASS_DATA (c
)->attr
.allocatable
)
2889 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
2890 && c
->ts
.u
.derived
->attr
.alloc_comp
))
2893 sym
->attr
.alloc_comp
= 1;
2896 /* Look for pointer components. */
2898 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2899 && CLASS_DATA (c
)->attr
.class_pointer
)
2900 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
2903 sym
->attr
.pointer_comp
= 1;
2906 /* Look for procedure pointer components. */
2907 if (c
->attr
.proc_pointer
2908 || (c
->ts
.type
== BT_DERIVED
2909 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
2910 sym
->attr
.proc_pointer_comp
= 1;
2912 /* Looking for coarray components. */
2913 if (c
->attr
.codimension
2914 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2915 && CLASS_DATA (c
)->attr
.codimension
))
2918 sym
->attr
.coarray_comp
= 1;
2921 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
2922 && !c
->attr
.pointer
)
2925 sym
->attr
.coarray_comp
= 1;
2928 /* Looking for lock_type components. */
2929 if ((c
->ts
.type
== BT_DERIVED
2930 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2931 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
2932 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2933 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2934 == INTMOD_ISO_FORTRAN_ENV
2935 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2936 == ISOFORTRAN_LOCK_TYPE
)
2937 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
2938 && !allocatable
&& !pointer
))
2942 sym
->attr
.lock_comp
= 1;
2945 /* Looking for event_type components. */
2946 if ((c
->ts
.type
== BT_DERIVED
2947 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2948 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2949 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
2950 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
2951 == INTMOD_ISO_FORTRAN_ENV
2952 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
2953 == ISOFORTRAN_EVENT_TYPE
)
2954 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
2955 && !allocatable
&& !pointer
))
2959 sym
->attr
.event_comp
= 1;
2962 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
2963 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
2964 unless there are nondirect [allocatable or pointer] components
2965 involved (cf. 1.3.33.1 and 1.3.33.3). */
2967 if (pointer
&& !coarray
&& lock_type
)
2968 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
2969 "codimension or be a subcomponent of a coarray, "
2970 "which is not possible as the component has the "
2971 "pointer attribute", c
->name
, &c
->loc
);
2972 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
2973 && c
->ts
.u
.derived
->attr
.lock_comp
)
2974 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
2975 "of type LOCK_TYPE, which must have a codimension or be a "
2976 "subcomponent of a coarray", c
->name
, &c
->loc
);
2978 if (lock_type
&& allocatable
&& !coarray
)
2979 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
2980 "a codimension", c
->name
, &c
->loc
);
2981 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
2982 && c
->ts
.u
.derived
->attr
.lock_comp
)
2983 gfc_error ("Allocatable component %s at %L must have a codimension as "
2984 "it has a noncoarray subcomponent of type LOCK_TYPE",
2987 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
2988 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2989 "subcomponent of type LOCK_TYPE must have a codimension or "
2990 "be a subcomponent of a coarray. (Variables of type %s may "
2991 "not have a codimension as already a coarray "
2992 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
2994 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
2995 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
2996 "subcomponent of type LOCK_TYPE must have a codimension or "
2997 "be a subcomponent of a coarray. (Variables of type %s may "
2998 "not have a codimension as %s at %L has a codimension or a "
2999 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3000 sym
->name
, c
->name
, &c
->loc
);
3002 /* Similarly for EVENT TYPE. */
3004 if (pointer
&& !coarray
&& event_type
)
3005 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3006 "codimension or be a subcomponent of a coarray, "
3007 "which is not possible as the component has the "
3008 "pointer attribute", c
->name
, &c
->loc
);
3009 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3010 && c
->ts
.u
.derived
->attr
.event_comp
)
3011 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3012 "of type EVENT_TYPE, which must have a codimension or be a "
3013 "subcomponent of a coarray", c
->name
, &c
->loc
);
3015 if (event_type
&& allocatable
&& !coarray
)
3016 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3017 "a codimension", c
->name
, &c
->loc
);
3018 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3019 && c
->ts
.u
.derived
->attr
.event_comp
)
3020 gfc_error ("Allocatable component %s at %L must have a codimension as "
3021 "it has a noncoarray subcomponent of type EVENT_TYPE",
3024 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3025 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3026 "subcomponent of type EVENT_TYPE must have a codimension or "
3027 "be a subcomponent of a coarray. (Variables of type %s may "
3028 "not have a codimension as already a coarray "
3029 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3031 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3032 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3033 "subcomponent of type EVENT_TYPE must have a codimension or "
3034 "be a subcomponent of a coarray. (Variables of type %s may "
3035 "not have a codimension as %s at %L has a codimension or a "
3036 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3037 sym
->name
, c
->name
, &c
->loc
);
3039 /* Look for private components. */
3040 if (sym
->component_access
== ACCESS_PRIVATE
3041 || c
->attr
.access
== ACCESS_PRIVATE
3042 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3043 sym
->attr
.private_comp
= 1;
3045 if (lockp
) *lockp
= lock_comp
;
3046 if (eventp
) *eventp
= event_comp
;
3050 static void parse_struct_map (gfc_statement
);
3052 /* Parse a union component definition within a structure definition. */
3060 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3063 accept_statement(ST_UNION
);
3064 push_state (&s
, COMP_UNION
, gfc_new_block
);
3071 st
= next_statement ();
3072 /* Only MAP declarations valid within a union. */
3079 accept_statement (ST_MAP
);
3080 parse_struct_map (ST_MAP
);
3081 /* Add a component to the union for each map. */
3082 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3084 gfc_internal_error ("failed to create map component '%s'",
3085 gfc_new_block
->name
);
3086 reject_statement ();
3089 c
->ts
.type
= BT_DERIVED
;
3090 c
->ts
.u
.derived
= gfc_new_block
;
3091 /* Normally components get their initialization expressions when they
3092 are created in decl.c (build_struct) so we can look through the
3093 flat component list for initializers during resolution. Unions and
3094 maps create components along with their type definitions so we
3095 have to generate initializers here. */
3096 c
->initializer
= gfc_default_initializer (&c
->ts
);
3101 accept_statement (ST_END_UNION
);
3105 unexpected_statement (st
);
3110 for (c
= un
->components
; c
; c
= c
->next
)
3111 check_component (un
, c
, &lock_comp
, &event_comp
);
3113 /* Add the union as a component in its parent structure. */
3115 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3117 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3118 reject_statement ();
3121 c
->ts
.type
= BT_UNION
;
3122 c
->ts
.u
.derived
= un
;
3123 c
->initializer
= gfc_default_initializer (&c
->ts
);
3125 un
->attr
.zero_comp
= un
->components
== NULL
;
3129 /* Parse a STRUCTURE or MAP. */
3132 parse_struct_map (gfc_statement block
)
3138 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3139 gfc_compile_state comp
;
3142 if (block
== ST_STRUCTURE_DECL
)
3144 comp
= COMP_STRUCTURE
;
3145 ends
= ST_END_STRUCTURE
;
3149 gcc_assert (block
== ST_MAP
);
3154 accept_statement(block
);
3155 push_state (&s
, comp
, gfc_new_block
);
3157 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3160 while (compiling_type
)
3162 st
= next_statement ();
3168 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3169 case ST_STRUCTURE_DECL
:
3170 /* Let a more specific error make it to decode_statement(). */
3171 if (gfc_error_check () == 0)
3172 gfc_error ("Syntax error in nested structure declaration at %C");
3173 reject_statement ();
3174 /* Skip the rest of this statement. */
3175 gfc_error_recovery ();
3179 accept_statement (ST_UNION
);
3184 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3185 accept_statement (ST_DATA_DECL
);
3186 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3187 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3188 parse_struct_map (ST_STRUCTURE_DECL
);
3191 case ST_END_STRUCTURE
:
3195 accept_statement (st
);
3199 unexpected_statement (st
);
3203 unexpected_statement (st
);
3208 /* Validate each component. */
3209 sym
= gfc_current_block ();
3210 for (c
= sym
->components
; c
; c
= c
->next
)
3211 check_component (sym
, c
, &lock_comp
, &event_comp
);
3213 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3215 /* Allow parse_union to find this structure to add to its list of maps. */
3216 if (block
== ST_MAP
)
3217 gfc_new_block
= gfc_current_block ();
3223 /* Parse a derived type. */
3226 parse_derived (void)
3228 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3232 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3234 accept_statement (ST_DERIVED_DECL
);
3235 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3237 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3244 while (compiling_type
)
3246 st
= next_statement ();
3254 accept_statement (st
);
3259 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3266 if (!seen_component
)
3267 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3268 "definition at %C without components");
3270 accept_statement (ST_END_TYPE
);
3274 if (!gfc_find_state (COMP_MODULE
))
3276 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3283 gfc_error ("PRIVATE statement at %C must precede "
3284 "structure components");
3289 gfc_error ("Duplicate PRIVATE statement at %C");
3291 s
.sym
->component_access
= ACCESS_PRIVATE
;
3293 accept_statement (ST_PRIVATE
);
3300 gfc_error ("SEQUENCE statement at %C must precede "
3301 "structure components");
3305 if (gfc_current_block ()->attr
.sequence
)
3306 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3311 gfc_error ("Duplicate SEQUENCE statement at %C");
3315 gfc_add_sequence (&gfc_current_block ()->attr
,
3316 gfc_current_block ()->name
, NULL
);
3320 gfc_notify_std (GFC_STD_F2003
,
3321 "CONTAINS block in derived type"
3322 " definition at %C");
3324 accept_statement (ST_CONTAINS
);
3325 parse_derived_contains ();
3329 unexpected_statement (st
);
3334 /* need to verify that all fields of the derived type are
3335 * interoperable with C if the type is declared to be bind(c)
3337 sym
= gfc_current_block ();
3338 for (c
= sym
->components
; c
; c
= c
->next
)
3339 check_component (sym
, c
, &lock_comp
, &event_comp
);
3341 if (!seen_component
)
3342 sym
->attr
.zero_comp
= 1;
3348 /* Parse an ENUM. */
3356 int seen_enumerator
= 0;
3358 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3362 while (compiling_enum
)
3364 st
= next_statement ();
3372 seen_enumerator
= 1;
3373 accept_statement (st
);
3378 if (!seen_enumerator
)
3379 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3380 accept_statement (st
);
3384 gfc_free_enum_history ();
3385 unexpected_statement (st
);
3393 /* Parse an interface. We must be able to deal with the possibility
3394 of recursive interfaces. The parse_spec() subroutine is mutually
3395 recursive with parse_interface(). */
3397 static gfc_statement
parse_spec (gfc_statement
);
3400 parse_interface (void)
3402 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3403 gfc_symbol
*prog_unit
, *sym
;
3404 gfc_interface_info save
;
3405 gfc_state_data s1
, s2
;
3408 accept_statement (ST_INTERFACE
);
3410 current_interface
.ns
= gfc_current_ns
;
3411 save
= current_interface
;
3413 sym
= (current_interface
.type
== INTERFACE_GENERIC
3414 || current_interface
.type
== INTERFACE_USER_OP
)
3415 ? gfc_new_block
: NULL
;
3417 push_state (&s1
, COMP_INTERFACE
, sym
);
3418 current_state
= COMP_NONE
;
3421 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3423 st
= next_statement ();
3431 if (st
== ST_SUBROUTINE
)
3432 new_state
= COMP_SUBROUTINE
;
3433 else if (st
== ST_FUNCTION
)
3434 new_state
= COMP_FUNCTION
;
3435 if (gfc_new_block
->attr
.pointer
)
3437 gfc_new_block
->attr
.pointer
= 0;
3438 gfc_new_block
->attr
.proc_pointer
= 1;
3440 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3441 gfc_new_block
->formal
, NULL
))
3443 reject_statement ();
3444 gfc_free_namespace (gfc_current_ns
);
3447 /* F2008 C1210 forbids the IMPORT statement in module procedure
3448 interface bodies and the flag is set to import symbols. */
3449 if (gfc_new_block
->attr
.module_procedure
)
3450 gfc_current_ns
->has_import_set
= 1;
3454 case ST_MODULE_PROC
: /* The module procedure matcher makes
3455 sure the context is correct. */
3456 accept_statement (st
);
3457 gfc_free_namespace (gfc_current_ns
);
3460 case ST_END_INTERFACE
:
3461 gfc_free_namespace (gfc_current_ns
);
3462 gfc_current_ns
= current_interface
.ns
;
3466 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3467 gfc_ascii_statement (st
));
3468 reject_statement ();
3469 gfc_free_namespace (gfc_current_ns
);
3474 /* Make sure that the generic name has the right attribute. */
3475 if (current_interface
.type
== INTERFACE_GENERIC
3476 && current_state
== COMP_NONE
)
3478 if (new_state
== COMP_FUNCTION
&& sym
)
3479 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3480 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3481 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3483 current_state
= new_state
;
3486 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3488 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3489 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3490 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3491 "cannot be the same as an intrinsic type",
3492 gfc_new_block
->name
);
3495 push_state (&s2
, new_state
, gfc_new_block
);
3496 accept_statement (st
);
3497 prog_unit
= gfc_new_block
;
3498 prog_unit
->formal_ns
= gfc_current_ns
;
3499 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3500 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3504 /* Read data declaration statements. */
3505 st
= parse_spec (ST_NONE
);
3506 in_specification_block
= true;
3508 /* Since the interface block does not permit an IMPLICIT statement,
3509 the default type for the function or the result must be taken
3510 from the formal namespace. */
3511 if (new_state
== COMP_FUNCTION
)
3513 if (prog_unit
->result
== prog_unit
3514 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3515 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3516 else if (prog_unit
->result
!= prog_unit
3517 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3518 gfc_set_default_type (prog_unit
->result
, 1,
3519 prog_unit
->formal_ns
);
3522 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3524 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3525 gfc_ascii_statement (st
));
3526 reject_statement ();
3530 /* Add EXTERNAL attribute to function or subroutine. */
3531 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3532 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3534 current_interface
= save
;
3535 gfc_add_interface (prog_unit
);
3538 if (current_interface
.ns
3539 && current_interface
.ns
->proc_name
3540 && strcmp (current_interface
.ns
->proc_name
->name
,
3541 prog_unit
->name
) == 0)
3542 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3543 "enclosing procedure", prog_unit
->name
,
3544 ¤t_interface
.ns
->proc_name
->declared_at
);
3553 /* Associate function characteristics by going back to the function
3554 declaration and rematching the prefix. */
3557 match_deferred_characteristics (gfc_typespec
* ts
)
3560 match m
= MATCH_ERROR
;
3561 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3563 loc
= gfc_current_locus
;
3565 gfc_current_locus
= gfc_current_block ()->declared_at
;
3568 gfc_buffer_error (true);
3569 m
= gfc_match_prefix (ts
);
3570 gfc_buffer_error (false);
3572 if (ts
->type
== BT_DERIVED
)
3580 /* Only permit one go at the characteristic association. */
3584 /* Set the function locus correctly. If we have not found the
3585 function name, there is an error. */
3587 && gfc_match ("function% %n", name
) == MATCH_YES
3588 && strcmp (name
, gfc_current_block ()->name
) == 0)
3590 gfc_current_block ()->declared_at
= gfc_current_locus
;
3591 gfc_commit_symbols ();
3596 gfc_undo_symbols ();
3599 gfc_current_locus
=loc
;
3604 /* Check specification-expressions in the function result of the currently
3605 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3606 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3607 scope are not yet parsed so this has to be delayed up to parse_spec. */
3610 check_function_result_typed (void)
3614 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3616 if (!gfc_current_ns
->proc_name
->result
) return;
3618 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3620 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3621 /* TODO: Extend when KIND type parameters are implemented. */
3622 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3623 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3627 /* Parse a set of specification statements. Returns the statement
3628 that doesn't fit. */
3630 static gfc_statement
3631 parse_spec (gfc_statement st
)
3634 bool function_result_typed
= false;
3635 bool bad_characteristic
= false;
3638 in_specification_block
= true;
3640 verify_st_order (&ss
, ST_NONE
, false);
3642 st
= next_statement ();
3644 /* If we are not inside a function or don't have a result specified so far,
3645 do nothing special about it. */
3646 if (gfc_current_state () != COMP_FUNCTION
)
3647 function_result_typed
= true;
3650 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3653 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3654 function_result_typed
= true;
3659 /* If we're inside a BLOCK construct, some statements are disallowed.
3660 Check this here. Attribute declaration statements like INTENT, OPTIONAL
3661 or VALUE are also disallowed, but they don't have a particular ST_*
3662 key so we have to check for them individually in their matcher routine. */
3663 if (gfc_current_state () == COMP_BLOCK
)
3667 case ST_IMPLICIT_NONE
:
3670 case ST_EQUIVALENCE
:
3671 case ST_STATEMENT_FUNCTION
:
3672 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
3673 gfc_ascii_statement (st
));
3674 reject_statement ();
3680 else if (gfc_current_state () == COMP_BLOCK_DATA
)
3681 /* Fortran 2008, C1116. */
3688 case ST_DERIVED_DECL
:
3689 case ST_END_BLOCK_DATA
:
3690 case ST_EQUIVALENCE
:
3692 case ST_IMPLICIT_NONE
:
3694 case ST_STRUCTURE_DECL
:
3703 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
3704 gfc_ascii_statement (st
));
3705 reject_statement ();
3709 /* If we find a statement that can not be followed by an IMPLICIT statement
3710 (and thus we can expect to see none any further), type the function result
3711 if it has not yet been typed. Be careful not to give the END statement
3712 to verify_st_order! */
3713 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
3715 bool verify_now
= false;
3717 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
3722 verify_st_order (&dummyss
, ST_NONE
, false);
3723 verify_st_order (&dummyss
, st
, false);
3725 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
3731 check_function_result_typed ();
3732 function_result_typed
= true;
3741 case ST_IMPLICIT_NONE
:
3743 if (!function_result_typed
)
3745 check_function_result_typed ();
3746 function_result_typed
= true;
3752 case ST_DATA
: /* Not allowed in interfaces */
3753 if (gfc_current_state () == COMP_INTERFACE
)
3763 case ST_STRUCTURE_DECL
:
3764 case ST_DERIVED_DECL
:
3768 if (!verify_st_order (&ss
, st
, false))
3770 reject_statement ();
3771 st
= next_statement ();
3781 case ST_STRUCTURE_DECL
:
3782 parse_struct_map (ST_STRUCTURE_DECL
);
3785 case ST_DERIVED_DECL
:
3791 if (gfc_current_state () != COMP_MODULE
)
3793 gfc_error ("%s statement must appear in a MODULE",
3794 gfc_ascii_statement (st
));
3795 reject_statement ();
3799 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
3801 gfc_error ("%s statement at %C follows another accessibility "
3802 "specification", gfc_ascii_statement (st
));
3803 reject_statement ();
3807 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
3808 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
3812 case ST_STATEMENT_FUNCTION
:
3813 if (gfc_current_state () == COMP_MODULE
3814 || gfc_current_state () == COMP_SUBMODULE
)
3816 unexpected_statement (st
);
3824 accept_statement (st
);
3825 st
= next_statement ();
3829 accept_statement (st
);
3831 st
= next_statement ();
3834 case ST_GET_FCN_CHARACTERISTICS
:
3835 /* This statement triggers the association of a function's result
3837 ts
= &gfc_current_block ()->result
->ts
;
3838 if (match_deferred_characteristics (ts
) != MATCH_YES
)
3839 bad_characteristic
= true;
3841 st
= next_statement ();
3848 /* If match_deferred_characteristics failed, then there is an error. */
3849 if (bad_characteristic
)
3851 ts
= &gfc_current_block ()->result
->ts
;
3852 if (ts
->type
!= BT_DERIVED
)
3853 gfc_error ("Bad kind expression for function %qs at %L",
3854 gfc_current_block ()->name
,
3855 &gfc_current_block ()->declared_at
);
3857 gfc_error ("The type for function %qs at %L is not accessible",
3858 gfc_current_block ()->name
,
3859 &gfc_current_block ()->declared_at
);
3861 gfc_current_block ()->ts
.kind
= 0;
3862 /* Keep the derived type; if it's bad, it will be discovered later. */
3863 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
3864 ts
->type
= BT_UNKNOWN
;
3867 in_specification_block
= false;
3873 /* Parse a WHERE block, (not a simple WHERE statement). */
3876 parse_where_block (void)
3878 int seen_empty_else
;
3883 accept_statement (ST_WHERE_BLOCK
);
3884 top
= gfc_state_stack
->tail
;
3886 push_state (&s
, COMP_WHERE
, gfc_new_block
);
3888 d
= add_statement ();
3889 d
->expr1
= top
->expr1
;
3895 seen_empty_else
= 0;
3899 st
= next_statement ();
3905 case ST_WHERE_BLOCK
:
3906 parse_where_block ();
3911 accept_statement (st
);
3915 if (seen_empty_else
)
3917 gfc_error ("ELSEWHERE statement at %C follows previous "
3918 "unmasked ELSEWHERE");
3919 reject_statement ();
3923 if (new_st
.expr1
== NULL
)
3924 seen_empty_else
= 1;
3926 d
= new_level (gfc_state_stack
->head
);
3928 d
->expr1
= new_st
.expr1
;
3930 accept_statement (st
);
3935 accept_statement (st
);
3939 gfc_error ("Unexpected %s statement in WHERE block at %C",
3940 gfc_ascii_statement (st
));
3941 reject_statement ();
3945 while (st
!= ST_END_WHERE
);
3951 /* Parse a FORALL block (not a simple FORALL statement). */
3954 parse_forall_block (void)
3960 accept_statement (ST_FORALL_BLOCK
);
3961 top
= gfc_state_stack
->tail
;
3963 push_state (&s
, COMP_FORALL
, gfc_new_block
);
3965 d
= add_statement ();
3966 d
->op
= EXEC_FORALL
;
3971 st
= next_statement ();
3976 case ST_POINTER_ASSIGNMENT
:
3979 accept_statement (st
);
3982 case ST_WHERE_BLOCK
:
3983 parse_where_block ();
3986 case ST_FORALL_BLOCK
:
3987 parse_forall_block ();
3991 accept_statement (st
);
3998 gfc_error ("Unexpected %s statement in FORALL block at %C",
3999 gfc_ascii_statement (st
));
4001 reject_statement ();
4005 while (st
!= ST_END_FORALL
);
4011 static gfc_statement
parse_executable (gfc_statement
);
4013 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4016 parse_if_block (void)
4025 accept_statement (ST_IF_BLOCK
);
4027 top
= gfc_state_stack
->tail
;
4028 push_state (&s
, COMP_IF
, gfc_new_block
);
4030 new_st
.op
= EXEC_IF
;
4031 d
= add_statement ();
4033 d
->expr1
= top
->expr1
;
4039 st
= parse_executable (ST_NONE
);
4049 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4050 "statement at %L", &else_locus
);
4052 reject_statement ();
4056 d
= new_level (gfc_state_stack
->head
);
4058 d
->expr1
= new_st
.expr1
;
4060 accept_statement (st
);
4067 gfc_error ("Duplicate ELSE statements at %L and %C",
4069 reject_statement ();
4074 else_locus
= gfc_current_locus
;
4076 d
= new_level (gfc_state_stack
->head
);
4079 accept_statement (st
);
4087 unexpected_statement (st
);
4091 while (st
!= ST_ENDIF
);
4094 accept_statement (st
);
4098 /* Parse a SELECT block. */
4101 parse_select_block (void)
4107 accept_statement (ST_SELECT_CASE
);
4109 cp
= gfc_state_stack
->tail
;
4110 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4112 /* Make sure that the next statement is a CASE or END SELECT. */
4115 st
= next_statement ();
4118 if (st
== ST_END_SELECT
)
4120 /* Empty SELECT CASE is OK. */
4121 accept_statement (st
);
4128 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4131 reject_statement ();
4134 /* At this point, we're got a nonempty select block. */
4135 cp
= new_level (cp
);
4138 accept_statement (st
);
4142 st
= parse_executable (ST_NONE
);
4149 cp
= new_level (gfc_state_stack
->head
);
4151 gfc_clear_new_st ();
4153 accept_statement (st
);
4159 /* Can't have an executable statement because of
4160 parse_executable(). */
4162 unexpected_statement (st
);
4166 while (st
!= ST_END_SELECT
);
4169 accept_statement (st
);
4173 /* Pop the current selector from the SELECT TYPE stack. */
4176 select_type_pop (void)
4178 gfc_select_type_stack
*old
= select_type_stack
;
4179 select_type_stack
= old
->prev
;
4184 /* Parse a SELECT TYPE construct (F03:R821). */
4187 parse_select_type_block (void)
4193 gfc_current_ns
= new_st
.ext
.block
.ns
;
4194 accept_statement (ST_SELECT_TYPE
);
4196 cp
= gfc_state_stack
->tail
;
4197 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4199 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4203 st
= next_statement ();
4206 if (st
== ST_END_SELECT
)
4207 /* Empty SELECT CASE is OK. */
4209 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4212 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4213 "following SELECT TYPE at %C");
4215 reject_statement ();
4218 /* At this point, we're got a nonempty select block. */
4219 cp
= new_level (cp
);
4222 accept_statement (st
);
4226 st
= parse_executable (ST_NONE
);
4234 cp
= new_level (gfc_state_stack
->head
);
4236 gfc_clear_new_st ();
4238 accept_statement (st
);
4244 /* Can't have an executable statement because of
4245 parse_executable(). */
4247 unexpected_statement (st
);
4251 while (st
!= ST_END_SELECT
);
4255 accept_statement (st
);
4256 gfc_current_ns
= gfc_current_ns
->parent
;
4261 /* Given a symbol, make sure it is not an iteration variable for a DO
4262 statement. This subroutine is called when the symbol is seen in a
4263 context that causes it to become redefined. If the symbol is an
4264 iterator, we generate an error message and return nonzero. */
4267 gfc_check_do_variable (gfc_symtree
*st
)
4271 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4272 if (s
->do_variable
== st
)
4274 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4275 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4283 /* Checks to see if the current statement label closes an enddo.
4284 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4285 an error) if it incorrectly closes an ENDDO. */
4288 check_do_closure (void)
4292 if (gfc_statement_label
== NULL
)
4295 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4296 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4300 return 0; /* No loops to close */
4302 if (p
->ext
.end_do_label
== gfc_statement_label
)
4304 if (p
== gfc_state_stack
)
4307 gfc_error ("End of nonblock DO statement at %C is within another block");
4311 /* At this point, the label doesn't terminate the innermost loop.
4312 Make sure it doesn't terminate another one. */
4313 for (; p
; p
= p
->previous
)
4314 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4315 && p
->ext
.end_do_label
== gfc_statement_label
)
4317 gfc_error ("End of nonblock DO statement at %C is interwoven "
4318 "with another DO loop");
4326 /* Parse a series of contained program units. */
4328 static void parse_progunit (gfc_statement
);
4331 /* Parse a CRITICAL block. */
4334 parse_critical_block (void)
4337 gfc_state_data s
, *sd
;
4340 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4341 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4342 gfc_error_now (is_oacc (sd
)
4343 ? "CRITICAL block inside of OpenACC region at %C"
4344 : "CRITICAL block inside of OpenMP region at %C");
4346 s
.ext
.end_do_label
= new_st
.label1
;
4348 accept_statement (ST_CRITICAL
);
4349 top
= gfc_state_stack
->tail
;
4351 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4353 d
= add_statement ();
4354 d
->op
= EXEC_CRITICAL
;
4359 st
= parse_executable (ST_NONE
);
4367 case ST_END_CRITICAL
:
4368 if (s
.ext
.end_do_label
!= NULL
4369 && s
.ext
.end_do_label
!= gfc_statement_label
)
4370 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4371 "match CRITICAL label");
4373 if (gfc_statement_label
!= NULL
)
4375 new_st
.op
= EXEC_NOP
;
4381 unexpected_statement (st
);
4385 while (st
!= ST_END_CRITICAL
);
4388 accept_statement (st
);
4392 /* Set up the local namespace for a BLOCK construct. */
4395 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4397 gfc_namespace
* my_ns
;
4398 static int numblock
= 1;
4400 my_ns
= gfc_get_namespace (parent_ns
, 1);
4401 my_ns
->construct_entities
= 1;
4403 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4404 code generation (so it must not be NULL).
4405 We set its recursive argument if our container procedure is recursive, so
4406 that local variables are accordingly placed on the stack when it
4407 will be necessary. */
4409 my_ns
->proc_name
= gfc_new_block
;
4413 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4415 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4416 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4417 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4418 my_ns
->proc_name
->name
, NULL
);
4420 gfc_commit_symbol (my_ns
->proc_name
);
4423 if (parent_ns
->proc_name
)
4424 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4430 /* Parse a BLOCK construct. */
4433 parse_block_construct (void)
4435 gfc_namespace
* my_ns
;
4436 gfc_namespace
* my_parent
;
4439 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4441 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4443 new_st
.op
= EXEC_BLOCK
;
4444 new_st
.ext
.block
.ns
= my_ns
;
4445 new_st
.ext
.block
.assoc
= NULL
;
4446 accept_statement (ST_BLOCK
);
4448 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4449 gfc_current_ns
= my_ns
;
4450 my_parent
= my_ns
->parent
;
4452 parse_progunit (ST_NONE
);
4454 /* Don't depend on the value of gfc_current_ns; it might have been
4455 reset if the block had errors and was cleaned up. */
4456 gfc_current_ns
= my_parent
;
4462 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4463 behind the scenes with compiler-generated variables. */
4466 parse_associate (void)
4468 gfc_namespace
* my_ns
;
4471 gfc_association_list
* a
;
4473 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4475 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4477 new_st
.op
= EXEC_BLOCK
;
4478 new_st
.ext
.block
.ns
= my_ns
;
4479 gcc_assert (new_st
.ext
.block
.assoc
);
4481 /* Add all associate-names as BLOCK variables. Creating them is enough
4482 for now, they'll get their values during trans-* phase. */
4483 gfc_current_ns
= my_ns
;
4484 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4488 gfc_array_ref
*array_ref
;
4490 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4494 sym
->attr
.flavor
= FL_VARIABLE
;
4496 sym
->declared_at
= a
->where
;
4497 gfc_set_sym_referenced (sym
);
4499 /* Initialize the typespec. It is not available in all cases,
4500 however, as it may only be set on the target during resolution.
4501 Still, sometimes it helps to have it right now -- especially
4502 for parsing component references on the associate-name
4503 in case of association to a derived-type. */
4504 sym
->ts
= a
->target
->ts
;
4506 /* Check if the target expression is array valued. This can not always
4507 be done by looking at target.rank, because that might not have been
4508 set yet. Therefore traverse the chain of refs, looking for the last
4509 array ref and evaluate that. */
4511 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4512 if (ref
->type
== REF_ARRAY
)
4513 array_ref
= &ref
->u
.ar
;
4514 if (array_ref
|| a
->target
->rank
)
4521 /* Count the dimension, that have a non-scalar extend. */
4522 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4523 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4524 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4525 && array_ref
->end
[dim
] == NULL
4526 && array_ref
->start
[dim
] != NULL
))
4530 rank
= a
->target
->rank
;
4531 /* When the rank is greater than zero then sym will be an array. */
4532 if (sym
->ts
.type
== BT_CLASS
)
4534 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4535 || (CLASS_DATA (sym
)->as
4536 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4538 /* Don't just (re-)set the attr and as in the sym.ts,
4539 because this modifies the target's attr and as. Copy the
4540 data and do a build_class_symbol. */
4541 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4542 int corank
= gfc_get_corank (a
->target
);
4547 as
= gfc_get_array_spec ();
4548 as
->type
= AS_DEFERRED
;
4550 as
->corank
= corank
;
4551 attr
.dimension
= rank
? 1 : 0;
4552 attr
.codimension
= corank
? 1 : 0;
4557 attr
.dimension
= attr
.codimension
= 0;
4560 type
= CLASS_DATA (sym
)->ts
;
4561 if (!gfc_build_class_symbol (&type
,
4565 sym
->ts
.type
= BT_CLASS
;
4566 sym
->attr
.class_ok
= 1;
4569 sym
->attr
.class_ok
= 1;
4571 else if ((!sym
->as
&& rank
!= 0)
4572 || (sym
->as
&& sym
->as
->rank
!= rank
))
4574 as
= gfc_get_array_spec ();
4575 as
->type
= AS_DEFERRED
;
4577 as
->corank
= gfc_get_corank (a
->target
);
4579 sym
->attr
.dimension
= 1;
4581 sym
->attr
.codimension
= 1;
4586 accept_statement (ST_ASSOCIATE
);
4587 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
4590 st
= parse_executable (ST_NONE
);
4597 accept_statement (st
);
4598 my_ns
->code
= gfc_state_stack
->head
;
4602 unexpected_statement (st
);
4606 gfc_current_ns
= gfc_current_ns
->parent
;
4611 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
4612 handled inside of parse_executable(), because they aren't really
4616 parse_do_block (void)
4625 s
.ext
.end_do_label
= new_st
.label1
;
4627 if (new_st
.ext
.iterator
!= NULL
)
4628 stree
= new_st
.ext
.iterator
->var
->symtree
;
4632 accept_statement (ST_DO
);
4634 top
= gfc_state_stack
->tail
;
4635 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
4638 s
.do_variable
= stree
;
4640 top
->block
= new_level (top
);
4641 top
->block
->op
= EXEC_DO
;
4644 st
= parse_executable (ST_NONE
);
4652 if (s
.ext
.end_do_label
!= NULL
4653 && s
.ext
.end_do_label
!= gfc_statement_label
)
4654 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
4657 if (gfc_statement_label
!= NULL
)
4659 new_st
.op
= EXEC_NOP
;
4664 case ST_IMPLIED_ENDDO
:
4665 /* If the do-stmt of this DO construct has a do-construct-name,
4666 the corresponding end-do must be an end-do-stmt (with a matching
4667 name, but in that case we must have seen ST_ENDDO first).
4668 We only complain about this in pedantic mode. */
4669 if (gfc_current_block () != NULL
)
4670 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
4671 &gfc_current_block()->declared_at
);
4676 unexpected_statement (st
);
4681 accept_statement (st
);
4685 /* Parse the statements of OpenMP do/parallel do. */
4687 static gfc_statement
4688 parse_omp_do (gfc_statement omp_st
)
4694 accept_statement (omp_st
);
4696 cp
= gfc_state_stack
->tail
;
4697 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4698 np
= new_level (cp
);
4704 st
= next_statement ();
4707 else if (st
== ST_DO
)
4710 unexpected_statement (st
);
4714 if (gfc_statement_label
!= NULL
4715 && gfc_state_stack
->previous
!= NULL
4716 && gfc_state_stack
->previous
->state
== COMP_DO
4717 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4725 there should be no !$OMP END DO. */
4727 return ST_IMPLIED_ENDDO
;
4730 check_do_closure ();
4733 st
= next_statement ();
4734 gfc_statement omp_end_st
= ST_OMP_END_DO
;
4737 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
4738 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
4739 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
4741 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
4742 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
4744 case ST_OMP_DISTRIBUTE_SIMD
:
4745 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
4747 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
4748 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
4749 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
4750 case ST_OMP_PARALLEL_DO_SIMD
:
4751 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
4753 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
4754 case ST_OMP_TARGET_PARALLEL_DO
:
4755 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO
;
4757 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
4758 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
4760 case ST_OMP_TARGET_SIMD
: omp_end_st
= ST_OMP_END_TARGET_SIMD
; break;
4761 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
4762 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
4764 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4765 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4767 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4768 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4770 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
4771 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
4773 case ST_OMP_TASKLOOP
: omp_end_st
= ST_OMP_END_TASKLOOP
; break;
4774 case ST_OMP_TASKLOOP_SIMD
: omp_end_st
= ST_OMP_END_TASKLOOP_SIMD
; break;
4775 case ST_OMP_TEAMS_DISTRIBUTE
:
4776 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
4778 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
4779 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
4781 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
4782 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
4784 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
4785 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
4787 default: gcc_unreachable ();
4789 if (st
== omp_end_st
)
4791 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
4792 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
4794 gcc_assert (new_st
.op
== EXEC_NOP
);
4795 gfc_clear_new_st ();
4796 gfc_commit_symbols ();
4797 gfc_warning_check ();
4798 st
= next_statement ();
4804 /* Parse the statements of OpenMP atomic directive. */
4806 static gfc_statement
4807 parse_omp_oacc_atomic (bool omp_p
)
4809 gfc_statement st
, st_atomic
, st_end_atomic
;
4816 st_atomic
= ST_OMP_ATOMIC
;
4817 st_end_atomic
= ST_OMP_END_ATOMIC
;
4821 st_atomic
= ST_OACC_ATOMIC
;
4822 st_end_atomic
= ST_OACC_END_ATOMIC
;
4824 accept_statement (st_atomic
);
4826 cp
= gfc_state_stack
->tail
;
4827 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4828 np
= new_level (cp
);
4831 np
->ext
.omp_atomic
= cp
->ext
.omp_atomic
;
4832 count
= 1 + ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4833 == GFC_OMP_ATOMIC_CAPTURE
);
4837 st
= next_statement ();
4840 else if (st
== ST_ASSIGNMENT
)
4842 accept_statement (st
);
4846 unexpected_statement (st
);
4851 st
= next_statement ();
4852 if (st
== st_end_atomic
)
4854 gfc_clear_new_st ();
4855 gfc_commit_symbols ();
4856 gfc_warning_check ();
4857 st
= next_statement ();
4859 else if ((cp
->ext
.omp_atomic
& GFC_OMP_ATOMIC_MASK
)
4860 == GFC_OMP_ATOMIC_CAPTURE
)
4861 gfc_error ("Missing !$OMP END ATOMIC after !$OMP ATOMIC CAPTURE at %C");
4866 /* Parse the statements of an OpenACC structured block. */
4869 parse_oacc_structured_block (gfc_statement acc_st
)
4871 gfc_statement st
, acc_end_st
;
4873 gfc_state_data s
, *sd
;
4875 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4876 if (sd
->state
== COMP_CRITICAL
)
4877 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4879 accept_statement (acc_st
);
4881 cp
= gfc_state_stack
->tail
;
4882 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4883 np
= new_level (cp
);
4888 case ST_OACC_PARALLEL
:
4889 acc_end_st
= ST_OACC_END_PARALLEL
;
4891 case ST_OACC_KERNELS
:
4892 acc_end_st
= ST_OACC_END_KERNELS
;
4895 acc_end_st
= ST_OACC_END_DATA
;
4897 case ST_OACC_HOST_DATA
:
4898 acc_end_st
= ST_OACC_END_HOST_DATA
;
4906 st
= parse_executable (ST_NONE
);
4909 else if (st
!= acc_end_st
)
4911 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
4912 reject_statement ();
4915 while (st
!= acc_end_st
);
4917 gcc_assert (new_st
.op
== EXEC_NOP
);
4919 gfc_clear_new_st ();
4920 gfc_commit_symbols ();
4921 gfc_warning_check ();
4925 /* Parse the statements of OpenACC loop/parallel loop/kernels loop. */
4927 static gfc_statement
4928 parse_oacc_loop (gfc_statement acc_st
)
4932 gfc_state_data s
, *sd
;
4934 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4935 if (sd
->state
== COMP_CRITICAL
)
4936 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
4938 accept_statement (acc_st
);
4940 cp
= gfc_state_stack
->tail
;
4941 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
4942 np
= new_level (cp
);
4948 st
= next_statement ();
4951 else if (st
== ST_DO
)
4955 gfc_error ("Expected DO loop at %C");
4956 reject_statement ();
4961 if (gfc_statement_label
!= NULL
4962 && gfc_state_stack
->previous
!= NULL
4963 && gfc_state_stack
->previous
->state
== COMP_DO
4964 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
4967 return ST_IMPLIED_ENDDO
;
4970 check_do_closure ();
4973 st
= next_statement ();
4974 if (st
== ST_OACC_END_LOOP
)
4975 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
4976 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
4977 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
4978 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
4980 gcc_assert (new_st
.op
== EXEC_NOP
);
4981 gfc_clear_new_st ();
4982 gfc_commit_symbols ();
4983 gfc_warning_check ();
4984 st
= next_statement ();
4990 /* Parse the statements of an OpenMP structured block. */
4993 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
4995 gfc_statement st
, omp_end_st
;
4999 accept_statement (omp_st
);
5001 cp
= gfc_state_stack
->tail
;
5002 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5003 np
= new_level (cp
);
5009 case ST_OMP_PARALLEL
:
5010 omp_end_st
= ST_OMP_END_PARALLEL
;
5012 case ST_OMP_PARALLEL_SECTIONS
:
5013 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
5015 case ST_OMP_SECTIONS
:
5016 omp_end_st
= ST_OMP_END_SECTIONS
;
5018 case ST_OMP_ORDERED
:
5019 omp_end_st
= ST_OMP_END_ORDERED
;
5021 case ST_OMP_CRITICAL
:
5022 omp_end_st
= ST_OMP_END_CRITICAL
;
5025 omp_end_st
= ST_OMP_END_MASTER
;
5028 omp_end_st
= ST_OMP_END_SINGLE
;
5031 omp_end_st
= ST_OMP_END_TARGET
;
5033 case ST_OMP_TARGET_DATA
:
5034 omp_end_st
= ST_OMP_END_TARGET_DATA
;
5036 case ST_OMP_TARGET_TEAMS
:
5037 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
5039 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5040 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5042 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5043 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5045 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5046 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5048 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5049 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5052 omp_end_st
= ST_OMP_END_TASK
;
5054 case ST_OMP_TASKGROUP
:
5055 omp_end_st
= ST_OMP_END_TASKGROUP
;
5058 omp_end_st
= ST_OMP_END_TEAMS
;
5060 case ST_OMP_TEAMS_DISTRIBUTE
:
5061 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5063 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5064 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5066 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5067 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5069 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5070 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5072 case ST_OMP_DISTRIBUTE
:
5073 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
5075 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5076 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5078 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5079 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5081 case ST_OMP_DISTRIBUTE_SIMD
:
5082 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
5084 case ST_OMP_WORKSHARE
:
5085 omp_end_st
= ST_OMP_END_WORKSHARE
;
5087 case ST_OMP_PARALLEL_WORKSHARE
:
5088 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
5096 if (workshare_stmts_only
)
5098 /* Inside of !$omp workshare, only
5101 where statements and constructs
5102 forall statements and constructs
5106 are allowed. For !$omp critical these
5107 restrictions apply recursively. */
5110 st
= next_statement ();
5121 accept_statement (st
);
5124 case ST_WHERE_BLOCK
:
5125 parse_where_block ();
5128 case ST_FORALL_BLOCK
:
5129 parse_forall_block ();
5132 case ST_OMP_PARALLEL
:
5133 case ST_OMP_PARALLEL_SECTIONS
:
5134 parse_omp_structured_block (st
, false);
5137 case ST_OMP_PARALLEL_WORKSHARE
:
5138 case ST_OMP_CRITICAL
:
5139 parse_omp_structured_block (st
, true);
5142 case ST_OMP_PARALLEL_DO
:
5143 case ST_OMP_PARALLEL_DO_SIMD
:
5144 st
= parse_omp_do (st
);
5148 st
= parse_omp_oacc_atomic (true);
5159 st
= next_statement ();
5163 st
= parse_executable (ST_NONE
);
5166 else if (st
== ST_OMP_SECTION
5167 && (omp_st
== ST_OMP_SECTIONS
5168 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
5170 np
= new_level (np
);
5174 else if (st
!= omp_end_st
)
5175 unexpected_statement (st
);
5177 while (st
!= omp_end_st
);
5181 case EXEC_OMP_END_NOWAIT
:
5182 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5184 case EXEC_OMP_END_CRITICAL
:
5185 if (((cp
->ext
.omp_clauses
== NULL
) ^ (new_st
.ext
.omp_name
== NULL
))
5186 || (new_st
.ext
.omp_name
!= NULL
5187 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
5188 new_st
.ext
.omp_name
) != 0))
5189 gfc_error ("Name after !$omp critical and !$omp end critical does "
5191 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
5192 new_st
.ext
.omp_name
= NULL
;
5194 case EXEC_OMP_END_SINGLE
:
5195 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
5196 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
5197 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
5198 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5206 gfc_clear_new_st ();
5207 gfc_commit_symbols ();
5208 gfc_warning_check ();
5213 /* Accept a series of executable statements. We return the first
5214 statement that doesn't fit to the caller. Any block statements are
5215 passed on to the correct handler, which usually passes the buck
5218 static gfc_statement
5219 parse_executable (gfc_statement st
)
5224 st
= next_statement ();
5228 close_flag
= check_do_closure ();
5233 case ST_END_PROGRAM
:
5236 case ST_END_FUNCTION
:
5241 case ST_END_SUBROUTINE
:
5246 case ST_SELECT_CASE
:
5247 gfc_error ("%s statement at %C cannot terminate a non-block "
5248 "DO loop", gfc_ascii_statement (st
));
5261 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5262 "first executable statement");
5268 accept_statement (st
);
5269 if (close_flag
== 1)
5270 return ST_IMPLIED_ENDDO
;
5274 parse_block_construct ();
5285 case ST_SELECT_CASE
:
5286 parse_select_block ();
5289 case ST_SELECT_TYPE
:
5290 parse_select_type_block ();
5295 if (check_do_closure () == 1)
5296 return ST_IMPLIED_ENDDO
;
5300 parse_critical_block ();
5303 case ST_WHERE_BLOCK
:
5304 parse_where_block ();
5307 case ST_FORALL_BLOCK
:
5308 parse_forall_block ();
5311 case ST_OACC_PARALLEL_LOOP
:
5312 case ST_OACC_KERNELS_LOOP
:
5314 st
= parse_oacc_loop (st
);
5315 if (st
== ST_IMPLIED_ENDDO
)
5319 case ST_OACC_PARALLEL
:
5320 case ST_OACC_KERNELS
:
5322 case ST_OACC_HOST_DATA
:
5323 parse_oacc_structured_block (st
);
5326 case ST_OMP_PARALLEL
:
5327 case ST_OMP_PARALLEL_SECTIONS
:
5328 case ST_OMP_SECTIONS
:
5329 case ST_OMP_ORDERED
:
5330 case ST_OMP_CRITICAL
:
5334 case ST_OMP_TARGET_DATA
:
5335 case ST_OMP_TARGET_PARALLEL
:
5336 case ST_OMP_TARGET_TEAMS
:
5339 case ST_OMP_TASKGROUP
:
5340 parse_omp_structured_block (st
, false);
5343 case ST_OMP_WORKSHARE
:
5344 case ST_OMP_PARALLEL_WORKSHARE
:
5345 parse_omp_structured_block (st
, true);
5348 case ST_OMP_DISTRIBUTE
:
5349 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5350 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5351 case ST_OMP_DISTRIBUTE_SIMD
:
5353 case ST_OMP_DO_SIMD
:
5354 case ST_OMP_PARALLEL_DO
:
5355 case ST_OMP_PARALLEL_DO_SIMD
:
5357 case ST_OMP_TARGET_PARALLEL_DO
:
5358 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5359 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5360 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5361 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5362 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5363 case ST_OMP_TASKLOOP
:
5364 case ST_OMP_TASKLOOP_SIMD
:
5365 case ST_OMP_TEAMS_DISTRIBUTE
:
5366 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5367 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5368 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5369 st
= parse_omp_do (st
);
5370 if (st
== ST_IMPLIED_ENDDO
)
5374 case ST_OACC_ATOMIC
:
5375 st
= parse_omp_oacc_atomic (false);
5379 st
= parse_omp_oacc_atomic (true);
5386 st
= next_statement ();
5391 /* Fix the symbols for sibling functions. These are incorrectly added to
5392 the child namespace as the parser didn't know about this procedure. */
5395 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5399 gfc_symbol
*old_sym
;
5401 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5403 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5405 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5406 goto fixup_contained
;
5408 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5409 && sym
->attr
.generic
&& sym
->attr
.function
)
5410 ||(sym
->attr
.flavor
== FL_DERIVED
5411 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5412 goto fixup_contained
;
5414 old_sym
= st
->n
.sym
;
5415 if (old_sym
->ns
== ns
5416 && !old_sym
->attr
.contained
5418 /* By 14.6.1.3, host association should be excluded
5419 for the following. */
5420 && !(old_sym
->attr
.external
5421 || (old_sym
->ts
.type
!= BT_UNKNOWN
5422 && !old_sym
->attr
.implicit_type
)
5423 || old_sym
->attr
.flavor
== FL_PARAMETER
5424 || old_sym
->attr
.use_assoc
5425 || old_sym
->attr
.in_common
5426 || old_sym
->attr
.in_equivalence
5427 || old_sym
->attr
.data
5428 || old_sym
->attr
.dummy
5429 || old_sym
->attr
.result
5430 || old_sym
->attr
.dimension
5431 || old_sym
->attr
.allocatable
5432 || old_sym
->attr
.intrinsic
5433 || old_sym
->attr
.generic
5434 || old_sym
->attr
.flavor
== FL_NAMELIST
5435 || old_sym
->attr
.flavor
== FL_LABEL
5436 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
5438 /* Replace it with the symbol from the parent namespace. */
5442 gfc_release_symbol (old_sym
);
5446 /* Do the same for any contained procedures. */
5447 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
5452 parse_contained (int module
)
5454 gfc_namespace
*ns
, *parent_ns
, *tmp
;
5455 gfc_state_data s1
, s2
;
5460 int contains_statements
= 0;
5463 push_state (&s1
, COMP_CONTAINS
, NULL
);
5464 parent_ns
= gfc_current_ns
;
5468 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
5470 gfc_current_ns
->sibling
= parent_ns
->contained
;
5471 parent_ns
->contained
= gfc_current_ns
;
5474 /* Process the next available statement. We come here if we got an error
5475 and rejected the last statement. */
5476 old_loc
= gfc_current_locus
;
5477 st
= next_statement ();
5486 contains_statements
= 1;
5487 accept_statement (st
);
5490 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
5493 /* For internal procedures, create/update the symbol in the
5494 parent namespace. */
5498 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
5499 gfc_error ("Contained procedure %qs at %C is already "
5500 "ambiguous", gfc_new_block
->name
);
5503 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
5505 &gfc_new_block
->declared_at
))
5507 if (st
== ST_FUNCTION
)
5508 gfc_add_function (&sym
->attr
, sym
->name
,
5509 &gfc_new_block
->declared_at
);
5511 gfc_add_subroutine (&sym
->attr
, sym
->name
,
5512 &gfc_new_block
->declared_at
);
5516 gfc_commit_symbols ();
5519 sym
= gfc_new_block
;
5521 /* Mark this as a contained function, so it isn't replaced
5522 by other module functions. */
5523 sym
->attr
.contained
= 1;
5525 /* Set implicit_pure so that it can be reset if any of the
5526 tests for purity fail. This is used for some optimisation
5527 during translation. */
5528 if (!sym
->attr
.pure
)
5529 sym
->attr
.implicit_pure
= 1;
5531 parse_progunit (ST_NONE
);
5533 /* Fix up any sibling functions that refer to this one. */
5534 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
5535 /* Or refer to any of its alternate entry points. */
5536 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
5537 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
5539 gfc_current_ns
->code
= s2
.head
;
5540 gfc_current_ns
= parent_ns
;
5545 /* These statements are associated with the end of the host unit. */
5546 case ST_END_FUNCTION
:
5548 case ST_END_SUBMODULE
:
5549 case ST_END_PROGRAM
:
5550 case ST_END_SUBROUTINE
:
5551 accept_statement (st
);
5552 gfc_current_ns
->code
= s1
.head
;
5556 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
5557 gfc_ascii_statement (st
));
5558 reject_statement ();
5564 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
5565 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
5566 && st
!= ST_END_PROGRAM
);
5568 /* The first namespace in the list is guaranteed to not have
5569 anything (worthwhile) in it. */
5570 tmp
= gfc_current_ns
;
5571 gfc_current_ns
= parent_ns
;
5572 if (seen_error
&& tmp
->refs
> 1)
5573 gfc_free_namespace (tmp
);
5575 ns
= gfc_current_ns
->contained
;
5576 gfc_current_ns
->contained
= ns
->sibling
;
5577 gfc_free_namespace (ns
);
5580 if (!contains_statements
)
5581 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
5582 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
5586 /* The result variable in a MODULE PROCEDURE needs to be created and
5587 its characteristics copied from the interface since it is neither
5588 declared in the procedure declaration nor in the specification
5592 get_modproc_result (void)
5595 if (gfc_state_stack
->previous
5596 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
5597 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
5599 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
5601 && proc
->attr
.function
5603 && proc
->tlink
->result
5604 && proc
->tlink
->result
!= proc
->tlink
)
5606 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
5607 gfc_set_sym_referenced (proc
->result
);
5608 proc
->result
->attr
.if_source
= IFSRC_DECL
;
5609 gfc_commit_symbol (proc
->result
);
5615 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
5618 parse_progunit (gfc_statement st
)
5624 && gfc_new_block
->abr_modproc_decl
5625 && gfc_new_block
->attr
.function
)
5626 get_modproc_result ();
5628 st
= parse_spec (st
);
5635 /* This is not allowed within BLOCK! */
5636 if (gfc_current_state () != COMP_BLOCK
)
5641 accept_statement (st
);
5648 if (gfc_current_state () == COMP_FUNCTION
)
5649 gfc_check_function_type (gfc_current_ns
);
5654 st
= parse_executable (st
);
5662 /* This is not allowed within BLOCK! */
5663 if (gfc_current_state () != COMP_BLOCK
)
5668 accept_statement (st
);
5675 unexpected_statement (st
);
5676 reject_statement ();
5677 st
= next_statement ();
5683 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
5684 if (p
->state
== COMP_CONTAINS
)
5687 if (gfc_find_state (COMP_MODULE
) == true
5688 || gfc_find_state (COMP_SUBMODULE
) == true)
5693 gfc_error ("CONTAINS statement at %C is already in a contained "
5695 reject_statement ();
5696 st
= next_statement ();
5700 parse_contained (0);
5703 gfc_current_ns
->code
= gfc_state_stack
->head
;
5707 /* Come here to complain about a global symbol already in use as
5711 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
5716 where
= &gfc_current_locus
;
5726 case GSYM_SUBROUTINE
:
5727 name
= "SUBROUTINE";
5732 case GSYM_BLOCK_DATA
:
5733 name
= "BLOCK DATA";
5739 gfc_internal_error ("gfc_global_used(): Bad type");
5743 if (sym
->binding_label
)
5744 gfc_error ("Global binding name %qs at %L is already being used as a %s "
5745 "at %L", sym
->binding_label
, where
, name
, &sym
->where
);
5747 gfc_error ("Global name %qs at %L is already being used as a %s at %L",
5748 sym
->name
, where
, name
, &sym
->where
);
5752 /* Parse a block data program unit. */
5755 parse_block_data (void)
5758 static locus blank_locus
;
5759 static int blank_block
=0;
5762 gfc_current_ns
->proc_name
= gfc_new_block
;
5763 gfc_current_ns
->is_block_data
= 1;
5765 if (gfc_new_block
== NULL
)
5768 gfc_error ("Blank BLOCK DATA at %C conflicts with "
5769 "prior BLOCK DATA at %L", &blank_locus
);
5773 blank_locus
= gfc_current_locus
;
5778 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5780 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
5781 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5784 s
->type
= GSYM_BLOCK_DATA
;
5785 s
->where
= gfc_new_block
->declared_at
;
5790 st
= parse_spec (ST_NONE
);
5792 while (st
!= ST_END_BLOCK_DATA
)
5794 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
5795 gfc_ascii_statement (st
));
5796 reject_statement ();
5797 st
= next_statement ();
5802 /* Following the association of the ancestor (sub)module symbols, they
5803 must be set host rather than use associated and all must be public.
5804 They are flagged up by 'used_in_submodule' so that they can be set
5805 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
5806 linker chokes on multiple symbol definitions. */
5809 set_syms_host_assoc (gfc_symbol
*sym
)
5816 if (sym
->attr
.module_procedure
)
5817 sym
->attr
.external
= 0;
5819 /* sym->attr.access = ACCESS_PUBLIC; */
5821 sym
->attr
.use_assoc
= 0;
5822 sym
->attr
.host_assoc
= 1;
5823 sym
->attr
.used_in_submodule
=1;
5825 if (sym
->attr
.flavor
== FL_DERIVED
)
5827 for (c
= sym
->components
; c
; c
= c
->next
)
5828 c
->attr
.access
= ACCESS_PUBLIC
;
5832 /* Parse a module subprogram. */
5841 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5842 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
5843 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5846 s
->type
= GSYM_MODULE
;
5847 s
->where
= gfc_new_block
->declared_at
;
5851 /* Something is nulling the module_list after this point. This is good
5852 since it allows us to 'USE' the parent modules that the submodule
5853 inherits and to set (most) of the symbols as host associated. */
5854 if (gfc_current_state () == COMP_SUBMODULE
)
5857 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
5860 st
= parse_spec (ST_NONE
);
5870 parse_contained (1);
5874 case ST_END_SUBMODULE
:
5875 accept_statement (st
);
5879 gfc_error ("Unexpected %s statement in MODULE at %C",
5880 gfc_ascii_statement (st
));
5883 reject_statement ();
5884 st
= next_statement ();
5888 /* Make sure not to free the namespace twice on error. */
5890 s
->ns
= gfc_current_ns
;
5894 /* Add a procedure name to the global symbol table. */
5897 add_global_procedure (bool sub
)
5901 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
5902 name is a global identifier. */
5903 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
5905 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5908 || (s
->type
!= GSYM_UNKNOWN
5909 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5911 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5912 /* Silence follow-up errors. */
5913 gfc_new_block
->binding_label
= NULL
;
5917 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5918 s
->sym_name
= gfc_new_block
->name
;
5919 s
->where
= gfc_new_block
->declared_at
;
5921 s
->ns
= gfc_current_ns
;
5925 /* Don't add the symbol multiple times. */
5926 if (gfc_new_block
->binding_label
5927 && (!gfc_notification_std (GFC_STD_F2008
)
5928 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
5930 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
);
5933 || (s
->type
!= GSYM_UNKNOWN
5934 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
5936 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5937 /* Silence follow-up errors. */
5938 gfc_new_block
->binding_label
= NULL
;
5942 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
5943 s
->sym_name
= gfc_new_block
->name
;
5944 s
->binding_label
= gfc_new_block
->binding_label
;
5945 s
->where
= gfc_new_block
->declared_at
;
5947 s
->ns
= gfc_current_ns
;
5953 /* Add a program to the global symbol table. */
5956 add_global_program (void)
5960 if (gfc_new_block
== NULL
)
5962 s
= gfc_get_gsymbol (gfc_new_block
->name
);
5964 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
5965 gfc_global_used (s
, &gfc_new_block
->declared_at
);
5968 s
->type
= GSYM_PROGRAM
;
5969 s
->where
= gfc_new_block
->declared_at
;
5971 s
->ns
= gfc_current_ns
;
5976 /* Resolve all the program units. */
5978 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
5980 gfc_free_dt_list ();
5981 gfc_current_ns
= gfc_global_ns_list
;
5982 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
5984 if (gfc_current_ns
->proc_name
5985 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
5986 continue; /* Already resolved. */
5988 if (gfc_current_ns
->proc_name
)
5989 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
5990 gfc_resolve (gfc_current_ns
);
5991 gfc_current_ns
->derived_types
= gfc_derived_types
;
5992 gfc_derived_types
= NULL
;
5998 clean_up_modules (gfc_gsymbol
*gsym
)
6003 clean_up_modules (gsym
->left
);
6004 clean_up_modules (gsym
->right
);
6006 if (gsym
->type
!= GSYM_MODULE
|| !gsym
->ns
)
6009 gfc_current_ns
= gsym
->ns
;
6010 gfc_derived_types
= gfc_current_ns
->derived_types
;
6017 /* Translate all the program units. This could be in a different order
6018 to resolution if there are forward references in the file. */
6020 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6024 gfc_current_ns
= gfc_global_ns_list
;
6025 gfc_get_errors (NULL
, &errors
);
6027 /* We first translate all modules to make sure that later parts
6028 of the program can use the decl. Then we translate the nonmodules. */
6030 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6032 if (!gfc_current_ns
->proc_name
6033 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6036 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6037 gfc_derived_types
= gfc_current_ns
->derived_types
;
6038 gfc_generate_module_code (gfc_current_ns
);
6039 gfc_current_ns
->translated
= 1;
6042 gfc_current_ns
= gfc_global_ns_list
;
6043 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6045 if (gfc_current_ns
->proc_name
6046 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6049 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6050 gfc_derived_types
= gfc_current_ns
->derived_types
;
6051 gfc_generate_code (gfc_current_ns
);
6052 gfc_current_ns
->translated
= 1;
6055 /* Clean up all the namespaces after translation. */
6056 gfc_current_ns
= gfc_global_ns_list
;
6057 for (;gfc_current_ns
;)
6061 if (gfc_current_ns
->proc_name
6062 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6064 gfc_current_ns
= gfc_current_ns
->sibling
;
6068 ns
= gfc_current_ns
->sibling
;
6069 gfc_derived_types
= gfc_current_ns
->derived_types
;
6071 gfc_current_ns
= ns
;
6074 clean_up_modules (gfc_gsym_root
);
6078 /* Top level parser. */
6081 gfc_parse_file (void)
6083 int seen_program
, errors_before
, errors
;
6084 gfc_state_data top
, s
;
6087 gfc_namespace
*next
;
6089 gfc_start_source_files ();
6091 top
.state
= COMP_NONE
;
6093 top
.previous
= NULL
;
6094 top
.head
= top
.tail
= NULL
;
6095 top
.do_variable
= NULL
;
6097 gfc_state_stack
= &top
;
6099 gfc_clear_new_st ();
6101 gfc_statement_label
= NULL
;
6103 if (setjmp (eof_buf
))
6104 return false; /* Come here on unexpected EOF */
6106 /* Prepare the global namespace that will contain the
6108 gfc_global_ns_list
= next
= NULL
;
6113 /* Exit early for empty files. */
6117 in_specification_block
= true;
6120 st
= next_statement ();
6129 goto duplicate_main
;
6131 prog_locus
= gfc_current_locus
;
6133 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6134 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
6135 accept_statement (st
);
6136 add_global_program ();
6137 parse_progunit (ST_NONE
);
6141 add_global_procedure (true);
6142 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
6143 accept_statement (st
);
6144 parse_progunit (ST_NONE
);
6148 add_global_procedure (false);
6149 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
6150 accept_statement (st
);
6151 parse_progunit (ST_NONE
);
6155 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
6156 accept_statement (st
);
6157 parse_block_data ();
6161 push_state (&s
, COMP_MODULE
, gfc_new_block
);
6162 accept_statement (st
);
6164 gfc_get_errors (NULL
, &errors_before
);
6169 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
6170 accept_statement (st
);
6172 gfc_get_errors (NULL
, &errors_before
);
6176 /* Anything else starts a nameless main program block. */
6179 goto duplicate_main
;
6181 prog_locus
= gfc_current_locus
;
6183 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6184 main_program_symbol (gfc_current_ns
, "MAIN__");
6185 parse_progunit (st
);
6189 /* Handle the non-program units. */
6190 gfc_current_ns
->code
= s
.head
;
6192 gfc_resolve (gfc_current_ns
);
6194 /* Dump the parse tree if requested. */
6195 if (flag_dump_fortran_original
)
6196 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6198 gfc_get_errors (NULL
, &errors
);
6199 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
6201 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
6202 gfc_current_ns
->derived_types
= gfc_derived_types
;
6203 gfc_derived_types
= NULL
;
6209 gfc_generate_code (gfc_current_ns
);
6217 /* The main program and non-contained procedures are put
6218 in the global namespace list, so that they can be processed
6219 later and all their interfaces resolved. */
6220 gfc_current_ns
->code
= s
.head
;
6223 for (; next
->sibling
; next
= next
->sibling
)
6225 next
->sibling
= gfc_current_ns
;
6228 gfc_global_ns_list
= gfc_current_ns
;
6230 next
= gfc_current_ns
;
6236 /* Do the resolution. */
6237 resolve_all_program_units (gfc_global_ns_list
);
6239 /* Do the parse tree dump. */
6240 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6242 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6243 if (!gfc_current_ns
->proc_name
6244 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6246 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6247 fputs ("------------------------------------------\n\n", stdout
);
6250 /* Do the translation. */
6251 translate_all_program_units (gfc_global_ns_list
);
6253 gfc_end_source_files ();
6257 /* If we see a duplicate main program, shut down. If the second
6258 instance is an implied main program, i.e. data decls or executable
6259 statements, we're in for lots of errors. */
6260 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6261 reject_statement ();
6266 /* Return true if this state data represents an OpenACC region. */
6268 is_oacc (gfc_state_data
*sd
)
6270 switch (sd
->construct
->op
)
6272 case EXEC_OACC_PARALLEL_LOOP
:
6273 case EXEC_OACC_PARALLEL
:
6274 case EXEC_OACC_KERNELS_LOOP
:
6275 case EXEC_OACC_KERNELS
:
6276 case EXEC_OACC_DATA
:
6277 case EXEC_OACC_HOST_DATA
:
6278 case EXEC_OACC_LOOP
:
6279 case EXEC_OACC_UPDATE
:
6280 case EXEC_OACC_WAIT
:
6281 case EXEC_OACC_CACHE
:
6282 case EXEC_OACC_ENTER_DATA
:
6283 case EXEC_OACC_EXIT_DATA
:
6284 case EXEC_OACC_ATOMIC
:
6285 case EXEC_OACC_ROUTINE
: