2 Copyright (C) 2000-2021 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
);
429 match (NULL
, gfc_match_select_rank
, ST_SELECT_RANK
);
431 /* General statement matching: Instead of testing every possible
432 statement, we eliminate most possibilities by peeking at the
438 match ("abstract% interface", gfc_match_abstract_interface
,
440 match ("allocate", gfc_match_allocate
, ST_ALLOCATE
);
441 match ("allocatable", gfc_match_allocatable
, ST_ATTR_DECL
);
442 match ("assign", gfc_match_assign
, ST_LABEL_ASSIGNMENT
);
443 match ("asynchronous", gfc_match_asynchronous
, ST_ATTR_DECL
);
444 match ("automatic", gfc_match_automatic
, ST_ATTR_DECL
);
448 match ("backspace", gfc_match_backspace
, ST_BACKSPACE
);
449 match ("block data", gfc_match_block_data
, ST_BLOCK_DATA
);
450 match (NULL
, gfc_match_bind_c_stmt
, ST_ATTR_DECL
);
454 match ("call", gfc_match_call
, ST_CALL
);
455 match ("change team", gfc_match_change_team
, ST_CHANGE_TEAM
);
456 match ("close", gfc_match_close
, ST_CLOSE
);
457 match ("continue", gfc_match_continue
, ST_CONTINUE
);
458 match ("contiguous", gfc_match_contiguous
, ST_ATTR_DECL
);
459 match ("cycle", gfc_match_cycle
, ST_CYCLE
);
460 match ("case", gfc_match_case
, ST_CASE
);
461 match ("common", gfc_match_common
, ST_COMMON
);
462 match ("contains", gfc_match_eos
, ST_CONTAINS
);
463 match ("class", gfc_match_class_is
, ST_CLASS_IS
);
464 match ("codimension", gfc_match_codimension
, ST_ATTR_DECL
);
468 match ("deallocate", gfc_match_deallocate
, ST_DEALLOCATE
);
469 match ("data", gfc_match_data
, ST_DATA
);
470 match ("dimension", gfc_match_dimension
, ST_ATTR_DECL
);
474 match ("end file", gfc_match_endfile
, ST_END_FILE
);
475 match ("end team", gfc_match_end_team
, ST_END_TEAM
);
476 match ("exit", gfc_match_exit
, ST_EXIT
);
477 match ("else", gfc_match_else
, ST_ELSE
);
478 match ("else where", gfc_match_elsewhere
, ST_ELSEWHERE
);
479 match ("else if", gfc_match_elseif
, ST_ELSEIF
);
480 match ("error stop", gfc_match_error_stop
, ST_ERROR_STOP
);
481 match ("enum , bind ( c )", gfc_match_enum
, ST_ENUM
);
483 if (gfc_match_end (&st
) == MATCH_YES
)
486 match ("entry% ", gfc_match_entry
, ST_ENTRY
);
487 match ("equivalence", gfc_match_equivalence
, ST_EQUIVALENCE
);
488 match ("external", gfc_match_external
, ST_ATTR_DECL
);
489 match ("event post", gfc_match_event_post
, ST_EVENT_POST
);
490 match ("event wait", gfc_match_event_wait
, ST_EVENT_WAIT
);
494 match ("fail image", gfc_match_fail_image
, ST_FAIL_IMAGE
);
495 match ("final", gfc_match_final_decl
, ST_FINAL
);
496 match ("flush", gfc_match_flush
, ST_FLUSH
);
497 match ("form team", gfc_match_form_team
, ST_FORM_TEAM
);
498 match ("format", gfc_match_format
, ST_FORMAT
);
502 match ("generic", gfc_match_generic
, ST_GENERIC
);
503 match ("go to", gfc_match_goto
, ST_GOTO
);
507 match ("inquire", gfc_match_inquire
, ST_INQUIRE
);
508 match ("implicit", gfc_match_implicit
, ST_IMPLICIT
);
509 match ("implicit% none", gfc_match_implicit_none
, ST_IMPLICIT_NONE
);
510 match ("import", gfc_match_import
, ST_IMPORT
);
511 match ("interface", gfc_match_interface
, ST_INTERFACE
);
512 match ("intent", gfc_match_intent
, ST_ATTR_DECL
);
513 match ("intrinsic", gfc_match_intrinsic
, ST_ATTR_DECL
);
517 match ("lock", gfc_match_lock
, ST_LOCK
);
521 match ("map", gfc_match_map
, ST_MAP
);
522 match ("module% procedure", gfc_match_modproc
, ST_MODULE_PROC
);
523 match ("module", gfc_match_module
, ST_MODULE
);
527 match ("nullify", gfc_match_nullify
, ST_NULLIFY
);
528 match ("namelist", gfc_match_namelist
, ST_NAMELIST
);
532 match ("open", gfc_match_open
, ST_OPEN
);
533 match ("optional", gfc_match_optional
, ST_ATTR_DECL
);
537 match ("print", gfc_match_print
, ST_WRITE
);
538 match ("pause", gfc_match_pause
, ST_PAUSE
);
539 match ("pointer", gfc_match_pointer
, ST_ATTR_DECL
);
540 if (gfc_match_private (&st
) == MATCH_YES
)
542 match ("procedure", gfc_match_procedure
, ST_PROCEDURE
);
543 match ("program", gfc_match_program
, ST_PROGRAM
);
544 if (gfc_match_public (&st
) == MATCH_YES
)
546 match ("protected", gfc_match_protected
, ST_ATTR_DECL
);
550 match ("rank", gfc_match_rank_is
, ST_RANK
);
551 match ("read", gfc_match_read
, ST_READ
);
552 match ("return", gfc_match_return
, ST_RETURN
);
553 match ("rewind", gfc_match_rewind
, ST_REWIND
);
557 match ("structure", gfc_match_structure_decl
, ST_STRUCTURE_DECL
);
558 match ("sequence", gfc_match_eos
, ST_SEQUENCE
);
559 match ("stop", gfc_match_stop
, ST_STOP
);
560 match ("save", gfc_match_save
, ST_ATTR_DECL
);
561 match ("static", gfc_match_static
, ST_ATTR_DECL
);
562 match ("submodule", gfc_match_submodule
, ST_SUBMODULE
);
563 match ("sync all", gfc_match_sync_all
, ST_SYNC_ALL
);
564 match ("sync images", gfc_match_sync_images
, ST_SYNC_IMAGES
);
565 match ("sync memory", gfc_match_sync_memory
, ST_SYNC_MEMORY
);
566 match ("sync team", gfc_match_sync_team
, ST_SYNC_TEAM
);
570 match ("target", gfc_match_target
, ST_ATTR_DECL
);
571 match ("type", gfc_match_derived_decl
, ST_DERIVED_DECL
);
572 match ("type is", gfc_match_type_is
, ST_TYPE_IS
);
576 match ("union", gfc_match_union
, ST_UNION
);
577 match ("unlock", gfc_match_unlock
, ST_UNLOCK
);
581 match ("value", gfc_match_value
, ST_ATTR_DECL
);
582 match ("volatile", gfc_match_volatile
, ST_ATTR_DECL
);
586 match ("wait", gfc_match_wait
, ST_WAIT
);
587 match ("write", gfc_match_write
, ST_WRITE
);
591 /* All else has failed, so give up. See if any of the matchers has
592 stored an error message of some sort. Suppress the "Unclassifiable
593 statement" if a previous error message was emitted, e.g., by
595 if (!gfc_error_check ())
598 gfc_get_errors (NULL
, &ecnt
);
600 gfc_error_now ("Unclassifiable statement at %C");
605 gfc_error_recovery ();
610 /* Like match and if spec_only, goto do_spec_only without actually
612 /* If the directive matched but the clauses failed, do not start
613 matching the next directive in the same switch statement. */
614 #define matcha(keyword, subr, st) \
617 if (spec_only && gfc_match (keyword) == MATCH_YES) \
619 else if ((m2 = match_word (keyword, subr, &old_locus)) \
622 else if (m2 == MATCH_ERROR) \
623 goto error_handling; \
625 undo_new_statement (); \
629 decode_oacc_directive (void)
633 bool spec_only
= false;
635 gfc_enforce_clean_symbol_state ();
637 gfc_clear_error (); /* Clear any pending errors. */
638 gfc_clear_warning (); /* Clear any pending warnings. */
640 gfc_matching_function
= false;
642 if (gfc_current_state () == COMP_FUNCTION
643 && gfc_current_block ()->result
->ts
.kind
== -1)
646 old_locus
= gfc_current_locus
;
648 /* General OpenACC directive matching: Instead of testing every possible
649 statement, we eliminate most possibilities by peeking at the
652 c
= gfc_peek_ascii_char ();
657 matcha ("routine", gfc_match_oacc_routine
, ST_OACC_ROUTINE
);
661 gfc_unset_implicit_pure (NULL
);
664 gfc_error_now ("OpenACC directives other than ROUTINE may not appear in PURE "
672 matcha ("atomic", gfc_match_oacc_atomic
, ST_OACC_ATOMIC
);
675 matcha ("cache", gfc_match_oacc_cache
, ST_OACC_CACHE
);
678 matcha ("data", gfc_match_oacc_data
, ST_OACC_DATA
);
679 match ("declare", gfc_match_oacc_declare
, ST_OACC_DECLARE
);
682 matcha ("end atomic", gfc_match_omp_eos_error
, ST_OACC_END_ATOMIC
);
683 matcha ("end data", gfc_match_omp_eos_error
, ST_OACC_END_DATA
);
684 matcha ("end host_data", gfc_match_omp_eos_error
, ST_OACC_END_HOST_DATA
);
685 matcha ("end kernels loop", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS_LOOP
);
686 matcha ("end kernels", gfc_match_omp_eos_error
, ST_OACC_END_KERNELS
);
687 matcha ("end loop", gfc_match_omp_eos_error
, ST_OACC_END_LOOP
);
688 matcha ("end parallel loop", gfc_match_omp_eos_error
,
689 ST_OACC_END_PARALLEL_LOOP
);
690 matcha ("end parallel", gfc_match_omp_eos_error
, ST_OACC_END_PARALLEL
);
691 matcha ("end serial loop", gfc_match_omp_eos_error
,
692 ST_OACC_END_SERIAL_LOOP
);
693 matcha ("end serial", gfc_match_omp_eos_error
, ST_OACC_END_SERIAL
);
694 matcha ("enter data", gfc_match_oacc_enter_data
, ST_OACC_ENTER_DATA
);
695 matcha ("exit data", gfc_match_oacc_exit_data
, ST_OACC_EXIT_DATA
);
698 matcha ("host_data", gfc_match_oacc_host_data
, ST_OACC_HOST_DATA
);
701 matcha ("parallel loop", gfc_match_oacc_parallel_loop
,
702 ST_OACC_PARALLEL_LOOP
);
703 matcha ("parallel", gfc_match_oacc_parallel
, ST_OACC_PARALLEL
);
706 matcha ("kernels loop", gfc_match_oacc_kernels_loop
,
707 ST_OACC_KERNELS_LOOP
);
708 matcha ("kernels", gfc_match_oacc_kernels
, ST_OACC_KERNELS
);
711 matcha ("loop", gfc_match_oacc_loop
, ST_OACC_LOOP
);
714 matcha ("serial loop", gfc_match_oacc_serial_loop
, ST_OACC_SERIAL_LOOP
);
715 matcha ("serial", gfc_match_oacc_serial
, ST_OACC_SERIAL
);
718 matcha ("update", gfc_match_oacc_update
, ST_OACC_UPDATE
);
721 matcha ("wait", gfc_match_oacc_wait
, ST_OACC_WAIT
);
725 /* Directive not found or stored an error message.
726 Check and give up. */
729 if (gfc_error_check () == 0)
730 gfc_error_now ("Unclassifiable OpenACC directive at %C");
734 gfc_error_recovery ();
741 gfc_buffer_error (false);
742 gfc_current_locus
= old_locus
;
743 return ST_GET_FCN_CHARACTERISTICS
;
746 /* Like match, but set a flag simd_matched if keyword matched
747 and if spec_only, goto do_spec_only without actually matching. */
748 #define matchs(keyword, subr, st) \
751 if (spec_only && gfc_match (keyword) == MATCH_YES) \
753 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
754 &simd_matched)) == MATCH_YES) \
759 else if (m2 == MATCH_ERROR) \
760 goto error_handling; \
762 undo_new_statement (); \
765 /* Like match, but don't match anything if not -fopenmp
766 and if spec_only, goto do_spec_only without actually matching. */
767 /* If the directive matched but the clauses failed, do not start
768 matching the next directive in the same switch statement. */
769 #define matcho(keyword, subr, st) \
774 else if (spec_only && gfc_match (keyword) == MATCH_YES) \
776 else if ((m2 = match_word (keyword, subr, &old_locus)) \
782 else if (m2 == MATCH_ERROR) \
783 goto error_handling; \
785 undo_new_statement (); \
788 /* Like match, but set a flag simd_matched if keyword matched. */
789 #define matchds(keyword, subr, st) \
792 if ((m2 = match_word_omp_simd (keyword, subr, &old_locus, \
793 &simd_matched)) == MATCH_YES) \
798 else if (m2 == MATCH_ERROR) \
799 goto error_handling; \
801 undo_new_statement (); \
804 /* Like match, but don't match anything if not -fopenmp. */
805 #define matchdo(keyword, subr, st) \
810 else if ((m2 = match_word (keyword, subr, &old_locus)) \
816 else if (m2 == MATCH_ERROR) \
817 goto error_handling; \
819 undo_new_statement (); \
823 decode_omp_directive (void)
827 bool simd_matched
= false;
828 bool spec_only
= false;
829 gfc_statement ret
= ST_NONE
;
832 gfc_enforce_clean_symbol_state ();
834 gfc_clear_error (); /* Clear any pending errors. */
835 gfc_clear_warning (); /* Clear any pending warnings. */
837 gfc_matching_function
= false;
839 if (gfc_current_state () == COMP_FUNCTION
840 && gfc_current_block ()->result
->ts
.kind
== -1)
843 old_locus
= gfc_current_locus
;
845 /* General OpenMP directive matching: Instead of testing every possible
846 statement, we eliminate most possibilities by peeking at the
849 c
= gfc_peek_ascii_char ();
851 /* match is for directives that should be recognized only if
852 -fopenmp, matchs for directives that should be recognized
853 if either -fopenmp or -fopenmp-simd.
854 Handle only the directives allowed in PURE procedures
855 first (those also shall not turn off implicit pure). */
859 matchds ("declare simd", gfc_match_omp_declare_simd
,
860 ST_OMP_DECLARE_SIMD
);
861 matchdo ("declare target", gfc_match_omp_declare_target
,
862 ST_OMP_DECLARE_TARGET
);
865 matchs ("simd", gfc_match_omp_simd
, ST_OMP_SIMD
);
870 if (flag_openmp
&& gfc_pure (NULL
))
872 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
873 "at %C may not appear in PURE procedures");
874 gfc_error_recovery ();
878 /* match is for directives that should be recognized only if
879 -fopenmp, matchs for directives that should be recognized
880 if either -fopenmp or -fopenmp-simd. */
884 matcho ("atomic", gfc_match_omp_atomic
, ST_OMP_ATOMIC
);
887 matcho ("barrier", gfc_match_omp_barrier
, ST_OMP_BARRIER
);
890 matcho ("cancellation% point", gfc_match_omp_cancellation_point
,
891 ST_OMP_CANCELLATION_POINT
);
892 matcho ("cancel", gfc_match_omp_cancel
, ST_OMP_CANCEL
);
893 matcho ("critical", gfc_match_omp_critical
, ST_OMP_CRITICAL
);
896 matchds ("declare reduction", gfc_match_omp_declare_reduction
,
897 ST_OMP_DECLARE_REDUCTION
);
898 matcho ("depobj", gfc_match_omp_depobj
, ST_OMP_DEPOBJ
);
899 matchs ("distribute parallel do simd",
900 gfc_match_omp_distribute_parallel_do_simd
,
901 ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
);
902 matcho ("distribute parallel do", gfc_match_omp_distribute_parallel_do
,
903 ST_OMP_DISTRIBUTE_PARALLEL_DO
);
904 matchs ("distribute simd", gfc_match_omp_distribute_simd
,
905 ST_OMP_DISTRIBUTE_SIMD
);
906 matcho ("distribute", gfc_match_omp_distribute
, ST_OMP_DISTRIBUTE
);
907 matchs ("do simd", gfc_match_omp_do_simd
, ST_OMP_DO_SIMD
);
908 matcho ("do", gfc_match_omp_do
, ST_OMP_DO
);
911 matcho ("error", gfc_match_omp_error
, ST_OMP_ERROR
);
912 matcho ("end atomic", gfc_match_omp_eos_error
, ST_OMP_END_ATOMIC
);
913 matcho ("end critical", gfc_match_omp_end_critical
, ST_OMP_END_CRITICAL
);
914 matchs ("end distribute parallel do simd", gfc_match_omp_eos_error
,
915 ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
);
916 matcho ("end distribute parallel do", gfc_match_omp_eos_error
,
917 ST_OMP_END_DISTRIBUTE_PARALLEL_DO
);
918 matchs ("end distribute simd", gfc_match_omp_eos_error
,
919 ST_OMP_END_DISTRIBUTE_SIMD
);
920 matcho ("end distribute", gfc_match_omp_eos_error
, ST_OMP_END_DISTRIBUTE
);
921 matchs ("end do simd", gfc_match_omp_end_nowait
, ST_OMP_END_DO_SIMD
);
922 matcho ("end do", gfc_match_omp_end_nowait
, ST_OMP_END_DO
);
923 matchs ("end simd", gfc_match_omp_eos_error
, ST_OMP_END_SIMD
);
924 matcho ("end masked taskloop simd", gfc_match_omp_eos_error
,
925 ST_OMP_END_MASKED_TASKLOOP_SIMD
);
926 matcho ("end masked taskloop", gfc_match_omp_eos_error
,
927 ST_OMP_END_MASKED_TASKLOOP
);
928 matcho ("end masked", gfc_match_omp_eos_error
, ST_OMP_END_MASKED
);
929 matcho ("end master taskloop simd", gfc_match_omp_eos_error
,
930 ST_OMP_END_MASTER_TASKLOOP_SIMD
);
931 matcho ("end master taskloop", gfc_match_omp_eos_error
,
932 ST_OMP_END_MASTER_TASKLOOP
);
933 matcho ("end master", gfc_match_omp_eos_error
, ST_OMP_END_MASTER
);
934 matchs ("end ordered", gfc_match_omp_eos_error
, ST_OMP_END_ORDERED
);
935 matchs ("end parallel do simd", gfc_match_omp_eos_error
,
936 ST_OMP_END_PARALLEL_DO_SIMD
);
937 matcho ("end parallel do", gfc_match_omp_eos_error
, ST_OMP_END_PARALLEL_DO
);
938 matcho ("end parallel masked taskloop simd", gfc_match_omp_eos_error
,
939 ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
);
940 matcho ("end parallel masked taskloop", gfc_match_omp_eos_error
,
941 ST_OMP_END_PARALLEL_MASKED_TASKLOOP
);
942 matcho ("end parallel masked", gfc_match_omp_eos_error
,
943 ST_OMP_END_PARALLEL_MASKED
);
944 matcho ("end parallel master taskloop simd", gfc_match_omp_eos_error
,
945 ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
);
946 matcho ("end parallel master taskloop", gfc_match_omp_eos_error
,
947 ST_OMP_END_PARALLEL_MASTER_TASKLOOP
);
948 matcho ("end parallel master", gfc_match_omp_eos_error
,
949 ST_OMP_END_PARALLEL_MASTER
);
950 matcho ("end parallel sections", gfc_match_omp_eos_error
,
951 ST_OMP_END_PARALLEL_SECTIONS
);
952 matcho ("end parallel workshare", gfc_match_omp_eos_error
,
953 ST_OMP_END_PARALLEL_WORKSHARE
);
954 matcho ("end parallel", gfc_match_omp_eos_error
, ST_OMP_END_PARALLEL
);
955 matcho ("end scope", gfc_match_omp_end_nowait
, ST_OMP_END_SCOPE
);
956 matcho ("end sections", gfc_match_omp_end_nowait
, ST_OMP_END_SECTIONS
);
957 matcho ("end single", gfc_match_omp_end_single
, ST_OMP_END_SINGLE
);
958 matcho ("end target data", gfc_match_omp_eos_error
, ST_OMP_END_TARGET_DATA
);
959 matchs ("end target parallel do simd", gfc_match_omp_eos_error
,
960 ST_OMP_END_TARGET_PARALLEL_DO_SIMD
);
961 matcho ("end target parallel do", gfc_match_omp_eos_error
,
962 ST_OMP_END_TARGET_PARALLEL_DO
);
963 matcho ("end target parallel", gfc_match_omp_eos_error
,
964 ST_OMP_END_TARGET_PARALLEL
);
965 matchs ("end target simd", gfc_match_omp_eos_error
, ST_OMP_END_TARGET_SIMD
);
966 matchs ("end target teams distribute parallel do simd",
967 gfc_match_omp_eos_error
,
968 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
969 matcho ("end target teams distribute parallel do", gfc_match_omp_eos_error
,
970 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
971 matchs ("end target teams distribute simd", gfc_match_omp_eos_error
,
972 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
);
973 matcho ("end target teams distribute", gfc_match_omp_eos_error
,
974 ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
);
975 matcho ("end target teams", gfc_match_omp_eos_error
, ST_OMP_END_TARGET_TEAMS
);
976 matcho ("end target", gfc_match_omp_eos_error
, ST_OMP_END_TARGET
);
977 matcho ("end taskgroup", gfc_match_omp_eos_error
, ST_OMP_END_TASKGROUP
);
978 matchs ("end taskloop simd", gfc_match_omp_eos_error
,
979 ST_OMP_END_TASKLOOP_SIMD
);
980 matcho ("end taskloop", gfc_match_omp_eos_error
, ST_OMP_END_TASKLOOP
);
981 matcho ("end task", gfc_match_omp_eos_error
, ST_OMP_END_TASK
);
982 matchs ("end teams distribute parallel do simd", gfc_match_omp_eos_error
,
983 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
984 matcho ("end teams distribute parallel do", gfc_match_omp_eos_error
,
985 ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
);
986 matchs ("end teams distribute simd", gfc_match_omp_eos_error
,
987 ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
);
988 matcho ("end teams distribute", gfc_match_omp_eos_error
,
989 ST_OMP_END_TEAMS_DISTRIBUTE
);
990 matcho ("end teams", gfc_match_omp_eos_error
, ST_OMP_END_TEAMS
);
991 matcho ("end workshare", gfc_match_omp_end_nowait
,
992 ST_OMP_END_WORKSHARE
);
995 matcho ("flush", gfc_match_omp_flush
, ST_OMP_FLUSH
);
998 matcho ("masked taskloop simd", gfc_match_omp_masked_taskloop_simd
,
999 ST_OMP_MASKED_TASKLOOP_SIMD
);
1000 matcho ("masked taskloop", gfc_match_omp_masked_taskloop
,
1001 ST_OMP_MASKED_TASKLOOP
);
1002 matcho ("masked", gfc_match_omp_masked
, ST_OMP_MASKED
);
1003 matcho ("master taskloop simd", gfc_match_omp_master_taskloop_simd
,
1004 ST_OMP_MASTER_TASKLOOP_SIMD
);
1005 matcho ("master taskloop", gfc_match_omp_master_taskloop
,
1006 ST_OMP_MASTER_TASKLOOP
);
1007 matcho ("master", gfc_match_omp_master
, ST_OMP_MASTER
);
1010 matcho ("nothing", gfc_match_omp_nothing
, ST_NONE
);
1013 matcho ("loop", gfc_match_omp_loop
, ST_OMP_LOOP
);
1016 if (gfc_match ("ordered depend (") == MATCH_YES
)
1018 gfc_current_locus
= old_locus
;
1021 matcho ("ordered", gfc_match_omp_ordered_depend
,
1022 ST_OMP_ORDERED_DEPEND
);
1025 matchs ("ordered", gfc_match_omp_ordered
, ST_OMP_ORDERED
);
1028 matchs ("parallel do simd", gfc_match_omp_parallel_do_simd
,
1029 ST_OMP_PARALLEL_DO_SIMD
);
1030 matcho ("parallel do", gfc_match_omp_parallel_do
, ST_OMP_PARALLEL_DO
);
1031 matcho ("parallel loop", gfc_match_omp_parallel_loop
,
1032 ST_OMP_PARALLEL_LOOP
);
1033 matcho ("parallel masked taskloop simd",
1034 gfc_match_omp_parallel_masked_taskloop_simd
,
1035 ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
);
1036 matcho ("parallel masked taskloop",
1037 gfc_match_omp_parallel_masked_taskloop
,
1038 ST_OMP_PARALLEL_MASKED_TASKLOOP
);
1039 matcho ("parallel masked", gfc_match_omp_parallel_masked
,
1040 ST_OMP_PARALLEL_MASKED
);
1041 matcho ("parallel master taskloop simd",
1042 gfc_match_omp_parallel_master_taskloop_simd
,
1043 ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
);
1044 matcho ("parallel master taskloop",
1045 gfc_match_omp_parallel_master_taskloop
,
1046 ST_OMP_PARALLEL_MASTER_TASKLOOP
);
1047 matcho ("parallel master", gfc_match_omp_parallel_master
,
1048 ST_OMP_PARALLEL_MASTER
);
1049 matcho ("parallel sections", gfc_match_omp_parallel_sections
,
1050 ST_OMP_PARALLEL_SECTIONS
);
1051 matcho ("parallel workshare", gfc_match_omp_parallel_workshare
,
1052 ST_OMP_PARALLEL_WORKSHARE
);
1053 matcho ("parallel", gfc_match_omp_parallel
, ST_OMP_PARALLEL
);
1056 matcho ("requires", gfc_match_omp_requires
, ST_OMP_REQUIRES
);
1059 matcho ("scan", gfc_match_omp_scan
, ST_OMP_SCAN
);
1060 matcho ("scope", gfc_match_omp_scope
, ST_OMP_SCOPE
);
1061 matcho ("sections", gfc_match_omp_sections
, ST_OMP_SECTIONS
);
1062 matcho ("section", gfc_match_omp_eos_error
, ST_OMP_SECTION
);
1063 matcho ("single", gfc_match_omp_single
, ST_OMP_SINGLE
);
1066 matcho ("target data", gfc_match_omp_target_data
, ST_OMP_TARGET_DATA
);
1067 matcho ("target enter data", gfc_match_omp_target_enter_data
,
1068 ST_OMP_TARGET_ENTER_DATA
);
1069 matcho ("target exit data", gfc_match_omp_target_exit_data
,
1070 ST_OMP_TARGET_EXIT_DATA
);
1071 matchs ("target parallel do simd", gfc_match_omp_target_parallel_do_simd
,
1072 ST_OMP_TARGET_PARALLEL_DO_SIMD
);
1073 matcho ("target parallel do", gfc_match_omp_target_parallel_do
,
1074 ST_OMP_TARGET_PARALLEL_DO
);
1075 matcho ("target parallel loop", gfc_match_omp_target_parallel_loop
,
1076 ST_OMP_TARGET_PARALLEL_LOOP
);
1077 matcho ("target parallel", gfc_match_omp_target_parallel
,
1078 ST_OMP_TARGET_PARALLEL
);
1079 matchs ("target simd", gfc_match_omp_target_simd
, ST_OMP_TARGET_SIMD
);
1080 matchs ("target teams distribute parallel do simd",
1081 gfc_match_omp_target_teams_distribute_parallel_do_simd
,
1082 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1083 matcho ("target teams distribute parallel do",
1084 gfc_match_omp_target_teams_distribute_parallel_do
,
1085 ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1086 matchs ("target teams distribute simd",
1087 gfc_match_omp_target_teams_distribute_simd
,
1088 ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
);
1089 matcho ("target teams distribute", gfc_match_omp_target_teams_distribute
,
1090 ST_OMP_TARGET_TEAMS_DISTRIBUTE
);
1091 matcho ("target teams loop", gfc_match_omp_target_teams_loop
,
1092 ST_OMP_TARGET_TEAMS_LOOP
);
1093 matcho ("target teams", gfc_match_omp_target_teams
, ST_OMP_TARGET_TEAMS
);
1094 matcho ("target update", gfc_match_omp_target_update
,
1095 ST_OMP_TARGET_UPDATE
);
1096 matcho ("target", gfc_match_omp_target
, ST_OMP_TARGET
);
1097 matcho ("taskgroup", gfc_match_omp_taskgroup
, ST_OMP_TASKGROUP
);
1098 matchs ("taskloop simd", gfc_match_omp_taskloop_simd
,
1099 ST_OMP_TASKLOOP_SIMD
);
1100 matcho ("taskloop", gfc_match_omp_taskloop
, ST_OMP_TASKLOOP
);
1101 matcho ("taskwait", gfc_match_omp_taskwait
, ST_OMP_TASKWAIT
);
1102 matcho ("taskyield", gfc_match_omp_taskyield
, ST_OMP_TASKYIELD
);
1103 matcho ("task", gfc_match_omp_task
, ST_OMP_TASK
);
1104 matchs ("teams distribute parallel do simd",
1105 gfc_match_omp_teams_distribute_parallel_do_simd
,
1106 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
);
1107 matcho ("teams distribute parallel do",
1108 gfc_match_omp_teams_distribute_parallel_do
,
1109 ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
);
1110 matchs ("teams distribute simd", gfc_match_omp_teams_distribute_simd
,
1111 ST_OMP_TEAMS_DISTRIBUTE_SIMD
);
1112 matcho ("teams distribute", gfc_match_omp_teams_distribute
,
1113 ST_OMP_TEAMS_DISTRIBUTE
);
1114 matcho ("teams loop", gfc_match_omp_teams_loop
, ST_OMP_TEAMS_LOOP
);
1115 matcho ("teams", gfc_match_omp_teams
, ST_OMP_TEAMS
);
1116 matchdo ("threadprivate", gfc_match_omp_threadprivate
,
1117 ST_OMP_THREADPRIVATE
);
1120 matcho ("workshare", gfc_match_omp_workshare
, ST_OMP_WORKSHARE
);
1124 /* All else has failed, so give up. See if any of the matchers has
1125 stored an error message of some sort. Don't error out if
1126 not -fopenmp and simd_matched is false, i.e. if a directive other
1127 than one marked with match has been seen. */
1130 if (flag_openmp
|| simd_matched
)
1132 if (!gfc_error_check ())
1133 gfc_error_now ("Unclassifiable OpenMP directive at %C");
1136 reject_statement ();
1138 gfc_error_recovery ();
1145 gfc_unset_implicit_pure (NULL
);
1147 if (!flag_openmp
&& gfc_pure (NULL
))
1149 gfc_error_now ("OpenMP directives other than SIMD or DECLARE TARGET "
1150 "at %C may not appear in PURE procedures");
1151 reject_statement ();
1152 gfc_error_recovery ();
1158 case ST_OMP_DECLARE_TARGET
:
1160 case ST_OMP_TARGET_DATA
:
1161 case ST_OMP_TARGET_ENTER_DATA
:
1162 case ST_OMP_TARGET_EXIT_DATA
:
1163 case ST_OMP_TARGET_TEAMS
:
1164 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
1165 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
1166 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
1167 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
1168 case ST_OMP_TARGET_TEAMS_LOOP
:
1169 case ST_OMP_TARGET_PARALLEL
:
1170 case ST_OMP_TARGET_PARALLEL_DO
:
1171 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
1172 case ST_OMP_TARGET_PARALLEL_LOOP
:
1173 case ST_OMP_TARGET_SIMD
:
1174 case ST_OMP_TARGET_UPDATE
:
1176 gfc_namespace
*prog_unit
= gfc_current_ns
;
1177 while (prog_unit
->parent
)
1179 if (gfc_state_stack
->previous
1180 && gfc_state_stack
->previous
->state
== COMP_INTERFACE
)
1182 prog_unit
= prog_unit
->parent
;
1184 prog_unit
->omp_target_seen
= true;
1188 if (new_st
.ext
.omp_clauses
->at
!= OMP_AT_EXECUTION
)
1196 reject_statement ();
1198 gfc_buffer_error (false);
1199 gfc_current_locus
= old_locus
;
1200 return ST_GET_FCN_CHARACTERISTICS
;
1203 static gfc_statement
1204 decode_gcc_attribute (void)
1208 gfc_enforce_clean_symbol_state ();
1210 gfc_clear_error (); /* Clear any pending errors. */
1211 gfc_clear_warning (); /* Clear any pending warnings. */
1212 old_locus
= gfc_current_locus
;
1214 match ("attributes", gfc_match_gcc_attributes
, ST_ATTR_DECL
);
1215 match ("unroll", gfc_match_gcc_unroll
, ST_NONE
);
1216 match ("builtin", gfc_match_gcc_builtin
, ST_NONE
);
1217 match ("ivdep", gfc_match_gcc_ivdep
, ST_NONE
);
1218 match ("vector", gfc_match_gcc_vector
, ST_NONE
);
1219 match ("novector", gfc_match_gcc_novector
, ST_NONE
);
1221 /* All else has failed, so give up. See if any of the matchers has
1222 stored an error message of some sort. */
1224 if (!gfc_error_check ())
1227 gfc_error_now ("Unclassifiable GCC directive at %C");
1229 gfc_warning_now (0, "Unclassifiable GCC directive at %C, ignored");
1232 reject_statement ();
1234 gfc_error_recovery ();
1241 /* Assert next length characters to be equal to token in free form. */
1244 verify_token_free (const char* token
, int length
, bool last_was_use_stmt
)
1249 c
= gfc_next_ascii_char ();
1250 for (i
= 0; i
< length
; i
++, c
= gfc_next_ascii_char ())
1251 gcc_assert (c
== token
[i
]);
1253 gcc_assert (gfc_is_whitespace(c
));
1254 gfc_gobble_whitespace ();
1255 if (last_was_use_stmt
)
1259 /* Get the next statement in free form source. */
1261 static gfc_statement
1268 at_bol
= gfc_at_bol ();
1269 gfc_gobble_whitespace ();
1271 c
= gfc_peek_ascii_char ();
1277 /* Found a statement label? */
1278 m
= gfc_match_st_label (&gfc_statement_label
);
1280 d
= gfc_peek_ascii_char ();
1281 if (m
!= MATCH_YES
|| !gfc_is_whitespace (d
))
1283 gfc_match_small_literal_int (&i
, &cnt
);
1286 gfc_error_now ("Too many digits in statement label at %C");
1289 gfc_error_now ("Zero is not a valid statement label at %C");
1292 c
= gfc_next_ascii_char ();
1295 if (!gfc_is_whitespace (c
))
1296 gfc_error_now ("Non-numeric character in statement label at %C");
1302 label_locus
= gfc_current_locus
;
1304 gfc_gobble_whitespace ();
1306 if (at_bol
&& gfc_peek_ascii_char () == ';')
1308 gfc_error_now ("Semicolon at %C needs to be preceded by "
1310 gfc_next_ascii_char (); /* Eat up the semicolon. */
1314 if (gfc_match_eos () == MATCH_YES
)
1315 gfc_error_now ("Statement label without statement at %L",
1321 /* Comments have already been skipped by the time we get here,
1322 except for GCC attributes and OpenMP/OpenACC directives. */
1324 gfc_next_ascii_char (); /* Eat up the exclamation sign. */
1325 c
= gfc_peek_ascii_char ();
1331 c
= gfc_next_ascii_char ();
1332 for (i
= 0; i
< 4; i
++, c
= gfc_next_ascii_char ())
1333 gcc_assert (c
== "gcc$"[i
]);
1335 gfc_gobble_whitespace ();
1336 return decode_gcc_attribute ();
1341 /* Since both OpenMP and OpenACC directives starts with
1342 !$ character sequence, we must check all flags combinations */
1343 if ((flag_openmp
|| flag_openmp_simd
)
1346 verify_token_free ("$omp", 4, last_was_use_stmt
);
1347 return decode_omp_directive ();
1349 else if ((flag_openmp
|| flag_openmp_simd
)
1352 gfc_next_ascii_char (); /* Eat up dollar character */
1353 c
= gfc_peek_ascii_char ();
1357 verify_token_free ("omp", 3, last_was_use_stmt
);
1358 return decode_omp_directive ();
1362 verify_token_free ("acc", 3, last_was_use_stmt
);
1363 return decode_oacc_directive ();
1366 else if (flag_openacc
)
1368 verify_token_free ("$acc", 4, last_was_use_stmt
);
1369 return decode_oacc_directive ();
1375 if (at_bol
&& c
== ';')
1377 if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1378 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1380 gfc_next_ascii_char (); /* Eat up the semicolon. */
1384 return decode_statement ();
1387 /* Assert next length characters to be equal to token in fixed form. */
1390 verify_token_fixed (const char *token
, int length
, bool last_was_use_stmt
)
1393 char c
= gfc_next_char_literal (NONSTRING
);
1395 for (i
= 0; i
< length
; i
++, c
= gfc_next_char_literal (NONSTRING
))
1396 gcc_assert ((char) gfc_wide_tolower (c
) == token
[i
]);
1398 if (c
!= ' ' && c
!= '0')
1400 gfc_buffer_error (false);
1401 gfc_error ("Bad continuation line at %C");
1404 if (last_was_use_stmt
)
1410 /* Get the next statement in fixed-form source. */
1412 static gfc_statement
1415 int label
, digit_flag
, i
;
1420 return decode_statement ();
1422 /* Skip past the current label field, parsing a statement label if
1423 one is there. This is a weird number parser, since the number is
1424 contained within five columns and can have any kind of embedded
1425 spaces. We also check for characters that make the rest of the
1431 for (i
= 0; i
< 5; i
++)
1433 c
= gfc_next_char_literal (NONSTRING
);
1450 label
= label
* 10 + ((unsigned char) c
- '0');
1451 label_locus
= gfc_current_locus
;
1455 /* Comments have already been skipped by the time we get
1456 here, except for GCC attributes and OpenMP directives. */
1459 c
= gfc_next_char_literal (NONSTRING
);
1461 if (TOLOWER (c
) == 'g')
1463 for (i
= 0; i
< 4; i
++, c
= gfc_next_char_literal (NONSTRING
))
1464 gcc_assert (TOLOWER (c
) == "gcc$"[i
]);
1466 return decode_gcc_attribute ();
1470 if ((flag_openmp
|| flag_openmp_simd
)
1473 if (!verify_token_fixed ("omp", 3, last_was_use_stmt
))
1475 return decode_omp_directive ();
1477 else if ((flag_openmp
|| flag_openmp_simd
)
1480 c
= gfc_next_char_literal(NONSTRING
);
1481 if (c
== 'o' || c
== 'O')
1483 if (!verify_token_fixed ("mp", 2, last_was_use_stmt
))
1485 return decode_omp_directive ();
1487 else if (c
== 'a' || c
== 'A')
1489 if (!verify_token_fixed ("cc", 2, last_was_use_stmt
))
1491 return decode_oacc_directive ();
1494 else if (flag_openacc
)
1496 if (!verify_token_fixed ("acc", 3, last_was_use_stmt
))
1498 return decode_oacc_directive ();
1503 /* Comments have already been skipped by the time we get
1504 here so don't bother checking for them. */
1507 gfc_buffer_error (false);
1508 gfc_error ("Non-numeric character in statement label at %C");
1516 gfc_warning_now (0, "Zero is not a valid statement label at %C");
1519 /* We've found a valid statement label. */
1520 gfc_statement_label
= gfc_get_st_label (label
);
1524 /* Since this line starts a statement, it cannot be a continuation
1525 of a previous statement. If we see something here besides a
1526 space or zero, it must be a bad continuation line. */
1528 c
= gfc_next_char_literal (NONSTRING
);
1532 if (c
!= ' ' && c
!= '0')
1534 gfc_buffer_error (false);
1535 gfc_error ("Bad continuation line at %C");
1539 /* Now that we've taken care of the statement label columns, we have
1540 to make sure that the first nonblank character is not a '!'. If
1541 it is, the rest of the line is a comment. */
1545 loc
= gfc_current_locus
;
1546 c
= gfc_next_char_literal (NONSTRING
);
1548 while (gfc_is_whitespace (c
));
1552 gfc_current_locus
= loc
;
1557 gfc_error_now ("Semicolon at %C needs to be preceded by statement");
1558 else if (!(gfc_option
.allow_std
& GFC_STD_F2008
))
1559 gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
1564 if (gfc_match_eos () == MATCH_YES
)
1567 /* At this point, we've got a nonblank statement to parse. */
1568 return decode_statement ();
1572 gfc_error_now ("Statement label without statement at %L", &label_locus
);
1574 gfc_current_locus
.lb
->truncated
= 0;
1575 gfc_advance_line ();
1580 /* Return the next non-ST_NONE statement to the caller. We also worry
1581 about including files and the ends of include files at this stage. */
1583 static gfc_statement
1584 next_statement (void)
1589 gfc_enforce_clean_symbol_state ();
1591 gfc_new_block
= NULL
;
1593 gfc_current_ns
->old_equiv
= gfc_current_ns
->equiv
;
1594 gfc_current_ns
->old_data
= gfc_current_ns
->data
;
1597 gfc_statement_label
= NULL
;
1598 gfc_buffer_error (true);
1601 gfc_advance_line ();
1603 gfc_skip_comments ();
1611 if (gfc_define_undef_line ())
1614 old_locus
= gfc_current_locus
;
1616 st
= (gfc_current_form
== FORM_FIXED
) ? next_fixed () : next_free ();
1622 gfc_buffer_error (false);
1624 if (st
== ST_GET_FCN_CHARACTERISTICS
)
1626 if (gfc_statement_label
!= NULL
)
1628 gfc_free_st_label (gfc_statement_label
);
1629 gfc_statement_label
= NULL
;
1631 gfc_current_locus
= old_locus
;
1635 check_statement_label (st
);
1641 /****************************** Parser ***********************************/
1643 /* The parser subroutines are of type 'try' that fail if the file ends
1646 /* Macros that expand to case-labels for various classes of
1647 statements. Start with executable statements that directly do
1650 #define case_executable case ST_ALLOCATE: case ST_BACKSPACE: case ST_CALL: \
1651 case ST_CLOSE: case ST_CONTINUE: case ST_DEALLOCATE: case ST_END_FILE: \
1652 case ST_GOTO: case ST_INQUIRE: case ST_NULLIFY: case ST_OPEN: \
1653 case ST_READ: case ST_RETURN: case ST_REWIND: case ST_SIMPLE_IF: \
1654 case ST_PAUSE: case ST_STOP: case ST_WAIT: case ST_WRITE: \
1655 case ST_POINTER_ASSIGNMENT: case ST_EXIT: case ST_CYCLE: \
1656 case ST_ASSIGNMENT: case ST_ARITHMETIC_IF: case ST_WHERE: case ST_FORALL: \
1657 case ST_LABEL_ASSIGNMENT: case ST_FLUSH: case ST_OMP_FLUSH: \
1658 case ST_OMP_BARRIER: case ST_OMP_TASKWAIT: case ST_OMP_TASKYIELD: \
1659 case ST_OMP_CANCEL: case ST_OMP_CANCELLATION_POINT: case ST_OMP_DEPOBJ: \
1660 case ST_OMP_TARGET_UPDATE: case ST_OMP_TARGET_ENTER_DATA: \
1661 case ST_OMP_TARGET_EXIT_DATA: case ST_OMP_ORDERED_DEPEND: case ST_OMP_ERROR: \
1662 case ST_ERROR_STOP: case ST_OMP_SCAN: case ST_SYNC_ALL: \
1663 case ST_SYNC_IMAGES: case ST_SYNC_MEMORY: case ST_LOCK: case ST_UNLOCK: \
1664 case ST_FORM_TEAM: case ST_CHANGE_TEAM: \
1665 case ST_END_TEAM: case ST_SYNC_TEAM: \
1666 case ST_EVENT_POST: case ST_EVENT_WAIT: case ST_FAIL_IMAGE: \
1667 case ST_OACC_UPDATE: case ST_OACC_WAIT: case ST_OACC_CACHE: \
1668 case ST_OACC_ENTER_DATA: case ST_OACC_EXIT_DATA
1670 /* Statements that mark other executable statements. */
1672 #define case_exec_markers case ST_DO: case ST_FORALL_BLOCK: \
1673 case ST_IF_BLOCK: case ST_BLOCK: case ST_ASSOCIATE: \
1674 case ST_WHERE_BLOCK: case ST_SELECT_CASE: case ST_SELECT_TYPE: \
1675 case ST_SELECT_RANK: case ST_OMP_PARALLEL: case ST_OMP_PARALLEL_MASKED: \
1676 case ST_OMP_PARALLEL_MASKED_TASKLOOP: \
1677 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD: case ST_OMP_PARALLEL_MASTER: \
1678 case ST_OMP_PARALLEL_MASTER_TASKLOOP: \
1679 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD: \
1680 case ST_OMP_PARALLEL_SECTIONS: case ST_OMP_SECTIONS: case ST_OMP_ORDERED: \
1681 case ST_OMP_CRITICAL: case ST_OMP_MASKED: case ST_OMP_MASKED_TASKLOOP: \
1682 case ST_OMP_MASKED_TASKLOOP_SIMD: \
1683 case ST_OMP_MASTER: case ST_OMP_MASTER_TASKLOOP: \
1684 case ST_OMP_MASTER_TASKLOOP_SIMD: case ST_OMP_SCOPE: case ST_OMP_SINGLE: \
1685 case ST_OMP_DO: case ST_OMP_PARALLEL_DO: case ST_OMP_ATOMIC: \
1686 case ST_OMP_WORKSHARE: case ST_OMP_PARALLEL_WORKSHARE: \
1687 case ST_OMP_TASK: case ST_OMP_TASKGROUP: case ST_OMP_SIMD: \
1688 case ST_OMP_DO_SIMD: case ST_OMP_PARALLEL_DO_SIMD: case ST_OMP_TARGET: \
1689 case ST_OMP_TARGET_DATA: case ST_OMP_TARGET_TEAMS: \
1690 case ST_OMP_TARGET_TEAMS_DISTRIBUTE: \
1691 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: \
1692 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1693 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: \
1694 case ST_OMP_TEAMS: case ST_OMP_TEAMS_DISTRIBUTE: \
1695 case ST_OMP_TEAMS_DISTRIBUTE_SIMD: \
1696 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO: \
1697 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_DISTRIBUTE: \
1698 case ST_OMP_DISTRIBUTE_SIMD: case ST_OMP_DISTRIBUTE_PARALLEL_DO: \
1699 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case ST_OMP_TARGET_PARALLEL: \
1700 case ST_OMP_TARGET_PARALLEL_DO: case ST_OMP_TARGET_PARALLEL_DO_SIMD: \
1701 case ST_OMP_TARGET_SIMD: case ST_OMP_TASKLOOP: case ST_OMP_TASKLOOP_SIMD: \
1702 case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
1703 case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
1705 case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
1706 case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
1707 case ST_OACC_KERNELS_LOOP: case ST_OACC_SERIAL_LOOP: case ST_OACC_SERIAL: \
1710 /* Declaration statements */
1712 #define case_decl case ST_ATTR_DECL: case ST_COMMON: case ST_DATA_DECL: \
1713 case ST_EQUIVALENCE: case ST_NAMELIST: case ST_STATEMENT_FUNCTION: \
1714 case ST_TYPE: case ST_INTERFACE: case ST_PROCEDURE
1716 /* OpenMP and OpenACC declaration statements, which may appear anywhere in
1717 the specification part. */
1719 #define case_omp_decl case ST_OMP_THREADPRIVATE: case ST_OMP_DECLARE_SIMD: \
1720 case ST_OMP_DECLARE_TARGET: case ST_OMP_DECLARE_REDUCTION: \
1721 case ST_OMP_REQUIRES: case ST_OACC_ROUTINE: case ST_OACC_DECLARE
1723 /* Block end statements. Errors associated with interchanging these
1724 are detected in gfc_match_end(). */
1726 #define case_end case ST_END_BLOCK_DATA: case ST_END_FUNCTION: \
1727 case ST_END_PROGRAM: case ST_END_SUBROUTINE: \
1728 case ST_END_BLOCK: case ST_END_ASSOCIATE
1731 /* Push a new state onto the stack. */
1734 push_state (gfc_state_data
*p
, gfc_compile_state new_state
, gfc_symbol
*sym
)
1736 p
->state
= new_state
;
1737 p
->previous
= gfc_state_stack
;
1739 p
->head
= p
->tail
= NULL
;
1740 p
->do_variable
= NULL
;
1741 if (p
->state
!= COMP_DO
&& p
->state
!= COMP_DO_CONCURRENT
)
1742 p
->ext
.oacc_declare_clauses
= NULL
;
1744 /* If this the state of a construct like BLOCK, DO or IF, the corresponding
1745 construct statement was accepted right before pushing the state. Thus,
1746 the construct's gfc_code is available as tail of the parent state. */
1747 gcc_assert (gfc_state_stack
);
1748 p
->construct
= gfc_state_stack
->tail
;
1750 gfc_state_stack
= p
;
1754 /* Pop the current state. */
1758 gfc_state_stack
= gfc_state_stack
->previous
;
1762 /* Try to find the given state in the state stack. */
1765 gfc_find_state (gfc_compile_state state
)
1769 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1770 if (p
->state
== state
)
1773 return (p
== NULL
) ? false : true;
1777 /* Starts a new level in the statement list. */
1780 new_level (gfc_code
*q
)
1784 p
= q
->block
= gfc_get_code (EXEC_NOP
);
1786 gfc_state_stack
->head
= gfc_state_stack
->tail
= p
;
1792 /* Add the current new_st code structure and adds it to the current
1793 program unit. As a side-effect, it zeroes the new_st. */
1796 add_statement (void)
1800 p
= XCNEW (gfc_code
);
1803 p
->loc
= gfc_current_locus
;
1805 if (gfc_state_stack
->head
== NULL
)
1806 gfc_state_stack
->head
= p
;
1808 gfc_state_stack
->tail
->next
= p
;
1810 while (p
->next
!= NULL
)
1813 gfc_state_stack
->tail
= p
;
1815 gfc_clear_new_st ();
1821 /* Frees everything associated with the current statement. */
1824 undo_new_statement (void)
1826 gfc_free_statements (new_st
.block
);
1827 gfc_free_statements (new_st
.next
);
1828 gfc_free_statement (&new_st
);
1829 gfc_clear_new_st ();
1833 /* If the current statement has a statement label, make sure that it
1834 is allowed to, or should have one. */
1837 check_statement_label (gfc_statement st
)
1841 if (gfc_statement_label
== NULL
)
1843 if (st
== ST_FORMAT
)
1844 gfc_error ("FORMAT statement at %L does not have a statement label",
1851 case ST_END_PROGRAM
:
1852 case ST_END_FUNCTION
:
1853 case ST_END_SUBROUTINE
:
1857 case ST_END_CRITICAL
:
1859 case ST_END_ASSOCIATE
:
1862 if (st
== ST_ENDDO
|| st
== ST_CONTINUE
)
1863 type
= ST_LABEL_DO_TARGET
;
1865 type
= ST_LABEL_TARGET
;
1869 type
= ST_LABEL_FORMAT
;
1872 /* Statement labels are not restricted from appearing on a
1873 particular line. However, there are plenty of situations
1874 where the resulting label can't be referenced. */
1877 type
= ST_LABEL_BAD_TARGET
;
1881 gfc_define_st_label (gfc_statement_label
, type
, &label_locus
);
1883 new_st
.here
= gfc_statement_label
;
1887 /* Figures out what the enclosing program unit is. This will be a
1888 function, subroutine, program, block data or module. */
1891 gfc_enclosing_unit (gfc_compile_state
* result
)
1895 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
1896 if (p
->state
== COMP_FUNCTION
|| p
->state
== COMP_SUBROUTINE
1897 || p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
1898 || p
->state
== COMP_BLOCK_DATA
|| p
->state
== COMP_PROGRAM
)
1907 *result
= COMP_PROGRAM
;
1912 /* Translate a statement enum to a string. */
1915 gfc_ascii_statement (gfc_statement st
)
1921 case ST_ARITHMETIC_IF
:
1922 p
= _("arithmetic IF");
1931 p
= _("attribute declaration");
1967 p
= _("data declaration");
1981 case ST_STRUCTURE_DECL
:
1984 case ST_DERIVED_DECL
:
1985 p
= _("derived type declaration");
2008 case ST_CHANGE_TEAM
:
2020 case ST_END_ASSOCIATE
:
2021 p
= "END ASSOCIATE";
2026 case ST_END_BLOCK_DATA
:
2027 p
= "END BLOCK DATA";
2029 case ST_END_CRITICAL
:
2041 case ST_END_FUNCTION
:
2047 case ST_END_INTERFACE
:
2048 p
= "END INTERFACE";
2053 case ST_END_SUBMODULE
:
2054 p
= "END SUBMODULE";
2056 case ST_END_PROGRAM
:
2062 case ST_END_SUBROUTINE
:
2063 p
= "END SUBROUTINE";
2068 case ST_END_STRUCTURE
:
2069 p
= "END STRUCTURE";
2083 case ST_EQUIVALENCE
:
2095 case ST_FORALL_BLOCK
: /* Fall through */
2117 case ST_IMPLICIT_NONE
:
2118 p
= "IMPLICIT NONE";
2120 case ST_IMPLIED_ENDDO
:
2121 p
= _("implied END DO");
2153 case ST_MODULE_PROC
:
2154 p
= "MODULE PROCEDURE";
2186 case ST_SYNC_IMAGES
:
2189 case ST_SYNC_MEMORY
:
2204 case ST_WHERE_BLOCK
: /* Fall through */
2215 p
= _("assignment");
2217 case ST_POINTER_ASSIGNMENT
:
2218 p
= _("pointer assignment");
2220 case ST_SELECT_CASE
:
2223 case ST_SELECT_TYPE
:
2226 case ST_SELECT_RANK
:
2244 case ST_STATEMENT_FUNCTION
:
2245 p
= "STATEMENT FUNCTION";
2247 case ST_LABEL_ASSIGNMENT
:
2248 p
= "LABEL ASSIGNMENT";
2251 p
= "ENUM DEFINITION";
2254 p
= "ENUMERATOR DEFINITION";
2259 case ST_OACC_PARALLEL_LOOP
:
2260 p
= "!$ACC PARALLEL LOOP";
2262 case ST_OACC_END_PARALLEL_LOOP
:
2263 p
= "!$ACC END PARALLEL LOOP";
2265 case ST_OACC_PARALLEL
:
2266 p
= "!$ACC PARALLEL";
2268 case ST_OACC_END_PARALLEL
:
2269 p
= "!$ACC END PARALLEL";
2271 case ST_OACC_KERNELS
:
2272 p
= "!$ACC KERNELS";
2274 case ST_OACC_END_KERNELS
:
2275 p
= "!$ACC END KERNELS";
2277 case ST_OACC_KERNELS_LOOP
:
2278 p
= "!$ACC KERNELS LOOP";
2280 case ST_OACC_END_KERNELS_LOOP
:
2281 p
= "!$ACC END KERNELS LOOP";
2283 case ST_OACC_SERIAL_LOOP
:
2284 p
= "!$ACC SERIAL LOOP";
2286 case ST_OACC_END_SERIAL_LOOP
:
2287 p
= "!$ACC END SERIAL LOOP";
2289 case ST_OACC_SERIAL
:
2292 case ST_OACC_END_SERIAL
:
2293 p
= "!$ACC END SERIAL";
2298 case ST_OACC_END_DATA
:
2299 p
= "!$ACC END DATA";
2301 case ST_OACC_HOST_DATA
:
2302 p
= "!$ACC HOST_DATA";
2304 case ST_OACC_END_HOST_DATA
:
2305 p
= "!$ACC END HOST_DATA";
2310 case ST_OACC_END_LOOP
:
2311 p
= "!$ACC END LOOP";
2313 case ST_OACC_DECLARE
:
2314 p
= "!$ACC DECLARE";
2316 case ST_OACC_UPDATE
:
2325 case ST_OACC_ENTER_DATA
:
2326 p
= "!$ACC ENTER DATA";
2328 case ST_OACC_EXIT_DATA
:
2329 p
= "!$ACC EXIT DATA";
2331 case ST_OACC_ROUTINE
:
2332 p
= "!$ACC ROUTINE";
2334 case ST_OACC_ATOMIC
:
2337 case ST_OACC_END_ATOMIC
:
2338 p
= "!$ACC END ATOMIC";
2343 case ST_OMP_BARRIER
:
2344 p
= "!$OMP BARRIER";
2349 case ST_OMP_CANCELLATION_POINT
:
2350 p
= "!$OMP CANCELLATION POINT";
2352 case ST_OMP_CRITICAL
:
2353 p
= "!$OMP CRITICAL";
2355 case ST_OMP_DECLARE_REDUCTION
:
2356 p
= "!$OMP DECLARE REDUCTION";
2358 case ST_OMP_DECLARE_SIMD
:
2359 p
= "!$OMP DECLARE SIMD";
2361 case ST_OMP_DECLARE_TARGET
:
2362 p
= "!$OMP DECLARE TARGET";
2367 case ST_OMP_DISTRIBUTE
:
2368 p
= "!$OMP DISTRIBUTE";
2370 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
2371 p
= "!$OMP DISTRIBUTE PARALLEL DO";
2373 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
2374 p
= "!$OMP DISTRIBUTE PARALLEL DO SIMD";
2376 case ST_OMP_DISTRIBUTE_SIMD
:
2377 p
= "!$OMP DISTRIBUTE SIMD";
2382 case ST_OMP_DO_SIMD
:
2383 p
= "!$OMP DO SIMD";
2385 case ST_OMP_END_ATOMIC
:
2386 p
= "!$OMP END ATOMIC";
2388 case ST_OMP_END_CRITICAL
:
2389 p
= "!$OMP END CRITICAL";
2391 case ST_OMP_END_DISTRIBUTE
:
2392 p
= "!$OMP END DISTRIBUTE";
2394 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO
:
2395 p
= "!$OMP END DISTRIBUTE PARALLEL DO";
2397 case ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
:
2398 p
= "!$OMP END DISTRIBUTE PARALLEL DO SIMD";
2400 case ST_OMP_END_DISTRIBUTE_SIMD
:
2401 p
= "!$OMP END DISTRIBUTE SIMD";
2406 case ST_OMP_END_DO_SIMD
:
2407 p
= "!$OMP END DO SIMD";
2409 case ST_OMP_END_SCOPE
:
2410 p
= "!$OMP END SCOPE";
2412 case ST_OMP_END_SIMD
:
2413 p
= "!$OMP END SIMD";
2415 case ST_OMP_END_LOOP
:
2416 p
= "!$OMP END LOOP";
2418 case ST_OMP_END_MASKED
:
2419 p
= "!$OMP END MASKED";
2421 case ST_OMP_END_MASKED_TASKLOOP
:
2422 p
= "!$OMP END MASKED TASKLOOP";
2424 case ST_OMP_END_MASKED_TASKLOOP_SIMD
:
2425 p
= "!$OMP END MASKED TASKLOOP SIMD";
2427 case ST_OMP_END_MASTER
:
2428 p
= "!$OMP END MASTER";
2430 case ST_OMP_END_MASTER_TASKLOOP
:
2431 p
= "!$OMP END MASTER TASKLOOP";
2433 case ST_OMP_END_MASTER_TASKLOOP_SIMD
:
2434 p
= "!$OMP END MASTER TASKLOOP SIMD";
2436 case ST_OMP_END_ORDERED
:
2437 p
= "!$OMP END ORDERED";
2439 case ST_OMP_END_PARALLEL
:
2440 p
= "!$OMP END PARALLEL";
2442 case ST_OMP_END_PARALLEL_DO
:
2443 p
= "!$OMP END PARALLEL DO";
2445 case ST_OMP_END_PARALLEL_DO_SIMD
:
2446 p
= "!$OMP END PARALLEL DO SIMD";
2448 case ST_OMP_END_PARALLEL_LOOP
:
2449 p
= "!$OMP END PARALLEL LOOP";
2451 case ST_OMP_END_PARALLEL_MASKED
:
2452 p
= "!$OMP END PARALLEL MASKED";
2454 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP
:
2455 p
= "!$OMP END PARALLEL MASKED TASKLOOP";
2457 case ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
:
2458 p
= "!$OMP END PARALLEL MASKED TASKLOOP SIMD";
2460 case ST_OMP_END_PARALLEL_MASTER
:
2461 p
= "!$OMP END PARALLEL MASTER";
2463 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP
:
2464 p
= "!$OMP END PARALLEL MASTER TASKLOOP";
2466 case ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
:
2467 p
= "!$OMP END PARALLEL MASTER TASKLOOP SIMD";
2469 case ST_OMP_END_PARALLEL_SECTIONS
:
2470 p
= "!$OMP END PARALLEL SECTIONS";
2472 case ST_OMP_END_PARALLEL_WORKSHARE
:
2473 p
= "!$OMP END PARALLEL WORKSHARE";
2475 case ST_OMP_END_SECTIONS
:
2476 p
= "!$OMP END SECTIONS";
2478 case ST_OMP_END_SINGLE
:
2479 p
= "!$OMP END SINGLE";
2481 case ST_OMP_END_TASK
:
2482 p
= "!$OMP END TASK";
2484 case ST_OMP_END_TARGET
:
2485 p
= "!$OMP END TARGET";
2487 case ST_OMP_END_TARGET_DATA
:
2488 p
= "!$OMP END TARGET DATA";
2490 case ST_OMP_END_TARGET_PARALLEL
:
2491 p
= "!$OMP END TARGET PARALLEL";
2493 case ST_OMP_END_TARGET_PARALLEL_DO
:
2494 p
= "!$OMP END TARGET PARALLEL DO";
2496 case ST_OMP_END_TARGET_PARALLEL_DO_SIMD
:
2497 p
= "!$OMP END TARGET PARALLEL DO SIMD";
2499 case ST_OMP_END_TARGET_PARALLEL_LOOP
:
2500 p
= "!$OMP END TARGET PARALLEL LOOP";
2502 case ST_OMP_END_TARGET_SIMD
:
2503 p
= "!$OMP END TARGET SIMD";
2505 case ST_OMP_END_TARGET_TEAMS
:
2506 p
= "!$OMP END TARGET TEAMS";
2508 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
:
2509 p
= "!$OMP END TARGET TEAMS DISTRIBUTE";
2511 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2512 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO";
2514 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2515 p
= "!$OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2517 case ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2518 p
= "!$OMP END TARGET TEAMS DISTRIBUTE SIMD";
2520 case ST_OMP_END_TARGET_TEAMS_LOOP
:
2521 p
= "!$OMP END TARGET TEAMS LOOP";
2523 case ST_OMP_END_TASKGROUP
:
2524 p
= "!$OMP END TASKGROUP";
2526 case ST_OMP_END_TASKLOOP
:
2527 p
= "!$OMP END TASKLOOP";
2529 case ST_OMP_END_TASKLOOP_SIMD
:
2530 p
= "!$OMP END TASKLOOP SIMD";
2532 case ST_OMP_END_TEAMS
:
2533 p
= "!$OMP END TEAMS";
2535 case ST_OMP_END_TEAMS_DISTRIBUTE
:
2536 p
= "!$OMP END TEAMS DISTRIBUTE";
2538 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2539 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO";
2541 case ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2542 p
= "!$OMP END TEAMS DISTRIBUTE PARALLEL DO SIMD";
2544 case ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
:
2545 p
= "!$OMP END TEAMS DISTRIBUTE SIMD";
2547 case ST_OMP_END_TEAMS_LOOP
:
2548 p
= "!$OMP END TEAMS LOP";
2550 case ST_OMP_END_WORKSHARE
:
2551 p
= "!$OMP END WORKSHARE";
2565 case ST_OMP_MASKED_TASKLOOP
:
2566 p
= "!$OMP MASKED TASKLOOP";
2568 case ST_OMP_MASKED_TASKLOOP_SIMD
:
2569 p
= "!$OMP MASKED TASKLOOP SIMD";
2574 case ST_OMP_MASTER_TASKLOOP
:
2575 p
= "!$OMP MASTER TASKLOOP";
2577 case ST_OMP_MASTER_TASKLOOP_SIMD
:
2578 p
= "!$OMP MASTER TASKLOOP SIMD";
2580 case ST_OMP_ORDERED
:
2581 case ST_OMP_ORDERED_DEPEND
:
2582 p
= "!$OMP ORDERED";
2584 case ST_OMP_PARALLEL
:
2585 p
= "!$OMP PARALLEL";
2587 case ST_OMP_PARALLEL_DO
:
2588 p
= "!$OMP PARALLEL DO";
2590 case ST_OMP_PARALLEL_LOOP
:
2591 p
= "!$OMP PARALLEL LOOP";
2593 case ST_OMP_PARALLEL_DO_SIMD
:
2594 p
= "!$OMP PARALLEL DO SIMD";
2596 case ST_OMP_PARALLEL_MASKED
:
2597 p
= "!$OMP PARALLEL MASKED";
2599 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
2600 p
= "!$OMP PARALLEL MASKED TASKLOOP";
2602 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
2603 p
= "!$OMP PARALLEL MASKED TASKLOOP SIMD";
2605 case ST_OMP_PARALLEL_MASTER
:
2606 p
= "!$OMP PARALLEL MASTER";
2608 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
2609 p
= "!$OMP PARALLEL MASTER TASKLOOP";
2611 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
2612 p
= "!$OMP PARALLEL MASTER TASKLOOP SIMD";
2614 case ST_OMP_PARALLEL_SECTIONS
:
2615 p
= "!$OMP PARALLEL SECTIONS";
2617 case ST_OMP_PARALLEL_WORKSHARE
:
2618 p
= "!$OMP PARALLEL WORKSHARE";
2620 case ST_OMP_REQUIRES
:
2621 p
= "!$OMP REQUIRES";
2629 case ST_OMP_SECTIONS
:
2630 p
= "!$OMP SECTIONS";
2632 case ST_OMP_SECTION
:
2633 p
= "!$OMP SECTION";
2644 case ST_OMP_TARGET_DATA
:
2645 p
= "!$OMP TARGET DATA";
2647 case ST_OMP_TARGET_ENTER_DATA
:
2648 p
= "!$OMP TARGET ENTER DATA";
2650 case ST_OMP_TARGET_EXIT_DATA
:
2651 p
= "!$OMP TARGET EXIT DATA";
2653 case ST_OMP_TARGET_PARALLEL
:
2654 p
= "!$OMP TARGET PARALLEL";
2656 case ST_OMP_TARGET_PARALLEL_DO
:
2657 p
= "!$OMP TARGET PARALLEL DO";
2659 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
2660 p
= "!$OMP TARGET PARALLEL DO SIMD";
2662 case ST_OMP_TARGET_PARALLEL_LOOP
:
2663 p
= "!$OMP TARGET PARALLEL LOOP";
2665 case ST_OMP_TARGET_SIMD
:
2666 p
= "!$OMP TARGET SIMD";
2668 case ST_OMP_TARGET_TEAMS
:
2669 p
= "!$OMP TARGET TEAMS";
2671 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
2672 p
= "!$OMP TARGET TEAMS DISTRIBUTE";
2674 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2675 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO";
2677 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2678 p
= "!$OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD";
2680 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
2681 p
= "!$OMP TARGET TEAMS DISTRIBUTE SIMD";
2683 case ST_OMP_TARGET_TEAMS_LOOP
:
2684 p
= "!$OMP TARGET TEAMS LOOP";
2686 case ST_OMP_TARGET_UPDATE
:
2687 p
= "!$OMP TARGET UPDATE";
2692 case ST_OMP_TASKGROUP
:
2693 p
= "!$OMP TASKGROUP";
2695 case ST_OMP_TASKLOOP
:
2696 p
= "!$OMP TASKLOOP";
2698 case ST_OMP_TASKLOOP_SIMD
:
2699 p
= "!$OMP TASKLOOP SIMD";
2701 case ST_OMP_TASKWAIT
:
2702 p
= "!$OMP TASKWAIT";
2704 case ST_OMP_TASKYIELD
:
2705 p
= "!$OMP TASKYIELD";
2710 case ST_OMP_TEAMS_DISTRIBUTE
:
2711 p
= "!$OMP TEAMS DISTRIBUTE";
2713 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
2714 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO";
2716 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
2717 p
= "!$OMP TEAMS DISTRIBUTE PARALLEL DO SIMD";
2719 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
2720 p
= "!$OMP TEAMS DISTRIBUTE SIMD";
2722 case ST_OMP_TEAMS_LOOP
:
2723 p
= "!$OMP TEAMS LOOP";
2725 case ST_OMP_THREADPRIVATE
:
2726 p
= "!$OMP THREADPRIVATE";
2728 case ST_OMP_WORKSHARE
:
2729 p
= "!$OMP WORKSHARE";
2732 gfc_internal_error ("gfc_ascii_statement(): Bad statement code");
2739 /* Create a symbol for the main program and assign it to ns->proc_name. */
2742 main_program_symbol (gfc_namespace
*ns
, const char *name
)
2744 gfc_symbol
*main_program
;
2745 symbol_attribute attr
;
2747 gfc_get_symbol (name
, ns
, &main_program
);
2748 gfc_clear_attr (&attr
);
2749 attr
.flavor
= FL_PROGRAM
;
2750 attr
.proc
= PROC_UNKNOWN
;
2751 attr
.subroutine
= 1;
2752 attr
.access
= ACCESS_PUBLIC
;
2753 attr
.is_main_program
= 1;
2754 main_program
->attr
= attr
;
2755 main_program
->declared_at
= gfc_current_locus
;
2756 ns
->proc_name
= main_program
;
2757 gfc_commit_symbols ();
2761 /* Do whatever is necessary to accept the last statement. */
2764 accept_statement (gfc_statement st
)
2768 case ST_IMPLICIT_NONE
:
2776 gfc_current_ns
->proc_name
= gfc_new_block
;
2779 /* If the statement is the end of a block, lay down a special code
2780 that allows a branch to the end of the block from within the
2781 construct. IF and SELECT are treated differently from DO
2782 (where EXEC_NOP is added inside the loop) for two
2784 1. END DO has a meaning in the sense that after a GOTO to
2785 it, the loop counter must be increased.
2786 2. IF blocks and SELECT blocks can consist of multiple
2787 parallel blocks (IF ... ELSE IF ... ELSE ... END IF).
2788 Putting the label before the END IF would make the jump
2789 from, say, the ELSE IF block to the END IF illegal. */
2793 case ST_END_CRITICAL
:
2794 if (gfc_statement_label
!= NULL
)
2796 new_st
.op
= EXEC_END_NESTED_BLOCK
;
2801 /* In the case of BLOCK and ASSOCIATE blocks, there cannot be more than
2802 one parallel block. Thus, we add the special code to the nested block
2803 itself, instead of the parent one. */
2805 case ST_END_ASSOCIATE
:
2806 if (gfc_statement_label
!= NULL
)
2808 new_st
.op
= EXEC_END_BLOCK
;
2813 /* The end-of-program unit statements do not get the special
2814 marker and require a statement of some sort if they are a
2817 case ST_END_PROGRAM
:
2818 case ST_END_FUNCTION
:
2819 case ST_END_SUBROUTINE
:
2820 if (gfc_statement_label
!= NULL
)
2822 new_st
.op
= EXEC_RETURN
;
2827 new_st
.op
= EXEC_END_PROCEDURE
;
2843 gfc_commit_symbols ();
2844 gfc_warning_check ();
2845 gfc_clear_new_st ();
2849 /* Undo anything tentative that has been built for the current statement,
2850 except if a gfc_charlen structure has been added to current namespace's
2851 list of gfc_charlen structure. */
2854 reject_statement (void)
2856 gfc_free_equiv_until (gfc_current_ns
->equiv
, gfc_current_ns
->old_equiv
);
2857 gfc_current_ns
->equiv
= gfc_current_ns
->old_equiv
;
2859 gfc_reject_data (gfc_current_ns
);
2861 gfc_new_block
= NULL
;
2862 gfc_undo_symbols ();
2863 gfc_clear_warning ();
2864 undo_new_statement ();
2868 /* Generic complaint about an out of order statement. We also do
2869 whatever is necessary to clean up. */
2872 unexpected_statement (gfc_statement st
)
2874 gfc_error ("Unexpected %s statement at %C", gfc_ascii_statement (st
));
2876 reject_statement ();
2880 /* Given the next statement seen by the matcher, make sure that it is
2881 in proper order with the last. This subroutine is initialized by
2882 calling it with an argument of ST_NONE. If there is a problem, we
2883 issue an error and return false. Otherwise we return true.
2885 Individual parsers need to verify that the statements seen are
2886 valid before calling here, i.e., ENTRY statements are not allowed in
2887 INTERFACE blocks. The following diagram is taken from the standard:
2889 +---------------------------------------+
2890 | program subroutine function module |
2891 +---------------------------------------+
2893 +---------------------------------------+
2895 +---------------------------------------+
2897 | +-----------+------------------+
2898 | | parameter | implicit |
2899 | +-----------+------------------+
2900 | format | | derived type |
2901 | entry | parameter | interface |
2902 | | data | specification |
2903 | | | statement func |
2904 | +-----------+------------------+
2905 | | data | executable |
2906 +--------+-----------+------------------+
2908 +---------------------------------------+
2909 | internal module/subprogram |
2910 +---------------------------------------+
2912 +---------------------------------------+
2921 ORDER_IMPLICIT_NONE
,
2929 enum state_order state
;
2930 gfc_statement last_statement
;
2936 verify_st_order (st_state
*p
, gfc_statement st
, bool silent
)
2942 p
->state
= ORDER_START
;
2946 if (p
->state
> ORDER_USE
)
2948 p
->state
= ORDER_USE
;
2952 if (p
->state
> ORDER_IMPORT
)
2954 p
->state
= ORDER_IMPORT
;
2957 case ST_IMPLICIT_NONE
:
2958 if (p
->state
> ORDER_IMPLICIT
)
2961 /* The '>' sign cannot be a '>=', because a FORMAT or ENTRY
2962 statement disqualifies a USE but not an IMPLICIT NONE.
2963 Duplicate IMPLICIT NONEs are caught when the implicit types
2966 p
->state
= ORDER_IMPLICIT_NONE
;
2970 if (p
->state
> ORDER_IMPLICIT
)
2972 p
->state
= ORDER_IMPLICIT
;
2977 if (p
->state
< ORDER_IMPLICIT_NONE
)
2978 p
->state
= ORDER_IMPLICIT_NONE
;
2982 if (p
->state
>= ORDER_EXEC
)
2984 if (p
->state
< ORDER_IMPLICIT
)
2985 p
->state
= ORDER_IMPLICIT
;
2989 if (p
->state
< ORDER_SPEC
)
2990 p
->state
= ORDER_SPEC
;
2995 case ST_STRUCTURE_DECL
:
2996 case ST_DERIVED_DECL
:
2998 if (p
->state
>= ORDER_EXEC
)
3000 if (p
->state
< ORDER_SPEC
)
3001 p
->state
= ORDER_SPEC
;
3005 /* The OpenMP/OpenACC directives have to be somewhere in the specification
3006 part, but there are no further requirements on their ordering.
3007 Thus don't adjust p->state, just ignore them. */
3008 if (p
->state
>= ORDER_EXEC
)
3014 if (p
->state
< ORDER_EXEC
)
3015 p
->state
= ORDER_EXEC
;
3022 /* All is well, record the statement in case we need it next time. */
3023 p
->where
= gfc_current_locus
;
3024 p
->last_statement
= st
;
3029 gfc_error ("%s statement at %C cannot follow %s statement at %L",
3030 gfc_ascii_statement (st
),
3031 gfc_ascii_statement (p
->last_statement
), &p
->where
);
3037 /* Handle an unexpected end of file. This is a show-stopper... */
3039 static void unexpected_eof (void) ATTRIBUTE_NORETURN
;
3042 unexpected_eof (void)
3046 gfc_error ("Unexpected end of file in %qs", gfc_source_file
);
3048 /* Memory cleanup. Move to "second to last". */
3049 for (p
= gfc_state_stack
; p
&& p
->previous
&& p
->previous
->previous
;
3052 gfc_current_ns
->code
= (p
&& p
->previous
) ? p
->head
: NULL
;
3055 longjmp (eof_buf
, 1);
3057 /* Avoids build error on systems where longjmp is not declared noreturn. */
3062 /* Parse the CONTAINS section of a derived type definition. */
3064 gfc_access gfc_typebound_default_access
;
3067 parse_derived_contains (void)
3070 bool seen_private
= false;
3071 bool seen_comps
= false;
3072 bool error_flag
= false;
3075 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3076 gcc_assert (gfc_current_block ());
3078 /* Derived-types with SEQUENCE and/or BIND(C) must not have a CONTAINS
3080 if (gfc_current_block ()->attr
.sequence
)
3081 gfc_error ("Derived-type %qs with SEQUENCE must not have a CONTAINS"
3082 " section at %C", gfc_current_block ()->name
);
3083 if (gfc_current_block ()->attr
.is_bind_c
)
3084 gfc_error ("Derived-type %qs with BIND(C) must not have a CONTAINS"
3085 " section at %C", gfc_current_block ()->name
);
3087 accept_statement (ST_CONTAINS
);
3088 push_state (&s
, COMP_DERIVED_CONTAINS
, NULL
);
3090 gfc_typebound_default_access
= ACCESS_PUBLIC
;
3096 st
= next_statement ();
3104 gfc_error ("Components in TYPE at %C must precede CONTAINS");
3108 if (!gfc_notify_std (GFC_STD_F2003
, "Type-bound procedure at %C"))
3111 accept_statement (ST_PROCEDURE
);
3116 if (!gfc_notify_std (GFC_STD_F2003
, "GENERIC binding at %C"))
3119 accept_statement (ST_GENERIC
);
3124 if (!gfc_notify_std (GFC_STD_F2003
, "FINAL procedure declaration"
3128 accept_statement (ST_FINAL
);
3136 && (!gfc_notify_std(GFC_STD_F2008
, "Derived type definition "
3137 "at %C with empty CONTAINS section")))
3140 /* ST_END_TYPE is accepted by parse_derived after return. */
3144 if (!gfc_find_state (COMP_MODULE
))
3146 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3153 gfc_error ("PRIVATE statement at %C must precede procedure"
3160 gfc_error ("Duplicate PRIVATE statement at %C");
3164 accept_statement (ST_PRIVATE
);
3165 gfc_typebound_default_access
= ACCESS_PRIVATE
;
3166 seen_private
= true;
3170 gfc_error ("SEQUENCE statement at %C must precede CONTAINS");
3174 gfc_error ("Already inside a CONTAINS block at %C");
3178 unexpected_statement (st
);
3186 reject_statement ();
3190 gcc_assert (gfc_current_state () == COMP_DERIVED
);
3196 /* Set attributes for the parent symbol based on the attributes of a component
3197 and raise errors if conflicting attributes are found for the component. */
3200 check_component (gfc_symbol
*sym
, gfc_component
*c
, gfc_component
**lockp
,
3201 gfc_component
**eventp
)
3203 bool coarray
, lock_type
, event_type
, allocatable
, pointer
;
3204 coarray
= lock_type
= event_type
= allocatable
= pointer
= false;
3205 gfc_component
*lock_comp
= NULL
, *event_comp
= NULL
;
3207 if (lockp
) lock_comp
= *lockp
;
3208 if (eventp
) event_comp
= *eventp
;
3210 /* Look for allocatable components. */
3211 if (c
->attr
.allocatable
3212 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3213 && CLASS_DATA (c
)->attr
.allocatable
)
3214 || (c
->ts
.type
== BT_DERIVED
&& !c
->attr
.pointer
3215 && c
->ts
.u
.derived
->attr
.alloc_comp
))
3218 sym
->attr
.alloc_comp
= 1;
3221 /* Look for pointer components. */
3223 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3224 && CLASS_DATA (c
)->attr
.class_pointer
)
3225 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.pointer_comp
))
3228 sym
->attr
.pointer_comp
= 1;
3231 /* Look for procedure pointer components. */
3232 if (c
->attr
.proc_pointer
3233 || (c
->ts
.type
== BT_DERIVED
3234 && c
->ts
.u
.derived
->attr
.proc_pointer_comp
))
3235 sym
->attr
.proc_pointer_comp
= 1;
3237 /* Looking for coarray components. */
3238 if (c
->attr
.codimension
3239 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3240 && CLASS_DATA (c
)->attr
.codimension
))
3243 sym
->attr
.coarray_comp
= 1;
3246 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.coarray_comp
3247 && !c
->attr
.pointer
)
3250 sym
->attr
.coarray_comp
= 1;
3253 /* Looking for lock_type components. */
3254 if ((c
->ts
.type
== BT_DERIVED
3255 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3256 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
)
3257 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3258 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3259 == INTMOD_ISO_FORTRAN_ENV
3260 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3261 == ISOFORTRAN_LOCK_TYPE
)
3262 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.lock_comp
3263 && !allocatable
&& !pointer
))
3267 sym
->attr
.lock_comp
= 1;
3270 /* Looking for event_type components. */
3271 if ((c
->ts
.type
== BT_DERIVED
3272 && c
->ts
.u
.derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
3273 && c
->ts
.u
.derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
3274 || (c
->ts
.type
== BT_CLASS
&& c
->attr
.class_ok
3275 && CLASS_DATA (c
)->ts
.u
.derived
->from_intmod
3276 == INTMOD_ISO_FORTRAN_ENV
3277 && CLASS_DATA (c
)->ts
.u
.derived
->intmod_sym_id
3278 == ISOFORTRAN_EVENT_TYPE
)
3279 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.event_comp
3280 && !allocatable
&& !pointer
))
3284 sym
->attr
.event_comp
= 1;
3287 /* Check for F2008, C1302 - and recall that pointers may not be coarrays
3288 (5.3.14) and that subobjects of coarray are coarray themselves (2.4.7),
3289 unless there are nondirect [allocatable or pointer] components
3290 involved (cf. 1.3.33.1 and 1.3.33.3). */
3292 if (pointer
&& !coarray
&& lock_type
)
3293 gfc_error ("Component %s at %L of type LOCK_TYPE must have a "
3294 "codimension or be a subcomponent of a coarray, "
3295 "which is not possible as the component has the "
3296 "pointer attribute", c
->name
, &c
->loc
);
3297 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3298 && c
->ts
.u
.derived
->attr
.lock_comp
)
3299 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3300 "of type LOCK_TYPE, which must have a codimension or be a "
3301 "subcomponent of a coarray", c
->name
, &c
->loc
);
3303 if (lock_type
&& allocatable
&& !coarray
)
3304 gfc_error ("Allocatable component %s at %L of type LOCK_TYPE must have "
3305 "a codimension", c
->name
, &c
->loc
);
3306 else if (lock_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3307 && c
->ts
.u
.derived
->attr
.lock_comp
)
3308 gfc_error ("Allocatable component %s at %L must have a codimension as "
3309 "it has a noncoarray subcomponent of type LOCK_TYPE",
3312 if (sym
->attr
.coarray_comp
&& !coarray
&& lock_type
)
3313 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3314 "subcomponent of type LOCK_TYPE must have a codimension or "
3315 "be a subcomponent of a coarray. (Variables of type %s may "
3316 "not have a codimension as already a coarray "
3317 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3319 if (sym
->attr
.lock_comp
&& coarray
&& !lock_type
)
3320 gfc_error ("Noncoarray component %s at %L of type LOCK_TYPE or with "
3321 "subcomponent of type LOCK_TYPE must have a codimension or "
3322 "be a subcomponent of a coarray. (Variables of type %s may "
3323 "not have a codimension as %s at %L has a codimension or a "
3324 "coarray subcomponent)", lock_comp
->name
, &lock_comp
->loc
,
3325 sym
->name
, c
->name
, &c
->loc
);
3327 /* Similarly for EVENT TYPE. */
3329 if (pointer
&& !coarray
&& event_type
)
3330 gfc_error ("Component %s at %L of type EVENT_TYPE must have a "
3331 "codimension or be a subcomponent of a coarray, "
3332 "which is not possible as the component has the "
3333 "pointer attribute", c
->name
, &c
->loc
);
3334 else if (pointer
&& !coarray
&& c
->ts
.type
== BT_DERIVED
3335 && c
->ts
.u
.derived
->attr
.event_comp
)
3336 gfc_error ("Pointer component %s at %L has a noncoarray subcomponent "
3337 "of type EVENT_TYPE, which must have a codimension or be a "
3338 "subcomponent of a coarray", c
->name
, &c
->loc
);
3340 if (event_type
&& allocatable
&& !coarray
)
3341 gfc_error ("Allocatable component %s at %L of type EVENT_TYPE must have "
3342 "a codimension", c
->name
, &c
->loc
);
3343 else if (event_type
&& allocatable
&& c
->ts
.type
== BT_DERIVED
3344 && c
->ts
.u
.derived
->attr
.event_comp
)
3345 gfc_error ("Allocatable component %s at %L must have a codimension as "
3346 "it has a noncoarray subcomponent of type EVENT_TYPE",
3349 if (sym
->attr
.coarray_comp
&& !coarray
&& event_type
)
3350 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3351 "subcomponent of type EVENT_TYPE must have a codimension or "
3352 "be a subcomponent of a coarray. (Variables of type %s may "
3353 "not have a codimension as already a coarray "
3354 "subcomponent exists)", c
->name
, &c
->loc
, sym
->name
);
3356 if (sym
->attr
.event_comp
&& coarray
&& !event_type
)
3357 gfc_error ("Noncoarray component %s at %L of type EVENT_TYPE or with "
3358 "subcomponent of type EVENT_TYPE must have a codimension or "
3359 "be a subcomponent of a coarray. (Variables of type %s may "
3360 "not have a codimension as %s at %L has a codimension or a "
3361 "coarray subcomponent)", event_comp
->name
, &event_comp
->loc
,
3362 sym
->name
, c
->name
, &c
->loc
);
3364 /* Look for private components. */
3365 if (sym
->component_access
== ACCESS_PRIVATE
3366 || c
->attr
.access
== ACCESS_PRIVATE
3367 || (c
->ts
.type
== BT_DERIVED
&& c
->ts
.u
.derived
->attr
.private_comp
))
3368 sym
->attr
.private_comp
= 1;
3370 if (lockp
) *lockp
= lock_comp
;
3371 if (eventp
) *eventp
= event_comp
;
3375 static void parse_struct_map (gfc_statement
);
3377 /* Parse a union component definition within a structure definition. */
3385 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3388 accept_statement(ST_UNION
);
3389 push_state (&s
, COMP_UNION
, gfc_new_block
);
3396 st
= next_statement ();
3397 /* Only MAP declarations valid within a union. */
3404 accept_statement (ST_MAP
);
3405 parse_struct_map (ST_MAP
);
3406 /* Add a component to the union for each map. */
3407 if (!gfc_add_component (un
, gfc_new_block
->name
, &c
))
3409 gfc_internal_error ("failed to create map component '%s'",
3410 gfc_new_block
->name
);
3411 reject_statement ();
3414 c
->ts
.type
= BT_DERIVED
;
3415 c
->ts
.u
.derived
= gfc_new_block
;
3416 /* Normally components get their initialization expressions when they
3417 are created in decl.c (build_struct) so we can look through the
3418 flat component list for initializers during resolution. Unions and
3419 maps create components along with their type definitions so we
3420 have to generate initializers here. */
3421 c
->initializer
= gfc_default_initializer (&c
->ts
);
3426 accept_statement (ST_END_UNION
);
3430 unexpected_statement (st
);
3435 for (c
= un
->components
; c
; c
= c
->next
)
3436 check_component (un
, c
, &lock_comp
, &event_comp
);
3438 /* Add the union as a component in its parent structure. */
3440 if (!gfc_add_component (gfc_current_block (), un
->name
, &c
))
3442 gfc_internal_error ("failed to create union component '%s'", un
->name
);
3443 reject_statement ();
3446 c
->ts
.type
= BT_UNION
;
3447 c
->ts
.u
.derived
= un
;
3448 c
->initializer
= gfc_default_initializer (&c
->ts
);
3450 un
->attr
.zero_comp
= un
->components
== NULL
;
3454 /* Parse a STRUCTURE or MAP. */
3457 parse_struct_map (gfc_statement block
)
3463 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3464 gfc_compile_state comp
;
3467 if (block
== ST_STRUCTURE_DECL
)
3469 comp
= COMP_STRUCTURE
;
3470 ends
= ST_END_STRUCTURE
;
3474 gcc_assert (block
== ST_MAP
);
3479 accept_statement(block
);
3480 push_state (&s
, comp
, gfc_new_block
);
3482 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3485 while (compiling_type
)
3487 st
= next_statement ();
3493 /* Nested structure declarations will be captured as ST_DATA_DECL. */
3494 case ST_STRUCTURE_DECL
:
3495 /* Let a more specific error make it to decode_statement(). */
3496 if (gfc_error_check () == 0)
3497 gfc_error ("Syntax error in nested structure declaration at %C");
3498 reject_statement ();
3499 /* Skip the rest of this statement. */
3500 gfc_error_recovery ();
3504 accept_statement (ST_UNION
);
3509 /* The data declaration was a nested/ad-hoc STRUCTURE field. */
3510 accept_statement (ST_DATA_DECL
);
3511 if (gfc_new_block
&& gfc_new_block
!= gfc_current_block ()
3512 && gfc_new_block
->attr
.flavor
== FL_STRUCT
)
3513 parse_struct_map (ST_STRUCTURE_DECL
);
3516 case ST_END_STRUCTURE
:
3520 accept_statement (st
);
3524 unexpected_statement (st
);
3528 unexpected_statement (st
);
3533 /* Validate each component. */
3534 sym
= gfc_current_block ();
3535 for (c
= sym
->components
; c
; c
= c
->next
)
3536 check_component (sym
, c
, &lock_comp
, &event_comp
);
3538 sym
->attr
.zero_comp
= (sym
->components
== NULL
);
3540 /* Allow parse_union to find this structure to add to its list of maps. */
3541 if (block
== ST_MAP
)
3542 gfc_new_block
= gfc_current_block ();
3548 /* Parse a derived type. */
3551 parse_derived (void)
3553 int compiling_type
, seen_private
, seen_sequence
, seen_component
;
3557 gfc_component
*c
, *lock_comp
= NULL
, *event_comp
= NULL
;
3559 accept_statement (ST_DERIVED_DECL
);
3560 push_state (&s
, COMP_DERIVED
, gfc_new_block
);
3562 gfc_new_block
->component_access
= ACCESS_PUBLIC
;
3569 while (compiling_type
)
3571 st
= next_statement ();
3579 accept_statement (st
);
3584 gfc_error ("FINAL declaration at %C must be inside CONTAINS");
3591 if (!seen_component
)
3592 gfc_notify_std (GFC_STD_F2003
, "Derived type "
3593 "definition at %C without components");
3595 accept_statement (ST_END_TYPE
);
3599 if (!gfc_find_state (COMP_MODULE
))
3601 gfc_error ("PRIVATE statement in TYPE at %C must be inside "
3608 gfc_error ("PRIVATE statement at %C must precede "
3609 "structure components");
3614 gfc_error ("Duplicate PRIVATE statement at %C");
3616 s
.sym
->component_access
= ACCESS_PRIVATE
;
3618 accept_statement (ST_PRIVATE
);
3625 gfc_error ("SEQUENCE statement at %C must precede "
3626 "structure components");
3630 if (gfc_current_block ()->attr
.sequence
)
3631 gfc_warning (0, "SEQUENCE attribute at %C already specified in "
3636 gfc_error ("Duplicate SEQUENCE statement at %C");
3640 gfc_add_sequence (&gfc_current_block ()->attr
,
3641 gfc_current_block ()->name
, NULL
);
3645 gfc_notify_std (GFC_STD_F2003
,
3646 "CONTAINS block in derived type"
3647 " definition at %C");
3649 accept_statement (ST_CONTAINS
);
3650 parse_derived_contains ();
3654 unexpected_statement (st
);
3659 /* need to verify that all fields of the derived type are
3660 * interoperable with C if the type is declared to be bind(c)
3662 sym
= gfc_current_block ();
3663 for (c
= sym
->components
; c
; c
= c
->next
)
3664 check_component (sym
, c
, &lock_comp
, &event_comp
);
3666 if (!seen_component
)
3667 sym
->attr
.zero_comp
= 1;
3673 /* Parse an ENUM. */
3681 int seen_enumerator
= 0;
3683 push_state (&s
, COMP_ENUM
, gfc_new_block
);
3687 while (compiling_enum
)
3689 st
= next_statement ();
3697 seen_enumerator
= 1;
3698 accept_statement (st
);
3703 if (!seen_enumerator
)
3704 gfc_error ("ENUM declaration at %C has no ENUMERATORS");
3705 accept_statement (st
);
3709 gfc_free_enum_history ();
3710 unexpected_statement (st
);
3718 /* Parse an interface. We must be able to deal with the possibility
3719 of recursive interfaces. The parse_spec() subroutine is mutually
3720 recursive with parse_interface(). */
3722 static gfc_statement
parse_spec (gfc_statement
);
3725 parse_interface (void)
3727 gfc_compile_state new_state
= COMP_NONE
, current_state
;
3728 gfc_symbol
*prog_unit
, *sym
;
3729 gfc_interface_info save
;
3730 gfc_state_data s1
, s2
;
3733 accept_statement (ST_INTERFACE
);
3735 current_interface
.ns
= gfc_current_ns
;
3736 save
= current_interface
;
3738 sym
= (current_interface
.type
== INTERFACE_GENERIC
3739 || current_interface
.type
== INTERFACE_USER_OP
)
3740 ? gfc_new_block
: NULL
;
3742 push_state (&s1
, COMP_INTERFACE
, sym
);
3743 current_state
= COMP_NONE
;
3746 gfc_current_ns
= gfc_get_namespace (current_interface
.ns
, 0);
3748 st
= next_statement ();
3756 if (st
== ST_SUBROUTINE
)
3757 new_state
= COMP_SUBROUTINE
;
3758 else if (st
== ST_FUNCTION
)
3759 new_state
= COMP_FUNCTION
;
3760 if (gfc_new_block
->attr
.pointer
)
3762 gfc_new_block
->attr
.pointer
= 0;
3763 gfc_new_block
->attr
.proc_pointer
= 1;
3765 if (!gfc_add_explicit_interface (gfc_new_block
, IFSRC_IFBODY
,
3766 gfc_new_block
->formal
, NULL
))
3768 reject_statement ();
3769 gfc_free_namespace (gfc_current_ns
);
3772 /* F2008 C1210 forbids the IMPORT statement in module procedure
3773 interface bodies and the flag is set to import symbols. */
3774 if (gfc_new_block
->attr
.module_procedure
)
3775 gfc_current_ns
->has_import_set
= 1;
3779 case ST_MODULE_PROC
: /* The module procedure matcher makes
3780 sure the context is correct. */
3781 accept_statement (st
);
3782 gfc_free_namespace (gfc_current_ns
);
3785 case ST_END_INTERFACE
:
3786 gfc_free_namespace (gfc_current_ns
);
3787 gfc_current_ns
= current_interface
.ns
;
3791 gfc_error ("Unexpected %s statement in INTERFACE block at %C",
3792 gfc_ascii_statement (st
));
3793 reject_statement ();
3794 gfc_free_namespace (gfc_current_ns
);
3799 /* Make sure that the generic name has the right attribute. */
3800 if (current_interface
.type
== INTERFACE_GENERIC
3801 && current_state
== COMP_NONE
)
3803 if (new_state
== COMP_FUNCTION
&& sym
)
3804 gfc_add_function (&sym
->attr
, sym
->name
, NULL
);
3805 else if (new_state
== COMP_SUBROUTINE
&& sym
)
3806 gfc_add_subroutine (&sym
->attr
, sym
->name
, NULL
);
3808 current_state
= new_state
;
3811 if (current_interface
.type
== INTERFACE_ABSTRACT
)
3813 gfc_add_abstract (&gfc_new_block
->attr
, &gfc_current_locus
);
3814 if (gfc_is_intrinsic_typename (gfc_new_block
->name
))
3815 gfc_error ("Name %qs of ABSTRACT INTERFACE at %C "
3816 "cannot be the same as an intrinsic type",
3817 gfc_new_block
->name
);
3820 push_state (&s2
, new_state
, gfc_new_block
);
3821 accept_statement (st
);
3822 prog_unit
= gfc_new_block
;
3823 prog_unit
->formal_ns
= gfc_current_ns
;
3824 if (prog_unit
== prog_unit
->formal_ns
->proc_name
3825 && prog_unit
->ns
!= prog_unit
->formal_ns
)
3829 /* Read data declaration statements. */
3830 st
= parse_spec (ST_NONE
);
3831 in_specification_block
= true;
3833 /* Since the interface block does not permit an IMPLICIT statement,
3834 the default type for the function or the result must be taken
3835 from the formal namespace. */
3836 if (new_state
== COMP_FUNCTION
)
3838 if (prog_unit
->result
== prog_unit
3839 && prog_unit
->ts
.type
== BT_UNKNOWN
)
3840 gfc_set_default_type (prog_unit
, 1, prog_unit
->formal_ns
);
3841 else if (prog_unit
->result
!= prog_unit
3842 && prog_unit
->result
->ts
.type
== BT_UNKNOWN
)
3843 gfc_set_default_type (prog_unit
->result
, 1,
3844 prog_unit
->formal_ns
);
3847 if (st
!= ST_END_SUBROUTINE
&& st
!= ST_END_FUNCTION
)
3849 gfc_error ("Unexpected %s statement at %C in INTERFACE body",
3850 gfc_ascii_statement (st
));
3851 reject_statement ();
3855 /* Add EXTERNAL attribute to function or subroutine. */
3856 if (current_interface
.type
!= INTERFACE_ABSTRACT
&& !prog_unit
->attr
.dummy
)
3857 gfc_add_external (&prog_unit
->attr
, &gfc_current_locus
);
3859 current_interface
= save
;
3860 gfc_add_interface (prog_unit
);
3863 if (current_interface
.ns
3864 && current_interface
.ns
->proc_name
3865 && strcmp (current_interface
.ns
->proc_name
->name
,
3866 prog_unit
->name
) == 0)
3867 gfc_error ("INTERFACE procedure %qs at %L has the same name as the "
3868 "enclosing procedure", prog_unit
->name
,
3869 ¤t_interface
.ns
->proc_name
->declared_at
);
3878 /* Associate function characteristics by going back to the function
3879 declaration and rematching the prefix. */
3882 match_deferred_characteristics (gfc_typespec
* ts
)
3885 match m
= MATCH_ERROR
;
3886 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3888 loc
= gfc_current_locus
;
3890 gfc_current_locus
= gfc_current_block ()->declared_at
;
3893 gfc_buffer_error (true);
3894 m
= gfc_match_prefix (ts
);
3895 gfc_buffer_error (false);
3897 if (ts
->type
== BT_DERIVED
)
3905 /* Only permit one go at the characteristic association. */
3909 /* Set the function locus correctly. If we have not found the
3910 function name, there is an error. */
3912 && gfc_match ("function% %n", name
) == MATCH_YES
3913 && strcmp (name
, gfc_current_block ()->name
) == 0)
3915 gfc_current_block ()->declared_at
= gfc_current_locus
;
3916 gfc_commit_symbols ();
3921 gfc_undo_symbols ();
3924 gfc_current_locus
=loc
;
3929 /* Check specification-expressions in the function result of the currently
3930 parsed block and ensure they are typed (give an IMPLICIT type if necessary).
3931 For return types specified in a FUNCTION prefix, the IMPLICIT rules of the
3932 scope are not yet parsed so this has to be delayed up to parse_spec. */
3935 check_function_result_typed (void)
3939 gcc_assert (gfc_current_state () == COMP_FUNCTION
);
3941 if (!gfc_current_ns
->proc_name
->result
) return;
3943 ts
= gfc_current_ns
->proc_name
->result
->ts
;
3945 /* Check type-parameters, at the moment only CHARACTER lengths possible. */
3946 /* TODO: Extend when KIND type parameters are implemented. */
3947 if (ts
.type
== BT_CHARACTER
&& ts
.u
.cl
&& ts
.u
.cl
->length
)
3948 gfc_expr_check_typed (ts
.u
.cl
->length
, gfc_current_ns
, true);
3952 /* Parse a set of specification statements. Returns the statement
3953 that doesn't fit. */
3955 static gfc_statement
3956 parse_spec (gfc_statement st
)
3959 bool function_result_typed
= false;
3960 bool bad_characteristic
= false;
3963 in_specification_block
= true;
3965 verify_st_order (&ss
, ST_NONE
, false);
3967 st
= next_statement ();
3969 /* If we are not inside a function or don't have a result specified so far,
3970 do nothing special about it. */
3971 if (gfc_current_state () != COMP_FUNCTION
)
3972 function_result_typed
= true;
3975 gfc_symbol
* proc
= gfc_current_ns
->proc_name
;
3978 if (proc
->result
->ts
.type
== BT_UNKNOWN
)
3979 function_result_typed
= true;
3984 /* If we're inside a BLOCK construct, some statements are disallowed.
3985 Check this here. Attribute declaration statements like INTENT, OPTIONAL
3986 or VALUE are also disallowed, but they don't have a particular ST_*
3987 key so we have to check for them individually in their matcher routine. */
3988 if (gfc_current_state () == COMP_BLOCK
)
3992 case ST_IMPLICIT_NONE
:
3995 case ST_EQUIVALENCE
:
3996 case ST_STATEMENT_FUNCTION
:
3997 gfc_error ("%s statement is not allowed inside of BLOCK at %C",
3998 gfc_ascii_statement (st
));
3999 reject_statement ();
4005 else if (gfc_current_state () == COMP_BLOCK_DATA
)
4006 /* Fortran 2008, C1116. */
4013 case ST_DERIVED_DECL
:
4014 case ST_END_BLOCK_DATA
:
4015 case ST_EQUIVALENCE
:
4017 case ST_IMPLICIT_NONE
:
4018 case ST_OMP_THREADPRIVATE
:
4020 case ST_STRUCTURE_DECL
:
4029 gfc_error ("%s statement is not allowed inside of BLOCK DATA at %C",
4030 gfc_ascii_statement (st
));
4031 reject_statement ();
4035 /* If we find a statement that cannot be followed by an IMPLICIT statement
4036 (and thus we can expect to see none any further), type the function result
4037 if it has not yet been typed. Be careful not to give the END statement
4038 to verify_st_order! */
4039 if (!function_result_typed
&& st
!= ST_GET_FCN_CHARACTERISTICS
)
4041 bool verify_now
= false;
4043 if (st
== ST_END_FUNCTION
|| st
== ST_CONTAINS
)
4048 verify_st_order (&dummyss
, ST_NONE
, false);
4049 verify_st_order (&dummyss
, st
, false);
4051 if (!verify_st_order (&dummyss
, ST_IMPLICIT
, true))
4057 check_function_result_typed ();
4058 function_result_typed
= true;
4067 case ST_IMPLICIT_NONE
:
4069 if (!function_result_typed
)
4071 check_function_result_typed ();
4072 function_result_typed
= true;
4078 case ST_DATA
: /* Not allowed in interfaces */
4079 if (gfc_current_state () == COMP_INTERFACE
)
4089 case ST_STRUCTURE_DECL
:
4090 case ST_DERIVED_DECL
:
4094 if (!verify_st_order (&ss
, st
, false))
4096 reject_statement ();
4097 st
= next_statement ();
4107 case ST_STRUCTURE_DECL
:
4108 parse_struct_map (ST_STRUCTURE_DECL
);
4111 case ST_DERIVED_DECL
:
4117 if (gfc_current_state () != COMP_MODULE
)
4119 gfc_error ("%s statement must appear in a MODULE",
4120 gfc_ascii_statement (st
));
4121 reject_statement ();
4125 if (gfc_current_ns
->default_access
!= ACCESS_UNKNOWN
)
4127 gfc_error ("%s statement at %C follows another accessibility "
4128 "specification", gfc_ascii_statement (st
));
4129 reject_statement ();
4133 gfc_current_ns
->default_access
= (st
== ST_PUBLIC
)
4134 ? ACCESS_PUBLIC
: ACCESS_PRIVATE
;
4138 case ST_STATEMENT_FUNCTION
:
4139 if (gfc_current_state () == COMP_MODULE
4140 || gfc_current_state () == COMP_SUBMODULE
)
4142 unexpected_statement (st
);
4150 accept_statement (st
);
4151 st
= next_statement ();
4155 accept_statement (st
);
4157 st
= next_statement ();
4160 case ST_GET_FCN_CHARACTERISTICS
:
4161 /* This statement triggers the association of a function's result
4163 ts
= &gfc_current_block ()->result
->ts
;
4164 if (match_deferred_characteristics (ts
) != MATCH_YES
)
4165 bad_characteristic
= true;
4167 st
= next_statement ();
4174 /* If match_deferred_characteristics failed, then there is an error. */
4175 if (bad_characteristic
)
4177 ts
= &gfc_current_block ()->result
->ts
;
4178 if (ts
->type
!= BT_DERIVED
)
4179 gfc_error ("Bad kind expression for function %qs at %L",
4180 gfc_current_block ()->name
,
4181 &gfc_current_block ()->declared_at
);
4183 gfc_error ("The type for function %qs at %L is not accessible",
4184 gfc_current_block ()->name
,
4185 &gfc_current_block ()->declared_at
);
4187 gfc_current_block ()->ts
.kind
= 0;
4188 /* Keep the derived type; if it's bad, it will be discovered later. */
4189 if (!(ts
->type
== BT_DERIVED
&& ts
->u
.derived
))
4190 ts
->type
= BT_UNKNOWN
;
4193 in_specification_block
= false;
4199 /* Parse a WHERE block, (not a simple WHERE statement). */
4202 parse_where_block (void)
4204 int seen_empty_else
;
4209 accept_statement (ST_WHERE_BLOCK
);
4210 top
= gfc_state_stack
->tail
;
4212 push_state (&s
, COMP_WHERE
, gfc_new_block
);
4214 d
= add_statement ();
4215 d
->expr1
= top
->expr1
;
4221 seen_empty_else
= 0;
4225 st
= next_statement ();
4231 case ST_WHERE_BLOCK
:
4232 parse_where_block ();
4237 accept_statement (st
);
4241 if (seen_empty_else
)
4243 gfc_error ("ELSEWHERE statement at %C follows previous "
4244 "unmasked ELSEWHERE");
4245 reject_statement ();
4249 if (new_st
.expr1
== NULL
)
4250 seen_empty_else
= 1;
4252 d
= new_level (gfc_state_stack
->head
);
4254 d
->expr1
= new_st
.expr1
;
4256 accept_statement (st
);
4261 accept_statement (st
);
4265 gfc_error ("Unexpected %s statement in WHERE block at %C",
4266 gfc_ascii_statement (st
));
4267 reject_statement ();
4271 while (st
!= ST_END_WHERE
);
4277 /* Parse a FORALL block (not a simple FORALL statement). */
4280 parse_forall_block (void)
4286 accept_statement (ST_FORALL_BLOCK
);
4287 top
= gfc_state_stack
->tail
;
4289 push_state (&s
, COMP_FORALL
, gfc_new_block
);
4291 d
= add_statement ();
4292 d
->op
= EXEC_FORALL
;
4297 st
= next_statement ();
4302 case ST_POINTER_ASSIGNMENT
:
4305 accept_statement (st
);
4308 case ST_WHERE_BLOCK
:
4309 parse_where_block ();
4312 case ST_FORALL_BLOCK
:
4313 parse_forall_block ();
4317 accept_statement (st
);
4324 gfc_error ("Unexpected %s statement in FORALL block at %C",
4325 gfc_ascii_statement (st
));
4327 reject_statement ();
4331 while (st
!= ST_END_FORALL
);
4337 static gfc_statement
parse_executable (gfc_statement
);
4339 /* parse the statements of an IF-THEN-ELSEIF-ELSE-ENDIF block. */
4342 parse_if_block (void)
4351 accept_statement (ST_IF_BLOCK
);
4353 top
= gfc_state_stack
->tail
;
4354 push_state (&s
, COMP_IF
, gfc_new_block
);
4356 new_st
.op
= EXEC_IF
;
4357 d
= add_statement ();
4359 d
->expr1
= top
->expr1
;
4365 st
= parse_executable (ST_NONE
);
4375 gfc_error ("ELSE IF statement at %C cannot follow ELSE "
4376 "statement at %L", &else_locus
);
4378 reject_statement ();
4382 d
= new_level (gfc_state_stack
->head
);
4384 d
->expr1
= new_st
.expr1
;
4386 accept_statement (st
);
4393 gfc_error ("Duplicate ELSE statements at %L and %C",
4395 reject_statement ();
4400 else_locus
= gfc_current_locus
;
4402 d
= new_level (gfc_state_stack
->head
);
4405 accept_statement (st
);
4413 unexpected_statement (st
);
4417 while (st
!= ST_ENDIF
);
4420 accept_statement (st
);
4424 /* Parse a SELECT block. */
4427 parse_select_block (void)
4433 accept_statement (ST_SELECT_CASE
);
4435 cp
= gfc_state_stack
->tail
;
4436 push_state (&s
, COMP_SELECT
, gfc_new_block
);
4438 /* Make sure that the next statement is a CASE or END SELECT. */
4441 st
= next_statement ();
4444 if (st
== ST_END_SELECT
)
4446 /* Empty SELECT CASE is OK. */
4447 accept_statement (st
);
4454 gfc_error ("Expected a CASE or END SELECT statement following SELECT "
4457 reject_statement ();
4460 /* At this point, we've got a nonempty select block. */
4461 cp
= new_level (cp
);
4464 accept_statement (st
);
4468 st
= parse_executable (ST_NONE
);
4475 cp
= new_level (gfc_state_stack
->head
);
4477 gfc_clear_new_st ();
4479 accept_statement (st
);
4485 /* Can't have an executable statement because of
4486 parse_executable(). */
4488 unexpected_statement (st
);
4492 while (st
!= ST_END_SELECT
);
4495 accept_statement (st
);
4499 /* Pop the current selector from the SELECT TYPE stack. */
4502 select_type_pop (void)
4504 gfc_select_type_stack
*old
= select_type_stack
;
4505 select_type_stack
= old
->prev
;
4510 /* Parse a SELECT TYPE construct (F03:R821). */
4513 parse_select_type_block (void)
4519 gfc_current_ns
= new_st
.ext
.block
.ns
;
4520 accept_statement (ST_SELECT_TYPE
);
4522 cp
= gfc_state_stack
->tail
;
4523 push_state (&s
, COMP_SELECT_TYPE
, gfc_new_block
);
4525 /* Make sure that the next statement is a TYPE IS, CLASS IS, CLASS DEFAULT
4529 st
= next_statement ();
4532 if (st
== ST_END_SELECT
)
4533 /* Empty SELECT CASE is OK. */
4535 if (st
== ST_TYPE_IS
|| st
== ST_CLASS_IS
)
4538 gfc_error ("Expected TYPE IS, CLASS IS or END SELECT statement "
4539 "following SELECT TYPE at %C");
4541 reject_statement ();
4544 /* At this point, we've got a nonempty select block. */
4545 cp
= new_level (cp
);
4548 accept_statement (st
);
4552 st
= parse_executable (ST_NONE
);
4560 cp
= new_level (gfc_state_stack
->head
);
4562 gfc_clear_new_st ();
4564 accept_statement (st
);
4570 /* Can't have an executable statement because of
4571 parse_executable(). */
4573 unexpected_statement (st
);
4577 while (st
!= ST_END_SELECT
);
4581 accept_statement (st
);
4582 gfc_current_ns
= gfc_current_ns
->parent
;
4587 /* Parse a SELECT RANK construct. */
4590 parse_select_rank_block (void)
4596 gfc_current_ns
= new_st
.ext
.block
.ns
;
4597 accept_statement (ST_SELECT_RANK
);
4599 cp
= gfc_state_stack
->tail
;
4600 push_state (&s
, COMP_SELECT_RANK
, gfc_new_block
);
4602 /* Make sure that the next statement is a RANK IS or RANK DEFAULT. */
4605 st
= next_statement ();
4608 if (st
== ST_END_SELECT
)
4609 /* Empty SELECT CASE is OK. */
4614 gfc_error ("Expected RANK or RANK DEFAULT "
4615 "following SELECT RANK at %C");
4617 reject_statement ();
4620 /* At this point, we've got a nonempty select block. */
4621 cp
= new_level (cp
);
4624 accept_statement (st
);
4628 st
= parse_executable (ST_NONE
);
4635 cp
= new_level (gfc_state_stack
->head
);
4637 gfc_clear_new_st ();
4639 accept_statement (st
);
4645 /* Can't have an executable statement because of
4646 parse_executable(). */
4648 unexpected_statement (st
);
4652 while (st
!= ST_END_SELECT
);
4656 accept_statement (st
);
4657 gfc_current_ns
= gfc_current_ns
->parent
;
4662 /* Given a symbol, make sure it is not an iteration variable for a DO
4663 statement. This subroutine is called when the symbol is seen in a
4664 context that causes it to become redefined. If the symbol is an
4665 iterator, we generate an error message and return nonzero. */
4668 gfc_check_do_variable (gfc_symtree
*st
)
4675 for (s
=gfc_state_stack
; s
; s
= s
->previous
)
4676 if (s
->do_variable
== st
)
4678 gfc_error_now ("Variable %qs at %C cannot be redefined inside "
4679 "loop beginning at %L", st
->name
, &s
->head
->loc
);
4687 /* Checks to see if the current statement label closes an enddo.
4688 Returns 0 if not, 1 if closes an ENDDO correctly, or 2 (and issues
4689 an error) if it incorrectly closes an ENDDO. */
4692 check_do_closure (void)
4696 if (gfc_statement_label
== NULL
)
4699 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
4700 if (p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4704 return 0; /* No loops to close */
4706 if (p
->ext
.end_do_label
== gfc_statement_label
)
4708 if (p
== gfc_state_stack
)
4711 gfc_error ("End of nonblock DO statement at %C is within another block");
4715 /* At this point, the label doesn't terminate the innermost loop.
4716 Make sure it doesn't terminate another one. */
4717 for (; p
; p
= p
->previous
)
4718 if ((p
->state
== COMP_DO
|| p
->state
== COMP_DO_CONCURRENT
)
4719 && p
->ext
.end_do_label
== gfc_statement_label
)
4721 gfc_error ("End of nonblock DO statement at %C is interwoven "
4722 "with another DO loop");
4730 /* Parse a series of contained program units. */
4732 static void parse_progunit (gfc_statement
);
4735 /* Parse a CRITICAL block. */
4738 parse_critical_block (void)
4741 gfc_state_data s
, *sd
;
4744 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
4745 if (sd
->state
== COMP_OMP_STRUCTURED_BLOCK
)
4746 gfc_error_now (is_oacc (sd
)
4747 ? G_("CRITICAL block inside of OpenACC region at %C")
4748 : G_("CRITICAL block inside of OpenMP region at %C"));
4750 s
.ext
.end_do_label
= new_st
.label1
;
4752 accept_statement (ST_CRITICAL
);
4753 top
= gfc_state_stack
->tail
;
4755 push_state (&s
, COMP_CRITICAL
, gfc_new_block
);
4757 d
= add_statement ();
4758 d
->op
= EXEC_CRITICAL
;
4763 st
= parse_executable (ST_NONE
);
4771 case ST_END_CRITICAL
:
4772 if (s
.ext
.end_do_label
!= NULL
4773 && s
.ext
.end_do_label
!= gfc_statement_label
)
4774 gfc_error_now ("Statement label in END CRITICAL at %C does not "
4775 "match CRITICAL label");
4777 if (gfc_statement_label
!= NULL
)
4779 new_st
.op
= EXEC_NOP
;
4785 unexpected_statement (st
);
4789 while (st
!= ST_END_CRITICAL
);
4792 accept_statement (st
);
4796 /* Set up the local namespace for a BLOCK construct. */
4799 gfc_build_block_ns (gfc_namespace
*parent_ns
)
4801 gfc_namespace
* my_ns
;
4802 static int numblock
= 1;
4804 my_ns
= gfc_get_namespace (parent_ns
, 1);
4805 my_ns
->construct_entities
= 1;
4807 /* Give the BLOCK a symbol of flavor LABEL; this is later needed for correct
4808 code generation (so it must not be NULL).
4809 We set its recursive argument if our container procedure is recursive, so
4810 that local variables are accordingly placed on the stack when it
4811 will be necessary. */
4813 my_ns
->proc_name
= gfc_new_block
;
4817 char buffer
[20]; /* Enough to hold "block@2147483648\n". */
4819 snprintf(buffer
, sizeof(buffer
), "block@%d", numblock
++);
4820 gfc_get_symbol (buffer
, my_ns
, &my_ns
->proc_name
);
4821 t
= gfc_add_flavor (&my_ns
->proc_name
->attr
, FL_LABEL
,
4822 my_ns
->proc_name
->name
, NULL
);
4824 gfc_commit_symbol (my_ns
->proc_name
);
4827 if (parent_ns
->proc_name
)
4828 my_ns
->proc_name
->attr
.recursive
= parent_ns
->proc_name
->attr
.recursive
;
4834 /* Parse a BLOCK construct. */
4837 parse_block_construct (void)
4839 gfc_namespace
* my_ns
;
4840 gfc_namespace
* my_parent
;
4843 gfc_notify_std (GFC_STD_F2008
, "BLOCK construct at %C");
4845 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4847 new_st
.op
= EXEC_BLOCK
;
4848 new_st
.ext
.block
.ns
= my_ns
;
4849 new_st
.ext
.block
.assoc
= NULL
;
4850 accept_statement (ST_BLOCK
);
4852 push_state (&s
, COMP_BLOCK
, my_ns
->proc_name
);
4853 gfc_current_ns
= my_ns
;
4854 my_parent
= my_ns
->parent
;
4856 parse_progunit (ST_NONE
);
4858 /* Don't depend on the value of gfc_current_ns; it might have been
4859 reset if the block had errors and was cleaned up. */
4860 gfc_current_ns
= my_parent
;
4866 /* Parse an ASSOCIATE construct. This is essentially a BLOCK construct
4867 behind the scenes with compiler-generated variables. */
4870 parse_associate (void)
4872 gfc_namespace
* my_ns
;
4875 gfc_association_list
* a
;
4877 gfc_notify_std (GFC_STD_F2003
, "ASSOCIATE construct at %C");
4879 my_ns
= gfc_build_block_ns (gfc_current_ns
);
4881 new_st
.op
= EXEC_BLOCK
;
4882 new_st
.ext
.block
.ns
= my_ns
;
4883 gcc_assert (new_st
.ext
.block
.assoc
);
4885 /* Add all associate-names as BLOCK variables. Creating them is enough
4886 for now, they'll get their values during trans-* phase. */
4887 gfc_current_ns
= my_ns
;
4888 for (a
= new_st
.ext
.block
.assoc
; a
; a
= a
->next
)
4892 gfc_array_ref
*array_ref
;
4894 if (gfc_get_sym_tree (a
->name
, NULL
, &a
->st
, false))
4898 sym
->attr
.flavor
= FL_VARIABLE
;
4900 sym
->declared_at
= a
->where
;
4901 gfc_set_sym_referenced (sym
);
4903 /* Initialize the typespec. It is not available in all cases,
4904 however, as it may only be set on the target during resolution.
4905 Still, sometimes it helps to have it right now -- especially
4906 for parsing component references on the associate-name
4907 in case of association to a derived-type. */
4908 sym
->ts
= a
->target
->ts
;
4910 /* Check if the target expression is array valued. This cannot always
4911 be done by looking at target.rank, because that might not have been
4912 set yet. Therefore traverse the chain of refs, looking for the last
4913 array ref and evaluate that. */
4915 for (ref
= a
->target
->ref
; ref
; ref
= ref
->next
)
4916 if (ref
->type
== REF_ARRAY
)
4917 array_ref
= &ref
->u
.ar
;
4918 if (array_ref
|| a
->target
->rank
)
4925 /* Count the dimension, that have a non-scalar extend. */
4926 for (dim
= 0; dim
< array_ref
->dimen
; ++dim
)
4927 if (array_ref
->dimen_type
[dim
] != DIMEN_ELEMENT
4928 && !(array_ref
->dimen_type
[dim
] == DIMEN_UNKNOWN
4929 && array_ref
->end
[dim
] == NULL
4930 && array_ref
->start
[dim
] != NULL
))
4934 rank
= a
->target
->rank
;
4935 /* When the rank is greater than zero then sym will be an array. */
4936 if (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
))
4938 if ((!CLASS_DATA (sym
)->as
&& rank
!= 0)
4939 || (CLASS_DATA (sym
)->as
4940 && CLASS_DATA (sym
)->as
->rank
!= rank
))
4942 /* Don't just (re-)set the attr and as in the sym.ts,
4943 because this modifies the target's attr and as. Copy the
4944 data and do a build_class_symbol. */
4945 symbol_attribute attr
= CLASS_DATA (a
->target
)->attr
;
4946 int corank
= gfc_get_corank (a
->target
);
4951 as
= gfc_get_array_spec ();
4952 as
->type
= AS_DEFERRED
;
4954 as
->corank
= corank
;
4955 attr
.dimension
= rank
? 1 : 0;
4956 attr
.codimension
= corank
? 1 : 0;
4961 attr
.dimension
= attr
.codimension
= 0;
4964 type
= CLASS_DATA (sym
)->ts
;
4965 if (!gfc_build_class_symbol (&type
,
4969 sym
->ts
.type
= BT_CLASS
;
4970 sym
->attr
.class_ok
= 1;
4973 sym
->attr
.class_ok
= 1;
4975 else if ((!sym
->as
&& rank
!= 0)
4976 || (sym
->as
&& sym
->as
->rank
!= rank
))
4978 as
= gfc_get_array_spec ();
4979 as
->type
= AS_DEFERRED
;
4981 as
->corank
= gfc_get_corank (a
->target
);
4983 sym
->attr
.dimension
= 1;
4985 sym
->attr
.codimension
= 1;
4990 accept_statement (ST_ASSOCIATE
);
4991 push_state (&s
, COMP_ASSOCIATE
, my_ns
->proc_name
);
4994 st
= parse_executable (ST_NONE
);
5001 accept_statement (st
);
5002 my_ns
->code
= gfc_state_stack
->head
;
5006 unexpected_statement (st
);
5010 gfc_current_ns
= gfc_current_ns
->parent
;
5015 /* Parse a DO loop. Note that the ST_CYCLE and ST_EXIT statements are
5016 handled inside of parse_executable(), because they aren't really
5020 parse_do_block (void)
5029 s
.ext
.end_do_label
= new_st
.label1
;
5031 if (new_st
.ext
.iterator
!= NULL
)
5033 stree
= new_st
.ext
.iterator
->var
->symtree
;
5034 if (directive_unroll
!= -1)
5036 new_st
.ext
.iterator
->unroll
= directive_unroll
;
5037 directive_unroll
= -1;
5039 if (directive_ivdep
)
5041 new_st
.ext
.iterator
->ivdep
= directive_ivdep
;
5042 directive_ivdep
= false;
5044 if (directive_vector
)
5046 new_st
.ext
.iterator
->vector
= directive_vector
;
5047 directive_vector
= false;
5049 if (directive_novector
)
5051 new_st
.ext
.iterator
->novector
= directive_novector
;
5052 directive_novector
= false;
5058 accept_statement (ST_DO
);
5060 top
= gfc_state_stack
->tail
;
5061 push_state (&s
, do_op
== EXEC_DO_CONCURRENT
? COMP_DO_CONCURRENT
: COMP_DO
,
5064 s
.do_variable
= stree
;
5066 top
->block
= new_level (top
);
5067 top
->block
->op
= EXEC_DO
;
5070 st
= parse_executable (ST_NONE
);
5078 if (s
.ext
.end_do_label
!= NULL
5079 && s
.ext
.end_do_label
!= gfc_statement_label
)
5080 gfc_error_now ("Statement label in ENDDO at %C doesn't match "
5083 if (gfc_statement_label
!= NULL
)
5085 new_st
.op
= EXEC_NOP
;
5090 case ST_IMPLIED_ENDDO
:
5091 /* If the do-stmt of this DO construct has a do-construct-name,
5092 the corresponding end-do must be an end-do-stmt (with a matching
5093 name, but in that case we must have seen ST_ENDDO first).
5094 We only complain about this in pedantic mode. */
5095 if (gfc_current_block () != NULL
)
5096 gfc_error_now ("Named block DO at %L requires matching ENDDO name",
5097 &gfc_current_block()->declared_at
);
5102 unexpected_statement (st
);
5107 accept_statement (st
);
5111 /* Parse the statements of OpenMP do/parallel do. */
5113 static gfc_statement
5114 parse_omp_do (gfc_statement omp_st
)
5120 accept_statement (omp_st
);
5122 cp
= gfc_state_stack
->tail
;
5123 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5124 np
= new_level (cp
);
5130 st
= next_statement ();
5133 else if (st
== ST_DO
)
5136 unexpected_statement (st
);
5140 if (gfc_statement_label
!= NULL
5141 && gfc_state_stack
->previous
!= NULL
5142 && gfc_state_stack
->previous
->state
== COMP_DO
5143 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5151 there should be no !$OMP END DO. */
5153 return ST_IMPLIED_ENDDO
;
5156 check_do_closure ();
5159 st
= next_statement ();
5160 gfc_statement omp_end_st
= ST_OMP_END_DO
;
5163 case ST_OMP_DISTRIBUTE
: omp_end_st
= ST_OMP_END_DISTRIBUTE
; break;
5164 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5165 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO
;
5167 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5168 omp_end_st
= ST_OMP_END_DISTRIBUTE_PARALLEL_DO_SIMD
;
5170 case ST_OMP_DISTRIBUTE_SIMD
:
5171 omp_end_st
= ST_OMP_END_DISTRIBUTE_SIMD
;
5173 case ST_OMP_DO
: omp_end_st
= ST_OMP_END_DO
; break;
5174 case ST_OMP_DO_SIMD
: omp_end_st
= ST_OMP_END_DO_SIMD
; break;
5175 case ST_OMP_LOOP
: omp_end_st
= ST_OMP_END_LOOP
; break;
5176 case ST_OMP_PARALLEL_DO
: omp_end_st
= ST_OMP_END_PARALLEL_DO
; break;
5177 case ST_OMP_PARALLEL_DO_SIMD
:
5178 omp_end_st
= ST_OMP_END_PARALLEL_DO_SIMD
;
5180 case ST_OMP_PARALLEL_LOOP
:
5181 omp_end_st
= ST_OMP_END_PARALLEL_LOOP
;
5183 case ST_OMP_SIMD
: omp_end_st
= ST_OMP_END_SIMD
; break;
5184 case ST_OMP_TARGET_PARALLEL_DO
:
5185 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO
;
5187 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5188 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_DO_SIMD
;
5190 case ST_OMP_TARGET_PARALLEL_LOOP
:
5191 omp_end_st
= ST_OMP_END_TARGET_PARALLEL_LOOP
;
5193 case ST_OMP_TARGET_SIMD
: omp_end_st
= ST_OMP_END_TARGET_SIMD
; break;
5194 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5195 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE
;
5197 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5198 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5200 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5201 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5203 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5204 omp_end_st
= ST_OMP_END_TARGET_TEAMS_DISTRIBUTE_SIMD
;
5206 case ST_OMP_TARGET_TEAMS_LOOP
:
5207 omp_end_st
= ST_OMP_END_TARGET_TEAMS_LOOP
;
5209 case ST_OMP_TASKLOOP
: omp_end_st
= ST_OMP_END_TASKLOOP
; break;
5210 case ST_OMP_TASKLOOP_SIMD
: omp_end_st
= ST_OMP_END_TASKLOOP_SIMD
; break;
5211 case ST_OMP_MASKED_TASKLOOP
: omp_end_st
= ST_OMP_END_MASKED_TASKLOOP
; break;
5212 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5213 omp_end_st
= ST_OMP_END_MASKED_TASKLOOP_SIMD
;
5215 case ST_OMP_MASTER_TASKLOOP
: omp_end_st
= ST_OMP_END_MASTER_TASKLOOP
; break;
5216 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5217 omp_end_st
= ST_OMP_END_MASTER_TASKLOOP_SIMD
;
5219 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5220 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP
;
5222 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5223 omp_end_st
= ST_OMP_END_PARALLEL_MASKED_TASKLOOP_SIMD
;
5225 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5226 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP
;
5228 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5229 omp_end_st
= ST_OMP_END_PARALLEL_MASTER_TASKLOOP_SIMD
;
5231 case ST_OMP_TEAMS_DISTRIBUTE
:
5232 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5234 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5235 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO
;
5237 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5238 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
;
5240 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5241 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE_SIMD
;
5243 case ST_OMP_TEAMS_LOOP
:
5244 omp_end_st
= ST_OMP_END_TEAMS_LOOP
;
5246 default: gcc_unreachable ();
5248 if (st
== omp_end_st
)
5250 if (new_st
.op
== EXEC_OMP_END_NOWAIT
)
5251 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5253 gcc_assert (new_st
.op
== EXEC_NOP
);
5254 gfc_clear_new_st ();
5255 gfc_commit_symbols ();
5256 gfc_warning_check ();
5257 st
= next_statement ();
5263 /* Parse the statements of OpenMP atomic directive. */
5265 static gfc_statement
5266 parse_omp_oacc_atomic (bool omp_p
)
5268 gfc_statement st
, st_atomic
, st_end_atomic
;
5275 st_atomic
= ST_OMP_ATOMIC
;
5276 st_end_atomic
= ST_OMP_END_ATOMIC
;
5280 st_atomic
= ST_OACC_ATOMIC
;
5281 st_end_atomic
= ST_OACC_END_ATOMIC
;
5283 accept_statement (st_atomic
);
5285 cp
= gfc_state_stack
->tail
;
5286 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5287 np
= new_level (cp
);
5290 np
->ext
.omp_clauses
= cp
->ext
.omp_clauses
;
5291 cp
->ext
.omp_clauses
= NULL
;
5292 count
= 1 + np
->ext
.omp_clauses
->capture
;
5296 st
= next_statement ();
5299 else if (st
== ST_ASSIGNMENT
)
5301 accept_statement (st
);
5305 unexpected_statement (st
);
5310 st
= next_statement ();
5311 if (st
== st_end_atomic
)
5313 gfc_clear_new_st ();
5314 gfc_commit_symbols ();
5315 gfc_warning_check ();
5316 st
= next_statement ();
5318 else if (np
->ext
.omp_clauses
->capture
)
5319 gfc_error ("Missing !$OMP END ATOMIC after !$OMP ATOMIC CAPTURE at %C");
5324 /* Parse the statements of an OpenACC structured block. */
5327 parse_oacc_structured_block (gfc_statement acc_st
)
5329 gfc_statement st
, acc_end_st
;
5331 gfc_state_data s
, *sd
;
5333 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5334 if (sd
->state
== COMP_CRITICAL
)
5335 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5337 accept_statement (acc_st
);
5339 cp
= gfc_state_stack
->tail
;
5340 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5341 np
= new_level (cp
);
5346 case ST_OACC_PARALLEL
:
5347 acc_end_st
= ST_OACC_END_PARALLEL
;
5349 case ST_OACC_KERNELS
:
5350 acc_end_st
= ST_OACC_END_KERNELS
;
5352 case ST_OACC_SERIAL
:
5353 acc_end_st
= ST_OACC_END_SERIAL
;
5356 acc_end_st
= ST_OACC_END_DATA
;
5358 case ST_OACC_HOST_DATA
:
5359 acc_end_st
= ST_OACC_END_HOST_DATA
;
5367 st
= parse_executable (ST_NONE
);
5370 else if (st
!= acc_end_st
)
5372 gfc_error ("Expecting %s at %C", gfc_ascii_statement (acc_end_st
));
5373 reject_statement ();
5376 while (st
!= acc_end_st
);
5378 gcc_assert (new_st
.op
== EXEC_NOP
);
5380 gfc_clear_new_st ();
5381 gfc_commit_symbols ();
5382 gfc_warning_check ();
5386 /* Parse the statements of OpenACC 'loop', or combined compute 'loop'. */
5388 static gfc_statement
5389 parse_oacc_loop (gfc_statement acc_st
)
5393 gfc_state_data s
, *sd
;
5395 for (sd
= gfc_state_stack
; sd
; sd
= sd
->previous
)
5396 if (sd
->state
== COMP_CRITICAL
)
5397 gfc_error_now ("OpenACC directive inside of CRITICAL block at %C");
5399 accept_statement (acc_st
);
5401 cp
= gfc_state_stack
->tail
;
5402 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5403 np
= new_level (cp
);
5409 st
= next_statement ();
5412 else if (st
== ST_DO
)
5416 gfc_error ("Expected DO loop at %C");
5417 reject_statement ();
5422 if (gfc_statement_label
!= NULL
5423 && gfc_state_stack
->previous
!= NULL
5424 && gfc_state_stack
->previous
->state
== COMP_DO
5425 && gfc_state_stack
->previous
->ext
.end_do_label
== gfc_statement_label
)
5428 return ST_IMPLIED_ENDDO
;
5431 check_do_closure ();
5434 st
= next_statement ();
5435 if (st
== ST_OACC_END_LOOP
)
5436 gfc_warning (0, "Redundant !$ACC END LOOP at %C");
5437 if ((acc_st
== ST_OACC_PARALLEL_LOOP
&& st
== ST_OACC_END_PARALLEL_LOOP
) ||
5438 (acc_st
== ST_OACC_KERNELS_LOOP
&& st
== ST_OACC_END_KERNELS_LOOP
) ||
5439 (acc_st
== ST_OACC_SERIAL_LOOP
&& st
== ST_OACC_END_SERIAL_LOOP
) ||
5440 (acc_st
== ST_OACC_LOOP
&& st
== ST_OACC_END_LOOP
))
5442 gcc_assert (new_st
.op
== EXEC_NOP
);
5443 gfc_clear_new_st ();
5444 gfc_commit_symbols ();
5445 gfc_warning_check ();
5446 st
= next_statement ();
5452 /* Parse the statements of an OpenMP structured block. */
5455 parse_omp_structured_block (gfc_statement omp_st
, bool workshare_stmts_only
)
5457 gfc_statement st
, omp_end_st
;
5461 accept_statement (omp_st
);
5463 cp
= gfc_state_stack
->tail
;
5464 push_state (&s
, COMP_OMP_STRUCTURED_BLOCK
, NULL
);
5465 np
= new_level (cp
);
5471 case ST_OMP_PARALLEL
:
5472 omp_end_st
= ST_OMP_END_PARALLEL
;
5474 case ST_OMP_PARALLEL_MASKED
:
5475 omp_end_st
= ST_OMP_END_PARALLEL_MASKED
;
5477 case ST_OMP_PARALLEL_MASTER
:
5478 omp_end_st
= ST_OMP_END_PARALLEL_MASTER
;
5480 case ST_OMP_PARALLEL_SECTIONS
:
5481 omp_end_st
= ST_OMP_END_PARALLEL_SECTIONS
;
5484 omp_end_st
= ST_OMP_END_SCOPE
;
5486 case ST_OMP_SECTIONS
:
5487 omp_end_st
= ST_OMP_END_SECTIONS
;
5489 case ST_OMP_ORDERED
:
5490 omp_end_st
= ST_OMP_END_ORDERED
;
5492 case ST_OMP_CRITICAL
:
5493 omp_end_st
= ST_OMP_END_CRITICAL
;
5496 omp_end_st
= ST_OMP_END_MASKED
;
5499 omp_end_st
= ST_OMP_END_MASTER
;
5502 omp_end_st
= ST_OMP_END_SINGLE
;
5505 omp_end_st
= ST_OMP_END_TARGET
;
5507 case ST_OMP_TARGET_DATA
:
5508 omp_end_st
= ST_OMP_END_TARGET_DATA
;
5510 case ST_OMP_TARGET_PARALLEL
:
5511 omp_end_st
= ST_OMP_END_TARGET_PARALLEL
;
5513 case ST_OMP_TARGET_TEAMS
:
5514 omp_end_st
= ST_OMP_END_TARGET_TEAMS
;
5517 omp_end_st
= ST_OMP_END_TASK
;
5519 case ST_OMP_TASKGROUP
:
5520 omp_end_st
= ST_OMP_END_TASKGROUP
;
5523 omp_end_st
= ST_OMP_END_TEAMS
;
5525 case ST_OMP_TEAMS_DISTRIBUTE
:
5526 omp_end_st
= ST_OMP_END_TEAMS_DISTRIBUTE
;
5528 case ST_OMP_DISTRIBUTE
:
5529 omp_end_st
= ST_OMP_END_DISTRIBUTE
;
5531 case ST_OMP_WORKSHARE
:
5532 omp_end_st
= ST_OMP_END_WORKSHARE
;
5534 case ST_OMP_PARALLEL_WORKSHARE
:
5535 omp_end_st
= ST_OMP_END_PARALLEL_WORKSHARE
;
5543 if (workshare_stmts_only
)
5545 /* Inside of !$omp workshare, only
5548 where statements and constructs
5549 forall statements and constructs
5553 are allowed. For !$omp critical these
5554 restrictions apply recursively. */
5557 st
= next_statement ();
5568 accept_statement (st
);
5571 case ST_WHERE_BLOCK
:
5572 parse_where_block ();
5575 case ST_FORALL_BLOCK
:
5576 parse_forall_block ();
5579 case ST_OMP_PARALLEL
:
5580 case ST_OMP_PARALLEL_MASKED
:
5581 case ST_OMP_PARALLEL_MASTER
:
5582 case ST_OMP_PARALLEL_SECTIONS
:
5583 parse_omp_structured_block (st
, false);
5586 case ST_OMP_PARALLEL_WORKSHARE
:
5587 case ST_OMP_CRITICAL
:
5588 parse_omp_structured_block (st
, true);
5591 case ST_OMP_PARALLEL_DO
:
5592 case ST_OMP_PARALLEL_DO_SIMD
:
5593 st
= parse_omp_do (st
);
5597 st
= parse_omp_oacc_atomic (true);
5608 st
= next_statement ();
5612 st
= parse_executable (ST_NONE
);
5615 else if (st
== ST_OMP_SECTION
5616 && (omp_st
== ST_OMP_SECTIONS
5617 || omp_st
== ST_OMP_PARALLEL_SECTIONS
))
5619 np
= new_level (np
);
5623 else if (st
!= omp_end_st
)
5624 unexpected_statement (st
);
5626 while (st
!= omp_end_st
);
5630 case EXEC_OMP_END_NOWAIT
:
5631 cp
->ext
.omp_clauses
->nowait
|= new_st
.ext
.omp_bool
;
5633 case EXEC_OMP_END_CRITICAL
:
5634 if (((cp
->ext
.omp_clauses
->critical_name
== NULL
)
5635 ^ (new_st
.ext
.omp_name
== NULL
))
5636 || (new_st
.ext
.omp_name
!= NULL
5637 && strcmp (cp
->ext
.omp_clauses
->critical_name
,
5638 new_st
.ext
.omp_name
) != 0))
5639 gfc_error ("Name after !$omp critical and !$omp end critical does "
5641 free (CONST_CAST (char *, new_st
.ext
.omp_name
));
5642 new_st
.ext
.omp_name
= NULL
;
5644 case EXEC_OMP_END_SINGLE
:
5645 cp
->ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
]
5646 = new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
];
5647 new_st
.ext
.omp_clauses
->lists
[OMP_LIST_COPYPRIVATE
] = NULL
;
5648 gfc_free_omp_clauses (new_st
.ext
.omp_clauses
);
5656 gfc_clear_new_st ();
5657 gfc_commit_symbols ();
5658 gfc_warning_check ();
5663 /* Accept a series of executable statements. We return the first
5664 statement that doesn't fit to the caller. Any block statements are
5665 passed on to the correct handler, which usually passes the buck
5668 static gfc_statement
5669 parse_executable (gfc_statement st
)
5674 st
= next_statement ();
5678 close_flag
= check_do_closure ();
5683 case ST_END_PROGRAM
:
5686 case ST_END_FUNCTION
:
5691 case ST_END_SUBROUTINE
:
5696 case ST_SELECT_CASE
:
5697 gfc_error ("%s statement at %C cannot terminate a non-block "
5698 "DO loop", gfc_ascii_statement (st
));
5711 gfc_notify_std (GFC_STD_F95_OBS
, "DATA statement at %C after the "
5712 "first executable statement");
5718 accept_statement (st
);
5719 if (close_flag
== 1)
5720 return ST_IMPLIED_ENDDO
;
5724 parse_block_construct ();
5735 case ST_SELECT_CASE
:
5736 parse_select_block ();
5739 case ST_SELECT_TYPE
:
5740 parse_select_type_block ();
5743 case ST_SELECT_RANK
:
5744 parse_select_rank_block ();
5749 if (check_do_closure () == 1)
5750 return ST_IMPLIED_ENDDO
;
5754 parse_critical_block ();
5757 case ST_WHERE_BLOCK
:
5758 parse_where_block ();
5761 case ST_FORALL_BLOCK
:
5762 parse_forall_block ();
5765 case ST_OACC_PARALLEL_LOOP
:
5766 case ST_OACC_KERNELS_LOOP
:
5767 case ST_OACC_SERIAL_LOOP
:
5769 st
= parse_oacc_loop (st
);
5770 if (st
== ST_IMPLIED_ENDDO
)
5774 case ST_OACC_PARALLEL
:
5775 case ST_OACC_KERNELS
:
5776 case ST_OACC_SERIAL
:
5778 case ST_OACC_HOST_DATA
:
5779 parse_oacc_structured_block (st
);
5782 case ST_OMP_PARALLEL
:
5783 case ST_OMP_PARALLEL_MASKED
:
5784 case ST_OMP_PARALLEL_MASTER
:
5785 case ST_OMP_PARALLEL_SECTIONS
:
5786 case ST_OMP_ORDERED
:
5787 case ST_OMP_CRITICAL
:
5791 case ST_OMP_SECTIONS
:
5794 case ST_OMP_TARGET_DATA
:
5795 case ST_OMP_TARGET_PARALLEL
:
5796 case ST_OMP_TARGET_TEAMS
:
5799 case ST_OMP_TASKGROUP
:
5800 parse_omp_structured_block (st
, false);
5803 case ST_OMP_WORKSHARE
:
5804 case ST_OMP_PARALLEL_WORKSHARE
:
5805 parse_omp_structured_block (st
, true);
5808 case ST_OMP_DISTRIBUTE
:
5809 case ST_OMP_DISTRIBUTE_PARALLEL_DO
:
5810 case ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD
:
5811 case ST_OMP_DISTRIBUTE_SIMD
:
5813 case ST_OMP_DO_SIMD
:
5815 case ST_OMP_PARALLEL_DO
:
5816 case ST_OMP_PARALLEL_DO_SIMD
:
5817 case ST_OMP_PARALLEL_LOOP
:
5818 case ST_OMP_PARALLEL_MASKED_TASKLOOP
:
5819 case ST_OMP_PARALLEL_MASKED_TASKLOOP_SIMD
:
5820 case ST_OMP_PARALLEL_MASTER_TASKLOOP
:
5821 case ST_OMP_PARALLEL_MASTER_TASKLOOP_SIMD
:
5822 case ST_OMP_MASKED_TASKLOOP
:
5823 case ST_OMP_MASKED_TASKLOOP_SIMD
:
5824 case ST_OMP_MASTER_TASKLOOP
:
5825 case ST_OMP_MASTER_TASKLOOP_SIMD
:
5827 case ST_OMP_TARGET_PARALLEL_DO
:
5828 case ST_OMP_TARGET_PARALLEL_DO_SIMD
:
5829 case ST_OMP_TARGET_PARALLEL_LOOP
:
5830 case ST_OMP_TARGET_SIMD
:
5831 case ST_OMP_TARGET_TEAMS_DISTRIBUTE
:
5832 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5833 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5834 case ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD
:
5835 case ST_OMP_TARGET_TEAMS_LOOP
:
5836 case ST_OMP_TASKLOOP
:
5837 case ST_OMP_TASKLOOP_SIMD
:
5838 case ST_OMP_TEAMS_DISTRIBUTE
:
5839 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO
:
5840 case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD
:
5841 case ST_OMP_TEAMS_DISTRIBUTE_SIMD
:
5842 case ST_OMP_TEAMS_LOOP
:
5843 st
= parse_omp_do (st
);
5844 if (st
== ST_IMPLIED_ENDDO
)
5848 case ST_OACC_ATOMIC
:
5849 st
= parse_omp_oacc_atomic (false);
5853 st
= parse_omp_oacc_atomic (true);
5860 if (directive_unroll
!= -1)
5861 gfc_error ("%<GCC unroll%> directive not at the start of a loop at %C");
5863 if (directive_ivdep
)
5864 gfc_error ("%<GCC ivdep%> directive not at the start of a loop at %C");
5866 if (directive_vector
)
5867 gfc_error ("%<GCC vector%> directive not at the start of a loop at %C");
5869 if (directive_novector
)
5870 gfc_error ("%<GCC novector%> "
5871 "directive not at the start of a loop at %C");
5873 st
= next_statement ();
5878 /* Fix the symbols for sibling functions. These are incorrectly added to
5879 the child namespace as the parser didn't know about this procedure. */
5882 gfc_fixup_sibling_symbols (gfc_symbol
*sym
, gfc_namespace
*siblings
)
5886 gfc_symbol
*old_sym
;
5888 for (ns
= siblings
; ns
; ns
= ns
->sibling
)
5890 st
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
5892 if (!st
|| (st
->n
.sym
->attr
.dummy
&& ns
== st
->n
.sym
->ns
))
5893 goto fixup_contained
;
5895 if ((st
->n
.sym
->attr
.flavor
== FL_DERIVED
5896 && sym
->attr
.generic
&& sym
->attr
.function
)
5897 ||(sym
->attr
.flavor
== FL_DERIVED
5898 && st
->n
.sym
->attr
.generic
&& st
->n
.sym
->attr
.function
))
5899 goto fixup_contained
;
5901 old_sym
= st
->n
.sym
;
5902 if (old_sym
->ns
== ns
5903 && !old_sym
->attr
.contained
5905 /* By 14.6.1.3, host association should be excluded
5906 for the following. */
5907 && !(old_sym
->attr
.external
5908 || (old_sym
->ts
.type
!= BT_UNKNOWN
5909 && !old_sym
->attr
.implicit_type
)
5910 || old_sym
->attr
.flavor
== FL_PARAMETER
5911 || old_sym
->attr
.use_assoc
5912 || old_sym
->attr
.in_common
5913 || old_sym
->attr
.in_equivalence
5914 || old_sym
->attr
.data
5915 || old_sym
->attr
.dummy
5916 || old_sym
->attr
.result
5917 || old_sym
->attr
.dimension
5918 || old_sym
->attr
.allocatable
5919 || old_sym
->attr
.intrinsic
5920 || old_sym
->attr
.generic
5921 || old_sym
->attr
.flavor
== FL_NAMELIST
5922 || old_sym
->attr
.flavor
== FL_LABEL
5923 || old_sym
->attr
.proc
== PROC_ST_FUNCTION
))
5925 /* Replace it with the symbol from the parent namespace. */
5929 gfc_release_symbol (old_sym
);
5933 /* Do the same for any contained procedures. */
5934 gfc_fixup_sibling_symbols (sym
, ns
->contained
);
5939 parse_contained (int module
)
5941 gfc_namespace
*ns
, *parent_ns
, *tmp
;
5942 gfc_state_data s1
, s2
;
5947 int contains_statements
= 0;
5950 push_state (&s1
, COMP_CONTAINS
, NULL
);
5951 parent_ns
= gfc_current_ns
;
5955 gfc_current_ns
= gfc_get_namespace (parent_ns
, 1);
5957 gfc_current_ns
->sibling
= parent_ns
->contained
;
5958 parent_ns
->contained
= gfc_current_ns
;
5961 /* Process the next available statement. We come here if we got an error
5962 and rejected the last statement. */
5963 old_loc
= gfc_current_locus
;
5964 st
= next_statement ();
5973 contains_statements
= 1;
5974 accept_statement (st
);
5977 (st
== ST_FUNCTION
) ? COMP_FUNCTION
: COMP_SUBROUTINE
,
5980 /* For internal procedures, create/update the symbol in the
5981 parent namespace. */
5985 if (gfc_get_symbol (gfc_new_block
->name
, parent_ns
, &sym
))
5986 gfc_error ("Contained procedure %qs at %C is already "
5987 "ambiguous", gfc_new_block
->name
);
5990 if (gfc_add_procedure (&sym
->attr
, PROC_INTERNAL
,
5992 &gfc_new_block
->declared_at
))
5994 if (st
== ST_FUNCTION
)
5995 gfc_add_function (&sym
->attr
, sym
->name
,
5996 &gfc_new_block
->declared_at
);
5998 gfc_add_subroutine (&sym
->attr
, sym
->name
,
5999 &gfc_new_block
->declared_at
);
6003 gfc_commit_symbols ();
6006 sym
= gfc_new_block
;
6008 /* Mark this as a contained function, so it isn't replaced
6009 by other module functions. */
6010 sym
->attr
.contained
= 1;
6012 /* Set implicit_pure so that it can be reset if any of the
6013 tests for purity fail. This is used for some optimisation
6014 during translation. */
6015 if (!sym
->attr
.pure
)
6016 sym
->attr
.implicit_pure
= 1;
6018 parse_progunit (ST_NONE
);
6020 /* Fix up any sibling functions that refer to this one. */
6021 gfc_fixup_sibling_symbols (sym
, gfc_current_ns
);
6022 /* Or refer to any of its alternate entry points. */
6023 for (el
= gfc_current_ns
->entries
; el
; el
= el
->next
)
6024 gfc_fixup_sibling_symbols (el
->sym
, gfc_current_ns
);
6026 gfc_current_ns
->code
= s2
.head
;
6027 gfc_current_ns
= parent_ns
;
6032 /* These statements are associated with the end of the host unit. */
6033 case ST_END_FUNCTION
:
6035 case ST_END_SUBMODULE
:
6036 case ST_END_PROGRAM
:
6037 case ST_END_SUBROUTINE
:
6038 accept_statement (st
);
6039 gfc_current_ns
->code
= s1
.head
;
6043 gfc_error ("Unexpected %s statement in CONTAINS section at %C",
6044 gfc_ascii_statement (st
));
6045 reject_statement ();
6051 while (st
!= ST_END_FUNCTION
&& st
!= ST_END_SUBROUTINE
6052 && st
!= ST_END_MODULE
&& st
!= ST_END_SUBMODULE
6053 && st
!= ST_END_PROGRAM
);
6055 /* The first namespace in the list is guaranteed to not have
6056 anything (worthwhile) in it. */
6057 tmp
= gfc_current_ns
;
6058 gfc_current_ns
= parent_ns
;
6059 if (seen_error
&& tmp
->refs
> 1)
6060 gfc_free_namespace (tmp
);
6062 ns
= gfc_current_ns
->contained
;
6063 gfc_current_ns
->contained
= ns
->sibling
;
6064 gfc_free_namespace (ns
);
6067 if (!contains_statements
)
6068 gfc_notify_std (GFC_STD_F2008
, "CONTAINS statement without "
6069 "FUNCTION or SUBROUTINE statement at %L", &old_loc
);
6073 /* The result variable in a MODULE PROCEDURE needs to be created and
6074 its characteristics copied from the interface since it is neither
6075 declared in the procedure declaration nor in the specification
6079 get_modproc_result (void)
6082 if (gfc_state_stack
->previous
6083 && gfc_state_stack
->previous
->state
== COMP_CONTAINS
6084 && gfc_state_stack
->previous
->previous
->state
== COMP_SUBMODULE
)
6086 proc
= gfc_current_ns
->proc_name
? gfc_current_ns
->proc_name
: NULL
;
6088 && proc
->attr
.function
6090 && proc
->tlink
->result
6091 && proc
->tlink
->result
!= proc
->tlink
)
6093 gfc_copy_dummy_sym (&proc
->result
, proc
->tlink
->result
, 1);
6094 gfc_set_sym_referenced (proc
->result
);
6095 proc
->result
->attr
.if_source
= IFSRC_DECL
;
6096 gfc_commit_symbol (proc
->result
);
6102 /* Parse a PROGRAM, SUBROUTINE, FUNCTION unit or BLOCK construct. */
6105 parse_progunit (gfc_statement st
)
6110 gfc_adjust_builtins ();
6113 && gfc_new_block
->abr_modproc_decl
6114 && gfc_new_block
->attr
.function
)
6115 get_modproc_result ();
6117 st
= parse_spec (st
);
6124 /* This is not allowed within BLOCK! */
6125 if (gfc_current_state () != COMP_BLOCK
)
6130 accept_statement (st
);
6137 if (gfc_current_state () == COMP_FUNCTION
)
6138 gfc_check_function_type (gfc_current_ns
);
6143 st
= parse_executable (st
);
6151 /* This is not allowed within BLOCK! */
6152 if (gfc_current_state () != COMP_BLOCK
)
6157 accept_statement (st
);
6164 unexpected_statement (st
);
6165 reject_statement ();
6166 st
= next_statement ();
6172 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
6173 if (p
->state
== COMP_CONTAINS
)
6176 if (gfc_find_state (COMP_MODULE
) == true
6177 || gfc_find_state (COMP_SUBMODULE
) == true)
6182 gfc_error ("CONTAINS statement at %C is already in a contained "
6184 reject_statement ();
6185 st
= next_statement ();
6189 parse_contained (0);
6192 gfc_current_ns
->code
= gfc_state_stack
->head
;
6196 /* Come here to complain about a global symbol already in use as
6200 gfc_global_used (gfc_gsymbol
*sym
, locus
*where
)
6205 where
= &gfc_current_locus
;
6215 case GSYM_SUBROUTINE
:
6216 name
= "SUBROUTINE";
6221 case GSYM_BLOCK_DATA
:
6222 name
= "BLOCK DATA";
6233 if (sym
->binding_label
)
6234 gfc_error ("Global binding name %qs at %L is already being used "
6235 "as a %s at %L", sym
->binding_label
, where
, name
,
6238 gfc_error ("Global name %qs at %L is already being used as "
6239 "a %s at %L", sym
->name
, where
, name
, &sym
->where
);
6243 if (sym
->binding_label
)
6244 gfc_error ("Global binding name %qs at %L is already being used "
6245 "at %L", sym
->binding_label
, where
, &sym
->where
);
6247 gfc_error ("Global name %qs at %L is already being used at %L",
6248 sym
->name
, where
, &sym
->where
);
6253 /* Parse a block data program unit. */
6256 parse_block_data (void)
6259 static locus blank_locus
;
6260 static int blank_block
=0;
6263 gfc_current_ns
->proc_name
= gfc_new_block
;
6264 gfc_current_ns
->is_block_data
= 1;
6266 if (gfc_new_block
== NULL
)
6269 gfc_error ("Blank BLOCK DATA at %C conflicts with "
6270 "prior BLOCK DATA at %L", &blank_locus
);
6274 blank_locus
= gfc_current_locus
;
6279 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6281 || (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_BLOCK_DATA
))
6282 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6285 s
->type
= GSYM_BLOCK_DATA
;
6286 s
->where
= gfc_new_block
->declared_at
;
6291 st
= parse_spec (ST_NONE
);
6293 while (st
!= ST_END_BLOCK_DATA
)
6295 gfc_error ("Unexpected %s statement in BLOCK DATA at %C",
6296 gfc_ascii_statement (st
));
6297 reject_statement ();
6298 st
= next_statement ();
6303 /* Following the association of the ancestor (sub)module symbols, they
6304 must be set host rather than use associated and all must be public.
6305 They are flagged up by 'used_in_submodule' so that they can be set
6306 DECL_EXTERNAL in trans_decl.c(gfc_finish_var_decl). Otherwise the
6307 linker chokes on multiple symbol definitions. */
6310 set_syms_host_assoc (gfc_symbol
*sym
)
6313 const char dot
[2] = ".";
6314 /* Symbols take the form module.submodule_ or module.name_. */
6315 char parent1
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6316 char parent2
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
6321 if (sym
->attr
.module_procedure
)
6322 sym
->attr
.external
= 0;
6324 sym
->attr
.use_assoc
= 0;
6325 sym
->attr
.host_assoc
= 1;
6326 sym
->attr
.used_in_submodule
=1;
6328 if (sym
->attr
.flavor
== FL_DERIVED
)
6330 /* Derived types with PRIVATE components that are declared in
6331 modules other than the parent module must not be changed to be
6332 PUBLIC. The 'use-assoc' attribute must be reset so that the
6333 test in symbol.c(gfc_find_component) works correctly. This is
6334 not necessary for PRIVATE symbols since they are not read from
6336 memset(parent1
, '\0', sizeof(parent1
));
6337 memset(parent2
, '\0', sizeof(parent2
));
6338 strcpy (parent1
, gfc_new_block
->name
);
6339 strcpy (parent2
, sym
->module
);
6340 if (strcmp (strtok (parent1
, dot
), strtok (parent2
, dot
)) == 0)
6342 for (c
= sym
->components
; c
; c
= c
->next
)
6343 c
->attr
.access
= ACCESS_PUBLIC
;
6347 sym
->attr
.use_assoc
= 1;
6348 sym
->attr
.host_assoc
= 0;
6353 /* Parse a module subprogram. */
6362 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6363 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_MODULE
))
6364 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6367 s
->type
= GSYM_MODULE
;
6368 s
->where
= gfc_new_block
->declared_at
;
6372 /* Something is nulling the module_list after this point. This is good
6373 since it allows us to 'USE' the parent modules that the submodule
6374 inherits and to set (most) of the symbols as host associated. */
6375 if (gfc_current_state () == COMP_SUBMODULE
)
6378 gfc_traverse_ns (gfc_current_ns
, set_syms_host_assoc
);
6381 st
= parse_spec (ST_NONE
);
6391 parse_contained (1);
6395 case ST_END_SUBMODULE
:
6396 accept_statement (st
);
6400 gfc_error ("Unexpected %s statement in MODULE at %C",
6401 gfc_ascii_statement (st
));
6404 reject_statement ();
6405 st
= next_statement ();
6409 /* Make sure not to free the namespace twice on error. */
6411 s
->ns
= gfc_current_ns
;
6415 /* Add a procedure name to the global symbol table. */
6418 add_global_procedure (bool sub
)
6422 /* Only in Fortran 2003: For procedures with a binding label also the Fortran
6423 name is a global identifier. */
6424 if (!gfc_new_block
->binding_label
|| gfc_notification_std (GFC_STD_F2008
))
6426 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6429 || (s
->type
!= GSYM_UNKNOWN
6430 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6432 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6433 /* Silence follow-up errors. */
6434 gfc_new_block
->binding_label
= NULL
;
6438 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6439 s
->sym_name
= gfc_new_block
->name
;
6440 s
->where
= gfc_new_block
->declared_at
;
6442 s
->ns
= gfc_current_ns
;
6446 /* Don't add the symbol multiple times. */
6447 if (gfc_new_block
->binding_label
6448 && (!gfc_notification_std (GFC_STD_F2008
)
6449 || strcmp (gfc_new_block
->name
, gfc_new_block
->binding_label
) != 0))
6451 s
= gfc_get_gsymbol (gfc_new_block
->binding_label
, true);
6454 || (s
->type
!= GSYM_UNKNOWN
6455 && s
->type
!= (sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
)))
6457 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6458 /* Silence follow-up errors. */
6459 gfc_new_block
->binding_label
= NULL
;
6463 s
->type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
6464 s
->sym_name
= gfc_new_block
->name
;
6465 s
->binding_label
= gfc_new_block
->binding_label
;
6466 s
->where
= gfc_new_block
->declared_at
;
6468 s
->ns
= gfc_current_ns
;
6474 /* Add a program to the global symbol table. */
6477 add_global_program (void)
6481 if (gfc_new_block
== NULL
)
6483 s
= gfc_get_gsymbol (gfc_new_block
->name
, false);
6485 if (s
->defined
|| (s
->type
!= GSYM_UNKNOWN
&& s
->type
!= GSYM_PROGRAM
))
6486 gfc_global_used (s
, &gfc_new_block
->declared_at
);
6489 s
->type
= GSYM_PROGRAM
;
6490 s
->where
= gfc_new_block
->declared_at
;
6492 s
->ns
= gfc_current_ns
;
6497 /* Resolve all the program units. */
6499 resolve_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6501 gfc_derived_types
= NULL
;
6502 gfc_current_ns
= gfc_global_ns_list
;
6503 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6505 if (gfc_current_ns
->proc_name
6506 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6507 continue; /* Already resolved. */
6509 if (gfc_current_ns
->proc_name
)
6510 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6511 gfc_resolve (gfc_current_ns
);
6512 gfc_current_ns
->derived_types
= gfc_derived_types
;
6513 gfc_derived_types
= NULL
;
6519 clean_up_modules (gfc_gsymbol
*gsym
)
6524 clean_up_modules (gsym
->left
);
6525 clean_up_modules (gsym
->right
);
6527 if (gsym
->type
!= GSYM_MODULE
|| !gsym
->ns
)
6530 gfc_current_ns
= gsym
->ns
;
6531 gfc_derived_types
= gfc_current_ns
->derived_types
;
6538 /* Translate all the program units. This could be in a different order
6539 to resolution if there are forward references in the file. */
6541 translate_all_program_units (gfc_namespace
*gfc_global_ns_list
)
6545 gfc_current_ns
= gfc_global_ns_list
;
6546 gfc_get_errors (NULL
, &errors
);
6548 /* We first translate all modules to make sure that later parts
6549 of the program can use the decl. Then we translate the nonmodules. */
6551 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6553 if (!gfc_current_ns
->proc_name
6554 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6557 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6558 gfc_derived_types
= gfc_current_ns
->derived_types
;
6559 gfc_generate_module_code (gfc_current_ns
);
6560 gfc_current_ns
->translated
= 1;
6563 gfc_current_ns
= gfc_global_ns_list
;
6564 for (; !errors
&& gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6566 if (gfc_current_ns
->proc_name
6567 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6570 gfc_current_locus
= gfc_current_ns
->proc_name
->declared_at
;
6571 gfc_derived_types
= gfc_current_ns
->derived_types
;
6572 gfc_generate_code (gfc_current_ns
);
6573 gfc_current_ns
->translated
= 1;
6576 /* Clean up all the namespaces after translation. */
6577 gfc_current_ns
= gfc_global_ns_list
;
6578 for (;gfc_current_ns
;)
6582 if (gfc_current_ns
->proc_name
6583 && gfc_current_ns
->proc_name
->attr
.flavor
== FL_MODULE
)
6585 gfc_current_ns
= gfc_current_ns
->sibling
;
6589 ns
= gfc_current_ns
->sibling
;
6590 gfc_derived_types
= gfc_current_ns
->derived_types
;
6592 gfc_current_ns
= ns
;
6595 clean_up_modules (gfc_gsym_root
);
6599 /* Top level parser. */
6602 gfc_parse_file (void)
6604 int seen_program
, errors_before
, errors
;
6605 gfc_state_data top
, s
;
6608 gfc_namespace
*next
;
6610 gfc_start_source_files ();
6612 top
.state
= COMP_NONE
;
6614 top
.previous
= NULL
;
6615 top
.head
= top
.tail
= NULL
;
6616 top
.do_variable
= NULL
;
6618 gfc_state_stack
= &top
;
6620 gfc_clear_new_st ();
6622 gfc_statement_label
= NULL
;
6624 if (setjmp (eof_buf
))
6625 return false; /* Come here on unexpected EOF */
6627 /* Prepare the global namespace that will contain the
6629 gfc_global_ns_list
= next
= NULL
;
6634 /* Exit early for empty files. */
6638 in_specification_block
= true;
6641 st
= next_statement ();
6650 goto duplicate_main
;
6652 prog_locus
= gfc_current_locus
;
6654 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6655 main_program_symbol (gfc_current_ns
, gfc_new_block
->name
);
6656 accept_statement (st
);
6657 add_global_program ();
6658 parse_progunit (ST_NONE
);
6662 add_global_procedure (true);
6663 push_state (&s
, COMP_SUBROUTINE
, gfc_new_block
);
6664 accept_statement (st
);
6665 parse_progunit (ST_NONE
);
6669 add_global_procedure (false);
6670 push_state (&s
, COMP_FUNCTION
, gfc_new_block
);
6671 accept_statement (st
);
6672 parse_progunit (ST_NONE
);
6676 push_state (&s
, COMP_BLOCK_DATA
, gfc_new_block
);
6677 accept_statement (st
);
6678 parse_block_data ();
6682 push_state (&s
, COMP_MODULE
, gfc_new_block
);
6683 accept_statement (st
);
6685 gfc_get_errors (NULL
, &errors_before
);
6690 push_state (&s
, COMP_SUBMODULE
, gfc_new_block
);
6691 accept_statement (st
);
6693 gfc_get_errors (NULL
, &errors_before
);
6697 /* Anything else starts a nameless main program block. */
6700 goto duplicate_main
;
6702 prog_locus
= gfc_current_locus
;
6704 push_state (&s
, COMP_PROGRAM
, gfc_new_block
);
6705 main_program_symbol (gfc_current_ns
, "MAIN__");
6706 parse_progunit (st
);
6710 /* Handle the non-program units. */
6711 gfc_current_ns
->code
= s
.head
;
6713 gfc_resolve (gfc_current_ns
);
6715 /* Fix the implicit_pure attribute for those procedures who should
6717 while (gfc_fix_implicit_pure (gfc_current_ns
))
6720 /* Dump the parse tree if requested. */
6721 if (flag_dump_fortran_original
)
6722 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6724 gfc_get_errors (NULL
, &errors
);
6725 if (s
.state
== COMP_MODULE
|| s
.state
== COMP_SUBMODULE
)
6727 gfc_dump_module (s
.sym
->name
, errors_before
== errors
);
6728 gfc_current_ns
->derived_types
= gfc_derived_types
;
6729 gfc_derived_types
= NULL
;
6735 gfc_generate_code (gfc_current_ns
);
6743 /* The main program and non-contained procedures are put
6744 in the global namespace list, so that they can be processed
6745 later and all their interfaces resolved. */
6746 gfc_current_ns
->code
= s
.head
;
6749 for (; next
->sibling
; next
= next
->sibling
)
6751 next
->sibling
= gfc_current_ns
;
6754 gfc_global_ns_list
= gfc_current_ns
;
6756 next
= gfc_current_ns
;
6762 /* Do the resolution. */
6763 resolve_all_program_units (gfc_global_ns_list
);
6765 /* Go through all top-level namespaces and unset the implicit_pure
6766 attribute for any procedures that call something not pure or
6767 implicit_pure. Because the a procedure marked as not implicit_pure
6768 in one sweep may be called by another routine, we repeat this
6769 process until there are no more changes. */
6774 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6775 gfc_current_ns
= gfc_current_ns
->sibling
)
6777 if (gfc_fix_implicit_pure (gfc_current_ns
))
6783 /* Fixup for external procedures and resolve 'omp requires'. */
6786 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6787 gfc_current_ns
= gfc_current_ns
->sibling
)
6789 omp_requires
|= gfc_current_ns
->omp_requires
;
6790 gfc_check_externals (gfc_current_ns
);
6792 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6793 gfc_current_ns
= gfc_current_ns
->sibling
)
6794 gfc_check_omp_requires (gfc_current_ns
, omp_requires
);
6796 /* Do the parse tree dump. */
6797 gfc_current_ns
= flag_dump_fortran_original
? gfc_global_ns_list
: NULL
;
6799 for (; gfc_current_ns
; gfc_current_ns
= gfc_current_ns
->sibling
)
6800 if (!gfc_current_ns
->proc_name
6801 || gfc_current_ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
6803 gfc_dump_parse_tree (gfc_current_ns
, stdout
);
6804 fputs ("------------------------------------------\n\n", stdout
);
6807 /* Dump C prototypes. */
6808 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6811 "#include <stddef.h>\n"
6812 "#ifdef __cplusplus\n"
6813 "#include <complex>\n"
6814 "#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>\n"
6815 "#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>\n"
6816 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>\n"
6819 "#define __GFORTRAN_FLOAT_COMPLEX float _Complex\n"
6820 "#define __GFORTRAN_DOUBLE_COMPLEX double _Complex\n"
6821 "#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex\n"
6825 /* First dump BIND(C) prototypes. */
6826 if (flag_c_prototypes
)
6828 for (gfc_current_ns
= gfc_global_ns_list
; gfc_current_ns
;
6829 gfc_current_ns
= gfc_current_ns
->sibling
)
6830 gfc_dump_c_prototypes (gfc_current_ns
, stdout
);
6833 /* Dump external prototypes. */
6834 if (flag_c_prototypes_external
)
6835 gfc_dump_external_c_prototypes (stdout
);
6837 if (flag_c_prototypes
|| flag_c_prototypes_external
)
6838 fprintf (stdout
, "\n#ifdef __cplusplus\n}\n#endif\n");
6840 /* Do the translation. */
6841 translate_all_program_units (gfc_global_ns_list
);
6843 /* Dump the global symbol ist. We only do this here because part
6844 of it is generated after mangling the identifiers in
6847 if (flag_dump_fortran_global
)
6848 gfc_dump_global_symbols (stdout
);
6850 gfc_end_source_files ();
6854 /* If we see a duplicate main program, shut down. If the second
6855 instance is an implied main program, i.e. data decls or executable
6856 statements, we're in for lots of errors. */
6857 gfc_error ("Two main PROGRAMs at %L and %C", &prog_locus
);
6858 reject_statement ();
6863 /* Return true if this state data represents an OpenACC region. */
6865 is_oacc (gfc_state_data
*sd
)
6867 switch (sd
->construct
->op
)
6869 case EXEC_OACC_PARALLEL_LOOP
:
6870 case EXEC_OACC_PARALLEL
:
6871 case EXEC_OACC_KERNELS_LOOP
:
6872 case EXEC_OACC_KERNELS
:
6873 case EXEC_OACC_SERIAL_LOOP
:
6874 case EXEC_OACC_SERIAL
:
6875 case EXEC_OACC_DATA
:
6876 case EXEC_OACC_HOST_DATA
:
6877 case EXEC_OACC_LOOP
:
6878 case EXEC_OACC_UPDATE
:
6879 case EXEC_OACC_WAIT
:
6880 case EXEC_OACC_CACHE
:
6881 case EXEC_OACC_ENTER_DATA
:
6882 case EXEC_OACC_EXIT_DATA
:
6883 case EXEC_OACC_ATOMIC
:
6884 case EXEC_OACC_ROUTINE
: