1 /* Perform type resolution on the various structures.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
28 #include "arith.h" /* For gfc_compare_expr(). */
29 #include "dependency.h"
31 #include "target-memory.h" /* for gfc_simplify_transfer */
33 /* Types used in equivalence statements. */
37 SEQ_NONDEFAULT
, SEQ_NUMERIC
, SEQ_CHARACTER
, SEQ_MIXED
41 /* Stack to keep track of the nesting of blocks as we move through the
42 code. See resolve_branch() and resolve_code(). */
44 typedef struct code_stack
46 struct gfc_code
*head
, *current
;
47 struct code_stack
*prev
;
49 /* This bitmap keeps track of the targets valid for a branch from
50 inside this block except for END {IF|SELECT}s of enclosing
52 bitmap reachable_labels
;
56 static code_stack
*cs_base
= NULL
;
59 /* Nonzero if we're inside a FORALL block. */
61 static int forall_flag
;
63 /* Nonzero if we're inside a OpenMP WORKSHARE or PARALLEL WORKSHARE block. */
65 static int omp_workshare_flag
;
67 /* Nonzero if we are processing a formal arglist. The corresponding function
68 resets the flag each time that it is read. */
69 static int formal_arg_flag
= 0;
71 /* True if we are resolving a specification expression. */
72 static int specification_expr
= 0;
74 /* The id of the last entry seen. */
75 static int current_entry_id
;
77 /* We use bitmaps to determine if a branch target is valid. */
78 static bitmap_obstack labels_obstack
;
81 gfc_is_formal_arg (void)
83 return formal_arg_flag
;
86 /* Is the symbol host associated? */
88 is_sym_host_assoc (gfc_symbol
*sym
, gfc_namespace
*ns
)
90 for (ns
= ns
->parent
; ns
; ns
= ns
->parent
)
99 /* Ensure a typespec used is valid; for instance, TYPE(t) is invalid if t is
100 an ABSTRACT derived-type. If where is not NULL, an error message with that
101 locus is printed, optionally using name. */
104 resolve_typespec_used (gfc_typespec
* ts
, locus
* where
, const char* name
)
106 if (ts
->type
== BT_DERIVED
&& ts
->derived
->attr
.abstract
)
111 gfc_error ("'%s' at %L is of the ABSTRACT type '%s'",
112 name
, where
, ts
->derived
->name
);
114 gfc_error ("ABSTRACT type '%s' used at %L",
115 ts
->derived
->name
, where
);
125 /* Resolve types of formal argument lists. These have to be done early so that
126 the formal argument lists of module procedures can be copied to the
127 containing module before the individual procedures are resolved
128 individually. We also resolve argument lists of procedures in interface
129 blocks because they are self-contained scoping units.
131 Since a dummy argument cannot be a non-dummy procedure, the only
132 resort left for untyped names are the IMPLICIT types. */
135 resolve_formal_arglist (gfc_symbol
*proc
)
137 gfc_formal_arglist
*f
;
141 if (proc
->result
!= NULL
)
146 if (gfc_elemental (proc
)
147 || sym
->attr
.pointer
|| sym
->attr
.allocatable
148 || (sym
->as
&& sym
->as
->rank
> 0))
150 proc
->attr
.always_explicit
= 1;
151 sym
->attr
.always_explicit
= 1;
156 for (f
= proc
->formal
; f
; f
= f
->next
)
162 /* Alternate return placeholder. */
163 if (gfc_elemental (proc
))
164 gfc_error ("Alternate return specifier in elemental subroutine "
165 "'%s' at %L is not allowed", proc
->name
,
167 if (proc
->attr
.function
)
168 gfc_error ("Alternate return specifier in function "
169 "'%s' at %L is not allowed", proc
->name
,
174 if (sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
175 resolve_formal_arglist (sym
);
177 if (sym
->attr
.subroutine
|| sym
->attr
.external
|| sym
->attr
.intrinsic
)
179 if (gfc_pure (proc
) && !gfc_pure (sym
))
181 gfc_error ("Dummy procedure '%s' of PURE procedure at %L must "
182 "also be PURE", sym
->name
, &sym
->declared_at
);
186 if (gfc_elemental (proc
))
188 gfc_error ("Dummy procedure at %L not allowed in ELEMENTAL "
189 "procedure", &sym
->declared_at
);
193 if (sym
->attr
.function
194 && sym
->ts
.type
== BT_UNKNOWN
195 && sym
->attr
.intrinsic
)
197 gfc_intrinsic_sym
*isym
;
198 isym
= gfc_find_function (sym
->name
);
199 if (isym
== NULL
|| !isym
->specific
)
201 gfc_error ("Unable to find a specific INTRINSIC procedure "
202 "for the reference '%s' at %L", sym
->name
,
211 if (sym
->ts
.type
== BT_UNKNOWN
)
213 if (!sym
->attr
.function
|| sym
->result
== sym
)
214 gfc_set_default_type (sym
, 1, sym
->ns
);
217 gfc_resolve_array_spec (sym
->as
, 0);
219 /* We can't tell if an array with dimension (:) is assumed or deferred
220 shape until we know if it has the pointer or allocatable attributes.
222 if (sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_DEFERRED
223 && !(sym
->attr
.pointer
|| sym
->attr
.allocatable
))
225 sym
->as
->type
= AS_ASSUMED_SHAPE
;
226 for (i
= 0; i
< sym
->as
->rank
; i
++)
227 sym
->as
->lower
[i
] = gfc_int_expr (1);
230 if ((sym
->as
&& sym
->as
->rank
> 0 && sym
->as
->type
== AS_ASSUMED_SHAPE
)
231 || sym
->attr
.pointer
|| sym
->attr
.allocatable
|| sym
->attr
.target
232 || sym
->attr
.optional
)
234 proc
->attr
.always_explicit
= 1;
236 proc
->result
->attr
.always_explicit
= 1;
239 /* If the flavor is unknown at this point, it has to be a variable.
240 A procedure specification would have already set the type. */
242 if (sym
->attr
.flavor
== FL_UNKNOWN
)
243 gfc_add_flavor (&sym
->attr
, FL_VARIABLE
, sym
->name
, &sym
->declared_at
);
245 if (gfc_pure (proc
) && !sym
->attr
.pointer
246 && sym
->attr
.flavor
!= FL_PROCEDURE
)
248 if (proc
->attr
.function
&& sym
->attr
.intent
!= INTENT_IN
)
249 gfc_error ("Argument '%s' of pure function '%s' at %L must be "
250 "INTENT(IN)", sym
->name
, proc
->name
,
253 if (proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_UNKNOWN
)
254 gfc_error ("Argument '%s' of pure subroutine '%s' at %L must "
255 "have its INTENT specified", sym
->name
, proc
->name
,
259 if (gfc_elemental (proc
))
263 gfc_error ("Argument '%s' of elemental procedure at %L must "
264 "be scalar", sym
->name
, &sym
->declared_at
);
268 if (sym
->attr
.pointer
)
270 gfc_error ("Argument '%s' of elemental procedure at %L cannot "
271 "have the POINTER attribute", sym
->name
,
276 if (sym
->attr
.flavor
== FL_PROCEDURE
)
278 gfc_error ("Dummy procedure '%s' not allowed in elemental "
279 "procedure '%s' at %L", sym
->name
, proc
->name
,
285 /* Each dummy shall be specified to be scalar. */
286 if (proc
->attr
.proc
== PROC_ST_FUNCTION
)
290 gfc_error ("Argument '%s' of statement function at %L must "
291 "be scalar", sym
->name
, &sym
->declared_at
);
295 if (sym
->ts
.type
== BT_CHARACTER
)
297 gfc_charlen
*cl
= sym
->ts
.cl
;
298 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
300 gfc_error ("Character-valued argument '%s' of statement "
301 "function at %L must have constant length",
302 sym
->name
, &sym
->declared_at
);
312 /* Work function called when searching for symbols that have argument lists
313 associated with them. */
316 find_arglists (gfc_symbol
*sym
)
318 if (sym
->attr
.if_source
== IFSRC_UNKNOWN
|| sym
->ns
!= gfc_current_ns
)
321 resolve_formal_arglist (sym
);
325 /* Given a namespace, resolve all formal argument lists within the namespace.
329 resolve_formal_arglists (gfc_namespace
*ns
)
334 gfc_traverse_ns (ns
, find_arglists
);
339 resolve_contained_fntype (gfc_symbol
*sym
, gfc_namespace
*ns
)
343 /* If this namespace is not a function or an entry master function,
345 if (! sym
|| !(sym
->attr
.function
|| sym
->attr
.flavor
== FL_VARIABLE
)
346 || sym
->attr
.entry_master
)
349 /* Try to find out of what the return type is. */
350 if (sym
->result
->ts
.type
== BT_UNKNOWN
)
352 t
= gfc_set_default_type (sym
->result
, 0, ns
);
354 if (t
== FAILURE
&& !sym
->result
->attr
.untyped
)
356 if (sym
->result
== sym
)
357 gfc_error ("Contained function '%s' at %L has no IMPLICIT type",
358 sym
->name
, &sym
->declared_at
);
359 else if (!sym
->result
->attr
.proc_pointer
)
360 gfc_error ("Result '%s' of contained function '%s' at %L has "
361 "no IMPLICIT type", sym
->result
->name
, sym
->name
,
362 &sym
->result
->declared_at
);
363 sym
->result
->attr
.untyped
= 1;
367 /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
368 type, lists the only ways a character length value of * can be used:
369 dummy arguments of procedures, named constants, and function results
370 in external functions. Internal function results are not on that list;
371 ergo, not permitted. */
373 if (sym
->result
->ts
.type
== BT_CHARACTER
)
375 gfc_charlen
*cl
= sym
->result
->ts
.cl
;
376 if (!cl
|| !cl
->length
)
377 gfc_error ("Character-valued internal function '%s' at %L must "
378 "not be assumed length", sym
->name
, &sym
->declared_at
);
383 /* Add NEW_ARGS to the formal argument list of PROC, taking care not to
384 introduce duplicates. */
387 merge_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
389 gfc_formal_arglist
*f
, *new_arglist
;
392 for (; new_args
!= NULL
; new_args
= new_args
->next
)
394 new_sym
= new_args
->sym
;
395 /* See if this arg is already in the formal argument list. */
396 for (f
= proc
->formal
; f
; f
= f
->next
)
398 if (new_sym
== f
->sym
)
405 /* Add a new argument. Argument order is not important. */
406 new_arglist
= gfc_get_formal_arglist ();
407 new_arglist
->sym
= new_sym
;
408 new_arglist
->next
= proc
->formal
;
409 proc
->formal
= new_arglist
;
414 /* Flag the arguments that are not present in all entries. */
417 check_argument_lists (gfc_symbol
*proc
, gfc_formal_arglist
*new_args
)
419 gfc_formal_arglist
*f
, *head
;
422 for (f
= proc
->formal
; f
; f
= f
->next
)
427 for (new_args
= head
; new_args
; new_args
= new_args
->next
)
429 if (new_args
->sym
== f
->sym
)
436 f
->sym
->attr
.not_always_present
= 1;
441 /* Resolve alternate entry points. If a symbol has multiple entry points we
442 create a new master symbol for the main routine, and turn the existing
443 symbol into an entry point. */
446 resolve_entries (gfc_namespace
*ns
)
448 gfc_namespace
*old_ns
;
452 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
453 static int master_count
= 0;
455 if (ns
->proc_name
== NULL
)
458 /* No need to do anything if this procedure doesn't have alternate entry
463 /* We may already have resolved alternate entry points. */
464 if (ns
->proc_name
->attr
.entry_master
)
467 /* If this isn't a procedure something has gone horribly wrong. */
468 gcc_assert (ns
->proc_name
->attr
.flavor
== FL_PROCEDURE
);
470 /* Remember the current namespace. */
471 old_ns
= gfc_current_ns
;
475 /* Add the main entry point to the list of entry points. */
476 el
= gfc_get_entry_list ();
477 el
->sym
= ns
->proc_name
;
479 el
->next
= ns
->entries
;
481 ns
->proc_name
->attr
.entry
= 1;
483 /* If it is a module function, it needs to be in the right namespace
484 so that gfc_get_fake_result_decl can gather up the results. The
485 need for this arose in get_proc_name, where these beasts were
486 left in their own namespace, to keep prior references linked to
487 the entry declaration.*/
488 if (ns
->proc_name
->attr
.function
489 && ns
->parent
&& ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
492 /* Do the same for entries where the master is not a module
493 procedure. These are retained in the module namespace because
494 of the module procedure declaration. */
495 for (el
= el
->next
; el
; el
= el
->next
)
496 if (el
->sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
497 && el
->sym
->attr
.mod_proc
)
501 /* Add an entry statement for it. */
508 /* Create a new symbol for the master function. */
509 /* Give the internal function a unique name (within this file).
510 Also include the function name so the user has some hope of figuring
511 out what is going on. */
512 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "master.%d.%s",
513 master_count
++, ns
->proc_name
->name
);
514 gfc_get_ha_symbol (name
, &proc
);
515 gcc_assert (proc
!= NULL
);
517 gfc_add_procedure (&proc
->attr
, PROC_INTERNAL
, proc
->name
, NULL
);
518 if (ns
->proc_name
->attr
.subroutine
)
519 gfc_add_subroutine (&proc
->attr
, proc
->name
, NULL
);
523 gfc_typespec
*ts
, *fts
;
524 gfc_array_spec
*as
, *fas
;
525 gfc_add_function (&proc
->attr
, proc
->name
, NULL
);
527 fas
= ns
->entries
->sym
->as
;
528 fas
= fas
? fas
: ns
->entries
->sym
->result
->as
;
529 fts
= &ns
->entries
->sym
->result
->ts
;
530 if (fts
->type
== BT_UNKNOWN
)
531 fts
= gfc_get_default_type (ns
->entries
->sym
->result
, NULL
);
532 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
534 ts
= &el
->sym
->result
->ts
;
536 as
= as
? as
: el
->sym
->result
->as
;
537 if (ts
->type
== BT_UNKNOWN
)
538 ts
= gfc_get_default_type (el
->sym
->result
, NULL
);
540 if (! gfc_compare_types (ts
, fts
)
541 || (el
->sym
->result
->attr
.dimension
542 != ns
->entries
->sym
->result
->attr
.dimension
)
543 || (el
->sym
->result
->attr
.pointer
544 != ns
->entries
->sym
->result
->attr
.pointer
))
546 else if (as
&& fas
&& ns
->entries
->sym
->result
!= el
->sym
->result
547 && gfc_compare_array_spec (as
, fas
) == 0)
548 gfc_error ("Function %s at %L has entries with mismatched "
549 "array specifications", ns
->entries
->sym
->name
,
550 &ns
->entries
->sym
->declared_at
);
551 /* The characteristics need to match and thus both need to have
552 the same string length, i.e. both len=*, or both len=4.
553 Having both len=<variable> is also possible, but difficult to
554 check at compile time. */
555 else if (ts
->type
== BT_CHARACTER
&& ts
->cl
&& fts
->cl
556 && (((ts
->cl
->length
&& !fts
->cl
->length
)
557 ||(!ts
->cl
->length
&& fts
->cl
->length
))
559 && ts
->cl
->length
->expr_type
560 != fts
->cl
->length
->expr_type
)
562 && ts
->cl
->length
->expr_type
== EXPR_CONSTANT
563 && mpz_cmp (ts
->cl
->length
->value
.integer
,
564 fts
->cl
->length
->value
.integer
) != 0)))
565 gfc_notify_std (GFC_STD_GNU
, "Extension: Function %s at %L with "
566 "entries returning variables of different "
567 "string lengths", ns
->entries
->sym
->name
,
568 &ns
->entries
->sym
->declared_at
);
573 sym
= ns
->entries
->sym
->result
;
574 /* All result types the same. */
576 if (sym
->attr
.dimension
)
577 gfc_set_array_spec (proc
, gfc_copy_array_spec (sym
->as
), NULL
);
578 if (sym
->attr
.pointer
)
579 gfc_add_pointer (&proc
->attr
, NULL
);
583 /* Otherwise the result will be passed through a union by
585 proc
->attr
.mixed_entry_master
= 1;
586 for (el
= ns
->entries
; el
; el
= el
->next
)
588 sym
= el
->sym
->result
;
589 if (sym
->attr
.dimension
)
591 if (el
== ns
->entries
)
592 gfc_error ("FUNCTION result %s can't be an array in "
593 "FUNCTION %s at %L", sym
->name
,
594 ns
->entries
->sym
->name
, &sym
->declared_at
);
596 gfc_error ("ENTRY result %s can't be an array in "
597 "FUNCTION %s at %L", sym
->name
,
598 ns
->entries
->sym
->name
, &sym
->declared_at
);
600 else if (sym
->attr
.pointer
)
602 if (el
== ns
->entries
)
603 gfc_error ("FUNCTION result %s can't be a POINTER in "
604 "FUNCTION %s at %L", sym
->name
,
605 ns
->entries
->sym
->name
, &sym
->declared_at
);
607 gfc_error ("ENTRY result %s can't be a POINTER in "
608 "FUNCTION %s at %L", sym
->name
,
609 ns
->entries
->sym
->name
, &sym
->declared_at
);
614 if (ts
->type
== BT_UNKNOWN
)
615 ts
= gfc_get_default_type (sym
, NULL
);
619 if (ts
->kind
== gfc_default_integer_kind
)
623 if (ts
->kind
== gfc_default_real_kind
624 || ts
->kind
== gfc_default_double_kind
)
628 if (ts
->kind
== gfc_default_complex_kind
)
632 if (ts
->kind
== gfc_default_logical_kind
)
636 /* We will issue error elsewhere. */
644 if (el
== ns
->entries
)
645 gfc_error ("FUNCTION result %s can't be of type %s "
646 "in FUNCTION %s at %L", sym
->name
,
647 gfc_typename (ts
), ns
->entries
->sym
->name
,
650 gfc_error ("ENTRY result %s can't be of type %s "
651 "in FUNCTION %s at %L", sym
->name
,
652 gfc_typename (ts
), ns
->entries
->sym
->name
,
659 proc
->attr
.access
= ACCESS_PRIVATE
;
660 proc
->attr
.entry_master
= 1;
662 /* Merge all the entry point arguments. */
663 for (el
= ns
->entries
; el
; el
= el
->next
)
664 merge_argument_lists (proc
, el
->sym
->formal
);
666 /* Check the master formal arguments for any that are not
667 present in all entry points. */
668 for (el
= ns
->entries
; el
; el
= el
->next
)
669 check_argument_lists (proc
, el
->sym
->formal
);
671 /* Use the master function for the function body. */
672 ns
->proc_name
= proc
;
674 /* Finalize the new symbols. */
675 gfc_commit_symbols ();
677 /* Restore the original namespace. */
678 gfc_current_ns
= old_ns
;
683 has_default_initializer (gfc_symbol
*der
)
687 gcc_assert (der
->attr
.flavor
== FL_DERIVED
);
688 for (c
= der
->components
; c
; c
= c
->next
)
689 if ((c
->ts
.type
!= BT_DERIVED
&& c
->initializer
)
690 || (c
->ts
.type
== BT_DERIVED
691 && (!c
->attr
.pointer
&& has_default_initializer (c
->ts
.derived
))))
697 /* Resolve common variables. */
699 resolve_common_vars (gfc_symbol
*sym
, bool named_common
)
701 gfc_symbol
*csym
= sym
;
703 for (; csym
; csym
= csym
->common_next
)
705 if (csym
->value
|| csym
->attr
.data
)
707 if (!csym
->ns
->is_block_data
)
708 gfc_notify_std (GFC_STD_GNU
, "Variable '%s' at %L is in COMMON "
709 "but only in BLOCK DATA initialization is "
710 "allowed", csym
->name
, &csym
->declared_at
);
711 else if (!named_common
)
712 gfc_notify_std (GFC_STD_GNU
, "Initialized variable '%s' at %L is "
713 "in a blank COMMON but initialization is only "
714 "allowed in named common blocks", csym
->name
,
718 if (csym
->ts
.type
!= BT_DERIVED
)
721 if (!(csym
->ts
.derived
->attr
.sequence
722 || csym
->ts
.derived
->attr
.is_bind_c
))
723 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
724 "has neither the SEQUENCE nor the BIND(C) "
725 "attribute", csym
->name
, &csym
->declared_at
);
726 if (csym
->ts
.derived
->attr
.alloc_comp
)
727 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
728 "has an ultimate component that is "
729 "allocatable", csym
->name
, &csym
->declared_at
);
730 if (has_default_initializer (csym
->ts
.derived
))
731 gfc_error_now ("Derived type variable '%s' in COMMON at %L "
732 "may not have default initializer", csym
->name
,
735 if (csym
->attr
.flavor
== FL_UNKNOWN
&& !csym
->attr
.proc_pointer
)
736 gfc_add_flavor (&csym
->attr
, FL_VARIABLE
, csym
->name
, &csym
->declared_at
);
740 /* Resolve common blocks. */
742 resolve_common_blocks (gfc_symtree
*common_root
)
746 if (common_root
== NULL
)
749 if (common_root
->left
)
750 resolve_common_blocks (common_root
->left
);
751 if (common_root
->right
)
752 resolve_common_blocks (common_root
->right
);
754 resolve_common_vars (common_root
->n
.common
->head
, true);
756 gfc_find_symbol (common_root
->name
, gfc_current_ns
, 0, &sym
);
760 if (sym
->attr
.flavor
== FL_PARAMETER
)
761 gfc_error ("COMMON block '%s' at %L is used as PARAMETER at %L",
762 sym
->name
, &common_root
->n
.common
->where
, &sym
->declared_at
);
764 if (sym
->attr
.intrinsic
)
765 gfc_error ("COMMON block '%s' at %L is also an intrinsic procedure",
766 sym
->name
, &common_root
->n
.common
->where
);
767 else if (sym
->attr
.result
768 ||(sym
->attr
.function
&& gfc_current_ns
->proc_name
== sym
))
769 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
770 "that is also a function result", sym
->name
,
771 &common_root
->n
.common
->where
);
772 else if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.proc
!= PROC_INTERNAL
773 && sym
->attr
.proc
!= PROC_ST_FUNCTION
)
774 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: COMMON block '%s' at %L "
775 "that is also a global procedure", sym
->name
,
776 &common_root
->n
.common
->where
);
780 /* Resolve contained function types. Because contained functions can call one
781 another, they have to be worked out before any of the contained procedures
784 The good news is that if a function doesn't already have a type, the only
785 way it can get one is through an IMPLICIT type or a RESULT variable, because
786 by definition contained functions are contained namespace they're contained
787 in, not in a sibling or parent namespace. */
790 resolve_contained_functions (gfc_namespace
*ns
)
792 gfc_namespace
*child
;
795 resolve_formal_arglists (ns
);
797 for (child
= ns
->contained
; child
; child
= child
->sibling
)
799 /* Resolve alternate entry points first. */
800 resolve_entries (child
);
802 /* Then check function return types. */
803 resolve_contained_fntype (child
->proc_name
, child
);
804 for (el
= child
->entries
; el
; el
= el
->next
)
805 resolve_contained_fntype (el
->sym
, child
);
810 /* Resolve all of the elements of a structure constructor and make sure that
811 the types are correct. */
814 resolve_structure_cons (gfc_expr
*expr
)
816 gfc_constructor
*cons
;
822 cons
= expr
->value
.constructor
;
823 /* A constructor may have references if it is the result of substituting a
824 parameter variable. In this case we just pull out the component we
827 comp
= expr
->ref
->u
.c
.sym
->components
;
829 comp
= expr
->ts
.derived
->components
;
831 /* See if the user is trying to invoke a structure constructor for one of
832 the iso_c_binding derived types. */
833 if (expr
->ts
.derived
&& expr
->ts
.derived
->ts
.is_iso_c
&& cons
834 && cons
->expr
!= NULL
)
836 gfc_error ("Components of structure constructor '%s' at %L are PRIVATE",
837 expr
->ts
.derived
->name
, &(expr
->where
));
841 for (; comp
; comp
= comp
->next
, cons
= cons
->next
)
848 if (gfc_resolve_expr (cons
->expr
) == FAILURE
)
854 rank
= comp
->as
? comp
->as
->rank
: 0;
855 if (cons
->expr
->expr_type
!= EXPR_NULL
&& rank
!= cons
->expr
->rank
856 && (comp
->attr
.allocatable
|| cons
->expr
->rank
))
858 gfc_error ("The rank of the element in the derived type "
859 "constructor at %L does not match that of the "
860 "component (%d/%d)", &cons
->expr
->where
,
861 cons
->expr
->rank
, rank
);
865 /* If we don't have the right type, try to convert it. */
867 if (!gfc_compare_types (&cons
->expr
->ts
, &comp
->ts
))
870 if (comp
->attr
.pointer
&& cons
->expr
->ts
.type
!= BT_UNKNOWN
)
871 gfc_error ("The element in the derived type constructor at %L, "
872 "for pointer component '%s', is %s but should be %s",
873 &cons
->expr
->where
, comp
->name
,
874 gfc_basic_typename (cons
->expr
->ts
.type
),
875 gfc_basic_typename (comp
->ts
.type
));
877 t
= gfc_convert_type (cons
->expr
, &comp
->ts
, 1);
880 if (cons
->expr
->expr_type
== EXPR_NULL
881 && !(comp
->attr
.pointer
|| comp
->attr
.allocatable
))
884 gfc_error ("The NULL in the derived type constructor at %L is "
885 "being applied to component '%s', which is neither "
886 "a POINTER nor ALLOCATABLE", &cons
->expr
->where
,
890 if (!comp
->attr
.pointer
|| cons
->expr
->expr_type
== EXPR_NULL
)
893 a
= gfc_expr_attr (cons
->expr
);
895 if (!a
.pointer
&& !a
.target
)
898 gfc_error ("The element in the derived type constructor at %L, "
899 "for pointer component '%s' should be a POINTER or "
900 "a TARGET", &cons
->expr
->where
, comp
->name
);
908 /****************** Expression name resolution ******************/
910 /* Returns 0 if a symbol was not declared with a type or
911 attribute declaration statement, nonzero otherwise. */
914 was_declared (gfc_symbol
*sym
)
920 if (!a
.implicit_type
&& sym
->ts
.type
!= BT_UNKNOWN
)
923 if (a
.allocatable
|| a
.dimension
|| a
.dummy
|| a
.external
|| a
.intrinsic
924 || a
.optional
|| a
.pointer
|| a
.save
|| a
.target
|| a
.volatile_
925 || a
.value
|| a
.access
!= ACCESS_UNKNOWN
|| a
.intent
!= INTENT_UNKNOWN
)
932 /* Determine if a symbol is generic or not. */
935 generic_sym (gfc_symbol
*sym
)
939 if (sym
->attr
.generic
||
940 (sym
->attr
.intrinsic
&& gfc_generic_intrinsic (sym
->name
)))
943 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
946 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
953 return generic_sym (s
);
960 /* Determine if a symbol is specific or not. */
963 specific_sym (gfc_symbol
*sym
)
967 if (sym
->attr
.if_source
== IFSRC_IFBODY
968 || sym
->attr
.proc
== PROC_MODULE
969 || sym
->attr
.proc
== PROC_INTERNAL
970 || sym
->attr
.proc
== PROC_ST_FUNCTION
971 || (sym
->attr
.intrinsic
&& gfc_specific_intrinsic (sym
->name
))
972 || sym
->attr
.external
)
975 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
978 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &s
);
980 return (s
== NULL
) ? 0 : specific_sym (s
);
984 /* Figure out if the procedure is specific, generic or unknown. */
987 { PTYPE_GENERIC
= 1, PTYPE_SPECIFIC
, PTYPE_UNKNOWN
}
991 procedure_kind (gfc_symbol
*sym
)
993 if (generic_sym (sym
))
994 return PTYPE_GENERIC
;
996 if (specific_sym (sym
))
997 return PTYPE_SPECIFIC
;
999 return PTYPE_UNKNOWN
;
1002 /* Check references to assumed size arrays. The flag need_full_assumed_size
1003 is nonzero when matching actual arguments. */
1005 static int need_full_assumed_size
= 0;
1008 check_assumed_size_reference (gfc_symbol
*sym
, gfc_expr
*e
)
1010 if (need_full_assumed_size
|| !(sym
->as
&& sym
->as
->type
== AS_ASSUMED_SIZE
))
1013 /* FIXME: The comparison "e->ref->u.ar.type == AR_FULL" is wrong.
1014 What should it be? */
1015 if ((e
->ref
->u
.ar
.end
[e
->ref
->u
.ar
.as
->rank
- 1] == NULL
)
1016 && (e
->ref
->u
.ar
.as
->type
== AS_ASSUMED_SIZE
)
1017 && (e
->ref
->u
.ar
.type
== AR_FULL
))
1019 gfc_error ("The upper bound in the last dimension must "
1020 "appear in the reference to the assumed size "
1021 "array '%s' at %L", sym
->name
, &e
->where
);
1028 /* Look for bad assumed size array references in argument expressions
1029 of elemental and array valued intrinsic procedures. Since this is
1030 called from procedure resolution functions, it only recurses at
1034 resolve_assumed_size_actual (gfc_expr
*e
)
1039 switch (e
->expr_type
)
1042 if (e
->symtree
&& check_assumed_size_reference (e
->symtree
->n
.sym
, e
))
1047 if (resolve_assumed_size_actual (e
->value
.op
.op1
)
1048 || resolve_assumed_size_actual (e
->value
.op
.op2
))
1059 /* Check a generic procedure, passed as an actual argument, to see if
1060 there is a matching specific name. If none, it is an error, and if
1061 more than one, the reference is ambiguous. */
1063 count_specific_procs (gfc_expr
*e
)
1070 sym
= e
->symtree
->n
.sym
;
1072 for (p
= sym
->generic
; p
; p
= p
->next
)
1073 if (strcmp (sym
->name
, p
->sym
->name
) == 0)
1075 e
->symtree
= gfc_find_symtree (p
->sym
->ns
->sym_root
,
1081 gfc_error ("'%s' at %L is ambiguous", e
->symtree
->n
.sym
->name
,
1085 gfc_error ("GENERIC procedure '%s' is not allowed as an actual "
1086 "argument at %L", sym
->name
, &e
->where
);
1092 /* See if a call to sym could possibly be a not allowed RECURSION because of
1093 a missing RECURIVE declaration. This means that either sym is the current
1094 context itself, or sym is the parent of a contained procedure calling its
1095 non-RECURSIVE containing procedure.
1096 This also works if sym is an ENTRY. */
1099 is_illegal_recursion (gfc_symbol
* sym
, gfc_namespace
* context
)
1101 gfc_symbol
* proc_sym
;
1102 gfc_symbol
* context_proc
;
1104 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
);
1106 /* If we've got an ENTRY, find real procedure. */
1107 if (sym
->attr
.entry
&& sym
->ns
->entries
)
1108 proc_sym
= sym
->ns
->entries
->sym
;
1112 /* If sym is RECURSIVE, all is well of course. */
1113 if (proc_sym
->attr
.recursive
|| gfc_option
.flag_recursive
)
1116 /* Find the context procdure's "real" symbol if it has entries. */
1117 context_proc
= (context
->entries
? context
->entries
->sym
1118 : context
->proc_name
);
1122 /* A call from sym's body to itself is recursion, of course. */
1123 if (context_proc
== proc_sym
)
1126 /* The same is true if context is a contained procedure and sym the
1128 if (context_proc
->attr
.contained
)
1130 gfc_symbol
* parent_proc
;
1132 gcc_assert (context
->parent
);
1133 parent_proc
= (context
->parent
->entries
? context
->parent
->entries
->sym
1134 : context
->parent
->proc_name
);
1136 if (parent_proc
== proc_sym
)
1144 /* Resolve an intrinsic procedure: Set its function/subroutine attribute,
1145 its typespec and formal argument list. */
1148 resolve_intrinsic (gfc_symbol
*sym
, locus
*loc
)
1150 gfc_intrinsic_sym
*isym
= gfc_find_function (sym
->name
);
1153 if (!sym
->attr
.function
&&
1154 gfc_add_function (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1160 isym
= gfc_find_subroutine (sym
->name
);
1162 if (!sym
->attr
.subroutine
&&
1163 gfc_add_subroutine (&sym
->attr
, sym
->name
, loc
) == FAILURE
)
1167 gfc_copy_formal_args_intr (sym
, isym
);
1172 /* Resolve a procedure expression, like passing it to a called procedure or as
1173 RHS for a procedure pointer assignment. */
1176 resolve_procedure_expression (gfc_expr
* expr
)
1180 if (expr
->expr_type
!= EXPR_VARIABLE
)
1182 gcc_assert (expr
->symtree
);
1184 sym
= expr
->symtree
->n
.sym
;
1186 if (sym
->attr
.intrinsic
)
1187 resolve_intrinsic (sym
, &expr
->where
);
1189 if (sym
->attr
.flavor
!= FL_PROCEDURE
1190 || (sym
->attr
.function
&& sym
->result
== sym
))
1193 /* A non-RECURSIVE procedure that is used as procedure expression within its
1194 own body is in danger of being called recursively. */
1195 if (is_illegal_recursion (sym
, gfc_current_ns
))
1196 gfc_warning ("Non-RECURSIVE procedure '%s' at %L is possibly calling"
1197 " itself recursively. Declare it RECURSIVE or use"
1198 " -frecursive", sym
->name
, &expr
->where
);
1204 /* Resolve an actual argument list. Most of the time, this is just
1205 resolving the expressions in the list.
1206 The exception is that we sometimes have to decide whether arguments
1207 that look like procedure arguments are really simple variable
1211 resolve_actual_arglist (gfc_actual_arglist
*arg
, procedure_type ptype
,
1212 bool no_formal_args
)
1215 gfc_symtree
*parent_st
;
1217 int save_need_full_assumed_size
;
1219 for (; arg
; arg
= arg
->next
)
1224 /* Check the label is a valid branching target. */
1227 if (arg
->label
->defined
== ST_LABEL_UNKNOWN
)
1229 gfc_error ("Label %d referenced at %L is never defined",
1230 arg
->label
->value
, &arg
->label
->where
);
1237 if (e
->expr_type
== EXPR_VARIABLE
1238 && e
->symtree
->n
.sym
->attr
.generic
1240 && count_specific_procs (e
) != 1)
1243 if (e
->ts
.type
!= BT_PROCEDURE
)
1245 save_need_full_assumed_size
= need_full_assumed_size
;
1246 if (e
->expr_type
!= EXPR_VARIABLE
)
1247 need_full_assumed_size
= 0;
1248 if (gfc_resolve_expr (e
) != SUCCESS
)
1250 need_full_assumed_size
= save_need_full_assumed_size
;
1254 /* See if the expression node should really be a variable reference. */
1256 sym
= e
->symtree
->n
.sym
;
1258 if (sym
->attr
.flavor
== FL_PROCEDURE
1259 || sym
->attr
.intrinsic
1260 || sym
->attr
.external
)
1264 /* If a procedure is not already determined to be something else
1265 check if it is intrinsic. */
1266 if (!sym
->attr
.intrinsic
1267 && !(sym
->attr
.external
|| sym
->attr
.use_assoc
1268 || sym
->attr
.if_source
== IFSRC_IFBODY
)
1269 && gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, e
->where
))
1270 sym
->attr
.intrinsic
= 1;
1272 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
1274 gfc_error ("Statement function '%s' at %L is not allowed as an "
1275 "actual argument", sym
->name
, &e
->where
);
1278 actual_ok
= gfc_intrinsic_actual_ok (sym
->name
,
1279 sym
->attr
.subroutine
);
1280 if (sym
->attr
.intrinsic
&& actual_ok
== 0)
1282 gfc_error ("Intrinsic '%s' at %L is not allowed as an "
1283 "actual argument", sym
->name
, &e
->where
);
1286 if (sym
->attr
.contained
&& !sym
->attr
.use_assoc
1287 && sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)
1289 gfc_error ("Internal procedure '%s' is not allowed as an "
1290 "actual argument at %L", sym
->name
, &e
->where
);
1293 if (sym
->attr
.elemental
&& !sym
->attr
.intrinsic
)
1295 gfc_error ("ELEMENTAL non-INTRINSIC procedure '%s' is not "
1296 "allowed as an actual argument at %L", sym
->name
,
1300 /* Check if a generic interface has a specific procedure
1301 with the same name before emitting an error. */
1302 if (sym
->attr
.generic
&& count_specific_procs (e
) != 1)
1305 /* Just in case a specific was found for the expression. */
1306 sym
= e
->symtree
->n
.sym
;
1308 /* If the symbol is the function that names the current (or
1309 parent) scope, then we really have a variable reference. */
1311 if (sym
->attr
.function
&& sym
->result
== sym
1312 && (sym
->ns
->proc_name
== sym
1313 || (sym
->ns
->parent
!= NULL
1314 && sym
->ns
->parent
->proc_name
== sym
)))
1317 /* If all else fails, see if we have a specific intrinsic. */
1318 if (sym
->ts
.type
== BT_UNKNOWN
&& sym
->attr
.intrinsic
)
1320 gfc_intrinsic_sym
*isym
;
1322 isym
= gfc_find_function (sym
->name
);
1323 if (isym
== NULL
|| !isym
->specific
)
1325 gfc_error ("Unable to find a specific INTRINSIC procedure "
1326 "for the reference '%s' at %L", sym
->name
,
1331 sym
->attr
.intrinsic
= 1;
1332 sym
->attr
.function
= 1;
1335 if (gfc_resolve_expr (e
) == FAILURE
)
1340 /* See if the name is a module procedure in a parent unit. */
1342 if (was_declared (sym
) || sym
->ns
->parent
== NULL
)
1345 if (gfc_find_sym_tree (sym
->name
, sym
->ns
->parent
, 1, &parent_st
))
1347 gfc_error ("Symbol '%s' at %L is ambiguous", sym
->name
, &e
->where
);
1351 if (parent_st
== NULL
)
1354 sym
= parent_st
->n
.sym
;
1355 e
->symtree
= parent_st
; /* Point to the right thing. */
1357 if (sym
->attr
.flavor
== FL_PROCEDURE
1358 || sym
->attr
.intrinsic
1359 || sym
->attr
.external
)
1361 if (gfc_resolve_expr (e
) == FAILURE
)
1367 e
->expr_type
= EXPR_VARIABLE
;
1369 if (sym
->as
!= NULL
)
1371 e
->rank
= sym
->as
->rank
;
1372 e
->ref
= gfc_get_ref ();
1373 e
->ref
->type
= REF_ARRAY
;
1374 e
->ref
->u
.ar
.type
= AR_FULL
;
1375 e
->ref
->u
.ar
.as
= sym
->as
;
1378 /* Expressions are assigned a default ts.type of BT_PROCEDURE in
1379 primary.c (match_actual_arg). If above code determines that it
1380 is a variable instead, it needs to be resolved as it was not
1381 done at the beginning of this function. */
1382 save_need_full_assumed_size
= need_full_assumed_size
;
1383 if (e
->expr_type
!= EXPR_VARIABLE
)
1384 need_full_assumed_size
= 0;
1385 if (gfc_resolve_expr (e
) != SUCCESS
)
1387 need_full_assumed_size
= save_need_full_assumed_size
;
1390 /* Check argument list functions %VAL, %LOC and %REF. There is
1391 nothing to do for %REF. */
1392 if (arg
->name
&& arg
->name
[0] == '%')
1394 if (strncmp ("%VAL", arg
->name
, 4) == 0)
1396 if (e
->ts
.type
== BT_CHARACTER
|| e
->ts
.type
== BT_DERIVED
)
1398 gfc_error ("By-value argument at %L is not of numeric "
1405 gfc_error ("By-value argument at %L cannot be an array or "
1406 "an array section", &e
->where
);
1410 /* Intrinsics are still PROC_UNKNOWN here. However,
1411 since same file external procedures are not resolvable
1412 in gfortran, it is a good deal easier to leave them to
1414 if (ptype
!= PROC_UNKNOWN
1415 && ptype
!= PROC_DUMMY
1416 && ptype
!= PROC_EXTERNAL
1417 && ptype
!= PROC_MODULE
)
1419 gfc_error ("By-value argument at %L is not allowed "
1420 "in this context", &e
->where
);
1425 /* Statement functions have already been excluded above. */
1426 else if (strncmp ("%LOC", arg
->name
, 4) == 0
1427 && e
->ts
.type
== BT_PROCEDURE
)
1429 if (e
->symtree
->n
.sym
->attr
.proc
== PROC_INTERNAL
)
1431 gfc_error ("Passing internal procedure at %L by location "
1432 "not allowed", &e
->where
);
1443 /* Do the checks of the actual argument list that are specific to elemental
1444 procedures. If called with c == NULL, we have a function, otherwise if
1445 expr == NULL, we have a subroutine. */
1448 resolve_elemental_actual (gfc_expr
*expr
, gfc_code
*c
)
1450 gfc_actual_arglist
*arg0
;
1451 gfc_actual_arglist
*arg
;
1452 gfc_symbol
*esym
= NULL
;
1453 gfc_intrinsic_sym
*isym
= NULL
;
1455 gfc_intrinsic_arg
*iformal
= NULL
;
1456 gfc_formal_arglist
*eformal
= NULL
;
1457 bool formal_optional
= false;
1458 bool set_by_optional
= false;
1462 /* Is this an elemental procedure? */
1463 if (expr
&& expr
->value
.function
.actual
!= NULL
)
1465 if (expr
->value
.function
.esym
!= NULL
1466 && expr
->value
.function
.esym
->attr
.elemental
)
1468 arg0
= expr
->value
.function
.actual
;
1469 esym
= expr
->value
.function
.esym
;
1471 else if (expr
->value
.function
.isym
!= NULL
1472 && expr
->value
.function
.isym
->elemental
)
1474 arg0
= expr
->value
.function
.actual
;
1475 isym
= expr
->value
.function
.isym
;
1480 else if (c
&& c
->ext
.actual
!= NULL
)
1482 arg0
= c
->ext
.actual
;
1484 if (c
->resolved_sym
)
1485 esym
= c
->resolved_sym
;
1487 esym
= c
->symtree
->n
.sym
;
1490 if (!esym
->attr
.elemental
)
1496 /* The rank of an elemental is the rank of its array argument(s). */
1497 for (arg
= arg0
; arg
; arg
= arg
->next
)
1499 if (arg
->expr
!= NULL
&& arg
->expr
->rank
> 0)
1501 rank
= arg
->expr
->rank
;
1502 if (arg
->expr
->expr_type
== EXPR_VARIABLE
1503 && arg
->expr
->symtree
->n
.sym
->attr
.optional
)
1504 set_by_optional
= true;
1506 /* Function specific; set the result rank and shape. */
1510 if (!expr
->shape
&& arg
->expr
->shape
)
1512 expr
->shape
= gfc_get_shape (rank
);
1513 for (i
= 0; i
< rank
; i
++)
1514 mpz_init_set (expr
->shape
[i
], arg
->expr
->shape
[i
]);
1521 /* If it is an array, it shall not be supplied as an actual argument
1522 to an elemental procedure unless an array of the same rank is supplied
1523 as an actual argument corresponding to a nonoptional dummy argument of
1524 that elemental procedure(12.4.1.5). */
1525 formal_optional
= false;
1527 iformal
= isym
->formal
;
1529 eformal
= esym
->formal
;
1531 for (arg
= arg0
; arg
; arg
= arg
->next
)
1535 if (eformal
->sym
&& eformal
->sym
->attr
.optional
)
1536 formal_optional
= true;
1537 eformal
= eformal
->next
;
1539 else if (isym
&& iformal
)
1541 if (iformal
->optional
)
1542 formal_optional
= true;
1543 iformal
= iformal
->next
;
1546 formal_optional
= true;
1548 if (pedantic
&& arg
->expr
!= NULL
1549 && arg
->expr
->expr_type
== EXPR_VARIABLE
1550 && arg
->expr
->symtree
->n
.sym
->attr
.optional
1553 && (set_by_optional
|| arg
->expr
->rank
!= rank
)
1554 && !(isym
&& isym
->id
== GFC_ISYM_CONVERSION
))
1556 gfc_warning ("'%s' at %L is an array and OPTIONAL; IF IT IS "
1557 "MISSING, it cannot be the actual argument of an "
1558 "ELEMENTAL procedure unless there is a non-optional "
1559 "argument with the same rank (12.4.1.5)",
1560 arg
->expr
->symtree
->n
.sym
->name
, &arg
->expr
->where
);
1565 for (arg
= arg0
; arg
; arg
= arg
->next
)
1567 if (arg
->expr
== NULL
|| arg
->expr
->rank
== 0)
1570 /* Being elemental, the last upper bound of an assumed size array
1571 argument must be present. */
1572 if (resolve_assumed_size_actual (arg
->expr
))
1575 /* Elemental procedure's array actual arguments must conform. */
1578 if (gfc_check_conformance ("elemental procedure", arg
->expr
, e
)
1586 /* INTENT(OUT) is only allowed for subroutines; if any actual argument
1587 is an array, the intent inout/out variable needs to be also an array. */
1588 if (rank
> 0 && esym
&& expr
== NULL
)
1589 for (eformal
= esym
->formal
, arg
= arg0
; arg
&& eformal
;
1590 arg
= arg
->next
, eformal
= eformal
->next
)
1591 if ((eformal
->sym
->attr
.intent
== INTENT_OUT
1592 || eformal
->sym
->attr
.intent
== INTENT_INOUT
)
1593 && arg
->expr
&& arg
->expr
->rank
== 0)
1595 gfc_error ("Actual argument at %L for INTENT(%s) dummy '%s' of "
1596 "ELEMENTAL subroutine '%s' is a scalar, but another "
1597 "actual argument is an array", &arg
->expr
->where
,
1598 (eformal
->sym
->attr
.intent
== INTENT_OUT
) ? "OUT"
1599 : "INOUT", eformal
->sym
->name
, esym
->name
);
1606 /* Go through each actual argument in ACTUAL and see if it can be
1607 implemented as an inlined, non-copying intrinsic. FNSYM is the
1608 function being called, or NULL if not known. */
1611 find_noncopying_intrinsics (gfc_symbol
*fnsym
, gfc_actual_arglist
*actual
)
1613 gfc_actual_arglist
*ap
;
1616 for (ap
= actual
; ap
; ap
= ap
->next
)
1618 && (expr
= gfc_get_noncopying_intrinsic_argument (ap
->expr
))
1619 && !gfc_check_fncall_dependency (expr
, INTENT_IN
, fnsym
, actual
,
1621 ap
->expr
->inline_noncopying_intrinsic
= 1;
1625 /* This function does the checking of references to global procedures
1626 as defined in sections 18.1 and 14.1, respectively, of the Fortran
1627 77 and 95 standards. It checks for a gsymbol for the name, making
1628 one if it does not already exist. If it already exists, then the
1629 reference being resolved must correspond to the type of gsymbol.
1630 Otherwise, the new symbol is equipped with the attributes of the
1631 reference. The corresponding code that is called in creating
1632 global entities is parse.c.
1634 In addition, for all but -std=legacy, the gsymbols are used to
1635 check the interfaces of external procedures from the same file.
1636 The namespace of the gsymbol is resolved and then, once this is
1637 done the interface is checked. */
1640 resolve_global_procedure (gfc_symbol
*sym
, locus
*where
,
1641 gfc_actual_arglist
**actual
, int sub
)
1647 type
= sub
? GSYM_SUBROUTINE
: GSYM_FUNCTION
;
1649 gsym
= gfc_get_gsymbol (sym
->name
);
1651 if ((gsym
->type
!= GSYM_UNKNOWN
&& gsym
->type
!= type
))
1652 gfc_global_used (gsym
, where
);
1654 if (gfc_option
.flag_whole_file
1655 && gsym
->type
!= GSYM_UNKNOWN
1657 && gsym
->ns
->proc_name
)
1659 /* Make sure that translation for the gsymbol occurs before
1660 the procedure currently being resolved. */
1661 ns
= gsym
->ns
->resolved
? NULL
: gfc_global_ns_list
;
1662 for (; ns
&& ns
!= gsym
->ns
; ns
= ns
->sibling
)
1664 if (ns
->sibling
== gsym
->ns
)
1666 ns
->sibling
= gsym
->ns
->sibling
;
1667 gsym
->ns
->sibling
= gfc_global_ns_list
;
1668 gfc_global_ns_list
= gsym
->ns
;
1673 if (!gsym
->ns
->resolved
)
1674 gfc_resolve (gsym
->ns
);
1676 gfc_procedure_use (gsym
->ns
->proc_name
, actual
, where
);
1679 if (gsym
->type
== GSYM_UNKNOWN
)
1682 gsym
->where
= *where
;
1689 /************* Function resolution *************/
1691 /* Resolve a function call known to be generic.
1692 Section 14.1.2.4.1. */
1695 resolve_generic_f0 (gfc_expr
*expr
, gfc_symbol
*sym
)
1699 if (sym
->attr
.generic
)
1701 s
= gfc_search_interface (sym
->generic
, 0, &expr
->value
.function
.actual
);
1704 expr
->value
.function
.name
= s
->name
;
1705 expr
->value
.function
.esym
= s
;
1707 if (s
->ts
.type
!= BT_UNKNOWN
)
1709 else if (s
->result
!= NULL
&& s
->result
->ts
.type
!= BT_UNKNOWN
)
1710 expr
->ts
= s
->result
->ts
;
1713 expr
->rank
= s
->as
->rank
;
1714 else if (s
->result
!= NULL
&& s
->result
->as
!= NULL
)
1715 expr
->rank
= s
->result
->as
->rank
;
1717 gfc_set_sym_referenced (expr
->value
.function
.esym
);
1722 /* TODO: Need to search for elemental references in generic
1726 if (sym
->attr
.intrinsic
)
1727 return gfc_intrinsic_func_interface (expr
, 0);
1734 resolve_generic_f (gfc_expr
*expr
)
1739 sym
= expr
->symtree
->n
.sym
;
1743 m
= resolve_generic_f0 (expr
, sym
);
1746 else if (m
== MATCH_ERROR
)
1750 if (sym
->ns
->parent
== NULL
)
1752 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
1756 if (!generic_sym (sym
))
1760 /* Last ditch attempt. See if the reference is to an intrinsic
1761 that possesses a matching interface. 14.1.2.4 */
1762 if (sym
&& !gfc_is_intrinsic (sym
, 0, expr
->where
))
1764 gfc_error ("There is no specific function for the generic '%s' at %L",
1765 expr
->symtree
->n
.sym
->name
, &expr
->where
);
1769 m
= gfc_intrinsic_func_interface (expr
, 0);
1773 gfc_error ("Generic function '%s' at %L is not consistent with a "
1774 "specific intrinsic interface", expr
->symtree
->n
.sym
->name
,
1781 /* Resolve a function call known to be specific. */
1784 resolve_specific_f0 (gfc_symbol
*sym
, gfc_expr
*expr
)
1788 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
1790 if (sym
->attr
.dummy
)
1792 sym
->attr
.proc
= PROC_DUMMY
;
1796 sym
->attr
.proc
= PROC_EXTERNAL
;
1800 if (sym
->attr
.proc
== PROC_MODULE
1801 || sym
->attr
.proc
== PROC_ST_FUNCTION
1802 || sym
->attr
.proc
== PROC_INTERNAL
)
1805 if (sym
->attr
.intrinsic
)
1807 m
= gfc_intrinsic_func_interface (expr
, 1);
1811 gfc_error ("Function '%s' at %L is INTRINSIC but is not compatible "
1812 "with an intrinsic", sym
->name
, &expr
->where
);
1820 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
1823 expr
->value
.function
.name
= sym
->name
;
1824 expr
->value
.function
.esym
= sym
;
1825 if (sym
->as
!= NULL
)
1826 expr
->rank
= sym
->as
->rank
;
1833 resolve_specific_f (gfc_expr
*expr
)
1838 sym
= expr
->symtree
->n
.sym
;
1842 m
= resolve_specific_f0 (sym
, expr
);
1845 if (m
== MATCH_ERROR
)
1848 if (sym
->ns
->parent
== NULL
)
1851 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
1857 gfc_error ("Unable to resolve the specific function '%s' at %L",
1858 expr
->symtree
->n
.sym
->name
, &expr
->where
);
1864 /* Resolve a procedure call not known to be generic nor specific. */
1867 resolve_unknown_f (gfc_expr
*expr
)
1872 sym
= expr
->symtree
->n
.sym
;
1874 if (sym
->attr
.dummy
)
1876 sym
->attr
.proc
= PROC_DUMMY
;
1877 expr
->value
.function
.name
= sym
->name
;
1881 /* See if we have an intrinsic function reference. */
1883 if (gfc_is_intrinsic (sym
, 0, expr
->where
))
1885 if (gfc_intrinsic_func_interface (expr
, 1) == MATCH_YES
)
1890 /* The reference is to an external name. */
1892 sym
->attr
.proc
= PROC_EXTERNAL
;
1893 expr
->value
.function
.name
= sym
->name
;
1894 expr
->value
.function
.esym
= expr
->symtree
->n
.sym
;
1896 if (sym
->as
!= NULL
)
1897 expr
->rank
= sym
->as
->rank
;
1899 /* Type of the expression is either the type of the symbol or the
1900 default type of the symbol. */
1903 gfc_procedure_use (sym
, &expr
->value
.function
.actual
, &expr
->where
);
1905 if (sym
->ts
.type
!= BT_UNKNOWN
)
1909 ts
= gfc_get_default_type (sym
, sym
->ns
);
1911 if (ts
->type
== BT_UNKNOWN
)
1913 gfc_error ("Function '%s' at %L has no IMPLICIT type",
1914 sym
->name
, &expr
->where
);
1925 /* Return true, if the symbol is an external procedure. */
1927 is_external_proc (gfc_symbol
*sym
)
1929 if (!sym
->attr
.dummy
&& !sym
->attr
.contained
1930 && !(sym
->attr
.intrinsic
1931 || gfc_is_intrinsic (sym
, sym
->attr
.subroutine
, sym
->declared_at
))
1932 && sym
->attr
.proc
!= PROC_ST_FUNCTION
1933 && !sym
->attr
.use_assoc
1941 /* Figure out if a function reference is pure or not. Also set the name
1942 of the function for a potential error message. Return nonzero if the
1943 function is PURE, zero if not. */
1945 pure_stmt_function (gfc_expr
*, gfc_symbol
*);
1948 pure_function (gfc_expr
*e
, const char **name
)
1954 if (e
->symtree
!= NULL
1955 && e
->symtree
->n
.sym
!= NULL
1956 && e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
1957 return pure_stmt_function (e
, e
->symtree
->n
.sym
);
1959 if (e
->value
.function
.esym
)
1961 pure
= gfc_pure (e
->value
.function
.esym
);
1962 *name
= e
->value
.function
.esym
->name
;
1964 else if (e
->value
.function
.isym
)
1966 pure
= e
->value
.function
.isym
->pure
1967 || e
->value
.function
.isym
->elemental
;
1968 *name
= e
->value
.function
.isym
->name
;
1972 /* Implicit functions are not pure. */
1974 *name
= e
->value
.function
.name
;
1982 impure_stmt_fcn (gfc_expr
*e
, gfc_symbol
*sym
,
1983 int *f ATTRIBUTE_UNUSED
)
1987 /* Don't bother recursing into other statement functions
1988 since they will be checked individually for purity. */
1989 if (e
->expr_type
!= EXPR_FUNCTION
1991 || e
->symtree
->n
.sym
== sym
1992 || e
->symtree
->n
.sym
->attr
.proc
== PROC_ST_FUNCTION
)
1995 return pure_function (e
, &name
) ? false : true;
2000 pure_stmt_function (gfc_expr
*e
, gfc_symbol
*sym
)
2002 return gfc_traverse_expr (e
, sym
, impure_stmt_fcn
, 0) ? 0 : 1;
2007 is_scalar_expr_ptr (gfc_expr
*expr
)
2009 gfc_try retval
= SUCCESS
;
2014 /* See if we have a gfc_ref, which means we have a substring, array
2015 reference, or a component. */
2016 if (expr
->ref
!= NULL
)
2019 while (ref
->next
!= NULL
)
2025 if (ref
->u
.ss
.length
!= NULL
2026 && ref
->u
.ss
.length
->length
!= NULL
2028 && ref
->u
.ss
.start
->expr_type
== EXPR_CONSTANT
2030 && ref
->u
.ss
.end
->expr_type
== EXPR_CONSTANT
)
2032 start
= (int) mpz_get_si (ref
->u
.ss
.start
->value
.integer
);
2033 end
= (int) mpz_get_si (ref
->u
.ss
.end
->value
.integer
);
2034 if (end
- start
+ 1 != 1)
2041 if (ref
->u
.ar
.type
== AR_ELEMENT
)
2043 else if (ref
->u
.ar
.type
== AR_FULL
)
2045 /* The user can give a full array if the array is of size 1. */
2046 if (ref
->u
.ar
.as
!= NULL
2047 && ref
->u
.ar
.as
->rank
== 1
2048 && ref
->u
.ar
.as
->type
== AS_EXPLICIT
2049 && ref
->u
.ar
.as
->lower
[0] != NULL
2050 && ref
->u
.ar
.as
->lower
[0]->expr_type
== EXPR_CONSTANT
2051 && ref
->u
.ar
.as
->upper
[0] != NULL
2052 && ref
->u
.ar
.as
->upper
[0]->expr_type
== EXPR_CONSTANT
)
2054 /* If we have a character string, we need to check if
2055 its length is one. */
2056 if (expr
->ts
.type
== BT_CHARACTER
)
2058 if (expr
->ts
.cl
== NULL
2059 || expr
->ts
.cl
->length
== NULL
2060 || mpz_cmp_si (expr
->ts
.cl
->length
->value
.integer
, 1)
2066 /* We have constant lower and upper bounds. If the
2067 difference between is 1, it can be considered a
2069 start
= (int) mpz_get_si
2070 (ref
->u
.ar
.as
->lower
[0]->value
.integer
);
2071 end
= (int) mpz_get_si
2072 (ref
->u
.ar
.as
->upper
[0]->value
.integer
);
2073 if (end
- start
+ 1 != 1)
2088 else if (expr
->ts
.type
== BT_CHARACTER
&& expr
->rank
== 0)
2090 /* Character string. Make sure it's of length 1. */
2091 if (expr
->ts
.cl
== NULL
2092 || expr
->ts
.cl
->length
== NULL
2093 || mpz_cmp_si (expr
->ts
.cl
->length
->value
.integer
, 1) != 0)
2096 else if (expr
->rank
!= 0)
2103 /* Match one of the iso_c_binding functions (c_associated or c_loc)
2104 and, in the case of c_associated, set the binding label based on
2108 gfc_iso_c_func_interface (gfc_symbol
*sym
, gfc_actual_arglist
*args
,
2109 gfc_symbol
**new_sym
)
2111 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2112 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
2113 int optional_arg
= 0, is_pointer
= 0;
2114 gfc_try retval
= SUCCESS
;
2115 gfc_symbol
*args_sym
;
2116 gfc_typespec
*arg_ts
;
2118 if (args
->expr
->expr_type
== EXPR_CONSTANT
2119 || args
->expr
->expr_type
== EXPR_OP
2120 || args
->expr
->expr_type
== EXPR_NULL
)
2122 gfc_error ("Argument to '%s' at %L is not a variable",
2123 sym
->name
, &(args
->expr
->where
));
2127 args_sym
= args
->expr
->symtree
->n
.sym
;
2129 /* The typespec for the actual arg should be that stored in the expr
2130 and not necessarily that of the expr symbol (args_sym), because
2131 the actual expression could be a part-ref of the expr symbol. */
2132 arg_ts
= &(args
->expr
->ts
);
2134 is_pointer
= gfc_is_data_pointer (args
->expr
);
2136 if (sym
->intmod_sym_id
== ISOCBINDING_ASSOCIATED
)
2138 /* If the user gave two args then they are providing something for
2139 the optional arg (the second cptr). Therefore, set the name and
2140 binding label to the c_associated for two cptrs. Otherwise,
2141 set c_associated to expect one cptr. */
2145 sprintf (name
, "%s_2", sym
->name
);
2146 sprintf (binding_label
, "%s_2", sym
->binding_label
);
2152 sprintf (name
, "%s_1", sym
->name
);
2153 sprintf (binding_label
, "%s_1", sym
->binding_label
);
2157 /* Get a new symbol for the version of c_associated that
2159 *new_sym
= get_iso_c_sym (sym
, name
, binding_label
, optional_arg
);
2161 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
2162 || sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2164 sprintf (name
, "%s", sym
->name
);
2165 sprintf (binding_label
, "%s", sym
->binding_label
);
2167 /* Error check the call. */
2168 if (args
->next
!= NULL
)
2170 gfc_error_now ("More actual than formal arguments in '%s' "
2171 "call at %L", name
, &(args
->expr
->where
));
2174 else if (sym
->intmod_sym_id
== ISOCBINDING_LOC
)
2176 /* Make sure we have either the target or pointer attribute. */
2177 if (!args_sym
->attr
.target
&& !is_pointer
)
2179 gfc_error_now ("Parameter '%s' to '%s' at %L must be either "
2180 "a TARGET or an associated pointer",
2182 sym
->name
, &(args
->expr
->where
));
2186 /* See if we have interoperable type and type param. */
2187 if (verify_c_interop (arg_ts
) == SUCCESS
2188 || gfc_check_any_c_kind (arg_ts
) == SUCCESS
)
2190 if (args_sym
->attr
.target
== 1)
2192 /* Case 1a, section 15.1.2.5, J3/04-007: variable that
2193 has the target attribute and is interoperable. */
2194 /* Case 1b, section 15.1.2.5, J3/04-007: allocated
2195 allocatable variable that has the TARGET attribute and
2196 is not an array of zero size. */
2197 if (args_sym
->attr
.allocatable
== 1)
2199 if (args_sym
->attr
.dimension
!= 0
2200 && (args_sym
->as
&& args_sym
->as
->rank
== 0))
2202 gfc_error_now ("Allocatable variable '%s' used as a "
2203 "parameter to '%s' at %L must not be "
2204 "an array of zero size",
2205 args_sym
->name
, sym
->name
,
2206 &(args
->expr
->where
));
2212 /* A non-allocatable target variable with C
2213 interoperable type and type parameters must be
2215 if (args_sym
&& args_sym
->attr
.dimension
)
2217 if (args_sym
->as
->type
== AS_ASSUMED_SHAPE
)
2219 gfc_error ("Assumed-shape array '%s' at %L "
2220 "cannot be an argument to the "
2221 "procedure '%s' because "
2222 "it is not C interoperable",
2224 &(args
->expr
->where
), sym
->name
);
2227 else if (args_sym
->as
->type
== AS_DEFERRED
)
2229 gfc_error ("Deferred-shape array '%s' at %L "
2230 "cannot be an argument to the "
2231 "procedure '%s' because "
2232 "it is not C interoperable",
2234 &(args
->expr
->where
), sym
->name
);
2239 /* Make sure it's not a character string. Arrays of
2240 any type should be ok if the variable is of a C
2241 interoperable type. */
2242 if (arg_ts
->type
== BT_CHARACTER
)
2243 if (arg_ts
->cl
!= NULL
2244 && (arg_ts
->cl
->length
== NULL
2245 || arg_ts
->cl
->length
->expr_type
2248 (arg_ts
->cl
->length
->value
.integer
, 1)
2250 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2252 gfc_error_now ("CHARACTER argument '%s' to '%s' "
2253 "at %L must have a length of 1",
2254 args_sym
->name
, sym
->name
,
2255 &(args
->expr
->where
));
2261 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2263 /* Case 1c, section 15.1.2.5, J3/04-007: an associated
2265 gfc_error_now ("Argument '%s' to '%s' at %L must be an "
2266 "associated scalar POINTER", args_sym
->name
,
2267 sym
->name
, &(args
->expr
->where
));
2273 /* The parameter is not required to be C interoperable. If it
2274 is not C interoperable, it must be a nonpolymorphic scalar
2275 with no length type parameters. It still must have either
2276 the pointer or target attribute, and it can be
2277 allocatable (but must be allocated when c_loc is called). */
2278 if (args
->expr
->rank
!= 0
2279 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2281 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2282 "scalar", args_sym
->name
, sym
->name
,
2283 &(args
->expr
->where
));
2286 else if (arg_ts
->type
== BT_CHARACTER
2287 && is_scalar_expr_ptr (args
->expr
) != SUCCESS
)
2289 gfc_error_now ("CHARACTER argument '%s' to '%s' at "
2290 "%L must have a length of 1",
2291 args_sym
->name
, sym
->name
,
2292 &(args
->expr
->where
));
2297 else if (sym
->intmod_sym_id
== ISOCBINDING_FUNLOC
)
2299 if (args_sym
->attr
.flavor
!= FL_PROCEDURE
)
2301 /* TODO: Update this error message to allow for procedure
2302 pointers once they are implemented. */
2303 gfc_error_now ("Parameter '%s' to '%s' at %L must be a "
2305 args_sym
->name
, sym
->name
,
2306 &(args
->expr
->where
));
2309 else if (args_sym
->attr
.is_bind_c
!= 1)
2311 gfc_error_now ("Parameter '%s' to '%s' at %L must be "
2313 args_sym
->name
, sym
->name
,
2314 &(args
->expr
->where
));
2319 /* for c_loc/c_funloc, the new symbol is the same as the old one */
2324 gfc_internal_error ("gfc_iso_c_func_interface(): Unhandled "
2325 "iso_c_binding function: '%s'!\n", sym
->name
);
2332 /* Resolve a function call, which means resolving the arguments, then figuring
2333 out which entity the name refers to. */
2334 /* TODO: Check procedure arguments so that an INTENT(IN) isn't passed
2335 to INTENT(OUT) or INTENT(INOUT). */
2338 resolve_function (gfc_expr
*expr
)
2340 gfc_actual_arglist
*arg
;
2345 procedure_type p
= PROC_INTRINSIC
;
2346 bool no_formal_args
;
2350 sym
= expr
->symtree
->n
.sym
;
2352 if (sym
&& sym
->attr
.intrinsic
2353 && resolve_intrinsic (sym
, &expr
->where
) == FAILURE
)
2356 if (sym
&& (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.subroutine
))
2358 gfc_error ("'%s' at %L is not a function", sym
->name
, &expr
->where
);
2362 if (sym
&& sym
->attr
.abstract
)
2364 gfc_error ("ABSTRACT INTERFACE '%s' must not be referenced at %L",
2365 sym
->name
, &expr
->where
);
2369 /* Switch off assumed size checking and do this again for certain kinds
2370 of procedure, once the procedure itself is resolved. */
2371 need_full_assumed_size
++;
2373 if (expr
->symtree
&& expr
->symtree
->n
.sym
)
2374 p
= expr
->symtree
->n
.sym
->attr
.proc
;
2376 no_formal_args
= sym
&& is_external_proc (sym
) && sym
->formal
== NULL
;
2377 if (resolve_actual_arglist (expr
->value
.function
.actual
,
2378 p
, no_formal_args
) == FAILURE
)
2381 /* Need to setup the call to the correct c_associated, depending on
2382 the number of cptrs to user gives to compare. */
2383 if (sym
&& sym
->attr
.is_iso_c
== 1)
2385 if (gfc_iso_c_func_interface (sym
, expr
->value
.function
.actual
, &sym
)
2389 /* Get the symtree for the new symbol (resolved func).
2390 the old one will be freed later, when it's no longer used. */
2391 gfc_find_sym_tree (sym
->name
, sym
->ns
, 1, &(expr
->symtree
));
2394 /* Resume assumed_size checking. */
2395 need_full_assumed_size
--;
2397 /* If the procedure is external, check for usage. */
2398 if (sym
&& is_external_proc (sym
))
2399 resolve_global_procedure (sym
, &expr
->where
,
2400 &expr
->value
.function
.actual
, 0);
2402 if (sym
&& sym
->ts
.type
== BT_CHARACTER
2404 && sym
->ts
.cl
->length
== NULL
2406 && expr
->value
.function
.esym
== NULL
2407 && !sym
->attr
.contained
)
2409 /* Internal procedures are taken care of in resolve_contained_fntype. */
2410 gfc_error ("Function '%s' is declared CHARACTER(*) and cannot "
2411 "be used at %L since it is not a dummy argument",
2412 sym
->name
, &expr
->where
);
2416 /* See if function is already resolved. */
2418 if (expr
->value
.function
.name
!= NULL
)
2420 if (expr
->ts
.type
== BT_UNKNOWN
)
2426 /* Apply the rules of section 14.1.2. */
2428 switch (procedure_kind (sym
))
2431 t
= resolve_generic_f (expr
);
2434 case PTYPE_SPECIFIC
:
2435 t
= resolve_specific_f (expr
);
2439 t
= resolve_unknown_f (expr
);
2443 gfc_internal_error ("resolve_function(): bad function type");
2447 /* If the expression is still a function (it might have simplified),
2448 then we check to see if we are calling an elemental function. */
2450 if (expr
->expr_type
!= EXPR_FUNCTION
)
2453 temp
= need_full_assumed_size
;
2454 need_full_assumed_size
= 0;
2456 if (resolve_elemental_actual (expr
, NULL
) == FAILURE
)
2459 if (omp_workshare_flag
2460 && expr
->value
.function
.esym
2461 && ! gfc_elemental (expr
->value
.function
.esym
))
2463 gfc_error ("User defined non-ELEMENTAL function '%s' at %L not allowed "
2464 "in WORKSHARE construct", expr
->value
.function
.esym
->name
,
2469 #define GENERIC_ID expr->value.function.isym->id
2470 else if (expr
->value
.function
.actual
!= NULL
2471 && expr
->value
.function
.isym
!= NULL
2472 && GENERIC_ID
!= GFC_ISYM_LBOUND
2473 && GENERIC_ID
!= GFC_ISYM_LEN
2474 && GENERIC_ID
!= GFC_ISYM_LOC
2475 && GENERIC_ID
!= GFC_ISYM_PRESENT
)
2477 /* Array intrinsics must also have the last upper bound of an
2478 assumed size array argument. UBOUND and SIZE have to be
2479 excluded from the check if the second argument is anything
2482 for (arg
= expr
->value
.function
.actual
; arg
; arg
= arg
->next
)
2484 if ((GENERIC_ID
== GFC_ISYM_UBOUND
|| GENERIC_ID
== GFC_ISYM_SIZE
)
2485 && arg
->next
!= NULL
&& arg
->next
->expr
)
2487 if (arg
->next
->expr
->expr_type
!= EXPR_CONSTANT
)
2490 if (arg
->next
->name
&& strncmp(arg
->next
->name
, "kind", 4) == 0)
2493 if ((int)mpz_get_si (arg
->next
->expr
->value
.integer
)
2498 if (arg
->expr
!= NULL
2499 && arg
->expr
->rank
> 0
2500 && resolve_assumed_size_actual (arg
->expr
))
2506 need_full_assumed_size
= temp
;
2509 if (!pure_function (expr
, &name
) && name
)
2513 gfc_error ("reference to non-PURE function '%s' at %L inside a "
2514 "FORALL %s", name
, &expr
->where
,
2515 forall_flag
== 2 ? "mask" : "block");
2518 else if (gfc_pure (NULL
))
2520 gfc_error ("Function reference to '%s' at %L is to a non-PURE "
2521 "procedure within a PURE procedure", name
, &expr
->where
);
2526 /* Functions without the RECURSIVE attribution are not allowed to
2527 * call themselves. */
2528 if (expr
->value
.function
.esym
&& !expr
->value
.function
.esym
->attr
.recursive
)
2531 esym
= expr
->value
.function
.esym
;
2533 if (is_illegal_recursion (esym
, gfc_current_ns
))
2535 if (esym
->attr
.entry
&& esym
->ns
->entries
)
2536 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
2537 " function '%s' is not RECURSIVE",
2538 esym
->name
, &expr
->where
, esym
->ns
->entries
->sym
->name
);
2540 gfc_error ("Function '%s' at %L cannot be called recursively, as it"
2541 " is not RECURSIVE", esym
->name
, &expr
->where
);
2547 /* Character lengths of use associated functions may contains references to
2548 symbols not referenced from the current program unit otherwise. Make sure
2549 those symbols are marked as referenced. */
2551 if (expr
->ts
.type
== BT_CHARACTER
&& expr
->value
.function
.esym
2552 && expr
->value
.function
.esym
->attr
.use_assoc
)
2554 gfc_expr_set_symbols_referenced (expr
->ts
.cl
->length
);
2558 && !((expr
->value
.function
.esym
2559 && expr
->value
.function
.esym
->attr
.elemental
)
2561 (expr
->value
.function
.isym
2562 && expr
->value
.function
.isym
->elemental
)))
2563 find_noncopying_intrinsics (expr
->value
.function
.esym
,
2564 expr
->value
.function
.actual
);
2566 /* Make sure that the expression has a typespec that works. */
2567 if (expr
->ts
.type
== BT_UNKNOWN
)
2569 if (expr
->symtree
->n
.sym
->result
2570 && expr
->symtree
->n
.sym
->result
->ts
.type
!= BT_UNKNOWN
2571 && !expr
->symtree
->n
.sym
->result
->attr
.proc_pointer
)
2572 expr
->ts
= expr
->symtree
->n
.sym
->result
->ts
;
2579 /************* Subroutine resolution *************/
2582 pure_subroutine (gfc_code
*c
, gfc_symbol
*sym
)
2588 gfc_error ("Subroutine call to '%s' in FORALL block at %L is not PURE",
2589 sym
->name
, &c
->loc
);
2590 else if (gfc_pure (NULL
))
2591 gfc_error ("Subroutine call to '%s' at %L is not PURE", sym
->name
,
2597 resolve_generic_s0 (gfc_code
*c
, gfc_symbol
*sym
)
2601 if (sym
->attr
.generic
)
2603 s
= gfc_search_interface (sym
->generic
, 1, &c
->ext
.actual
);
2606 c
->resolved_sym
= s
;
2607 pure_subroutine (c
, s
);
2611 /* TODO: Need to search for elemental references in generic interface. */
2614 if (sym
->attr
.intrinsic
)
2615 return gfc_intrinsic_sub_interface (c
, 0);
2622 resolve_generic_s (gfc_code
*c
)
2627 sym
= c
->symtree
->n
.sym
;
2631 m
= resolve_generic_s0 (c
, sym
);
2634 else if (m
== MATCH_ERROR
)
2638 if (sym
->ns
->parent
== NULL
)
2640 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2644 if (!generic_sym (sym
))
2648 /* Last ditch attempt. See if the reference is to an intrinsic
2649 that possesses a matching interface. 14.1.2.4 */
2650 sym
= c
->symtree
->n
.sym
;
2652 if (!gfc_is_intrinsic (sym
, 1, c
->loc
))
2654 gfc_error ("There is no specific subroutine for the generic '%s' at %L",
2655 sym
->name
, &c
->loc
);
2659 m
= gfc_intrinsic_sub_interface (c
, 0);
2663 gfc_error ("Generic subroutine '%s' at %L is not consistent with an "
2664 "intrinsic subroutine interface", sym
->name
, &c
->loc
);
2670 /* Set the name and binding label of the subroutine symbol in the call
2671 expression represented by 'c' to include the type and kind of the
2672 second parameter. This function is for resolving the appropriate
2673 version of c_f_pointer() and c_f_procpointer(). For example, a
2674 call to c_f_pointer() for a default integer pointer could have a
2675 name of c_f_pointer_i4. If no second arg exists, which is an error
2676 for these two functions, it defaults to the generic symbol's name
2677 and binding label. */
2680 set_name_and_label (gfc_code
*c
, gfc_symbol
*sym
,
2681 char *name
, char *binding_label
)
2683 gfc_expr
*arg
= NULL
;
2687 /* The second arg of c_f_pointer and c_f_procpointer determines
2688 the type and kind for the procedure name. */
2689 arg
= c
->ext
.actual
->next
->expr
;
2693 /* Set up the name to have the given symbol's name,
2694 plus the type and kind. */
2695 /* a derived type is marked with the type letter 'u' */
2696 if (arg
->ts
.type
== BT_DERIVED
)
2699 kind
= 0; /* set the kind as 0 for now */
2703 type
= gfc_type_letter (arg
->ts
.type
);
2704 kind
= arg
->ts
.kind
;
2707 if (arg
->ts
.type
== BT_CHARACTER
)
2708 /* Kind info for character strings not needed. */
2711 sprintf (name
, "%s_%c%d", sym
->name
, type
, kind
);
2712 /* Set up the binding label as the given symbol's label plus
2713 the type and kind. */
2714 sprintf (binding_label
, "%s_%c%d", sym
->binding_label
, type
, kind
);
2718 /* If the second arg is missing, set the name and label as
2719 was, cause it should at least be found, and the missing
2720 arg error will be caught by compare_parameters(). */
2721 sprintf (name
, "%s", sym
->name
);
2722 sprintf (binding_label
, "%s", sym
->binding_label
);
2729 /* Resolve a generic version of the iso_c_binding procedure given
2730 (sym) to the specific one based on the type and kind of the
2731 argument(s). Currently, this function resolves c_f_pointer() and
2732 c_f_procpointer based on the type and kind of the second argument
2733 (FPTR). Other iso_c_binding procedures aren't specially handled.
2734 Upon successfully exiting, c->resolved_sym will hold the resolved
2735 symbol. Returns MATCH_ERROR if an error occurred; MATCH_YES
2739 gfc_iso_c_sub_interface (gfc_code
*c
, gfc_symbol
*sym
)
2741 gfc_symbol
*new_sym
;
2742 /* this is fine, since we know the names won't use the max */
2743 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2744 char binding_label
[GFC_MAX_BINDING_LABEL_LEN
+ 1];
2745 /* default to success; will override if find error */
2746 match m
= MATCH_YES
;
2748 /* Make sure the actual arguments are in the necessary order (based on the
2749 formal args) before resolving. */
2750 gfc_procedure_use (sym
, &c
->ext
.actual
, &(c
->loc
));
2752 if ((sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
) ||
2753 (sym
->intmod_sym_id
== ISOCBINDING_F_PROCPOINTER
))
2755 set_name_and_label (c
, sym
, name
, binding_label
);
2757 if (sym
->intmod_sym_id
== ISOCBINDING_F_POINTER
)
2759 if (c
->ext
.actual
!= NULL
&& c
->ext
.actual
->next
!= NULL
)
2761 /* Make sure we got a third arg if the second arg has non-zero
2762 rank. We must also check that the type and rank are
2763 correct since we short-circuit this check in
2764 gfc_procedure_use() (called above to sort actual args). */
2765 if (c
->ext
.actual
->next
->expr
->rank
!= 0)
2767 if(c
->ext
.actual
->next
->next
== NULL
2768 || c
->ext
.actual
->next
->next
->expr
== NULL
)
2771 gfc_error ("Missing SHAPE parameter for call to %s "
2772 "at %L", sym
->name
, &(c
->loc
));
2774 else if (c
->ext
.actual
->next
->next
->expr
->ts
.type
2776 || c
->ext
.actual
->next
->next
->expr
->rank
!= 1)
2779 gfc_error ("SHAPE parameter for call to %s at %L must "
2780 "be a rank 1 INTEGER array", sym
->name
,
2787 if (m
!= MATCH_ERROR
)
2789 /* the 1 means to add the optional arg to formal list */
2790 new_sym
= get_iso_c_sym (sym
, name
, binding_label
, 1);
2792 /* for error reporting, say it's declared where the original was */
2793 new_sym
->declared_at
= sym
->declared_at
;
2798 /* no differences for c_loc or c_funloc */
2802 /* set the resolved symbol */
2803 if (m
!= MATCH_ERROR
)
2804 c
->resolved_sym
= new_sym
;
2806 c
->resolved_sym
= sym
;
2812 /* Resolve a subroutine call known to be specific. */
2815 resolve_specific_s0 (gfc_code
*c
, gfc_symbol
*sym
)
2819 if(sym
->attr
.is_iso_c
)
2821 m
= gfc_iso_c_sub_interface (c
,sym
);
2825 if (sym
->attr
.external
|| sym
->attr
.if_source
== IFSRC_IFBODY
)
2827 if (sym
->attr
.dummy
)
2829 sym
->attr
.proc
= PROC_DUMMY
;
2833 sym
->attr
.proc
= PROC_EXTERNAL
;
2837 if (sym
->attr
.proc
== PROC_MODULE
|| sym
->attr
.proc
== PROC_INTERNAL
)
2840 if (sym
->attr
.intrinsic
)
2842 m
= gfc_intrinsic_sub_interface (c
, 1);
2846 gfc_error ("Subroutine '%s' at %L is INTRINSIC but is not compatible "
2847 "with an intrinsic", sym
->name
, &c
->loc
);
2855 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
2857 c
->resolved_sym
= sym
;
2858 pure_subroutine (c
, sym
);
2865 resolve_specific_s (gfc_code
*c
)
2870 sym
= c
->symtree
->n
.sym
;
2874 m
= resolve_specific_s0 (c
, sym
);
2877 if (m
== MATCH_ERROR
)
2880 if (sym
->ns
->parent
== NULL
)
2883 gfc_find_symbol (sym
->name
, sym
->ns
->parent
, 1, &sym
);
2889 sym
= c
->symtree
->n
.sym
;
2890 gfc_error ("Unable to resolve the specific subroutine '%s' at %L",
2891 sym
->name
, &c
->loc
);
2897 /* Resolve a subroutine call not known to be generic nor specific. */
2900 resolve_unknown_s (gfc_code
*c
)
2904 sym
= c
->symtree
->n
.sym
;
2906 if (sym
->attr
.dummy
)
2908 sym
->attr
.proc
= PROC_DUMMY
;
2912 /* See if we have an intrinsic function reference. */
2914 if (gfc_is_intrinsic (sym
, 1, c
->loc
))
2916 if (gfc_intrinsic_sub_interface (c
, 1) == MATCH_YES
)
2921 /* The reference is to an external name. */
2924 gfc_procedure_use (sym
, &c
->ext
.actual
, &c
->loc
);
2926 c
->resolved_sym
= sym
;
2928 pure_subroutine (c
, sym
);
2934 /* Resolve a subroutine call. Although it was tempting to use the same code
2935 for functions, subroutines and functions are stored differently and this
2936 makes things awkward. */
2939 resolve_call (gfc_code
*c
)
2942 procedure_type ptype
= PROC_INTRINSIC
;
2943 gfc_symbol
*csym
, *sym
;
2944 bool no_formal_args
;
2946 csym
= c
->symtree
? c
->symtree
->n
.sym
: NULL
;
2948 if (csym
&& csym
->ts
.type
!= BT_UNKNOWN
)
2950 gfc_error ("'%s' at %L has a type, which is not consistent with "
2951 "the CALL at %L", csym
->name
, &csym
->declared_at
, &c
->loc
);
2955 if (csym
&& gfc_current_ns
->parent
&& csym
->ns
!= gfc_current_ns
)
2958 gfc_find_sym_tree (csym
->name
, gfc_current_ns
, 1, &st
);
2959 sym
= st
? st
->n
.sym
: NULL
;
2960 if (sym
&& csym
!= sym
2961 && sym
->ns
== gfc_current_ns
2962 && sym
->attr
.flavor
== FL_PROCEDURE
2963 && sym
->attr
.contained
)
2966 if (csym
->attr
.generic
)
2967 c
->symtree
->n
.sym
= sym
;
2970 csym
= c
->symtree
->n
.sym
;
2974 /* Subroutines without the RECURSIVE attribution are not allowed to
2975 * call themselves. */
2976 if (csym
&& is_illegal_recursion (csym
, gfc_current_ns
))
2978 if (csym
->attr
.entry
&& csym
->ns
->entries
)
2979 gfc_error ("ENTRY '%s' at %L cannot be called recursively, as"
2980 " subroutine '%s' is not RECURSIVE",
2981 csym
->name
, &c
->loc
, csym
->ns
->entries
->sym
->name
);
2983 gfc_error ("SUBROUTINE '%s' at %L cannot be called recursively, as it"
2984 " is not RECURSIVE", csym
->name
, &c
->loc
);
2989 /* Switch off assumed size checking and do this again for certain kinds
2990 of procedure, once the procedure itself is resolved. */
2991 need_full_assumed_size
++;
2994 ptype
= csym
->attr
.proc
;
2996 no_formal_args
= csym
&& is_external_proc (csym
) && csym
->formal
== NULL
;
2997 if (resolve_actual_arglist (c
->ext
.actual
, ptype
,
2998 no_formal_args
) == FAILURE
)
3001 /* Resume assumed_size checking. */
3002 need_full_assumed_size
--;
3004 /* If external, check for usage. */
3005 if (csym
&& is_external_proc (csym
))
3006 resolve_global_procedure (csym
, &c
->loc
, &c
->ext
.actual
, 1);
3009 if (c
->resolved_sym
== NULL
)
3011 c
->resolved_isym
= NULL
;
3012 switch (procedure_kind (csym
))
3015 t
= resolve_generic_s (c
);
3018 case PTYPE_SPECIFIC
:
3019 t
= resolve_specific_s (c
);
3023 t
= resolve_unknown_s (c
);
3027 gfc_internal_error ("resolve_subroutine(): bad function type");
3031 /* Some checks of elemental subroutine actual arguments. */
3032 if (resolve_elemental_actual (NULL
, c
) == FAILURE
)
3035 if (t
== SUCCESS
&& !(c
->resolved_sym
&& c
->resolved_sym
->attr
.elemental
))
3036 find_noncopying_intrinsics (c
->resolved_sym
, c
->ext
.actual
);
3041 /* Compare the shapes of two arrays that have non-NULL shapes. If both
3042 op1->shape and op2->shape are non-NULL return SUCCESS if their shapes
3043 match. If both op1->shape and op2->shape are non-NULL return FAILURE
3044 if their shapes do not match. If either op1->shape or op2->shape is
3045 NULL, return SUCCESS. */
3048 compare_shapes (gfc_expr
*op1
, gfc_expr
*op2
)
3055 if (op1
->shape
!= NULL
&& op2
->shape
!= NULL
)
3057 for (i
= 0; i
< op1
->rank
; i
++)
3059 if (mpz_cmp (op1
->shape
[i
], op2
->shape
[i
]) != 0)
3061 gfc_error ("Shapes for operands at %L and %L are not conformable",
3062 &op1
->where
, &op2
->where
);
3073 /* Resolve an operator expression node. This can involve replacing the
3074 operation with a user defined function call. */
3077 resolve_operator (gfc_expr
*e
)
3079 gfc_expr
*op1
, *op2
;
3081 bool dual_locus_error
;
3084 /* Resolve all subnodes-- give them types. */
3086 switch (e
->value
.op
.op
)
3089 if (gfc_resolve_expr (e
->value
.op
.op2
) == FAILURE
)
3092 /* Fall through... */
3095 case INTRINSIC_UPLUS
:
3096 case INTRINSIC_UMINUS
:
3097 case INTRINSIC_PARENTHESES
:
3098 if (gfc_resolve_expr (e
->value
.op
.op1
) == FAILURE
)
3103 /* Typecheck the new node. */
3105 op1
= e
->value
.op
.op1
;
3106 op2
= e
->value
.op
.op2
;
3107 dual_locus_error
= false;
3109 if ((op1
&& op1
->expr_type
== EXPR_NULL
)
3110 || (op2
&& op2
->expr_type
== EXPR_NULL
))
3112 sprintf (msg
, _("Invalid context for NULL() pointer at %%L"));
3116 switch (e
->value
.op
.op
)
3118 case INTRINSIC_UPLUS
:
3119 case INTRINSIC_UMINUS
:
3120 if (op1
->ts
.type
== BT_INTEGER
3121 || op1
->ts
.type
== BT_REAL
3122 || op1
->ts
.type
== BT_COMPLEX
)
3128 sprintf (msg
, _("Operand of unary numeric operator '%s' at %%L is %s"),
3129 gfc_op2string (e
->value
.op
.op
), gfc_typename (&e
->ts
));
3132 case INTRINSIC_PLUS
:
3133 case INTRINSIC_MINUS
:
3134 case INTRINSIC_TIMES
:
3135 case INTRINSIC_DIVIDE
:
3136 case INTRINSIC_POWER
:
3137 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3139 gfc_type_convert_binary (e
);
3144 _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
3145 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3146 gfc_typename (&op2
->ts
));
3149 case INTRINSIC_CONCAT
:
3150 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3151 && op1
->ts
.kind
== op2
->ts
.kind
)
3153 e
->ts
.type
= BT_CHARACTER
;
3154 e
->ts
.kind
= op1
->ts
.kind
;
3159 _("Operands of string concatenation operator at %%L are %s/%s"),
3160 gfc_typename (&op1
->ts
), gfc_typename (&op2
->ts
));
3166 case INTRINSIC_NEQV
:
3167 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3169 e
->ts
.type
= BT_LOGICAL
;
3170 e
->ts
.kind
= gfc_kind_max (op1
, op2
);
3171 if (op1
->ts
.kind
< e
->ts
.kind
)
3172 gfc_convert_type (op1
, &e
->ts
, 2);
3173 else if (op2
->ts
.kind
< e
->ts
.kind
)
3174 gfc_convert_type (op2
, &e
->ts
, 2);
3178 sprintf (msg
, _("Operands of logical operator '%s' at %%L are %s/%s"),
3179 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3180 gfc_typename (&op2
->ts
));
3185 if (op1
->ts
.type
== BT_LOGICAL
)
3187 e
->ts
.type
= BT_LOGICAL
;
3188 e
->ts
.kind
= op1
->ts
.kind
;
3192 sprintf (msg
, _("Operand of .not. operator at %%L is %s"),
3193 gfc_typename (&op1
->ts
));
3197 case INTRINSIC_GT_OS
:
3199 case INTRINSIC_GE_OS
:
3201 case INTRINSIC_LT_OS
:
3203 case INTRINSIC_LE_OS
:
3204 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
3206 strcpy (msg
, _("COMPLEX quantities cannot be compared at %L"));
3210 /* Fall through... */
3213 case INTRINSIC_EQ_OS
:
3215 case INTRINSIC_NE_OS
:
3216 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
3217 && op1
->ts
.kind
== op2
->ts
.kind
)
3219 e
->ts
.type
= BT_LOGICAL
;
3220 e
->ts
.kind
= gfc_default_logical_kind
;
3224 if (gfc_numeric_ts (&op1
->ts
) && gfc_numeric_ts (&op2
->ts
))
3226 gfc_type_convert_binary (e
);
3228 e
->ts
.type
= BT_LOGICAL
;
3229 e
->ts
.kind
= gfc_default_logical_kind
;
3233 if (op1
->ts
.type
== BT_LOGICAL
&& op2
->ts
.type
== BT_LOGICAL
)
3235 _("Logicals at %%L must be compared with %s instead of %s"),
3236 (e
->value
.op
.op
== INTRINSIC_EQ
3237 || e
->value
.op
.op
== INTRINSIC_EQ_OS
)
3238 ? ".eqv." : ".neqv.", gfc_op2string (e
->value
.op
.op
));
3241 _("Operands of comparison operator '%s' at %%L are %s/%s"),
3242 gfc_op2string (e
->value
.op
.op
), gfc_typename (&op1
->ts
),
3243 gfc_typename (&op2
->ts
));
3247 case INTRINSIC_USER
:
3248 if (e
->value
.op
.uop
->op
== NULL
)
3249 sprintf (msg
, _("Unknown operator '%s' at %%L"), e
->value
.op
.uop
->name
);
3250 else if (op2
== NULL
)
3251 sprintf (msg
, _("Operand of user operator '%s' at %%L is %s"),
3252 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
));
3254 sprintf (msg
, _("Operands of user operator '%s' at %%L are %s/%s"),
3255 e
->value
.op
.uop
->name
, gfc_typename (&op1
->ts
),
3256 gfc_typename (&op2
->ts
));
3260 case INTRINSIC_PARENTHESES
:
3262 if (e
->ts
.type
== BT_CHARACTER
)
3263 e
->ts
.cl
= op1
->ts
.cl
;
3267 gfc_internal_error ("resolve_operator(): Bad intrinsic");
3270 /* Deal with arrayness of an operand through an operator. */
3274 switch (e
->value
.op
.op
)
3276 case INTRINSIC_PLUS
:
3277 case INTRINSIC_MINUS
:
3278 case INTRINSIC_TIMES
:
3279 case INTRINSIC_DIVIDE
:
3280 case INTRINSIC_POWER
:
3281 case INTRINSIC_CONCAT
:
3285 case INTRINSIC_NEQV
:
3287 case INTRINSIC_EQ_OS
:
3289 case INTRINSIC_NE_OS
:
3291 case INTRINSIC_GT_OS
:
3293 case INTRINSIC_GE_OS
:
3295 case INTRINSIC_LT_OS
:
3297 case INTRINSIC_LE_OS
:
3299 if (op1
->rank
== 0 && op2
->rank
== 0)
3302 if (op1
->rank
== 0 && op2
->rank
!= 0)
3304 e
->rank
= op2
->rank
;
3306 if (e
->shape
== NULL
)
3307 e
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
3310 if (op1
->rank
!= 0 && op2
->rank
== 0)
3312 e
->rank
= op1
->rank
;
3314 if (e
->shape
== NULL
)
3315 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3318 if (op1
->rank
!= 0 && op2
->rank
!= 0)
3320 if (op1
->rank
== op2
->rank
)
3322 e
->rank
= op1
->rank
;
3323 if (e
->shape
== NULL
)
3325 t
= compare_shapes(op1
, op2
);
3329 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3334 /* Allow higher level expressions to work. */
3337 /* Try user-defined operators, and otherwise throw an error. */
3338 dual_locus_error
= true;
3340 _("Inconsistent ranks for operator at %%L and %%L"));
3347 case INTRINSIC_PARENTHESES
:
3349 case INTRINSIC_UPLUS
:
3350 case INTRINSIC_UMINUS
:
3351 /* Simply copy arrayness attribute */
3352 e
->rank
= op1
->rank
;
3354 if (e
->shape
== NULL
)
3355 e
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
3363 /* Attempt to simplify the expression. */
3366 t
= gfc_simplify_expr (e
, 0);
3367 /* Some calls do not succeed in simplification and return FAILURE
3368 even though there is no error; e.g. variable references to
3369 PARAMETER arrays. */
3370 if (!gfc_is_constant_expr (e
))
3377 if (gfc_extend_expr (e
) == SUCCESS
)
3380 if (dual_locus_error
)
3381 gfc_error (msg
, &op1
->where
, &op2
->where
);
3383 gfc_error (msg
, &e
->where
);
3389 /************** Array resolution subroutines **************/
3392 { CMP_LT
, CMP_EQ
, CMP_GT
, CMP_UNKNOWN
}
3395 /* Compare two integer expressions. */
3398 compare_bound (gfc_expr
*a
, gfc_expr
*b
)
3402 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
3403 || b
== NULL
|| b
->expr_type
!= EXPR_CONSTANT
)
3406 /* If either of the types isn't INTEGER, we must have
3407 raised an error earlier. */
3409 if (a
->ts
.type
!= BT_INTEGER
|| b
->ts
.type
!= BT_INTEGER
)
3412 i
= mpz_cmp (a
->value
.integer
, b
->value
.integer
);
3422 /* Compare an integer expression with an integer. */
3425 compare_bound_int (gfc_expr
*a
, int b
)
3429 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3432 if (a
->ts
.type
!= BT_INTEGER
)
3433 gfc_internal_error ("compare_bound_int(): Bad expression");
3435 i
= mpz_cmp_si (a
->value
.integer
, b
);
3445 /* Compare an integer expression with a mpz_t. */
3448 compare_bound_mpz_t (gfc_expr
*a
, mpz_t b
)
3452 if (a
== NULL
|| a
->expr_type
!= EXPR_CONSTANT
)
3455 if (a
->ts
.type
!= BT_INTEGER
)
3456 gfc_internal_error ("compare_bound_int(): Bad expression");
3458 i
= mpz_cmp (a
->value
.integer
, b
);
3468 /* Compute the last value of a sequence given by a triplet.
3469 Return 0 if it wasn't able to compute the last value, or if the
3470 sequence if empty, and 1 otherwise. */
3473 compute_last_value_for_triplet (gfc_expr
*start
, gfc_expr
*end
,
3474 gfc_expr
*stride
, mpz_t last
)
3478 if (start
== NULL
|| start
->expr_type
!= EXPR_CONSTANT
3479 || end
== NULL
|| end
->expr_type
!= EXPR_CONSTANT
3480 || (stride
!= NULL
&& stride
->expr_type
!= EXPR_CONSTANT
))
3483 if (start
->ts
.type
!= BT_INTEGER
|| end
->ts
.type
!= BT_INTEGER
3484 || (stride
!= NULL
&& stride
->ts
.type
!= BT_INTEGER
))
3487 if (stride
== NULL
|| compare_bound_int(stride
, 1) == CMP_EQ
)
3489 if (compare_bound (start
, end
) == CMP_GT
)
3491 mpz_set (last
, end
->value
.integer
);
3495 if (compare_bound_int (stride
, 0) == CMP_GT
)
3497 /* Stride is positive */
3498 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) > 0)
3503 /* Stride is negative */
3504 if (mpz_cmp (start
->value
.integer
, end
->value
.integer
) < 0)
3509 mpz_sub (rem
, end
->value
.integer
, start
->value
.integer
);
3510 mpz_tdiv_r (rem
, rem
, stride
->value
.integer
);
3511 mpz_sub (last
, end
->value
.integer
, rem
);
3518 /* Compare a single dimension of an array reference to the array
3522 check_dimension (int i
, gfc_array_ref
*ar
, gfc_array_spec
*as
)
3526 /* Given start, end and stride values, calculate the minimum and
3527 maximum referenced indexes. */
3529 switch (ar
->dimen_type
[i
])
3535 if (compare_bound (ar
->start
[i
], as
->lower
[i
]) == CMP_LT
)
3537 gfc_warning ("Array reference at %L is out of bounds "
3538 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3539 mpz_get_si (ar
->start
[i
]->value
.integer
),
3540 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3543 if (compare_bound (ar
->start
[i
], as
->upper
[i
]) == CMP_GT
)
3545 gfc_warning ("Array reference at %L is out of bounds "
3546 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3547 mpz_get_si (ar
->start
[i
]->value
.integer
),
3548 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3556 #define AR_START (ar->start[i] ? ar->start[i] : as->lower[i])
3557 #define AR_END (ar->end[i] ? ar->end[i] : as->upper[i])
3559 comparison comp_start_end
= compare_bound (AR_START
, AR_END
);
3561 /* Check for zero stride, which is not allowed. */
3562 if (compare_bound_int (ar
->stride
[i
], 0) == CMP_EQ
)
3564 gfc_error ("Illegal stride of zero at %L", &ar
->c_where
[i
]);
3568 /* if start == len || (stride > 0 && start < len)
3569 || (stride < 0 && start > len),
3570 then the array section contains at least one element. In this
3571 case, there is an out-of-bounds access if
3572 (start < lower || start > upper). */
3573 if (compare_bound (AR_START
, AR_END
) == CMP_EQ
3574 || ((compare_bound_int (ar
->stride
[i
], 0) == CMP_GT
3575 || ar
->stride
[i
] == NULL
) && comp_start_end
== CMP_LT
)
3576 || (compare_bound_int (ar
->stride
[i
], 0) == CMP_LT
3577 && comp_start_end
== CMP_GT
))
3579 if (compare_bound (AR_START
, as
->lower
[i
]) == CMP_LT
)
3581 gfc_warning ("Lower array reference at %L is out of bounds "
3582 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3583 mpz_get_si (AR_START
->value
.integer
),
3584 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3587 if (compare_bound (AR_START
, as
->upper
[i
]) == CMP_GT
)
3589 gfc_warning ("Lower array reference at %L is out of bounds "
3590 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3591 mpz_get_si (AR_START
->value
.integer
),
3592 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3597 /* If we can compute the highest index of the array section,
3598 then it also has to be between lower and upper. */
3599 mpz_init (last_value
);
3600 if (compute_last_value_for_triplet (AR_START
, AR_END
, ar
->stride
[i
],
3603 if (compare_bound_mpz_t (as
->lower
[i
], last_value
) == CMP_GT
)
3605 gfc_warning ("Upper array reference at %L is out of bounds "
3606 "(%ld < %ld) in dimension %d", &ar
->c_where
[i
],
3607 mpz_get_si (last_value
),
3608 mpz_get_si (as
->lower
[i
]->value
.integer
), i
+1);
3609 mpz_clear (last_value
);
3612 if (compare_bound_mpz_t (as
->upper
[i
], last_value
) == CMP_LT
)
3614 gfc_warning ("Upper array reference at %L is out of bounds "
3615 "(%ld > %ld) in dimension %d", &ar
->c_where
[i
],
3616 mpz_get_si (last_value
),
3617 mpz_get_si (as
->upper
[i
]->value
.integer
), i
+1);
3618 mpz_clear (last_value
);
3622 mpz_clear (last_value
);
3630 gfc_internal_error ("check_dimension(): Bad array reference");
3637 /* Compare an array reference with an array specification. */
3640 compare_spec_to_ref (gfc_array_ref
*ar
)
3647 /* TODO: Full array sections are only allowed as actual parameters. */
3648 if (as
->type
== AS_ASSUMED_SIZE
3649 && (/*ar->type == AR_FULL
3650 ||*/ (ar
->type
== AR_SECTION
3651 && ar
->dimen_type
[i
] == DIMEN_RANGE
&& ar
->end
[i
] == NULL
)))
3653 gfc_error ("Rightmost upper bound of assumed size array section "
3654 "not specified at %L", &ar
->where
);
3658 if (ar
->type
== AR_FULL
)
3661 if (as
->rank
!= ar
->dimen
)
3663 gfc_error ("Rank mismatch in array reference at %L (%d/%d)",
3664 &ar
->where
, ar
->dimen
, as
->rank
);
3668 for (i
= 0; i
< as
->rank
; i
++)
3669 if (check_dimension (i
, ar
, as
) == FAILURE
)
3676 /* Resolve one part of an array index. */
3679 gfc_resolve_index (gfc_expr
*index
, int check_scalar
)
3686 if (gfc_resolve_expr (index
) == FAILURE
)
3689 if (check_scalar
&& index
->rank
!= 0)
3691 gfc_error ("Array index at %L must be scalar", &index
->where
);
3695 if (index
->ts
.type
!= BT_INTEGER
&& index
->ts
.type
!= BT_REAL
)
3697 gfc_error ("Array index at %L must be of INTEGER type, found %s",
3698 &index
->where
, gfc_basic_typename (index
->ts
.type
));
3702 if (index
->ts
.type
== BT_REAL
)
3703 if (gfc_notify_std (GFC_STD_LEGACY
, "Extension: REAL array index at %L",
3704 &index
->where
) == FAILURE
)
3707 if (index
->ts
.kind
!= gfc_index_integer_kind
3708 || index
->ts
.type
!= BT_INTEGER
)
3711 ts
.type
= BT_INTEGER
;
3712 ts
.kind
= gfc_index_integer_kind
;
3714 gfc_convert_type_warn (index
, &ts
, 2, 0);
3720 /* Resolve a dim argument to an intrinsic function. */
3723 gfc_resolve_dim_arg (gfc_expr
*dim
)
3728 if (gfc_resolve_expr (dim
) == FAILURE
)
3733 gfc_error ("Argument dim at %L must be scalar", &dim
->where
);
3738 if (dim
->ts
.type
!= BT_INTEGER
)
3740 gfc_error ("Argument dim at %L must be of INTEGER type", &dim
->where
);
3744 if (dim
->ts
.kind
!= gfc_index_integer_kind
)
3748 ts
.type
= BT_INTEGER
;
3749 ts
.kind
= gfc_index_integer_kind
;
3751 gfc_convert_type_warn (dim
, &ts
, 2, 0);
3757 /* Given an expression that contains array references, update those array
3758 references to point to the right array specifications. While this is
3759 filled in during matching, this information is difficult to save and load
3760 in a module, so we take care of it here.
3762 The idea here is that the original array reference comes from the
3763 base symbol. We traverse the list of reference structures, setting
3764 the stored reference to references. Component references can
3765 provide an additional array specification. */
3768 find_array_spec (gfc_expr
*e
)
3772 gfc_symbol
*derived
;
3775 as
= e
->symtree
->n
.sym
->as
;
3778 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
3783 gfc_internal_error ("find_array_spec(): Missing spec");
3790 if (derived
== NULL
)
3791 derived
= e
->symtree
->n
.sym
->ts
.derived
;
3793 c
= derived
->components
;
3795 for (; c
; c
= c
->next
)
3796 if (c
== ref
->u
.c
.component
)
3798 /* Track the sequence of component references. */
3799 if (c
->ts
.type
== BT_DERIVED
)
3800 derived
= c
->ts
.derived
;
3805 gfc_internal_error ("find_array_spec(): Component not found");
3807 if (c
->attr
.dimension
)
3810 gfc_internal_error ("find_array_spec(): unused as(1)");
3821 gfc_internal_error ("find_array_spec(): unused as(2)");
3825 /* Resolve an array reference. */
3828 resolve_array_ref (gfc_array_ref
*ar
)
3830 int i
, check_scalar
;
3833 for (i
= 0; i
< ar
->dimen
; i
++)
3835 check_scalar
= ar
->dimen_type
[i
] == DIMEN_RANGE
;
3837 if (gfc_resolve_index (ar
->start
[i
], check_scalar
) == FAILURE
)
3839 if (gfc_resolve_index (ar
->end
[i
], check_scalar
) == FAILURE
)
3841 if (gfc_resolve_index (ar
->stride
[i
], check_scalar
) == FAILURE
)
3846 if (ar
->dimen_type
[i
] == DIMEN_UNKNOWN
)
3850 ar
->dimen_type
[i
] = DIMEN_ELEMENT
;
3854 ar
->dimen_type
[i
] = DIMEN_VECTOR
;
3855 if (e
->expr_type
== EXPR_VARIABLE
3856 && e
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
)
3857 ar
->start
[i
] = gfc_get_parentheses (e
);
3861 gfc_error ("Array index at %L is an array of rank %d",
3862 &ar
->c_where
[i
], e
->rank
);
3867 /* If the reference type is unknown, figure out what kind it is. */
3869 if (ar
->type
== AR_UNKNOWN
)
3871 ar
->type
= AR_ELEMENT
;
3872 for (i
= 0; i
< ar
->dimen
; i
++)
3873 if (ar
->dimen_type
[i
] == DIMEN_RANGE
3874 || ar
->dimen_type
[i
] == DIMEN_VECTOR
)
3876 ar
->type
= AR_SECTION
;
3881 if (!ar
->as
->cray_pointee
&& compare_spec_to_ref (ar
) == FAILURE
)
3889 resolve_substring (gfc_ref
*ref
)
3891 if (ref
->u
.ss
.start
!= NULL
)
3893 if (gfc_resolve_expr (ref
->u
.ss
.start
) == FAILURE
)
3896 if (ref
->u
.ss
.start
->ts
.type
!= BT_INTEGER
)
3898 gfc_error ("Substring start index at %L must be of type INTEGER",
3899 &ref
->u
.ss
.start
->where
);
3903 if (ref
->u
.ss
.start
->rank
!= 0)
3905 gfc_error ("Substring start index at %L must be scalar",
3906 &ref
->u
.ss
.start
->where
);
3910 if (compare_bound_int (ref
->u
.ss
.start
, 1) == CMP_LT
3911 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
3912 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
3914 gfc_error ("Substring start index at %L is less than one",
3915 &ref
->u
.ss
.start
->where
);
3920 if (ref
->u
.ss
.end
!= NULL
)
3922 if (gfc_resolve_expr (ref
->u
.ss
.end
) == FAILURE
)
3925 if (ref
->u
.ss
.end
->ts
.type
!= BT_INTEGER
)
3927 gfc_error ("Substring end index at %L must be of type INTEGER",
3928 &ref
->u
.ss
.end
->where
);
3932 if (ref
->u
.ss
.end
->rank
!= 0)
3934 gfc_error ("Substring end index at %L must be scalar",
3935 &ref
->u
.ss
.end
->where
);
3939 if (ref
->u
.ss
.length
!= NULL
3940 && compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.length
->length
) == CMP_GT
3941 && (compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_EQ
3942 || compare_bound (ref
->u
.ss
.end
, ref
->u
.ss
.start
) == CMP_GT
))
3944 gfc_error ("Substring end index at %L exceeds the string length",
3945 &ref
->u
.ss
.start
->where
);
3954 /* This function supplies missing substring charlens. */
3957 gfc_resolve_substring_charlen (gfc_expr
*e
)
3960 gfc_expr
*start
, *end
;
3962 for (char_ref
= e
->ref
; char_ref
; char_ref
= char_ref
->next
)
3963 if (char_ref
->type
== REF_SUBSTRING
)
3969 gcc_assert (char_ref
->next
== NULL
);
3973 if (e
->ts
.cl
->length
)
3974 gfc_free_expr (e
->ts
.cl
->length
);
3975 else if (e
->expr_type
== EXPR_VARIABLE
3976 && e
->symtree
->n
.sym
->attr
.dummy
)
3980 e
->ts
.type
= BT_CHARACTER
;
3981 e
->ts
.kind
= gfc_default_character_kind
;
3985 e
->ts
.cl
= gfc_get_charlen ();
3986 e
->ts
.cl
->next
= gfc_current_ns
->cl_list
;
3987 gfc_current_ns
->cl_list
= e
->ts
.cl
;
3990 if (char_ref
->u
.ss
.start
)
3991 start
= gfc_copy_expr (char_ref
->u
.ss
.start
);
3993 start
= gfc_int_expr (1);
3995 if (char_ref
->u
.ss
.end
)
3996 end
= gfc_copy_expr (char_ref
->u
.ss
.end
);
3997 else if (e
->expr_type
== EXPR_VARIABLE
)
3998 end
= gfc_copy_expr (e
->symtree
->n
.sym
->ts
.cl
->length
);
4005 /* Length = (end - start +1). */
4006 e
->ts
.cl
->length
= gfc_subtract (end
, start
);
4007 e
->ts
.cl
->length
= gfc_add (e
->ts
.cl
->length
, gfc_int_expr (1));
4009 e
->ts
.cl
->length
->ts
.type
= BT_INTEGER
;
4010 e
->ts
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;;
4012 /* Make sure that the length is simplified. */
4013 gfc_simplify_expr (e
->ts
.cl
->length
, 1);
4014 gfc_resolve_expr (e
->ts
.cl
->length
);
4018 /* Resolve subtype references. */
4021 resolve_ref (gfc_expr
*expr
)
4023 int current_part_dimension
, n_components
, seen_part_dimension
;
4026 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4027 if (ref
->type
== REF_ARRAY
&& ref
->u
.ar
.as
== NULL
)
4029 find_array_spec (expr
);
4033 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4037 if (resolve_array_ref (&ref
->u
.ar
) == FAILURE
)
4045 resolve_substring (ref
);
4049 /* Check constraints on part references. */
4051 current_part_dimension
= 0;
4052 seen_part_dimension
= 0;
4055 for (ref
= expr
->ref
; ref
; ref
= ref
->next
)
4060 switch (ref
->u
.ar
.type
)
4064 current_part_dimension
= 1;
4068 current_part_dimension
= 0;
4072 gfc_internal_error ("resolve_ref(): Bad array reference");
4078 if (current_part_dimension
|| seen_part_dimension
)
4080 if (ref
->u
.c
.component
->attr
.pointer
)
4082 gfc_error ("Component to the right of a part reference "
4083 "with nonzero rank must not have the POINTER "
4084 "attribute at %L", &expr
->where
);
4087 else if (ref
->u
.c
.component
->attr
.allocatable
)
4089 gfc_error ("Component to the right of a part reference "
4090 "with nonzero rank must not have the ALLOCATABLE "
4091 "attribute at %L", &expr
->where
);
4103 if (((ref
->type
== REF_COMPONENT
&& n_components
> 1)
4104 || ref
->next
== NULL
)
4105 && current_part_dimension
4106 && seen_part_dimension
)
4108 gfc_error ("Two or more part references with nonzero rank must "
4109 "not be specified at %L", &expr
->where
);
4113 if (ref
->type
== REF_COMPONENT
)
4115 if (current_part_dimension
)
4116 seen_part_dimension
= 1;
4118 /* reset to make sure */
4119 current_part_dimension
= 0;
4127 /* Given an expression, determine its shape. This is easier than it sounds.
4128 Leaves the shape array NULL if it is not possible to determine the shape. */
4131 expression_shape (gfc_expr
*e
)
4133 mpz_t array
[GFC_MAX_DIMENSIONS
];
4136 if (e
->rank
== 0 || e
->shape
!= NULL
)
4139 for (i
= 0; i
< e
->rank
; i
++)
4140 if (gfc_array_dimen_size (e
, i
, &array
[i
]) == FAILURE
)
4143 e
->shape
= gfc_get_shape (e
->rank
);
4145 memcpy (e
->shape
, array
, e
->rank
* sizeof (mpz_t
));
4150 for (i
--; i
>= 0; i
--)
4151 mpz_clear (array
[i
]);
4155 /* Given a variable expression node, compute the rank of the expression by
4156 examining the base symbol and any reference structures it may have. */
4159 expression_rank (gfc_expr
*e
)
4164 /* Just to make sure, because EXPR_COMPCALL's also have an e->ref and that
4165 could lead to serious confusion... */
4166 gcc_assert (e
->expr_type
!= EXPR_COMPCALL
);
4170 if (e
->expr_type
== EXPR_ARRAY
)
4172 /* Constructors can have a rank different from one via RESHAPE(). */
4174 if (e
->symtree
== NULL
)
4180 e
->rank
= (e
->symtree
->n
.sym
->as
== NULL
)
4181 ? 0 : e
->symtree
->n
.sym
->as
->rank
;
4187 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4189 if (ref
->type
!= REF_ARRAY
)
4192 if (ref
->u
.ar
.type
== AR_FULL
)
4194 rank
= ref
->u
.ar
.as
->rank
;
4198 if (ref
->u
.ar
.type
== AR_SECTION
)
4200 /* Figure out the rank of the section. */
4202 gfc_internal_error ("expression_rank(): Two array specs");
4204 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
4205 if (ref
->u
.ar
.dimen_type
[i
] == DIMEN_RANGE
4206 || ref
->u
.ar
.dimen_type
[i
] == DIMEN_VECTOR
)
4216 expression_shape (e
);
4220 /* Resolve a variable expression. */
4223 resolve_variable (gfc_expr
*e
)
4230 if (e
->symtree
== NULL
)
4233 if (e
->ref
&& resolve_ref (e
) == FAILURE
)
4236 sym
= e
->symtree
->n
.sym
;
4237 if (sym
->attr
.flavor
== FL_PROCEDURE
4238 && (!sym
->attr
.function
4239 || (sym
->attr
.function
&& sym
->result
4240 && sym
->result
->attr
.proc_pointer
4241 && !sym
->result
->attr
.function
)))
4243 e
->ts
.type
= BT_PROCEDURE
;
4244 goto resolve_procedure
;
4247 if (sym
->ts
.type
!= BT_UNKNOWN
)
4248 gfc_variable_attr (e
, &e
->ts
);
4251 /* Must be a simple variable reference. */
4252 if (gfc_set_default_type (sym
, 1, sym
->ns
) == FAILURE
)
4257 if (check_assumed_size_reference (sym
, e
))
4260 /* Deal with forward references to entries during resolve_code, to
4261 satisfy, at least partially, 12.5.2.5. */
4262 if (gfc_current_ns
->entries
4263 && current_entry_id
== sym
->entry_id
4266 && cs_base
->current
->op
!= EXEC_ENTRY
)
4268 gfc_entry_list
*entry
;
4269 gfc_formal_arglist
*formal
;
4273 /* If the symbol is a dummy... */
4274 if (sym
->attr
.dummy
&& sym
->ns
== gfc_current_ns
)
4276 entry
= gfc_current_ns
->entries
;
4279 /* ...test if the symbol is a parameter of previous entries. */
4280 for (; entry
&& entry
->id
<= current_entry_id
; entry
= entry
->next
)
4281 for (formal
= entry
->sym
->formal
; formal
; formal
= formal
->next
)
4283 if (formal
->sym
&& sym
->name
== formal
->sym
->name
)
4287 /* If it has not been seen as a dummy, this is an error. */
4290 if (specification_expr
)
4291 gfc_error ("Variable '%s', used in a specification expression"
4292 ", is referenced at %L before the ENTRY statement "
4293 "in which it is a parameter",
4294 sym
->name
, &cs_base
->current
->loc
);
4296 gfc_error ("Variable '%s' is used at %L before the ENTRY "
4297 "statement in which it is a parameter",
4298 sym
->name
, &cs_base
->current
->loc
);
4303 /* Now do the same check on the specification expressions. */
4304 specification_expr
= 1;
4305 if (sym
->ts
.type
== BT_CHARACTER
4306 && gfc_resolve_expr (sym
->ts
.cl
->length
) == FAILURE
)
4310 for (n
= 0; n
< sym
->as
->rank
; n
++)
4312 specification_expr
= 1;
4313 if (gfc_resolve_expr (sym
->as
->lower
[n
]) == FAILURE
)
4315 specification_expr
= 1;
4316 if (gfc_resolve_expr (sym
->as
->upper
[n
]) == FAILURE
)
4319 specification_expr
= 0;
4322 /* Update the symbol's entry level. */
4323 sym
->entry_id
= current_entry_id
+ 1;
4327 if (t
== SUCCESS
&& resolve_procedure_expression (e
) == FAILURE
)
4334 /* Checks to see that the correct symbol has been host associated.
4335 The only situation where this arises is that in which a twice
4336 contained function is parsed after the host association is made.
4337 Therefore, on detecting this, change the symbol in the expression
4338 and convert the array reference into an actual arglist if the old
4339 symbol is a variable. */
4341 check_host_association (gfc_expr
*e
)
4343 gfc_symbol
*sym
, *old_sym
;
4347 gfc_actual_arglist
*arg
, *tail
;
4348 bool retval
= e
->expr_type
== EXPR_FUNCTION
;
4350 /* If the expression is the result of substitution in
4351 interface.c(gfc_extend_expr) because there is no way in
4352 which the host association can be wrong. */
4353 if (e
->symtree
== NULL
4354 || e
->symtree
->n
.sym
== NULL
4355 || e
->user_operator
)
4358 old_sym
= e
->symtree
->n
.sym
;
4360 if (gfc_current_ns
->parent
4361 && old_sym
->ns
!= gfc_current_ns
)
4363 /* Use the 'USE' name so that renamed module symbols are
4364 correctly handled. */
4365 gfc_find_symbol (e
->symtree
->name
, gfc_current_ns
, 1, &sym
);
4367 if (sym
&& old_sym
!= sym
4368 && sym
->ts
.type
== old_sym
->ts
.type
4369 && sym
->attr
.flavor
== FL_PROCEDURE
4370 && sym
->attr
.contained
)
4372 /* Clear the shape, since it might not be valid. */
4373 if (e
->shape
!= NULL
)
4375 for (n
= 0; n
< e
->rank
; n
++)
4376 mpz_clear (e
->shape
[n
]);
4378 gfc_free (e
->shape
);
4381 /* Give the symbol a symtree in the right place! */
4382 gfc_get_sym_tree (sym
->name
, gfc_current_ns
, &st
);
4385 if (old_sym
->attr
.flavor
== FL_PROCEDURE
)
4387 /* Original was function so point to the new symbol, since
4388 the actual argument list is already attached to the
4390 e
->value
.function
.esym
= NULL
;
4395 /* Original was variable so convert array references into
4396 an actual arglist. This does not need any checking now
4397 since gfc_resolve_function will take care of it. */
4398 e
->value
.function
.actual
= NULL
;
4399 e
->expr_type
= EXPR_FUNCTION
;
4402 /* Ambiguity will not arise if the array reference is not
4403 the last reference. */
4404 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
4405 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
4408 gcc_assert (ref
->type
== REF_ARRAY
);
4410 /* Grab the start expressions from the array ref and
4411 copy them into actual arguments. */
4412 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
4414 arg
= gfc_get_actual_arglist ();
4415 arg
->expr
= gfc_copy_expr (ref
->u
.ar
.start
[n
]);
4416 if (e
->value
.function
.actual
== NULL
)
4417 tail
= e
->value
.function
.actual
= arg
;
4425 /* Dump the reference list and set the rank. */
4426 gfc_free_ref_list (e
->ref
);
4428 e
->rank
= sym
->as
? sym
->as
->rank
: 0;
4431 gfc_resolve_expr (e
);
4435 /* This might have changed! */
4436 return e
->expr_type
== EXPR_FUNCTION
;
4441 gfc_resolve_character_operator (gfc_expr
*e
)
4443 gfc_expr
*op1
= e
->value
.op
.op1
;
4444 gfc_expr
*op2
= e
->value
.op
.op2
;
4445 gfc_expr
*e1
= NULL
;
4446 gfc_expr
*e2
= NULL
;
4448 gcc_assert (e
->value
.op
.op
== INTRINSIC_CONCAT
);
4450 if (op1
->ts
.cl
&& op1
->ts
.cl
->length
)
4451 e1
= gfc_copy_expr (op1
->ts
.cl
->length
);
4452 else if (op1
->expr_type
== EXPR_CONSTANT
)
4453 e1
= gfc_int_expr (op1
->value
.character
.length
);
4455 if (op2
->ts
.cl
&& op2
->ts
.cl
->length
)
4456 e2
= gfc_copy_expr (op2
->ts
.cl
->length
);
4457 else if (op2
->expr_type
== EXPR_CONSTANT
)
4458 e2
= gfc_int_expr (op2
->value
.character
.length
);
4460 e
->ts
.cl
= gfc_get_charlen ();
4461 e
->ts
.cl
->next
= gfc_current_ns
->cl_list
;
4462 gfc_current_ns
->cl_list
= e
->ts
.cl
;
4467 e
->ts
.cl
->length
= gfc_add (e1
, e2
);
4468 e
->ts
.cl
->length
->ts
.type
= BT_INTEGER
;
4469 e
->ts
.cl
->length
->ts
.kind
= gfc_charlen_int_kind
;;
4470 gfc_simplify_expr (e
->ts
.cl
->length
, 0);
4471 gfc_resolve_expr (e
->ts
.cl
->length
);
4477 /* Ensure that an character expression has a charlen and, if possible, a
4478 length expression. */
4481 fixup_charlen (gfc_expr
*e
)
4483 /* The cases fall through so that changes in expression type and the need
4484 for multiple fixes are picked up. In all circumstances, a charlen should
4485 be available for the middle end to hang a backend_decl on. */
4486 switch (e
->expr_type
)
4489 gfc_resolve_character_operator (e
);
4492 if (e
->expr_type
== EXPR_ARRAY
)
4493 gfc_resolve_character_array_constructor (e
);
4495 case EXPR_SUBSTRING
:
4496 if (!e
->ts
.cl
&& e
->ref
)
4497 gfc_resolve_substring_charlen (e
);
4502 e
->ts
.cl
= gfc_get_charlen ();
4503 e
->ts
.cl
->next
= gfc_current_ns
->cl_list
;
4504 gfc_current_ns
->cl_list
= e
->ts
.cl
;
4512 /* Update an actual argument to include the passed-object for type-bound
4513 procedures at the right position. */
4515 static gfc_actual_arglist
*
4516 update_arglist_pass (gfc_actual_arglist
* lst
, gfc_expr
* po
, unsigned argpos
)
4518 gcc_assert (argpos
> 0);
4522 gfc_actual_arglist
* result
;
4524 result
= gfc_get_actual_arglist ();
4532 gcc_assert (argpos
> 1);
4534 lst
->next
= update_arglist_pass (lst
->next
, po
, argpos
- 1);
4539 /* Extract the passed-object from an EXPR_COMPCALL (a copy of it). */
4542 extract_compcall_passed_object (gfc_expr
* e
)
4546 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
4548 po
= gfc_get_expr ();
4549 po
->expr_type
= EXPR_VARIABLE
;
4550 po
->symtree
= e
->symtree
;
4551 po
->ref
= gfc_copy_ref (e
->ref
);
4553 if (gfc_resolve_expr (po
) == FAILURE
)
4560 /* Update the arglist of an EXPR_COMPCALL expression to include the
4564 update_compcall_arglist (gfc_expr
* e
)
4567 gfc_typebound_proc
* tbp
;
4569 tbp
= e
->value
.compcall
.tbp
;
4574 po
= extract_compcall_passed_object (e
);
4580 gfc_error ("Passed-object at %L must be scalar", &e
->where
);
4590 gcc_assert (tbp
->pass_arg_num
> 0);
4591 e
->value
.compcall
.actual
= update_arglist_pass (e
->value
.compcall
.actual
, po
,
4598 /* Check that the object a TBP is called on is valid, i.e. it must not be
4599 of ABSTRACT type (as in subobject%abstract_parent%tbp()). */
4602 check_typebound_baseobject (gfc_expr
* e
)
4606 base
= extract_compcall_passed_object (e
);
4610 gcc_assert (base
->ts
.type
== BT_DERIVED
);
4611 if (base
->ts
.derived
->attr
.abstract
)
4613 gfc_error ("Base object for type-bound procedure call at %L is of"
4614 " ABSTRACT type '%s'", &e
->where
, base
->ts
.derived
->name
);
4622 /* Resolve a call to a type-bound procedure, either function or subroutine,
4623 statically from the data in an EXPR_COMPCALL expression. The adapted
4624 arglist and the target-procedure symtree are returned. */
4627 resolve_typebound_static (gfc_expr
* e
, gfc_symtree
** target
,
4628 gfc_actual_arglist
** actual
)
4630 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
4631 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
4633 /* Update the actual arglist for PASS. */
4634 if (update_compcall_arglist (e
) == FAILURE
)
4637 *actual
= e
->value
.compcall
.actual
;
4638 *target
= e
->value
.compcall
.tbp
->u
.specific
;
4640 gfc_free_ref_list (e
->ref
);
4642 e
->value
.compcall
.actual
= NULL
;
4648 /* Given an EXPR_COMPCALL calling a GENERIC typebound procedure, figure out
4649 which of the specific bindings (if any) matches the arglist and transform
4650 the expression into a call of that binding. */
4653 resolve_typebound_generic_call (gfc_expr
* e
)
4655 gfc_typebound_proc
* genproc
;
4656 const char* genname
;
4658 gcc_assert (e
->expr_type
== EXPR_COMPCALL
);
4659 genname
= e
->value
.compcall
.name
;
4660 genproc
= e
->value
.compcall
.tbp
;
4662 if (!genproc
->is_generic
)
4665 /* Try the bindings on this type and in the inheritance hierarchy. */
4666 for (; genproc
; genproc
= genproc
->overridden
)
4670 gcc_assert (genproc
->is_generic
);
4671 for (g
= genproc
->u
.generic
; g
; g
= g
->next
)
4674 gfc_actual_arglist
* args
;
4677 gcc_assert (g
->specific
);
4679 if (g
->specific
->error
)
4682 target
= g
->specific
->u
.specific
->n
.sym
;
4684 /* Get the right arglist by handling PASS/NOPASS. */
4685 args
= gfc_copy_actual_arglist (e
->value
.compcall
.actual
);
4686 if (!g
->specific
->nopass
)
4689 po
= extract_compcall_passed_object (e
);
4693 gcc_assert (g
->specific
->pass_arg_num
> 0);
4694 gcc_assert (!g
->specific
->error
);
4695 args
= update_arglist_pass (args
, po
, g
->specific
->pass_arg_num
);
4697 resolve_actual_arglist (args
, target
->attr
.proc
,
4698 is_external_proc (target
) && !target
->formal
);
4700 /* Check if this arglist matches the formal. */
4701 matches
= gfc_arglist_matches_symbol (&args
, target
);
4703 /* Clean up and break out of the loop if we've found it. */
4704 gfc_free_actual_arglist (args
);
4707 e
->value
.compcall
.tbp
= g
->specific
;
4713 /* Nothing matching found! */
4714 gfc_error ("Found no matching specific binding for the call to the GENERIC"
4715 " '%s' at %L", genname
, &e
->where
);
4723 /* Resolve a call to a type-bound subroutine. */
4726 resolve_typebound_call (gfc_code
* c
)
4728 gfc_actual_arglist
* newactual
;
4729 gfc_symtree
* target
;
4731 /* Check that's really a SUBROUTINE. */
4732 if (!c
->expr
->value
.compcall
.tbp
->subroutine
)
4734 gfc_error ("'%s' at %L should be a SUBROUTINE",
4735 c
->expr
->value
.compcall
.name
, &c
->loc
);
4739 if (check_typebound_baseobject (c
->expr
) == FAILURE
)
4742 if (resolve_typebound_generic_call (c
->expr
) == FAILURE
)
4745 /* Transform into an ordinary EXEC_CALL for now. */
4747 if (resolve_typebound_static (c
->expr
, &target
, &newactual
) == FAILURE
)
4750 c
->ext
.actual
= newactual
;
4751 c
->symtree
= target
;
4754 gcc_assert (!c
->expr
->ref
&& !c
->expr
->value
.compcall
.actual
);
4755 gfc_free_expr (c
->expr
);
4758 return resolve_call (c
);
4762 /* Resolve a component-call expression. */
4765 resolve_compcall (gfc_expr
* e
)
4767 gfc_actual_arglist
* newactual
;
4768 gfc_symtree
* target
;
4770 /* Check that's really a FUNCTION. */
4771 if (!e
->value
.compcall
.tbp
->function
)
4773 gfc_error ("'%s' at %L should be a FUNCTION",
4774 e
->value
.compcall
.name
, &e
->where
);
4778 if (check_typebound_baseobject (e
) == FAILURE
)
4781 if (resolve_typebound_generic_call (e
) == FAILURE
)
4783 gcc_assert (!e
->value
.compcall
.tbp
->is_generic
);
4785 /* Take the rank from the function's symbol. */
4786 if (e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
)
4787 e
->rank
= e
->value
.compcall
.tbp
->u
.specific
->n
.sym
->as
->rank
;
4789 /* For now, we simply transform it into an EXPR_FUNCTION call with the same
4790 arglist to the TBP's binding target. */
4792 if (resolve_typebound_static (e
, &target
, &newactual
) == FAILURE
)
4795 e
->value
.function
.actual
= newactual
;
4796 e
->value
.function
.name
= e
->value
.compcall
.name
;
4797 e
->value
.function
.isym
= NULL
;
4798 e
->value
.function
.esym
= NULL
;
4799 e
->symtree
= target
;
4800 e
->ts
= target
->n
.sym
->ts
;
4801 e
->expr_type
= EXPR_FUNCTION
;
4803 return gfc_resolve_expr (e
);
4807 /* Resolve an expression. That is, make sure that types of operands agree
4808 with their operators, intrinsic operators are converted to function calls
4809 for overloaded types and unresolved function references are resolved. */
4812 gfc_resolve_expr (gfc_expr
*e
)
4819 switch (e
->expr_type
)
4822 t
= resolve_operator (e
);
4828 if (check_host_association (e
))
4829 t
= resolve_function (e
);
4832 t
= resolve_variable (e
);
4834 expression_rank (e
);
4837 if (e
->ts
.type
== BT_CHARACTER
&& e
->ts
.cl
== NULL
&& e
->ref
4838 && e
->ref
->type
!= REF_SUBSTRING
)
4839 gfc_resolve_substring_charlen (e
);
4844 t
= resolve_compcall (e
);
4847 case EXPR_SUBSTRING
:
4848 t
= resolve_ref (e
);
4858 if (resolve_ref (e
) == FAILURE
)
4861 t
= gfc_resolve_array_constructor (e
);
4862 /* Also try to expand a constructor. */
4865 expression_rank (e
);
4866 gfc_expand_constructor (e
);
4869 /* This provides the opportunity for the length of constructors with
4870 character valued function elements to propagate the string length
4871 to the expression. */
4872 if (t
== SUCCESS
&& e
->ts
.type
== BT_CHARACTER
)
4873 t
= gfc_resolve_character_array_constructor (e
);
4877 case EXPR_STRUCTURE
:
4878 t
= resolve_ref (e
);
4882 t
= resolve_structure_cons (e
);
4886 t
= gfc_simplify_expr (e
, 0);
4890 gfc_internal_error ("gfc_resolve_expr(): Bad expression type");
4893 if (e
->ts
.type
== BT_CHARACTER
&& t
== SUCCESS
&& !e
->ts
.cl
)
4900 /* Resolve an expression from an iterator. They must be scalar and have
4901 INTEGER or (optionally) REAL type. */
4904 gfc_resolve_iterator_expr (gfc_expr
*expr
, bool real_ok
,
4905 const char *name_msgid
)
4907 if (gfc_resolve_expr (expr
) == FAILURE
)
4910 if (expr
->rank
!= 0)
4912 gfc_error ("%s at %L must be a scalar", _(name_msgid
), &expr
->where
);
4916 if (expr
->ts
.type
!= BT_INTEGER
)
4918 if (expr
->ts
.type
== BT_REAL
)
4921 return gfc_notify_std (GFC_STD_F95_DEL
,
4922 "Deleted feature: %s at %L must be integer",
4923 _(name_msgid
), &expr
->where
);
4926 gfc_error ("%s at %L must be INTEGER", _(name_msgid
),
4933 gfc_error ("%s at %L must be INTEGER", _(name_msgid
), &expr
->where
);
4941 /* Resolve the expressions in an iterator structure. If REAL_OK is
4942 false allow only INTEGER type iterators, otherwise allow REAL types. */
4945 gfc_resolve_iterator (gfc_iterator
*iter
, bool real_ok
)
4947 if (gfc_resolve_iterator_expr (iter
->var
, real_ok
, "Loop variable")
4951 if (gfc_pure (NULL
) && gfc_impure_variable (iter
->var
->symtree
->n
.sym
))
4953 gfc_error ("Cannot assign to loop variable in PURE procedure at %L",
4958 if (gfc_resolve_iterator_expr (iter
->start
, real_ok
,
4959 "Start expression in DO loop") == FAILURE
)
4962 if (gfc_resolve_iterator_expr (iter
->end
, real_ok
,
4963 "End expression in DO loop") == FAILURE
)
4966 if (gfc_resolve_iterator_expr (iter
->step
, real_ok
,
4967 "Step expression in DO loop") == FAILURE
)
4970 if (iter
->step
->expr_type
== EXPR_CONSTANT
)
4972 if ((iter
->step
->ts
.type
== BT_INTEGER
4973 && mpz_cmp_ui (iter
->step
->value
.integer
, 0) == 0)
4974 || (iter
->step
->ts
.type
== BT_REAL
4975 && mpfr_sgn (iter
->step
->value
.real
) == 0))
4977 gfc_error ("Step expression in DO loop at %L cannot be zero",
4978 &iter
->step
->where
);
4983 /* Convert start, end, and step to the same type as var. */
4984 if (iter
->start
->ts
.kind
!= iter
->var
->ts
.kind
4985 || iter
->start
->ts
.type
!= iter
->var
->ts
.type
)
4986 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
4988 if (iter
->end
->ts
.kind
!= iter
->var
->ts
.kind
4989 || iter
->end
->ts
.type
!= iter
->var
->ts
.type
)
4990 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
4992 if (iter
->step
->ts
.kind
!= iter
->var
->ts
.kind
4993 || iter
->step
->ts
.type
!= iter
->var
->ts
.type
)
4994 gfc_convert_type (iter
->step
, &iter
->var
->ts
, 2);
4996 if (iter
->start
->expr_type
== EXPR_CONSTANT
4997 && iter
->end
->expr_type
== EXPR_CONSTANT
4998 && iter
->step
->expr_type
== EXPR_CONSTANT
)
5001 if (iter
->start
->ts
.type
== BT_INTEGER
)
5003 sgn
= mpz_cmp_ui (iter
->step
->value
.integer
, 0);
5004 cmp
= mpz_cmp (iter
->end
->value
.integer
, iter
->start
->value
.integer
);
5008 sgn
= mpfr_sgn (iter
->step
->value
.real
);
5009 cmp
= mpfr_cmp (iter
->end
->value
.real
, iter
->start
->value
.real
);
5011 if ((sgn
> 0 && cmp
< 0) || (sgn
< 0 && cmp
> 0))
5012 gfc_warning ("DO loop at %L will be executed zero times",
5013 &iter
->step
->where
);
5020 /* Traversal function for find_forall_index. f == 2 signals that
5021 that variable itself is not to be checked - only the references. */
5024 forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int *f
)
5026 if (expr
->expr_type
!= EXPR_VARIABLE
)
5029 /* A scalar assignment */
5030 if (!expr
->ref
|| *f
== 1)
5032 if (expr
->symtree
->n
.sym
== sym
)
5044 /* Check whether the FORALL index appears in the expression or not.
5045 Returns SUCCESS if SYM is found in EXPR. */
5048 find_forall_index (gfc_expr
*expr
, gfc_symbol
*sym
, int f
)
5050 if (gfc_traverse_expr (expr
, sym
, forall_index
, f
))
5057 /* Resolve a list of FORALL iterators. The FORALL index-name is constrained
5058 to be a scalar INTEGER variable. The subscripts and stride are scalar
5059 INTEGERs, and if stride is a constant it must be nonzero.
5060 Furthermore "A subscript or stride in a forall-triplet-spec shall
5061 not contain a reference to any index-name in the
5062 forall-triplet-spec-list in which it appears." (7.5.4.1) */
5065 resolve_forall_iterators (gfc_forall_iterator
*it
)
5067 gfc_forall_iterator
*iter
, *iter2
;
5069 for (iter
= it
; iter
; iter
= iter
->next
)
5071 if (gfc_resolve_expr (iter
->var
) == SUCCESS
5072 && (iter
->var
->ts
.type
!= BT_INTEGER
|| iter
->var
->rank
!= 0))
5073 gfc_error ("FORALL index-name at %L must be a scalar INTEGER",
5076 if (gfc_resolve_expr (iter
->start
) == SUCCESS
5077 && (iter
->start
->ts
.type
!= BT_INTEGER
|| iter
->start
->rank
!= 0))
5078 gfc_error ("FORALL start expression at %L must be a scalar INTEGER",
5079 &iter
->start
->where
);
5080 if (iter
->var
->ts
.kind
!= iter
->start
->ts
.kind
)
5081 gfc_convert_type (iter
->start
, &iter
->var
->ts
, 2);
5083 if (gfc_resolve_expr (iter
->end
) == SUCCESS
5084 && (iter
->end
->ts
.type
!= BT_INTEGER
|| iter
->end
->rank
!= 0))
5085 gfc_error ("FORALL end expression at %L must be a scalar INTEGER",
5087 if (iter
->var
->ts
.kind
!= iter
->end
->ts
.kind
)
5088 gfc_convert_type (iter
->end
, &iter
->var
->ts
, 2);
5090 if (gfc_resolve_expr (iter
->stride
) == SUCCESS
)
5092 if (iter
->stride
->ts
.type
!= BT_INTEGER
|| iter
->stride
->rank
!= 0)
5093 gfc_error ("FORALL stride expression at %L must be a scalar %s",
5094 &iter
->stride
->where
, "INTEGER");
5096 if (iter
->stride
->expr_type
== EXPR_CONSTANT
5097 && mpz_cmp_ui(iter
->stride
->value
.integer
, 0) == 0)
5098 gfc_error ("FORALL stride expression at %L cannot be zero",
5099 &iter
->stride
->where
);
5101 if (iter
->var
->ts
.kind
!= iter
->stride
->ts
.kind
)
5102 gfc_convert_type (iter
->stride
, &iter
->var
->ts
, 2);
5105 for (iter
= it
; iter
; iter
= iter
->next
)
5106 for (iter2
= iter
; iter2
; iter2
= iter2
->next
)
5108 if (find_forall_index (iter2
->start
,
5109 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
5110 || find_forall_index (iter2
->end
,
5111 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
5112 || find_forall_index (iter2
->stride
,
5113 iter
->var
->symtree
->n
.sym
, 0) == SUCCESS
)
5114 gfc_error ("FORALL index '%s' may not appear in triplet "
5115 "specification at %L", iter
->var
->symtree
->name
,
5116 &iter2
->start
->where
);
5121 /* Given a pointer to a symbol that is a derived type, see if it's
5122 inaccessible, i.e. if it's defined in another module and the components are
5123 PRIVATE. The search is recursive if necessary. Returns zero if no
5124 inaccessible components are found, nonzero otherwise. */
5127 derived_inaccessible (gfc_symbol
*sym
)
5131 if (sym
->attr
.use_assoc
&& sym
->attr
.private_comp
)
5134 for (c
= sym
->components
; c
; c
= c
->next
)
5136 if (c
->ts
.type
== BT_DERIVED
&& derived_inaccessible (c
->ts
.derived
))
5144 /* Resolve the argument of a deallocate expression. The expression must be
5145 a pointer or a full array. */
5148 resolve_deallocate_expr (gfc_expr
*e
)
5150 symbol_attribute attr
;
5151 int allocatable
, pointer
, check_intent_in
;
5154 /* Check INTENT(IN), unless the object is a sub-component of a pointer. */
5155 check_intent_in
= 1;
5157 if (gfc_resolve_expr (e
) == FAILURE
)
5160 if (e
->expr_type
!= EXPR_VARIABLE
)
5163 allocatable
= e
->symtree
->n
.sym
->attr
.allocatable
;
5164 pointer
= e
->symtree
->n
.sym
->attr
.pointer
;
5165 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
5168 check_intent_in
= 0;
5173 if (ref
->u
.ar
.type
!= AR_FULL
)
5178 allocatable
= (ref
->u
.c
.component
->as
!= NULL
5179 && ref
->u
.c
.component
->as
->type
== AS_DEFERRED
);
5180 pointer
= ref
->u
.c
.component
->attr
.pointer
;
5189 attr
= gfc_expr_attr (e
);
5191 if (allocatable
== 0 && attr
.pointer
== 0)
5194 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
5199 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
5201 gfc_error ("Cannot deallocate INTENT(IN) variable '%s' at %L",
5202 e
->symtree
->n
.sym
->name
, &e
->where
);
5210 /* Returns true if the expression e contains a reference to the symbol sym. */
5212 sym_in_expr (gfc_expr
*e
, gfc_symbol
*sym
, int *f ATTRIBUTE_UNUSED
)
5214 if (e
->expr_type
== EXPR_VARIABLE
&& e
->symtree
->n
.sym
== sym
)
5221 gfc_find_sym_in_expr (gfc_symbol
*sym
, gfc_expr
*e
)
5223 return gfc_traverse_expr (e
, sym
, sym_in_expr
, 0);
5227 /* Given the expression node e for an allocatable/pointer of derived type to be
5228 allocated, get the expression node to be initialized afterwards (needed for
5229 derived types with default initializers, and derived types with allocatable
5230 components that need nullification.) */
5233 expr_to_initialize (gfc_expr
*e
)
5239 result
= gfc_copy_expr (e
);
5241 /* Change the last array reference from AR_ELEMENT to AR_FULL. */
5242 for (ref
= result
->ref
; ref
; ref
= ref
->next
)
5243 if (ref
->type
== REF_ARRAY
&& ref
->next
== NULL
)
5245 ref
->u
.ar
.type
= AR_FULL
;
5247 for (i
= 0; i
< ref
->u
.ar
.dimen
; i
++)
5248 ref
->u
.ar
.start
[i
] = ref
->u
.ar
.end
[i
] = ref
->u
.ar
.stride
[i
] = NULL
;
5250 result
->rank
= ref
->u
.ar
.dimen
;
5258 /* Resolve the expression in an ALLOCATE statement, doing the additional
5259 checks to see whether the expression is OK or not. The expression must
5260 have a trailing array reference that gives the size of the array. */
5263 resolve_allocate_expr (gfc_expr
*e
, gfc_code
*code
)
5265 int i
, pointer
, allocatable
, dimension
, check_intent_in
;
5266 symbol_attribute attr
;
5267 gfc_ref
*ref
, *ref2
;
5274 /* Check INTENT(IN), unless the object is a sub-component of a pointer. */
5275 check_intent_in
= 1;
5277 if (gfc_resolve_expr (e
) == FAILURE
)
5280 /* Make sure the expression is allocatable or a pointer. If it is
5281 pointer, the next-to-last reference must be a pointer. */
5285 if (e
->expr_type
!= EXPR_VARIABLE
)
5288 attr
= gfc_expr_attr (e
);
5289 pointer
= attr
.pointer
;
5290 dimension
= attr
.dimension
;
5294 allocatable
= e
->symtree
->n
.sym
->attr
.allocatable
;
5295 pointer
= e
->symtree
->n
.sym
->attr
.pointer
;
5296 dimension
= e
->symtree
->n
.sym
->attr
.dimension
;
5298 for (ref
= e
->ref
; ref
; ref2
= ref
, ref
= ref
->next
)
5301 check_intent_in
= 0;
5306 if (ref
->next
!= NULL
)
5311 allocatable
= (ref
->u
.c
.component
->as
!= NULL
5312 && ref
->u
.c
.component
->as
->type
== AS_DEFERRED
);
5314 pointer
= ref
->u
.c
.component
->attr
.pointer
;
5315 dimension
= ref
->u
.c
.component
->attr
.dimension
;
5326 if (allocatable
== 0 && pointer
== 0)
5328 gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
5334 && e
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
5336 gfc_error ("Cannot allocate INTENT(IN) variable '%s' at %L",
5337 e
->symtree
->n
.sym
->name
, &e
->where
);
5341 /* Add default initializer for those derived types that need them. */
5342 if (e
->ts
.type
== BT_DERIVED
&& (init_e
= gfc_default_initializer (&e
->ts
)))
5344 init_st
= gfc_get_code ();
5345 init_st
->loc
= code
->loc
;
5346 init_st
->op
= EXEC_INIT_ASSIGN
;
5347 init_st
->expr
= expr_to_initialize (e
);
5348 init_st
->expr2
= init_e
;
5349 init_st
->next
= code
->next
;
5350 code
->next
= init_st
;
5353 if (pointer
&& dimension
== 0)
5356 /* Make sure the next-to-last reference node is an array specification. */
5358 if (ref2
== NULL
|| ref2
->type
!= REF_ARRAY
|| ref2
->u
.ar
.type
== AR_FULL
)
5360 gfc_error ("Array specification required in ALLOCATE statement "
5361 "at %L", &e
->where
);
5365 /* Make sure that the array section reference makes sense in the
5366 context of an ALLOCATE specification. */
5370 for (i
= 0; i
< ar
->dimen
; i
++)
5372 if (ref2
->u
.ar
.type
== AR_ELEMENT
)
5375 switch (ar
->dimen_type
[i
])
5381 if (ar
->start
[i
] != NULL
5382 && ar
->end
[i
] != NULL
5383 && ar
->stride
[i
] == NULL
)
5386 /* Fall Through... */
5390 gfc_error ("Bad array specification in ALLOCATE statement at %L",
5397 for (a
= code
->ext
.alloc_list
; a
; a
= a
->next
)
5399 sym
= a
->expr
->symtree
->n
.sym
;
5401 /* TODO - check derived type components. */
5402 if (sym
->ts
.type
== BT_DERIVED
)
5405 if ((ar
->start
[i
] != NULL
5406 && gfc_find_sym_in_expr (sym
, ar
->start
[i
]))
5407 || (ar
->end
[i
] != NULL
5408 && gfc_find_sym_in_expr (sym
, ar
->end
[i
])))
5410 gfc_error ("'%s' must not appear in the array specification at "
5411 "%L in the same ALLOCATE statement where it is "
5412 "itself allocated", sym
->name
, &ar
->where
);
5422 resolve_allocate_deallocate (gfc_code
*code
, const char *fcn
)
5424 gfc_expr
*stat
, *errmsg
, *pe
, *qe
;
5425 gfc_alloc
*a
, *p
, *q
;
5427 stat
= code
->expr
? code
->expr
: NULL
;
5429 errmsg
= code
->expr2
? code
->expr2
: NULL
;
5431 /* Check the stat variable. */
5434 if (stat
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
5435 gfc_error ("Stat-variable '%s' at %L cannot be INTENT(IN)",
5436 stat
->symtree
->n
.sym
->name
, &stat
->where
);
5438 if (gfc_pure (NULL
) && gfc_impure_variable (stat
->symtree
->n
.sym
))
5439 gfc_error ("Illegal stat-variable at %L for a PURE procedure",
5442 if (stat
->ts
.type
!= BT_INTEGER
5443 && !(stat
->ref
&& (stat
->ref
->type
== REF_ARRAY
5444 || stat
->ref
->type
== REF_COMPONENT
)))
5445 gfc_error ("Stat-variable at %L must be a scalar INTEGER "
5446 "variable", &stat
->where
);
5448 for (p
= code
->ext
.alloc_list
; p
; p
= p
->next
)
5449 if (p
->expr
->symtree
->n
.sym
->name
== stat
->symtree
->n
.sym
->name
)
5450 gfc_error ("Stat-variable at %L shall not be %sd within "
5451 "the same %s statement", &stat
->where
, fcn
, fcn
);
5454 /* Check the errmsg variable. */
5458 gfc_warning ("ERRMSG at %L is useless without a STAT tag",
5461 if (errmsg
->symtree
->n
.sym
->attr
.intent
== INTENT_IN
)
5462 gfc_error ("Errmsg-variable '%s' at %L cannot be INTENT(IN)",
5463 errmsg
->symtree
->n
.sym
->name
, &errmsg
->where
);
5465 if (gfc_pure (NULL
) && gfc_impure_variable (errmsg
->symtree
->n
.sym
))
5466 gfc_error ("Illegal errmsg-variable at %L for a PURE procedure",
5469 if (errmsg
->ts
.type
!= BT_CHARACTER
5471 && (errmsg
->ref
->type
== REF_ARRAY
5472 || errmsg
->ref
->type
== REF_COMPONENT
)))
5473 gfc_error ("Errmsg-variable at %L must be a scalar CHARACTER "
5474 "variable", &errmsg
->where
);
5476 for (p
= code
->ext
.alloc_list
; p
; p
= p
->next
)
5477 if (p
->expr
->symtree
->n
.sym
->name
== errmsg
->symtree
->n
.sym
->name
)
5478 gfc_error ("Errmsg-variable at %L shall not be %sd within "
5479 "the same %s statement", &errmsg
->where
, fcn
, fcn
);
5482 /* Check that an allocate-object appears only once in the statement.
5483 FIXME: Checking derived types is disabled. */
5484 for (p
= code
->ext
.alloc_list
; p
; p
= p
->next
)
5487 if ((pe
->ref
&& pe
->ref
->type
!= REF_COMPONENT
)
5488 && (pe
->symtree
->n
.sym
->ts
.type
!= BT_DERIVED
))
5490 for (q
= p
->next
; q
; q
= q
->next
)
5493 if ((qe
->ref
&& qe
->ref
->type
!= REF_COMPONENT
)
5494 && (qe
->symtree
->n
.sym
->ts
.type
!= BT_DERIVED
)
5495 && (pe
->symtree
->n
.sym
->name
== qe
->symtree
->n
.sym
->name
))
5496 gfc_error ("Allocate-object at %L also appears at %L",
5497 &pe
->where
, &qe
->where
);
5502 if (strcmp (fcn
, "ALLOCATE") == 0)
5504 for (a
= code
->ext
.alloc_list
; a
; a
= a
->next
)
5505 resolve_allocate_expr (a
->expr
, code
);
5509 for (a
= code
->ext
.alloc_list
; a
; a
= a
->next
)
5510 resolve_deallocate_expr (a
->expr
);
5515 /************ SELECT CASE resolution subroutines ************/
5517 /* Callback function for our mergesort variant. Determines interval
5518 overlaps for CASEs. Return <0 if op1 < op2, 0 for overlap, >0 for
5519 op1 > op2. Assumes we're not dealing with the default case.
5520 We have op1 = (:L), (K:L) or (K:) and op2 = (:N), (M:N) or (M:).
5521 There are nine situations to check. */
5524 compare_cases (const gfc_case
*op1
, const gfc_case
*op2
)
5528 if (op1
->low
== NULL
) /* op1 = (:L) */
5530 /* op2 = (:N), so overlap. */
5532 /* op2 = (M:) or (M:N), L < M */
5533 if (op2
->low
!= NULL
5534 && gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
5537 else if (op1
->high
== NULL
) /* op1 = (K:) */
5539 /* op2 = (M:), so overlap. */
5541 /* op2 = (:N) or (M:N), K > N */
5542 if (op2
->high
!= NULL
5543 && gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
5546 else /* op1 = (K:L) */
5548 if (op2
->low
== NULL
) /* op2 = (:N), K > N */
5549 retval
= (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
5551 else if (op2
->high
== NULL
) /* op2 = (M:), L < M */
5552 retval
= (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
5554 else /* op2 = (M:N) */
5558 if (gfc_compare_expr (op1
->high
, op2
->low
, INTRINSIC_LT
) < 0)
5561 else if (gfc_compare_expr (op1
->low
, op2
->high
, INTRINSIC_GT
) > 0)
5570 /* Merge-sort a double linked case list, detecting overlap in the
5571 process. LIST is the head of the double linked case list before it
5572 is sorted. Returns the head of the sorted list if we don't see any
5573 overlap, or NULL otherwise. */
5576 check_case_overlap (gfc_case
*list
)
5578 gfc_case
*p
, *q
, *e
, *tail
;
5579 int insize
, nmerges
, psize
, qsize
, cmp
, overlap_seen
;
5581 /* If the passed list was empty, return immediately. */
5588 /* Loop unconditionally. The only exit from this loop is a return
5589 statement, when we've finished sorting the case list. */
5596 /* Count the number of merges we do in this pass. */
5599 /* Loop while there exists a merge to be done. */
5604 /* Count this merge. */
5607 /* Cut the list in two pieces by stepping INSIZE places
5608 forward in the list, starting from P. */
5611 for (i
= 0; i
< insize
; i
++)
5620 /* Now we have two lists. Merge them! */
5621 while (psize
> 0 || (qsize
> 0 && q
!= NULL
))
5623 /* See from which the next case to merge comes from. */
5626 /* P is empty so the next case must come from Q. */
5631 else if (qsize
== 0 || q
== NULL
)
5640 cmp
= compare_cases (p
, q
);
5643 /* The whole case range for P is less than the
5651 /* The whole case range for Q is greater than
5652 the case range for P. */
5659 /* The cases overlap, or they are the same
5660 element in the list. Either way, we must
5661 issue an error and get the next case from P. */
5662 /* FIXME: Sort P and Q by line number. */
5663 gfc_error ("CASE label at %L overlaps with CASE "
5664 "label at %L", &p
->where
, &q
->where
);
5672 /* Add the next element to the merged list. */
5681 /* P has now stepped INSIZE places along, and so has Q. So
5682 they're the same. */
5687 /* If we have done only one merge or none at all, we've
5688 finished sorting the cases. */
5697 /* Otherwise repeat, merging lists twice the size. */
5703 /* Check to see if an expression is suitable for use in a CASE statement.
5704 Makes sure that all case expressions are scalar constants of the same
5705 type. Return FAILURE if anything is wrong. */
5708 validate_case_label_expr (gfc_expr
*e
, gfc_expr
*case_expr
)
5710 if (e
== NULL
) return SUCCESS
;
5712 if (e
->ts
.type
!= case_expr
->ts
.type
)
5714 gfc_error ("Expression in CASE statement at %L must be of type %s",
5715 &e
->where
, gfc_basic_typename (case_expr
->ts
.type
));
5719 /* C805 (R808) For a given case-construct, each case-value shall be of
5720 the same type as case-expr. For character type, length differences
5721 are allowed, but the kind type parameters shall be the same. */
5723 if (case_expr
->ts
.type
== BT_CHARACTER
&& e
->ts
.kind
!= case_expr
->ts
.kind
)
5725 gfc_error ("Expression in CASE statement at %L must be of kind %d",
5726 &e
->where
, case_expr
->ts
.kind
);
5730 /* Convert the case value kind to that of case expression kind, if needed.
5731 FIXME: Should a warning be issued? */
5732 if (e
->ts
.kind
!= case_expr
->ts
.kind
)
5733 gfc_convert_type_warn (e
, &case_expr
->ts
, 2, 0);
5737 gfc_error ("Expression in CASE statement at %L must be scalar",
5746 /* Given a completely parsed select statement, we:
5748 - Validate all expressions and code within the SELECT.
5749 - Make sure that the selection expression is not of the wrong type.
5750 - Make sure that no case ranges overlap.
5751 - Eliminate unreachable cases and unreachable code resulting from
5752 removing case labels.
5754 The standard does allow unreachable cases, e.g. CASE (5:3). But
5755 they are a hassle for code generation, and to prevent that, we just
5756 cut them out here. This is not necessary for overlapping cases
5757 because they are illegal and we never even try to generate code.
5759 We have the additional caveat that a SELECT construct could have
5760 been a computed GOTO in the source code. Fortunately we can fairly
5761 easily work around that here: The case_expr for a "real" SELECT CASE
5762 is in code->expr1, but for a computed GOTO it is in code->expr2. All
5763 we have to do is make sure that the case_expr is a scalar integer
5767 resolve_select (gfc_code
*code
)
5770 gfc_expr
*case_expr
;
5771 gfc_case
*cp
, *default_case
, *tail
, *head
;
5772 int seen_unreachable
;
5778 if (code
->expr
== NULL
)
5780 /* This was actually a computed GOTO statement. */
5781 case_expr
= code
->expr2
;
5782 if (case_expr
->ts
.type
!= BT_INTEGER
|| case_expr
->rank
!= 0)
5783 gfc_error ("Selection expression in computed GOTO statement "
5784 "at %L must be a scalar integer expression",
5787 /* Further checking is not necessary because this SELECT was built
5788 by the compiler, so it should always be OK. Just move the
5789 case_expr from expr2 to expr so that we can handle computed
5790 GOTOs as normal SELECTs from here on. */
5791 code
->expr
= code
->expr2
;
5796 case_expr
= code
->expr
;
5798 type
= case_expr
->ts
.type
;
5799 if (type
!= BT_LOGICAL
&& type
!= BT_INTEGER
&& type
!= BT_CHARACTER
)
5801 gfc_error ("Argument of SELECT statement at %L cannot be %s",
5802 &case_expr
->where
, gfc_typename (&case_expr
->ts
));
5804 /* Punt. Going on here just produce more garbage error messages. */
5808 if (case_expr
->rank
!= 0)
5810 gfc_error ("Argument of SELECT statement at %L must be a scalar "
5811 "expression", &case_expr
->where
);
5817 /* PR 19168 has a long discussion concerning a mismatch of the kinds
5818 of the SELECT CASE expression and its CASE values. Walk the lists
5819 of case values, and if we find a mismatch, promote case_expr to
5820 the appropriate kind. */
5822 if (type
== BT_LOGICAL
|| type
== BT_INTEGER
)
5824 for (body
= code
->block
; body
; body
= body
->block
)
5826 /* Walk the case label list. */
5827 for (cp
= body
->ext
.case_list
; cp
; cp
= cp
->next
)
5829 /* Intercept the DEFAULT case. It does not have a kind. */
5830 if (cp
->low
== NULL
&& cp
->high
== NULL
)
5833 /* Unreachable case ranges are discarded, so ignore. */
5834 if (cp
->low
!= NULL
&& cp
->high
!= NULL
5835 && cp
->low
!= cp
->high
5836 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
5839 /* FIXME: Should a warning be issued? */
5841 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->low
))
5842 gfc_convert_type_warn (case_expr
, &cp
->low
->ts
, 2, 0);
5844 if (cp
->high
!= NULL
5845 && case_expr
->ts
.kind
!= gfc_kind_max(case_expr
, cp
->high
))
5846 gfc_convert_type_warn (case_expr
, &cp
->high
->ts
, 2, 0);
5851 /* Assume there is no DEFAULT case. */
5852 default_case
= NULL
;
5857 for (body
= code
->block
; body
; body
= body
->block
)
5859 /* Assume the CASE list is OK, and all CASE labels can be matched. */
5861 seen_unreachable
= 0;
5863 /* Walk the case label list, making sure that all case labels
5865 for (cp
= body
->ext
.case_list
; cp
; cp
= cp
->next
)
5867 /* Count the number of cases in the whole construct. */
5870 /* Intercept the DEFAULT case. */
5871 if (cp
->low
== NULL
&& cp
->high
== NULL
)
5873 if (default_case
!= NULL
)
5875 gfc_error ("The DEFAULT CASE at %L cannot be followed "
5876 "by a second DEFAULT CASE at %L",
5877 &default_case
->where
, &cp
->where
);
5888 /* Deal with single value cases and case ranges. Errors are
5889 issued from the validation function. */
5890 if(validate_case_label_expr (cp
->low
, case_expr
) != SUCCESS
5891 || validate_case_label_expr (cp
->high
, case_expr
) != SUCCESS
)
5897 if (type
== BT_LOGICAL
5898 && ((cp
->low
== NULL
|| cp
->high
== NULL
)
5899 || cp
->low
!= cp
->high
))
5901 gfc_error ("Logical range in CASE statement at %L is not "
5902 "allowed", &cp
->low
->where
);
5907 if (type
== BT_LOGICAL
&& cp
->low
->expr_type
== EXPR_CONSTANT
)
5910 value
= cp
->low
->value
.logical
== 0 ? 2 : 1;
5911 if (value
& seen_logical
)
5913 gfc_error ("constant logical value in CASE statement "
5914 "is repeated at %L",
5919 seen_logical
|= value
;
5922 if (cp
->low
!= NULL
&& cp
->high
!= NULL
5923 && cp
->low
!= cp
->high
5924 && gfc_compare_expr (cp
->low
, cp
->high
, INTRINSIC_GT
) > 0)
5926 if (gfc_option
.warn_surprising
)
5927 gfc_warning ("Range specification at %L can never "
5928 "be matched", &cp
->where
);
5930 cp
->unreachable
= 1;
5931 seen_unreachable
= 1;
5935 /* If the case range can be matched, it can also overlap with
5936 other cases. To make sure it does not, we put it in a
5937 double linked list here. We sort that with a merge sort
5938 later on to detect any overlapping cases. */
5942 head
->right
= head
->left
= NULL
;
5947 tail
->right
->left
= tail
;
5954 /* It there was a failure in the previous case label, give up
5955 for this case label list. Continue with the next block. */
5959 /* See if any case labels that are unreachable have been seen.
5960 If so, we eliminate them. This is a bit of a kludge because
5961 the case lists for a single case statement (label) is a
5962 single forward linked lists. */
5963 if (seen_unreachable
)
5965 /* Advance until the first case in the list is reachable. */
5966 while (body
->ext
.case_list
!= NULL
5967 && body
->ext
.case_list
->unreachable
)
5969 gfc_case
*n
= body
->ext
.case_list
;
5970 body
->ext
.case_list
= body
->ext
.case_list
->next
;
5972 gfc_free_case_list (n
);
5975 /* Strip all other unreachable cases. */
5976 if (body
->ext
.case_list
)
5978 for (cp
= body
->ext
.case_list
; cp
->next
; cp
= cp
->next
)
5980 if (cp
->next
->unreachable
)
5982 gfc_case
*n
= cp
->next
;
5983 cp
->next
= cp
->next
->next
;
5985 gfc_free_case_list (n
);
5992 /* See if there were overlapping cases. If the check returns NULL,
5993 there was overlap. In that case we don't do anything. If head
5994 is non-NULL, we prepend the DEFAULT case. The sorted list can
5995 then used during code generation for SELECT CASE constructs with
5996 a case expression of a CHARACTER type. */
5999 head
= check_case_overlap (head
);
6001 /* Prepend the default_case if it is there. */
6002 if (head
!= NULL
&& default_case
)
6004 default_case
->left
= NULL
;
6005 default_case
->right
= head
;
6006 head
->left
= default_case
;
6010 /* Eliminate dead blocks that may be the result if we've seen
6011 unreachable case labels for a block. */
6012 for (body
= code
; body
&& body
->block
; body
= body
->block
)
6014 if (body
->block
->ext
.case_list
== NULL
)
6016 /* Cut the unreachable block from the code chain. */
6017 gfc_code
*c
= body
->block
;
6018 body
->block
= c
->block
;
6020 /* Kill the dead block, but not the blocks below it. */
6022 gfc_free_statements (c
);
6026 /* More than two cases is legal but insane for logical selects.
6027 Issue a warning for it. */
6028 if (gfc_option
.warn_surprising
&& type
== BT_LOGICAL
6030 gfc_warning ("Logical SELECT CASE block at %L has more that two cases",
6035 /* Resolve a transfer statement. This is making sure that:
6036 -- a derived type being transferred has only non-pointer components
6037 -- a derived type being transferred doesn't have private components, unless
6038 it's being transferred from the module where the type was defined
6039 -- we're not trying to transfer a whole assumed size array. */
6042 resolve_transfer (gfc_code
*code
)
6051 if (exp
->expr_type
!= EXPR_VARIABLE
&& exp
->expr_type
!= EXPR_FUNCTION
)
6054 sym
= exp
->symtree
->n
.sym
;
6057 /* Go to actual component transferred. */
6058 for (ref
= code
->expr
->ref
; ref
; ref
= ref
->next
)
6059 if (ref
->type
== REF_COMPONENT
)
6060 ts
= &ref
->u
.c
.component
->ts
;
6062 if (ts
->type
== BT_DERIVED
)
6064 /* Check that transferred derived type doesn't contain POINTER
6066 if (ts
->derived
->attr
.pointer_comp
)
6068 gfc_error ("Data transfer element at %L cannot have "
6069 "POINTER components", &code
->loc
);
6073 if (ts
->derived
->attr
.alloc_comp
)
6075 gfc_error ("Data transfer element at %L cannot have "
6076 "ALLOCATABLE components", &code
->loc
);
6080 if (derived_inaccessible (ts
->derived
))
6082 gfc_error ("Data transfer element at %L cannot have "
6083 "PRIVATE components",&code
->loc
);
6088 if (sym
->as
!= NULL
&& sym
->as
->type
== AS_ASSUMED_SIZE
6089 && exp
->ref
->type
== REF_ARRAY
&& exp
->ref
->u
.ar
.type
== AR_FULL
)
6091 gfc_error ("Data transfer element at %L cannot be a full reference to "
6092 "an assumed-size array", &code
->loc
);
6098 /*********** Toplevel code resolution subroutines ***********/
6100 /* Find the set of labels that are reachable from this block. We also
6101 record the last statement in each block. */
6104 find_reachable_labels (gfc_code
*block
)
6111 cs_base
->reachable_labels
= bitmap_obstack_alloc (&labels_obstack
);
6113 /* Collect labels in this block. We don't keep those corresponding
6114 to END {IF|SELECT}, these are checked in resolve_branch by going
6115 up through the code_stack. */
6116 for (c
= block
; c
; c
= c
->next
)
6118 if (c
->here
&& c
->op
!= EXEC_END_BLOCK
)
6119 bitmap_set_bit (cs_base
->reachable_labels
, c
->here
->value
);
6122 /* Merge with labels from parent block. */
6125 gcc_assert (cs_base
->prev
->reachable_labels
);
6126 bitmap_ior_into (cs_base
->reachable_labels
,
6127 cs_base
->prev
->reachable_labels
);
6131 /* Given a branch to a label, see if the branch is conforming.
6132 The code node describes where the branch is located. */
6135 resolve_branch (gfc_st_label
*label
, gfc_code
*code
)
6142 /* Step one: is this a valid branching target? */
6144 if (label
->defined
== ST_LABEL_UNKNOWN
)
6146 gfc_error ("Label %d referenced at %L is never defined", label
->value
,
6151 if (label
->defined
!= ST_LABEL_TARGET
)
6153 gfc_error ("Statement at %L is not a valid branch target statement "
6154 "for the branch statement at %L", &label
->where
, &code
->loc
);
6158 /* Step two: make sure this branch is not a branch to itself ;-) */
6160 if (code
->here
== label
)
6162 gfc_warning ("Branch at %L may result in an infinite loop", &code
->loc
);
6166 /* Step three: See if the label is in the same block as the
6167 branching statement. The hard work has been done by setting up
6168 the bitmap reachable_labels. */
6170 if (bitmap_bit_p (cs_base
->reachable_labels
, label
->value
))
6173 /* Step four: If we haven't found the label in the bitmap, it may
6174 still be the label of the END of the enclosing block, in which
6175 case we find it by going up the code_stack. */
6177 for (stack
= cs_base
; stack
; stack
= stack
->prev
)
6178 if (stack
->current
->next
&& stack
->current
->next
->here
== label
)
6183 gcc_assert (stack
->current
->next
->op
== EXEC_END_BLOCK
);
6187 /* The label is not in an enclosing block, so illegal. This was
6188 allowed in Fortran 66, so we allow it as extension. No
6189 further checks are necessary in this case. */
6190 gfc_notify_std (GFC_STD_LEGACY
, "Label at %L is not in the same block "
6191 "as the GOTO statement at %L", &label
->where
,
6197 /* Check whether EXPR1 has the same shape as EXPR2. */
6200 resolve_where_shape (gfc_expr
*expr1
, gfc_expr
*expr2
)
6202 mpz_t shape
[GFC_MAX_DIMENSIONS
];
6203 mpz_t shape2
[GFC_MAX_DIMENSIONS
];
6204 gfc_try result
= FAILURE
;
6207 /* Compare the rank. */
6208 if (expr1
->rank
!= expr2
->rank
)
6211 /* Compare the size of each dimension. */
6212 for (i
=0; i
<expr1
->rank
; i
++)
6214 if (gfc_array_dimen_size (expr1
, i
, &shape
[i
]) == FAILURE
)
6217 if (gfc_array_dimen_size (expr2
, i
, &shape2
[i
]) == FAILURE
)
6220 if (mpz_cmp (shape
[i
], shape2
[i
]))
6224 /* When either of the two expression is an assumed size array, we
6225 ignore the comparison of dimension sizes. */
6230 for (i
--; i
>= 0; i
--)
6232 mpz_clear (shape
[i
]);
6233 mpz_clear (shape2
[i
]);
6239 /* Check whether a WHERE assignment target or a WHERE mask expression
6240 has the same shape as the outmost WHERE mask expression. */
6243 resolve_where (gfc_code
*code
, gfc_expr
*mask
)
6249 cblock
= code
->block
;
6251 /* Store the first WHERE mask-expr of the WHERE statement or construct.
6252 In case of nested WHERE, only the outmost one is stored. */
6253 if (mask
== NULL
) /* outmost WHERE */
6255 else /* inner WHERE */
6262 /* Check if the mask-expr has a consistent shape with the
6263 outmost WHERE mask-expr. */
6264 if (resolve_where_shape (cblock
->expr
, e
) == FAILURE
)
6265 gfc_error ("WHERE mask at %L has inconsistent shape",
6266 &cblock
->expr
->where
);
6269 /* the assignment statement of a WHERE statement, or the first
6270 statement in where-body-construct of a WHERE construct */
6271 cnext
= cblock
->next
;
6276 /* WHERE assignment statement */
6279 /* Check shape consistent for WHERE assignment target. */
6280 if (e
&& resolve_where_shape (cnext
->expr
, e
) == FAILURE
)
6281 gfc_error ("WHERE assignment target at %L has "
6282 "inconsistent shape", &cnext
->expr
->where
);
6286 case EXEC_ASSIGN_CALL
:
6287 resolve_call (cnext
);
6288 if (!cnext
->resolved_sym
->attr
.elemental
)
6289 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
6290 &cnext
->ext
.actual
->expr
->where
);
6293 /* WHERE or WHERE construct is part of a where-body-construct */
6295 resolve_where (cnext
, e
);
6299 gfc_error ("Unsupported statement inside WHERE at %L",
6302 /* the next statement within the same where-body-construct */
6303 cnext
= cnext
->next
;
6305 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
6306 cblock
= cblock
->block
;
6311 /* Resolve assignment in FORALL construct.
6312 NVAR is the number of FORALL index variables, and VAR_EXPR records the
6313 FORALL index variables. */
6316 gfc_resolve_assign_in_forall (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
6320 for (n
= 0; n
< nvar
; n
++)
6322 gfc_symbol
*forall_index
;
6324 forall_index
= var_expr
[n
]->symtree
->n
.sym
;
6326 /* Check whether the assignment target is one of the FORALL index
6328 if ((code
->expr
->expr_type
== EXPR_VARIABLE
)
6329 && (code
->expr
->symtree
->n
.sym
== forall_index
))
6330 gfc_error ("Assignment to a FORALL index variable at %L",
6331 &code
->expr
->where
);
6334 /* If one of the FORALL index variables doesn't appear in the
6335 assignment variable, then there could be a many-to-one
6336 assignment. Emit a warning rather than an error because the
6337 mask could be resolving this problem. */
6338 if (find_forall_index (code
->expr
, forall_index
, 0) == FAILURE
)
6339 gfc_warning ("The FORALL with index '%s' is not used on the "
6340 "left side of the assignment at %L and so might "
6341 "cause multiple assignment to this object",
6342 var_expr
[n
]->symtree
->name
, &code
->expr
->where
);
6348 /* Resolve WHERE statement in FORALL construct. */
6351 gfc_resolve_where_code_in_forall (gfc_code
*code
, int nvar
,
6352 gfc_expr
**var_expr
)
6357 cblock
= code
->block
;
6360 /* the assignment statement of a WHERE statement, or the first
6361 statement in where-body-construct of a WHERE construct */
6362 cnext
= cblock
->next
;
6367 /* WHERE assignment statement */
6369 gfc_resolve_assign_in_forall (cnext
, nvar
, var_expr
);
6372 /* WHERE operator assignment statement */
6373 case EXEC_ASSIGN_CALL
:
6374 resolve_call (cnext
);
6375 if (!cnext
->resolved_sym
->attr
.elemental
)
6376 gfc_error("Non-ELEMENTAL user-defined assignment in WHERE at %L",
6377 &cnext
->ext
.actual
->expr
->where
);
6380 /* WHERE or WHERE construct is part of a where-body-construct */
6382 gfc_resolve_where_code_in_forall (cnext
, nvar
, var_expr
);
6386 gfc_error ("Unsupported statement inside WHERE at %L",
6389 /* the next statement within the same where-body-construct */
6390 cnext
= cnext
->next
;
6392 /* the next masked-elsewhere-stmt, elsewhere-stmt, or end-where-stmt */
6393 cblock
= cblock
->block
;
6398 /* Traverse the FORALL body to check whether the following errors exist:
6399 1. For assignment, check if a many-to-one assignment happens.
6400 2. For WHERE statement, check the WHERE body to see if there is any
6401 many-to-one assignment. */
6404 gfc_resolve_forall_body (gfc_code
*code
, int nvar
, gfc_expr
**var_expr
)
6408 c
= code
->block
->next
;
6414 case EXEC_POINTER_ASSIGN
:
6415 gfc_resolve_assign_in_forall (c
, nvar
, var_expr
);
6418 case EXEC_ASSIGN_CALL
:
6422 /* Because the gfc_resolve_blocks() will handle the nested FORALL,
6423 there is no need to handle it here. */
6427 gfc_resolve_where_code_in_forall(c
, nvar
, var_expr
);
6432 /* The next statement in the FORALL body. */
6438 /* Counts the number of iterators needed inside a forall construct, including
6439 nested forall constructs. This is used to allocate the needed memory
6440 in gfc_resolve_forall. */
6443 gfc_count_forall_iterators (gfc_code
*code
)
6445 int max_iters
, sub_iters
, current_iters
;
6446 gfc_forall_iterator
*fa
;
6448 gcc_assert(code
->op
== EXEC_FORALL
);
6452 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
6455 code
= code
->block
->next
;
6459 if (code
->op
== EXEC_FORALL
)
6461 sub_iters
= gfc_count_forall_iterators (code
);
6462 if (sub_iters
> max_iters
)
6463 max_iters
= sub_iters
;
6468 return current_iters
+ max_iters
;
6472 /* Given a FORALL construct, first resolve the FORALL iterator, then call
6473 gfc_resolve_forall_body to resolve the FORALL body. */
6476 gfc_resolve_forall (gfc_code
*code
, gfc_namespace
*ns
, int forall_save
)
6478 static gfc_expr
**var_expr
;
6479 static int total_var
= 0;
6480 static int nvar
= 0;
6482 gfc_forall_iterator
*fa
;
6487 /* Start to resolve a FORALL construct */
6488 if (forall_save
== 0)
6490 /* Count the total number of FORALL index in the nested FORALL
6491 construct in order to allocate the VAR_EXPR with proper size. */
6492 total_var
= gfc_count_forall_iterators (code
);
6494 /* Allocate VAR_EXPR with NUMBER_OF_FORALL_INDEX elements. */
6495 var_expr
= (gfc_expr
**) gfc_getmem (total_var
* sizeof (gfc_expr
*));
6498 /* The information about FORALL iterator, including FORALL index start, end
6499 and stride. The FORALL index can not appear in start, end or stride. */
6500 for (fa
= code
->ext
.forall_iterator
; fa
; fa
= fa
->next
)
6502 /* Check if any outer FORALL index name is the same as the current
6504 for (i
= 0; i
< nvar
; i
++)
6506 if (fa
->var
->symtree
->n
.sym
== var_expr
[i
]->symtree
->n
.sym
)
6508 gfc_error ("An outer FORALL construct already has an index "
6509 "with this name %L", &fa
->var
->where
);
6513 /* Record the current FORALL index. */
6514 var_expr
[nvar
] = gfc_copy_expr (fa
->var
);
6518 /* No memory leak. */
6519 gcc_assert (nvar
<= total_var
);
6522 /* Resolve the FORALL body. */
6523 gfc_resolve_forall_body (code
, nvar
, var_expr
);
6525 /* May call gfc_resolve_forall to resolve the inner FORALL loop. */
6526 gfc_resolve_blocks (code
->block
, ns
);
6530 /* Free only the VAR_EXPRs allocated in this frame. */
6531 for (i
= nvar
; i
< tmp
; i
++)
6532 gfc_free_expr (var_expr
[i
]);
6536 /* We are in the outermost FORALL construct. */
6537 gcc_assert (forall_save
== 0);
6539 /* VAR_EXPR is not needed any more. */
6540 gfc_free (var_expr
);
6546 /* Resolve lists of blocks found in IF, SELECT CASE, WHERE, FORALL ,GOTO and
6549 static void resolve_code (gfc_code
*, gfc_namespace
*);
6552 gfc_resolve_blocks (gfc_code
*b
, gfc_namespace
*ns
)
6556 for (; b
; b
= b
->block
)
6558 t
= gfc_resolve_expr (b
->expr
);
6559 if (gfc_resolve_expr (b
->expr2
) == FAILURE
)
6565 if (t
== SUCCESS
&& b
->expr
!= NULL
6566 && (b
->expr
->ts
.type
!= BT_LOGICAL
|| b
->expr
->rank
!= 0))
6567 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
6574 && (b
->expr
->ts
.type
!= BT_LOGICAL
|| b
->expr
->rank
== 0))
6575 gfc_error ("WHERE/ELSEWHERE clause at %L requires a LOGICAL array",
6580 resolve_branch (b
->label
, b
);
6593 case EXEC_OMP_ATOMIC
:
6594 case EXEC_OMP_CRITICAL
:
6596 case EXEC_OMP_MASTER
:
6597 case EXEC_OMP_ORDERED
:
6598 case EXEC_OMP_PARALLEL
:
6599 case EXEC_OMP_PARALLEL_DO
:
6600 case EXEC_OMP_PARALLEL_SECTIONS
:
6601 case EXEC_OMP_PARALLEL_WORKSHARE
:
6602 case EXEC_OMP_SECTIONS
:
6603 case EXEC_OMP_SINGLE
:
6605 case EXEC_OMP_TASKWAIT
:
6606 case EXEC_OMP_WORKSHARE
:
6610 gfc_internal_error ("resolve_block(): Bad block type");
6613 resolve_code (b
->next
, ns
);
6618 /* Does everything to resolve an ordinary assignment. Returns true
6619 if this is an interface assignment. */
6621 resolve_ordinary_assign (gfc_code
*code
, gfc_namespace
*ns
)
6631 if (gfc_extend_assign (code
, ns
) == SUCCESS
)
6633 lhs
= code
->ext
.actual
->expr
;
6634 rhs
= code
->ext
.actual
->next
->expr
;
6635 if (gfc_pure (NULL
) && !gfc_pure (code
->symtree
->n
.sym
))
6637 gfc_error ("Subroutine '%s' called instead of assignment at "
6638 "%L must be PURE", code
->symtree
->n
.sym
->name
,
6643 /* Make a temporary rhs when there is a default initializer
6644 and rhs is the same symbol as the lhs. */
6645 if (rhs
->expr_type
== EXPR_VARIABLE
6646 && rhs
->symtree
->n
.sym
->ts
.type
== BT_DERIVED
6647 && has_default_initializer (rhs
->symtree
->n
.sym
->ts
.derived
)
6648 && (lhs
->symtree
->n
.sym
== rhs
->symtree
->n
.sym
))
6649 code
->ext
.actual
->next
->expr
= gfc_get_parentheses (rhs
);
6658 && gfc_notify_std (GFC_STD_GNU
, "Extension: BOZ literal at %L outside "
6659 "a DATA statement and outside INT/REAL/DBLE/CMPLX",
6660 &code
->loc
) == FAILURE
)
6663 /* Handle the case of a BOZ literal on the RHS. */
6664 if (rhs
->is_boz
&& lhs
->ts
.type
!= BT_INTEGER
)
6667 if (gfc_option
.warn_surprising
)
6668 gfc_warning ("BOZ literal at %L is bitwise transferred "
6669 "non-integer symbol '%s'", &code
->loc
,
6670 lhs
->symtree
->n
.sym
->name
);
6672 if (!gfc_convert_boz (rhs
, &lhs
->ts
))
6674 if ((rc
= gfc_range_check (rhs
)) != ARITH_OK
)
6676 if (rc
== ARITH_UNDERFLOW
)
6677 gfc_error ("Arithmetic underflow of bit-wise transferred BOZ at %L"
6678 ". This check can be disabled with the option "
6679 "-fno-range-check", &rhs
->where
);
6680 else if (rc
== ARITH_OVERFLOW
)
6681 gfc_error ("Arithmetic overflow of bit-wise transferred BOZ at %L"
6682 ". This check can be disabled with the option "
6683 "-fno-range-check", &rhs
->where
);
6684 else if (rc
== ARITH_NAN
)
6685 gfc_error ("Arithmetic NaN of bit-wise transferred BOZ at %L"
6686 ". This check can be disabled with the option "
6687 "-fno-range-check", &rhs
->where
);
6693 if (lhs
->ts
.type
== BT_CHARACTER
6694 && gfc_option
.warn_character_truncation
)
6696 if (lhs
->ts
.cl
!= NULL
6697 && lhs
->ts
.cl
->length
!= NULL
6698 && lhs
->ts
.cl
->length
->expr_type
== EXPR_CONSTANT
)
6699 llen
= mpz_get_si (lhs
->ts
.cl
->length
->value
.integer
);
6701 if (rhs
->expr_type
== EXPR_CONSTANT
)
6702 rlen
= rhs
->value
.character
.length
;
6704 else if (rhs
->ts
.cl
!= NULL
6705 && rhs
->ts
.cl
->length
!= NULL
6706 && rhs
->ts
.cl
->length
->expr_type
== EXPR_CONSTANT
)
6707 rlen
= mpz_get_si (rhs
->ts
.cl
->length
->value
.integer
);
6709 if (rlen
&& llen
&& rlen
> llen
)
6710 gfc_warning_now ("CHARACTER expression will be truncated "
6711 "in assignment (%d/%d) at %L",
6712 llen
, rlen
, &code
->loc
);
6715 /* Ensure that a vector index expression for the lvalue is evaluated
6716 to a temporary if the lvalue symbol is referenced in it. */
6719 for (ref
= lhs
->ref
; ref
; ref
= ref
->next
)
6720 if (ref
->type
== REF_ARRAY
)
6722 for (n
= 0; n
< ref
->u
.ar
.dimen
; n
++)
6723 if (ref
->u
.ar
.dimen_type
[n
] == DIMEN_VECTOR
6724 && gfc_find_sym_in_expr (lhs
->symtree
->n
.sym
,
6725 ref
->u
.ar
.start
[n
]))
6727 = gfc_get_parentheses (ref
->u
.ar
.start
[n
]);
6731 if (gfc_pure (NULL
))
6733 if (gfc_impure_variable (lhs
->symtree
->n
.sym
))
6735 gfc_error ("Cannot assign to variable '%s' in PURE "
6737 lhs
->symtree
->n
.sym
->name
,
6742 if (lhs
->ts
.type
== BT_DERIVED
6743 && lhs
->expr_type
== EXPR_VARIABLE
6744 && lhs
->ts
.derived
->attr
.pointer_comp
6745 && gfc_impure_variable (rhs
->symtree
->n
.sym
))
6747 gfc_error ("The impure variable at %L is assigned to "
6748 "a derived type variable with a POINTER "
6749 "component in a PURE procedure (12.6)",
6755 gfc_check_assign (lhs
, rhs
, 1);
6759 /* Given a block of code, recursively resolve everything pointed to by this
6763 resolve_code (gfc_code
*code
, gfc_namespace
*ns
)
6765 int omp_workshare_save
;
6770 frame
.prev
= cs_base
;
6774 find_reachable_labels (code
);
6776 for (; code
; code
= code
->next
)
6778 frame
.current
= code
;
6779 forall_save
= forall_flag
;
6781 if (code
->op
== EXEC_FORALL
)
6784 gfc_resolve_forall (code
, ns
, forall_save
);
6787 else if (code
->block
)
6789 omp_workshare_save
= -1;
6792 case EXEC_OMP_PARALLEL_WORKSHARE
:
6793 omp_workshare_save
= omp_workshare_flag
;
6794 omp_workshare_flag
= 1;
6795 gfc_resolve_omp_parallel_blocks (code
, ns
);
6797 case EXEC_OMP_PARALLEL
:
6798 case EXEC_OMP_PARALLEL_DO
:
6799 case EXEC_OMP_PARALLEL_SECTIONS
:
6801 omp_workshare_save
= omp_workshare_flag
;
6802 omp_workshare_flag
= 0;
6803 gfc_resolve_omp_parallel_blocks (code
, ns
);
6806 gfc_resolve_omp_do_blocks (code
, ns
);
6808 case EXEC_OMP_WORKSHARE
:
6809 omp_workshare_save
= omp_workshare_flag
;
6810 omp_workshare_flag
= 1;
6813 gfc_resolve_blocks (code
->block
, ns
);
6817 if (omp_workshare_save
!= -1)
6818 omp_workshare_flag
= omp_workshare_save
;
6822 if (code
->op
!= EXEC_COMPCALL
)
6823 t
= gfc_resolve_expr (code
->expr
);
6824 forall_flag
= forall_save
;
6826 if (gfc_resolve_expr (code
->expr2
) == FAILURE
)
6832 case EXEC_END_BLOCK
:
6842 /* Keep track of which entry we are up to. */
6843 current_entry_id
= code
->ext
.entry
->id
;
6847 resolve_where (code
, NULL
);
6851 if (code
->expr
!= NULL
)
6853 if (code
->expr
->ts
.type
!= BT_INTEGER
)
6854 gfc_error ("ASSIGNED GOTO statement at %L requires an "
6855 "INTEGER variable", &code
->expr
->where
);
6856 else if (code
->expr
->symtree
->n
.sym
->attr
.assign
!= 1)
6857 gfc_error ("Variable '%s' has not been assigned a target "
6858 "label at %L", code
->expr
->symtree
->n
.sym
->name
,
6859 &code
->expr
->where
);
6862 resolve_branch (code
->label
, code
);
6866 if (code
->expr
!= NULL
6867 && (code
->expr
->ts
.type
!= BT_INTEGER
|| code
->expr
->rank
))
6868 gfc_error ("Alternate RETURN statement at %L requires a SCALAR-"
6869 "INTEGER return specifier", &code
->expr
->where
);
6872 case EXEC_INIT_ASSIGN
:
6879 if (resolve_ordinary_assign (code
, ns
))
6884 case EXEC_LABEL_ASSIGN
:
6885 if (code
->label
->defined
== ST_LABEL_UNKNOWN
)
6886 gfc_error ("Label %d referenced at %L is never defined",
6887 code
->label
->value
, &code
->label
->where
);
6889 && (code
->expr
->expr_type
!= EXPR_VARIABLE
6890 || code
->expr
->symtree
->n
.sym
->ts
.type
!= BT_INTEGER
6891 || code
->expr
->symtree
->n
.sym
->ts
.kind
6892 != gfc_default_integer_kind
6893 || code
->expr
->symtree
->n
.sym
->as
!= NULL
))
6894 gfc_error ("ASSIGN statement at %L requires a scalar "
6895 "default INTEGER variable", &code
->expr
->where
);
6898 case EXEC_POINTER_ASSIGN
:
6902 gfc_check_pointer_assign (code
->expr
, code
->expr2
);
6905 case EXEC_ARITHMETIC_IF
:
6907 && code
->expr
->ts
.type
!= BT_INTEGER
6908 && code
->expr
->ts
.type
!= BT_REAL
)
6909 gfc_error ("Arithmetic IF statement at %L requires a numeric "
6910 "expression", &code
->expr
->where
);
6912 resolve_branch (code
->label
, code
);
6913 resolve_branch (code
->label2
, code
);
6914 resolve_branch (code
->label3
, code
);
6918 if (t
== SUCCESS
&& code
->expr
!= NULL
6919 && (code
->expr
->ts
.type
!= BT_LOGICAL
6920 || code
->expr
->rank
!= 0))
6921 gfc_error ("IF clause at %L requires a scalar LOGICAL expression",
6922 &code
->expr
->where
);
6927 resolve_call (code
);
6931 resolve_typebound_call (code
);
6935 /* Select is complicated. Also, a SELECT construct could be
6936 a transformed computed GOTO. */
6937 resolve_select (code
);
6941 if (code
->ext
.iterator
!= NULL
)
6943 gfc_iterator
*iter
= code
->ext
.iterator
;
6944 if (gfc_resolve_iterator (iter
, true) != FAILURE
)
6945 gfc_resolve_do_iterator (code
, iter
->var
->symtree
->n
.sym
);
6950 if (code
->expr
== NULL
)
6951 gfc_internal_error ("resolve_code(): No expression on DO WHILE");
6953 && (code
->expr
->rank
!= 0
6954 || code
->expr
->ts
.type
!= BT_LOGICAL
))
6955 gfc_error ("Exit condition of DO WHILE loop at %L must be "
6956 "a scalar LOGICAL expression", &code
->expr
->where
);
6961 resolve_allocate_deallocate (code
, "ALLOCATE");
6965 case EXEC_DEALLOCATE
:
6967 resolve_allocate_deallocate (code
, "DEALLOCATE");
6972 if (gfc_resolve_open (code
->ext
.open
) == FAILURE
)
6975 resolve_branch (code
->ext
.open
->err
, code
);
6979 if (gfc_resolve_close (code
->ext
.close
) == FAILURE
)
6982 resolve_branch (code
->ext
.close
->err
, code
);
6985 case EXEC_BACKSPACE
:
6989 if (gfc_resolve_filepos (code
->ext
.filepos
) == FAILURE
)
6992 resolve_branch (code
->ext
.filepos
->err
, code
);
6996 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
6999 resolve_branch (code
->ext
.inquire
->err
, code
);
7003 gcc_assert (code
->ext
.inquire
!= NULL
);
7004 if (gfc_resolve_inquire (code
->ext
.inquire
) == FAILURE
)
7007 resolve_branch (code
->ext
.inquire
->err
, code
);
7011 if (gfc_resolve_wait (code
->ext
.wait
) == FAILURE
)
7014 resolve_branch (code
->ext
.wait
->err
, code
);
7015 resolve_branch (code
->ext
.wait
->end
, code
);
7016 resolve_branch (code
->ext
.wait
->eor
, code
);
7021 if (gfc_resolve_dt (code
->ext
.dt
) == FAILURE
)
7024 resolve_branch (code
->ext
.dt
->err
, code
);
7025 resolve_branch (code
->ext
.dt
->end
, code
);
7026 resolve_branch (code
->ext
.dt
->eor
, code
);
7030 resolve_transfer (code
);
7034 resolve_forall_iterators (code
->ext
.forall_iterator
);
7036 if (code
->expr
!= NULL
&& code
->expr
->ts
.type
!= BT_LOGICAL
)
7037 gfc_error ("FORALL mask clause at %L requires a LOGICAL "
7038 "expression", &code
->expr
->where
);
7041 case EXEC_OMP_ATOMIC
:
7042 case EXEC_OMP_BARRIER
:
7043 case EXEC_OMP_CRITICAL
:
7044 case EXEC_OMP_FLUSH
:
7046 case EXEC_OMP_MASTER
:
7047 case EXEC_OMP_ORDERED
:
7048 case EXEC_OMP_SECTIONS
:
7049 case EXEC_OMP_SINGLE
:
7050 case EXEC_OMP_TASKWAIT
:
7051 case EXEC_OMP_WORKSHARE
:
7052 gfc_resolve_omp_directive (code
, ns
);
7055 case EXEC_OMP_PARALLEL
:
7056 case EXEC_OMP_PARALLEL_DO
:
7057 case EXEC_OMP_PARALLEL_SECTIONS
:
7058 case EXEC_OMP_PARALLEL_WORKSHARE
:
7060 omp_workshare_save
= omp_workshare_flag
;
7061 omp_workshare_flag
= 0;
7062 gfc_resolve_omp_directive (code
, ns
);
7063 omp_workshare_flag
= omp_workshare_save
;
7067 gfc_internal_error ("resolve_code(): Bad statement code");
7071 cs_base
= frame
.prev
;
7075 /* Resolve initial values and make sure they are compatible with
7079 resolve_values (gfc_symbol
*sym
)
7081 if (sym
->value
== NULL
)
7084 if (gfc_resolve_expr (sym
->value
) == FAILURE
)
7087 gfc_check_assign_symbol (sym
, sym
->value
);
7091 /* Verify the binding labels for common blocks that are BIND(C). The label
7092 for a BIND(C) common block must be identical in all scoping units in which
7093 the common block is declared. Further, the binding label can not collide
7094 with any other global entity in the program. */
7097 resolve_bind_c_comms (gfc_symtree
*comm_block_tree
)
7099 if (comm_block_tree
->n
.common
->is_bind_c
== 1)
7101 gfc_gsymbol
*binding_label_gsym
;
7102 gfc_gsymbol
*comm_name_gsym
;
7104 /* See if a global symbol exists by the common block's name. It may
7105 be NULL if the common block is use-associated. */
7106 comm_name_gsym
= gfc_find_gsymbol (gfc_gsym_root
,
7107 comm_block_tree
->n
.common
->name
);
7108 if (comm_name_gsym
!= NULL
&& comm_name_gsym
->type
!= GSYM_COMMON
)
7109 gfc_error ("Binding label '%s' for common block '%s' at %L collides "
7110 "with the global entity '%s' at %L",
7111 comm_block_tree
->n
.common
->binding_label
,
7112 comm_block_tree
->n
.common
->name
,
7113 &(comm_block_tree
->n
.common
->where
),
7114 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
7115 else if (comm_name_gsym
!= NULL
7116 && strcmp (comm_name_gsym
->name
,
7117 comm_block_tree
->n
.common
->name
) == 0)
7119 /* TODO: Need to make sure the fields of gfc_gsymbol are initialized
7121 if (comm_name_gsym
->binding_label
== NULL
)
7122 /* No binding label for common block stored yet; save this one. */
7123 comm_name_gsym
->binding_label
=
7124 comm_block_tree
->n
.common
->binding_label
;
7126 if (strcmp (comm_name_gsym
->binding_label
,
7127 comm_block_tree
->n
.common
->binding_label
) != 0)
7129 /* Common block names match but binding labels do not. */
7130 gfc_error ("Binding label '%s' for common block '%s' at %L "
7131 "does not match the binding label '%s' for common "
7133 comm_block_tree
->n
.common
->binding_label
,
7134 comm_block_tree
->n
.common
->name
,
7135 &(comm_block_tree
->n
.common
->where
),
7136 comm_name_gsym
->binding_label
,
7137 comm_name_gsym
->name
,
7138 &(comm_name_gsym
->where
));
7143 /* There is no binding label (NAME="") so we have nothing further to
7144 check and nothing to add as a global symbol for the label. */
7145 if (comm_block_tree
->n
.common
->binding_label
[0] == '\0' )
7148 binding_label_gsym
=
7149 gfc_find_gsymbol (gfc_gsym_root
,
7150 comm_block_tree
->n
.common
->binding_label
);
7151 if (binding_label_gsym
== NULL
)
7153 /* Need to make a global symbol for the binding label to prevent
7154 it from colliding with another. */
7155 binding_label_gsym
=
7156 gfc_get_gsymbol (comm_block_tree
->n
.common
->binding_label
);
7157 binding_label_gsym
->sym_name
= comm_block_tree
->n
.common
->name
;
7158 binding_label_gsym
->type
= GSYM_COMMON
;
7162 /* If comm_name_gsym is NULL, the name common block is use
7163 associated and the name could be colliding. */
7164 if (binding_label_gsym
->type
!= GSYM_COMMON
)
7165 gfc_error ("Binding label '%s' for common block '%s' at %L "
7166 "collides with the global entity '%s' at %L",
7167 comm_block_tree
->n
.common
->binding_label
,
7168 comm_block_tree
->n
.common
->name
,
7169 &(comm_block_tree
->n
.common
->where
),
7170 binding_label_gsym
->name
,
7171 &(binding_label_gsym
->where
));
7172 else if (comm_name_gsym
!= NULL
7173 && (strcmp (binding_label_gsym
->name
,
7174 comm_name_gsym
->binding_label
) != 0)
7175 && (strcmp (binding_label_gsym
->sym_name
,
7176 comm_name_gsym
->name
) != 0))
7177 gfc_error ("Binding label '%s' for common block '%s' at %L "
7178 "collides with global entity '%s' at %L",
7179 binding_label_gsym
->name
, binding_label_gsym
->sym_name
,
7180 &(comm_block_tree
->n
.common
->where
),
7181 comm_name_gsym
->name
, &(comm_name_gsym
->where
));
7189 /* Verify any BIND(C) derived types in the namespace so we can report errors
7190 for them once, rather than for each variable declared of that type. */
7193 resolve_bind_c_derived_types (gfc_symbol
*derived_sym
)
7195 if (derived_sym
!= NULL
&& derived_sym
->attr
.flavor
== FL_DERIVED
7196 && derived_sym
->attr
.is_bind_c
== 1)
7197 verify_bind_c_derived_type (derived_sym
);
7203 /* Verify that any binding labels used in a given namespace do not collide
7204 with the names or binding labels of any global symbols. */
7207 gfc_verify_binding_labels (gfc_symbol
*sym
)
7211 if (sym
!= NULL
&& sym
->attr
.is_bind_c
&& sym
->attr
.is_iso_c
== 0
7212 && sym
->attr
.flavor
!= FL_DERIVED
&& sym
->binding_label
[0] != '\0')
7214 gfc_gsymbol
*bind_c_sym
;
7216 bind_c_sym
= gfc_find_gsymbol (gfc_gsym_root
, sym
->binding_label
);
7217 if (bind_c_sym
!= NULL
7218 && strcmp (bind_c_sym
->name
, sym
->binding_label
) == 0)
7220 if (sym
->attr
.if_source
== IFSRC_DECL
7221 && (bind_c_sym
->type
!= GSYM_SUBROUTINE
7222 && bind_c_sym
->type
!= GSYM_FUNCTION
)
7223 && ((sym
->attr
.contained
== 1
7224 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0)
7225 || (sym
->attr
.use_assoc
== 1
7226 && (strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0))))
7228 /* Make sure global procedures don't collide with anything. */
7229 gfc_error ("Binding label '%s' at %L collides with the global "
7230 "entity '%s' at %L", sym
->binding_label
,
7231 &(sym
->declared_at
), bind_c_sym
->name
,
7232 &(bind_c_sym
->where
));
7235 else if (sym
->attr
.contained
== 0
7236 && (sym
->attr
.if_source
== IFSRC_IFBODY
7237 && sym
->attr
.flavor
== FL_PROCEDURE
)
7238 && (bind_c_sym
->sym_name
!= NULL
7239 && strcmp (bind_c_sym
->sym_name
, sym
->name
) != 0))
7241 /* Make sure procedures in interface bodies don't collide. */
7242 gfc_error ("Binding label '%s' in interface body at %L collides "
7243 "with the global entity '%s' at %L",
7245 &(sym
->declared_at
), bind_c_sym
->name
,
7246 &(bind_c_sym
->where
));
7249 else if (sym
->attr
.contained
== 0
7250 && sym
->attr
.if_source
== IFSRC_UNKNOWN
)
7251 if ((sym
->attr
.use_assoc
&& bind_c_sym
->mod_name
7252 && strcmp (bind_c_sym
->mod_name
, sym
->module
) != 0)
7253 || sym
->attr
.use_assoc
== 0)
7255 gfc_error ("Binding label '%s' at %L collides with global "
7256 "entity '%s' at %L", sym
->binding_label
,
7257 &(sym
->declared_at
), bind_c_sym
->name
,
7258 &(bind_c_sym
->where
));
7263 /* Clear the binding label to prevent checking multiple times. */
7264 sym
->binding_label
[0] = '\0';
7266 else if (bind_c_sym
== NULL
)
7268 bind_c_sym
= gfc_get_gsymbol (sym
->binding_label
);
7269 bind_c_sym
->where
= sym
->declared_at
;
7270 bind_c_sym
->sym_name
= sym
->name
;
7272 if (sym
->attr
.use_assoc
== 1)
7273 bind_c_sym
->mod_name
= sym
->module
;
7275 if (sym
->ns
->proc_name
!= NULL
)
7276 bind_c_sym
->mod_name
= sym
->ns
->proc_name
->name
;
7278 if (sym
->attr
.contained
== 0)
7280 if (sym
->attr
.subroutine
)
7281 bind_c_sym
->type
= GSYM_SUBROUTINE
;
7282 else if (sym
->attr
.function
)
7283 bind_c_sym
->type
= GSYM_FUNCTION
;
7291 /* Resolve an index expression. */
7294 resolve_index_expr (gfc_expr
*e
)
7296 if (gfc_resolve_expr (e
) == FAILURE
)
7299 if (gfc_simplify_expr (e
, 0) == FAILURE
)
7302 if (gfc_specification_expr (e
) == FAILURE
)
7308 /* Resolve a charlen structure. */
7311 resolve_charlen (gfc_charlen
*cl
)
7320 specification_expr
= 1;
7322 if (resolve_index_expr (cl
->length
) == FAILURE
)
7324 specification_expr
= 0;
7328 /* "If the character length parameter value evaluates to a negative
7329 value, the length of character entities declared is zero." */
7330 if (cl
->length
&& !gfc_extract_int (cl
->length
, &i
) && i
< 0)
7332 gfc_warning_now ("CHARACTER variable has zero length at %L",
7333 &cl
->length
->where
);
7334 gfc_replace_expr (cl
->length
, gfc_int_expr (0));
7341 /* Test for non-constant shape arrays. */
7344 is_non_constant_shape_array (gfc_symbol
*sym
)
7350 not_constant
= false;
7351 if (sym
->as
!= NULL
)
7353 /* Unfortunately, !gfc_is_compile_time_shape hits a legal case that
7354 has not been simplified; parameter array references. Do the
7355 simplification now. */
7356 for (i
= 0; i
< sym
->as
->rank
; i
++)
7358 e
= sym
->as
->lower
[i
];
7359 if (e
&& (resolve_index_expr (e
) == FAILURE
7360 || !gfc_is_constant_expr (e
)))
7361 not_constant
= true;
7363 e
= sym
->as
->upper
[i
];
7364 if (e
&& (resolve_index_expr (e
) == FAILURE
7365 || !gfc_is_constant_expr (e
)))
7366 not_constant
= true;
7369 return not_constant
;
7372 /* Given a symbol and an initialization expression, add code to initialize
7373 the symbol to the function entry. */
7375 build_init_assign (gfc_symbol
*sym
, gfc_expr
*init
)
7379 gfc_namespace
*ns
= sym
->ns
;
7381 /* Search for the function namespace if this is a contained
7382 function without an explicit result. */
7383 if (sym
->attr
.function
&& sym
== sym
->result
7384 && sym
->name
!= sym
->ns
->proc_name
->name
)
7387 for (;ns
; ns
= ns
->sibling
)
7388 if (strcmp (ns
->proc_name
->name
, sym
->name
) == 0)
7394 gfc_free_expr (init
);
7398 /* Build an l-value expression for the result. */
7399 lval
= gfc_lval_expr_from_sym (sym
);
7401 /* Add the code at scope entry. */
7402 init_st
= gfc_get_code ();
7403 init_st
->next
= ns
->code
;
7406 /* Assign the default initializer to the l-value. */
7407 init_st
->loc
= sym
->declared_at
;
7408 init_st
->op
= EXEC_INIT_ASSIGN
;
7409 init_st
->expr
= lval
;
7410 init_st
->expr2
= init
;
7413 /* Assign the default initializer to a derived type variable or result. */
7416 apply_default_init (gfc_symbol
*sym
)
7418 gfc_expr
*init
= NULL
;
7420 if (sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
7423 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.derived
)
7424 init
= gfc_default_initializer (&sym
->ts
);
7429 build_init_assign (sym
, init
);
7432 /* Build an initializer for a local integer, real, complex, logical, or
7433 character variable, based on the command line flags finit-local-zero,
7434 finit-integer=, finit-real=, finit-logical=, and finit-runtime. Returns
7435 null if the symbol should not have a default initialization. */
7437 build_default_init_expr (gfc_symbol
*sym
)
7440 gfc_expr
*init_expr
;
7443 /* These symbols should never have a default initialization. */
7444 if ((sym
->attr
.dimension
&& !gfc_is_compile_time_shape (sym
->as
))
7445 || sym
->attr
.external
7447 || sym
->attr
.pointer
7448 || sym
->attr
.in_equivalence
7449 || sym
->attr
.in_common
7452 || sym
->attr
.cray_pointee
7453 || sym
->attr
.cray_pointer
)
7456 /* Now we'll try to build an initializer expression. */
7457 init_expr
= gfc_get_expr ();
7458 init_expr
->expr_type
= EXPR_CONSTANT
;
7459 init_expr
->ts
.type
= sym
->ts
.type
;
7460 init_expr
->ts
.kind
= sym
->ts
.kind
;
7461 init_expr
->where
= sym
->declared_at
;
7463 /* We will only initialize integers, reals, complex, logicals, and
7464 characters, and only if the corresponding command-line flags
7465 were set. Otherwise, we free init_expr and return null. */
7466 switch (sym
->ts
.type
)
7469 if (gfc_option
.flag_init_integer
!= GFC_INIT_INTEGER_OFF
)
7470 mpz_init_set_si (init_expr
->value
.integer
,
7471 gfc_option
.flag_init_integer_value
);
7474 gfc_free_expr (init_expr
);
7480 mpfr_init (init_expr
->value
.real
);
7481 switch (gfc_option
.flag_init_real
)
7483 case GFC_INIT_REAL_SNAN
:
7484 init_expr
->is_snan
= 1;
7486 case GFC_INIT_REAL_NAN
:
7487 mpfr_set_nan (init_expr
->value
.real
);
7490 case GFC_INIT_REAL_INF
:
7491 mpfr_set_inf (init_expr
->value
.real
, 1);
7494 case GFC_INIT_REAL_NEG_INF
:
7495 mpfr_set_inf (init_expr
->value
.real
, -1);
7498 case GFC_INIT_REAL_ZERO
:
7499 mpfr_set_ui (init_expr
->value
.real
, 0.0, GFC_RND_MODE
);
7503 gfc_free_expr (init_expr
);
7510 mpfr_init (init_expr
->value
.complex.r
);
7511 mpfr_init (init_expr
->value
.complex.i
);
7512 switch (gfc_option
.flag_init_real
)
7514 case GFC_INIT_REAL_SNAN
:
7515 init_expr
->is_snan
= 1;
7517 case GFC_INIT_REAL_NAN
:
7518 mpfr_set_nan (init_expr
->value
.complex.r
);
7519 mpfr_set_nan (init_expr
->value
.complex.i
);
7522 case GFC_INIT_REAL_INF
:
7523 mpfr_set_inf (init_expr
->value
.complex.r
, 1);
7524 mpfr_set_inf (init_expr
->value
.complex.i
, 1);
7527 case GFC_INIT_REAL_NEG_INF
:
7528 mpfr_set_inf (init_expr
->value
.complex.r
, -1);
7529 mpfr_set_inf (init_expr
->value
.complex.i
, -1);
7532 case GFC_INIT_REAL_ZERO
:
7533 mpfr_set_ui (init_expr
->value
.complex.r
, 0.0, GFC_RND_MODE
);
7534 mpfr_set_ui (init_expr
->value
.complex.i
, 0.0, GFC_RND_MODE
);
7538 gfc_free_expr (init_expr
);
7545 if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_FALSE
)
7546 init_expr
->value
.logical
= 0;
7547 else if (gfc_option
.flag_init_logical
== GFC_INIT_LOGICAL_TRUE
)
7548 init_expr
->value
.logical
= 1;
7551 gfc_free_expr (init_expr
);
7557 /* For characters, the length must be constant in order to
7558 create a default initializer. */
7559 if (gfc_option
.flag_init_character
== GFC_INIT_CHARACTER_ON
7560 && sym
->ts
.cl
->length
7561 && sym
->ts
.cl
->length
->expr_type
== EXPR_CONSTANT
)
7563 char_len
= mpz_get_si (sym
->ts
.cl
->length
->value
.integer
);
7564 init_expr
->value
.character
.length
= char_len
;
7565 init_expr
->value
.character
.string
= gfc_get_wide_string (char_len
+1);
7566 for (i
= 0; i
< char_len
; i
++)
7567 init_expr
->value
.character
.string
[i
]
7568 = (unsigned char) gfc_option
.flag_init_character_value
;
7572 gfc_free_expr (init_expr
);
7578 gfc_free_expr (init_expr
);
7584 /* Add an initialization expression to a local variable. */
7586 apply_default_init_local (gfc_symbol
*sym
)
7588 gfc_expr
*init
= NULL
;
7590 /* The symbol should be a variable or a function return value. */
7591 if ((sym
->attr
.flavor
!= FL_VARIABLE
&& !sym
->attr
.function
)
7592 || (sym
->attr
.function
&& sym
->result
!= sym
))
7595 /* Try to build the initializer expression. If we can't initialize
7596 this symbol, then init will be NULL. */
7597 init
= build_default_init_expr (sym
);
7601 /* For saved variables, we don't want to add an initializer at
7602 function entry, so we just add a static initializer. */
7603 if (sym
->attr
.save
|| sym
->ns
->save_all
)
7605 /* Don't clobber an existing initializer! */
7606 gcc_assert (sym
->value
== NULL
);
7611 build_init_assign (sym
, init
);
7614 /* Resolution of common features of flavors variable and procedure. */
7617 resolve_fl_var_and_proc (gfc_symbol
*sym
, int mp_flag
)
7619 /* Constraints on deferred shape variable. */
7620 if (sym
->as
== NULL
|| sym
->as
->type
!= AS_DEFERRED
)
7622 if (sym
->attr
.allocatable
)
7624 if (sym
->attr
.dimension
)
7625 gfc_error ("Allocatable array '%s' at %L must have "
7626 "a deferred shape", sym
->name
, &sym
->declared_at
);
7628 gfc_error ("Scalar object '%s' at %L may not be ALLOCATABLE",
7629 sym
->name
, &sym
->declared_at
);
7633 if (sym
->attr
.pointer
&& sym
->attr
.dimension
)
7635 gfc_error ("Array pointer '%s' at %L must have a deferred shape",
7636 sym
->name
, &sym
->declared_at
);
7643 if (!mp_flag
&& !sym
->attr
.allocatable
7644 && !sym
->attr
.pointer
&& !sym
->attr
.dummy
)
7646 gfc_error ("Array '%s' at %L cannot have a deferred shape",
7647 sym
->name
, &sym
->declared_at
);
7655 /* Additional checks for symbols with flavor variable and derived
7656 type. To be called from resolve_fl_variable. */
7659 resolve_fl_variable_derived (gfc_symbol
*sym
, int no_init_flag
)
7661 gcc_assert (sym
->ts
.type
== BT_DERIVED
);
7663 /* Check to see if a derived type is blocked from being host
7664 associated by the presence of another class I symbol in the same
7665 namespace. 14.6.1.3 of the standard and the discussion on
7666 comp.lang.fortran. */
7667 if (sym
->ns
!= sym
->ts
.derived
->ns
7668 && sym
->ns
->proc_name
->attr
.if_source
!= IFSRC_IFBODY
)
7671 gfc_find_symbol (sym
->ts
.derived
->name
, sym
->ns
, 0, &s
);
7672 if (s
&& s
->attr
.flavor
!= FL_DERIVED
)
7674 gfc_error ("The type '%s' cannot be host associated at %L "
7675 "because it is blocked by an incompatible object "
7676 "of the same name declared at %L",
7677 sym
->ts
.derived
->name
, &sym
->declared_at
,
7683 /* 4th constraint in section 11.3: "If an object of a type for which
7684 component-initialization is specified (R429) appears in the
7685 specification-part of a module and does not have the ALLOCATABLE
7686 or POINTER attribute, the object shall have the SAVE attribute."
7688 The check for initializers is performed with
7689 has_default_initializer because gfc_default_initializer generates
7690 a hidden default for allocatable components. */
7691 if (!(sym
->value
|| no_init_flag
) && sym
->ns
->proc_name
7692 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
7693 && !sym
->ns
->save_all
&& !sym
->attr
.save
7694 && !sym
->attr
.pointer
&& !sym
->attr
.allocatable
7695 && has_default_initializer (sym
->ts
.derived
))
7697 gfc_error("Object '%s' at %L must have the SAVE attribute for "
7698 "default initialization of a component",
7699 sym
->name
, &sym
->declared_at
);
7703 /* Assign default initializer. */
7704 if (!(sym
->value
|| sym
->attr
.pointer
|| sym
->attr
.allocatable
)
7705 && (!no_init_flag
|| sym
->attr
.intent
== INTENT_OUT
))
7707 sym
->value
= gfc_default_initializer (&sym
->ts
);
7714 /* Resolve symbols with flavor variable. */
7717 resolve_fl_variable (gfc_symbol
*sym
, int mp_flag
)
7719 int no_init_flag
, automatic_flag
;
7721 const char *auto_save_msg
;
7723 auto_save_msg
= "Automatic object '%s' at %L cannot have the "
7726 if (resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
7729 /* Set this flag to check that variables are parameters of all entries.
7730 This check is effected by the call to gfc_resolve_expr through
7731 is_non_constant_shape_array. */
7732 specification_expr
= 1;
7734 if (sym
->ns
->proc_name
7735 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
7736 || sym
->ns
->proc_name
->attr
.is_main_program
)
7737 && !sym
->attr
.use_assoc
7738 && !sym
->attr
.allocatable
7739 && !sym
->attr
.pointer
7740 && is_non_constant_shape_array (sym
))
7742 /* The shape of a main program or module array needs to be
7744 gfc_error ("The module or main program array '%s' at %L must "
7745 "have constant shape", sym
->name
, &sym
->declared_at
);
7746 specification_expr
= 0;
7750 if (sym
->ts
.type
== BT_CHARACTER
)
7752 /* Make sure that character string variables with assumed length are
7754 e
= sym
->ts
.cl
->length
;
7755 if (e
== NULL
&& !sym
->attr
.dummy
&& !sym
->attr
.result
)
7757 gfc_error ("Entity with assumed character length at %L must be a "
7758 "dummy argument or a PARAMETER", &sym
->declared_at
);
7762 if (e
&& sym
->attr
.save
&& !gfc_is_constant_expr (e
))
7764 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
7768 if (!gfc_is_constant_expr (e
)
7769 && !(e
->expr_type
== EXPR_VARIABLE
7770 && e
->symtree
->n
.sym
->attr
.flavor
== FL_PARAMETER
)
7771 && sym
->ns
->proc_name
7772 && (sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
7773 || sym
->ns
->proc_name
->attr
.is_main_program
)
7774 && !sym
->attr
.use_assoc
)
7776 gfc_error ("'%s' at %L must have constant character length "
7777 "in this context", sym
->name
, &sym
->declared_at
);
7782 if (sym
->value
== NULL
&& sym
->attr
.referenced
)
7783 apply_default_init_local (sym
); /* Try to apply a default initialization. */
7785 /* Determine if the symbol may not have an initializer. */
7786 no_init_flag
= automatic_flag
= 0;
7787 if (sym
->attr
.allocatable
|| sym
->attr
.external
|| sym
->attr
.dummy
7788 || sym
->attr
.intrinsic
|| sym
->attr
.result
)
7790 else if (sym
->attr
.dimension
&& !sym
->attr
.pointer
7791 && is_non_constant_shape_array (sym
))
7793 no_init_flag
= automatic_flag
= 1;
7795 /* Also, they must not have the SAVE attribute.
7796 SAVE_IMPLICIT is checked below. */
7797 if (sym
->attr
.save
== SAVE_EXPLICIT
)
7799 gfc_error (auto_save_msg
, sym
->name
, &sym
->declared_at
);
7804 /* Ensure that any initializer is simplified. */
7806 gfc_simplify_expr (sym
->value
, 1);
7808 /* Reject illegal initializers. */
7809 if (!sym
->mark
&& sym
->value
)
7811 if (sym
->attr
.allocatable
)
7812 gfc_error ("Allocatable '%s' at %L cannot have an initializer",
7813 sym
->name
, &sym
->declared_at
);
7814 else if (sym
->attr
.external
)
7815 gfc_error ("External '%s' at %L cannot have an initializer",
7816 sym
->name
, &sym
->declared_at
);
7817 else if (sym
->attr
.dummy
7818 && !(sym
->ts
.type
== BT_DERIVED
&& sym
->attr
.intent
== INTENT_OUT
))
7819 gfc_error ("Dummy '%s' at %L cannot have an initializer",
7820 sym
->name
, &sym
->declared_at
);
7821 else if (sym
->attr
.intrinsic
)
7822 gfc_error ("Intrinsic '%s' at %L cannot have an initializer",
7823 sym
->name
, &sym
->declared_at
);
7824 else if (sym
->attr
.result
)
7825 gfc_error ("Function result '%s' at %L cannot have an initializer",
7826 sym
->name
, &sym
->declared_at
);
7827 else if (automatic_flag
)
7828 gfc_error ("Automatic array '%s' at %L cannot have an initializer",
7829 sym
->name
, &sym
->declared_at
);
7836 if (sym
->ts
.type
== BT_DERIVED
)
7837 return resolve_fl_variable_derived (sym
, no_init_flag
);
7843 /* Resolve a procedure. */
7846 resolve_fl_procedure (gfc_symbol
*sym
, int mp_flag
)
7848 gfc_formal_arglist
*arg
;
7850 if (sym
->attr
.ambiguous_interfaces
&& !sym
->attr
.referenced
)
7851 gfc_warning ("Although not referenced, '%s' at %L has ambiguous "
7852 "interfaces", sym
->name
, &sym
->declared_at
);
7854 if (sym
->attr
.function
7855 && resolve_fl_var_and_proc (sym
, mp_flag
) == FAILURE
)
7858 if (sym
->ts
.type
== BT_CHARACTER
)
7860 gfc_charlen
*cl
= sym
->ts
.cl
;
7862 if (cl
&& cl
->length
&& gfc_is_constant_expr (cl
->length
)
7863 && resolve_charlen (cl
) == FAILURE
)
7866 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
7868 if (sym
->attr
.proc
== PROC_ST_FUNCTION
)
7870 gfc_error ("Character-valued statement function '%s' at %L must "
7871 "have constant length", sym
->name
, &sym
->declared_at
);
7875 if (sym
->attr
.external
&& sym
->formal
== NULL
7876 && cl
&& cl
->length
&& cl
->length
->expr_type
!= EXPR_CONSTANT
)
7878 gfc_error ("Automatic character length function '%s' at %L must "
7879 "have an explicit interface", sym
->name
,
7886 /* Ensure that derived type for are not of a private type. Internal
7887 module procedures are excluded by 2.2.3.3 - i.e., they are not
7888 externally accessible and can access all the objects accessible in
7890 if (!(sym
->ns
->parent
7891 && sym
->ns
->parent
->proc_name
->attr
.flavor
== FL_MODULE
)
7892 && gfc_check_access(sym
->attr
.access
, sym
->ns
->default_access
))
7894 gfc_interface
*iface
;
7896 for (arg
= sym
->formal
; arg
; arg
= arg
->next
)
7899 && arg
->sym
->ts
.type
== BT_DERIVED
7900 && !arg
->sym
->ts
.derived
->attr
.use_assoc
7901 && !gfc_check_access (arg
->sym
->ts
.derived
->attr
.access
,
7902 arg
->sym
->ts
.derived
->ns
->default_access
)
7903 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: '%s' is of a "
7904 "PRIVATE type and cannot be a dummy argument"
7905 " of '%s', which is PUBLIC at %L",
7906 arg
->sym
->name
, sym
->name
, &sym
->declared_at
)
7909 /* Stop this message from recurring. */
7910 arg
->sym
->ts
.derived
->attr
.access
= ACCESS_PUBLIC
;
7915 /* PUBLIC interfaces may expose PRIVATE procedures that take types
7916 PRIVATE to the containing module. */
7917 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
7919 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
7922 && arg
->sym
->ts
.type
== BT_DERIVED
7923 && !arg
->sym
->ts
.derived
->attr
.use_assoc
7924 && !gfc_check_access (arg
->sym
->ts
.derived
->attr
.access
,
7925 arg
->sym
->ts
.derived
->ns
->default_access
)
7926 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
7927 "'%s' in PUBLIC interface '%s' at %L "
7928 "takes dummy arguments of '%s' which is "
7929 "PRIVATE", iface
->sym
->name
, sym
->name
,
7930 &iface
->sym
->declared_at
,
7931 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
7933 /* Stop this message from recurring. */
7934 arg
->sym
->ts
.derived
->attr
.access
= ACCESS_PUBLIC
;
7940 /* PUBLIC interfaces may expose PRIVATE procedures that take types
7941 PRIVATE to the containing module. */
7942 for (iface
= sym
->generic
; iface
; iface
= iface
->next
)
7944 for (arg
= iface
->sym
->formal
; arg
; arg
= arg
->next
)
7947 && arg
->sym
->ts
.type
== BT_DERIVED
7948 && !arg
->sym
->ts
.derived
->attr
.use_assoc
7949 && !gfc_check_access (arg
->sym
->ts
.derived
->attr
.access
,
7950 arg
->sym
->ts
.derived
->ns
->default_access
)
7951 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: Procedure "
7952 "'%s' in PUBLIC interface '%s' at %L "
7953 "takes dummy arguments of '%s' which is "
7954 "PRIVATE", iface
->sym
->name
, sym
->name
,
7955 &iface
->sym
->declared_at
,
7956 gfc_typename (&arg
->sym
->ts
)) == FAILURE
)
7958 /* Stop this message from recurring. */
7959 arg
->sym
->ts
.derived
->attr
.access
= ACCESS_PUBLIC
;
7966 if (sym
->attr
.function
&& sym
->value
&& sym
->attr
.proc
!= PROC_ST_FUNCTION
7967 && !sym
->attr
.proc_pointer
)
7969 gfc_error ("Function '%s' at %L cannot have an initializer",
7970 sym
->name
, &sym
->declared_at
);
7974 /* An external symbol may not have an initializer because it is taken to be
7975 a procedure. Exception: Procedure Pointers. */
7976 if (sym
->attr
.external
&& sym
->value
&& !sym
->attr
.proc_pointer
)
7978 gfc_error ("External object '%s' at %L may not have an initializer",
7979 sym
->name
, &sym
->declared_at
);
7983 /* An elemental function is required to return a scalar 12.7.1 */
7984 if (sym
->attr
.elemental
&& sym
->attr
.function
&& sym
->as
)
7986 gfc_error ("ELEMENTAL function '%s' at %L must have a scalar "
7987 "result", sym
->name
, &sym
->declared_at
);
7988 /* Reset so that the error only occurs once. */
7989 sym
->attr
.elemental
= 0;
7993 /* 5.1.1.5 of the Standard: A function name declared with an asterisk
7994 char-len-param shall not be array-valued, pointer-valued, recursive
7995 or pure. ....snip... A character value of * may only be used in the
7996 following ways: (i) Dummy arg of procedure - dummy associates with
7997 actual length; (ii) To declare a named constant; or (iii) External
7998 function - but length must be declared in calling scoping unit. */
7999 if (sym
->attr
.function
8000 && sym
->ts
.type
== BT_CHARACTER
8001 && sym
->ts
.cl
&& sym
->ts
.cl
->length
== NULL
)
8003 if ((sym
->as
&& sym
->as
->rank
) || (sym
->attr
.pointer
)
8004 || (sym
->attr
.recursive
) || (sym
->attr
.pure
))
8006 if (sym
->as
&& sym
->as
->rank
)
8007 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
8008 "array-valued", sym
->name
, &sym
->declared_at
);
8010 if (sym
->attr
.pointer
)
8011 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
8012 "pointer-valued", sym
->name
, &sym
->declared_at
);
8015 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
8016 "pure", sym
->name
, &sym
->declared_at
);
8018 if (sym
->attr
.recursive
)
8019 gfc_error ("CHARACTER(*) function '%s' at %L cannot be "
8020 "recursive", sym
->name
, &sym
->declared_at
);
8025 /* Appendix B.2 of the standard. Contained functions give an
8026 error anyway. Fixed-form is likely to be F77/legacy. */
8027 if (!sym
->attr
.contained
&& gfc_current_form
!= FORM_FIXED
)
8028 gfc_notify_std (GFC_STD_F95_OBS
, "CHARACTER(*) function "
8029 "'%s' at %L is obsolescent in fortran 95",
8030 sym
->name
, &sym
->declared_at
);
8033 if (sym
->attr
.is_bind_c
&& sym
->attr
.is_c_interop
!= 1)
8035 gfc_formal_arglist
*curr_arg
;
8036 int has_non_interop_arg
= 0;
8038 if (verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
8039 sym
->common_block
) == FAILURE
)
8041 /* Clear these to prevent looking at them again if there was an
8043 sym
->attr
.is_bind_c
= 0;
8044 sym
->attr
.is_c_interop
= 0;
8045 sym
->ts
.is_c_interop
= 0;
8049 /* So far, no errors have been found. */
8050 sym
->attr
.is_c_interop
= 1;
8051 sym
->ts
.is_c_interop
= 1;
8054 curr_arg
= sym
->formal
;
8055 while (curr_arg
!= NULL
)
8057 /* Skip implicitly typed dummy args here. */
8058 if (curr_arg
->sym
->attr
.implicit_type
== 0)
8059 if (verify_c_interop_param (curr_arg
->sym
) == FAILURE
)
8060 /* If something is found to fail, record the fact so we
8061 can mark the symbol for the procedure as not being
8062 BIND(C) to try and prevent multiple errors being
8064 has_non_interop_arg
= 1;
8066 curr_arg
= curr_arg
->next
;
8069 /* See if any of the arguments were not interoperable and if so, clear
8070 the procedure symbol to prevent duplicate error messages. */
8071 if (has_non_interop_arg
!= 0)
8073 sym
->attr
.is_c_interop
= 0;
8074 sym
->ts
.is_c_interop
= 0;
8075 sym
->attr
.is_bind_c
= 0;
8079 if (!sym
->attr
.proc_pointer
)
8081 if (sym
->attr
.save
== SAVE_EXPLICIT
)
8083 gfc_error ("PROCEDURE attribute conflicts with SAVE attribute "
8084 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
8087 if (sym
->attr
.intent
)
8089 gfc_error ("PROCEDURE attribute conflicts with INTENT attribute "
8090 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
8093 if (sym
->attr
.subroutine
&& sym
->attr
.result
)
8095 gfc_error ("PROCEDURE attribute conflicts with RESULT attribute "
8096 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
8099 if (sym
->attr
.external
&& sym
->attr
.function
8100 && ((sym
->attr
.if_source
== IFSRC_DECL
&& !sym
->attr
.procedure
)
8101 || sym
->attr
.contained
))
8103 gfc_error ("EXTERNAL attribute conflicts with FUNCTION attribute "
8104 "in '%s' at %L", sym
->name
, &sym
->declared_at
);
8107 if (strcmp ("ppr@", sym
->name
) == 0)
8109 gfc_error ("Procedure pointer result '%s' at %L "
8110 "is missing the pointer attribute",
8111 sym
->ns
->proc_name
->name
, &sym
->declared_at
);
8120 /* Resolve a list of finalizer procedures. That is, after they have hopefully
8121 been defined and we now know their defined arguments, check that they fulfill
8122 the requirements of the standard for procedures used as finalizers. */
8125 gfc_resolve_finalizers (gfc_symbol
* derived
)
8127 gfc_finalizer
* list
;
8128 gfc_finalizer
** prev_link
; /* For removing wrong entries from the list. */
8129 gfc_try result
= SUCCESS
;
8130 bool seen_scalar
= false;
8132 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->finalizers
)
8135 /* Walk over the list of finalizer-procedures, check them, and if any one
8136 does not fit in with the standard's definition, print an error and remove
8137 it from the list. */
8138 prev_link
= &derived
->f2k_derived
->finalizers
;
8139 for (list
= derived
->f2k_derived
->finalizers
; list
; list
= *prev_link
)
8145 /* Skip this finalizer if we already resolved it. */
8146 if (list
->proc_tree
)
8148 prev_link
= &(list
->next
);
8152 /* Check this exists and is a SUBROUTINE. */
8153 if (!list
->proc_sym
->attr
.subroutine
)
8155 gfc_error ("FINAL procedure '%s' at %L is not a SUBROUTINE",
8156 list
->proc_sym
->name
, &list
->where
);
8160 /* We should have exactly one argument. */
8161 if (!list
->proc_sym
->formal
|| list
->proc_sym
->formal
->next
)
8163 gfc_error ("FINAL procedure at %L must have exactly one argument",
8167 arg
= list
->proc_sym
->formal
->sym
;
8169 /* This argument must be of our type. */
8170 if (arg
->ts
.type
!= BT_DERIVED
|| arg
->ts
.derived
!= derived
)
8172 gfc_error ("Argument of FINAL procedure at %L must be of type '%s'",
8173 &arg
->declared_at
, derived
->name
);
8177 /* It must neither be a pointer nor allocatable nor optional. */
8178 if (arg
->attr
.pointer
)
8180 gfc_error ("Argument of FINAL procedure at %L must not be a POINTER",
8184 if (arg
->attr
.allocatable
)
8186 gfc_error ("Argument of FINAL procedure at %L must not be"
8187 " ALLOCATABLE", &arg
->declared_at
);
8190 if (arg
->attr
.optional
)
8192 gfc_error ("Argument of FINAL procedure at %L must not be OPTIONAL",
8197 /* It must not be INTENT(OUT). */
8198 if (arg
->attr
.intent
== INTENT_OUT
)
8200 gfc_error ("Argument of FINAL procedure at %L must not be"
8201 " INTENT(OUT)", &arg
->declared_at
);
8205 /* Warn if the procedure is non-scalar and not assumed shape. */
8206 if (gfc_option
.warn_surprising
&& arg
->as
&& arg
->as
->rank
> 0
8207 && arg
->as
->type
!= AS_ASSUMED_SHAPE
)
8208 gfc_warning ("Non-scalar FINAL procedure at %L should have assumed"
8209 " shape argument", &arg
->declared_at
);
8211 /* Check that it does not match in kind and rank with a FINAL procedure
8212 defined earlier. To really loop over the *earlier* declarations,
8213 we need to walk the tail of the list as new ones were pushed at the
8215 /* TODO: Handle kind parameters once they are implemented. */
8216 my_rank
= (arg
->as
? arg
->as
->rank
: 0);
8217 for (i
= list
->next
; i
; i
= i
->next
)
8219 /* Argument list might be empty; that is an error signalled earlier,
8220 but we nevertheless continued resolving. */
8221 if (i
->proc_sym
->formal
)
8223 gfc_symbol
* i_arg
= i
->proc_sym
->formal
->sym
;
8224 const int i_rank
= (i_arg
->as
? i_arg
->as
->rank
: 0);
8225 if (i_rank
== my_rank
)
8227 gfc_error ("FINAL procedure '%s' declared at %L has the same"
8228 " rank (%d) as '%s'",
8229 list
->proc_sym
->name
, &list
->where
, my_rank
,
8236 /* Is this the/a scalar finalizer procedure? */
8237 if (!arg
->as
|| arg
->as
->rank
== 0)
8240 /* Find the symtree for this procedure. */
8241 gcc_assert (!list
->proc_tree
);
8242 list
->proc_tree
= gfc_find_sym_in_symtree (list
->proc_sym
);
8244 prev_link
= &list
->next
;
8247 /* Remove wrong nodes immediately from the list so we don't risk any
8248 troubles in the future when they might fail later expectations. */
8252 *prev_link
= list
->next
;
8253 gfc_free_finalizer (i
);
8256 /* Warn if we haven't seen a scalar finalizer procedure (but we know there
8257 were nodes in the list, must have been for arrays. It is surely a good
8258 idea to have a scalar version there if there's something to finalize. */
8259 if (gfc_option
.warn_surprising
&& result
== SUCCESS
&& !seen_scalar
)
8260 gfc_warning ("Only array FINAL procedures declared for derived type '%s'"
8261 " defined at %L, suggest also scalar one",
8262 derived
->name
, &derived
->declared_at
);
8264 /* TODO: Remove this error when finalization is finished. */
8265 gfc_error ("Finalization at %L is not yet implemented",
8266 &derived
->declared_at
);
8272 /* Check that it is ok for the typebound procedure proc to override the
8276 check_typebound_override (gfc_symtree
* proc
, gfc_symtree
* old
)
8279 const gfc_symbol
* proc_target
;
8280 const gfc_symbol
* old_target
;
8281 unsigned proc_pass_arg
, old_pass_arg
, argpos
;
8282 gfc_formal_arglist
* proc_formal
;
8283 gfc_formal_arglist
* old_formal
;
8285 /* This procedure should only be called for non-GENERIC proc. */
8286 gcc_assert (!proc
->n
.tb
->is_generic
);
8288 /* If the overwritten procedure is GENERIC, this is an error. */
8289 if (old
->n
.tb
->is_generic
)
8291 gfc_error ("Can't overwrite GENERIC '%s' at %L",
8292 old
->name
, &proc
->n
.tb
->where
);
8296 where
= proc
->n
.tb
->where
;
8297 proc_target
= proc
->n
.tb
->u
.specific
->n
.sym
;
8298 old_target
= old
->n
.tb
->u
.specific
->n
.sym
;
8300 /* Check that overridden binding is not NON_OVERRIDABLE. */
8301 if (old
->n
.tb
->non_overridable
)
8303 gfc_error ("'%s' at %L overrides a procedure binding declared"
8304 " NON_OVERRIDABLE", proc
->name
, &where
);
8308 /* It's an error to override a non-DEFERRED procedure with a DEFERRED one. */
8309 if (!old
->n
.tb
->deferred
&& proc
->n
.tb
->deferred
)
8311 gfc_error ("'%s' at %L must not be DEFERRED as it overrides a"
8312 " non-DEFERRED binding", proc
->name
, &where
);
8316 /* If the overridden binding is PURE, the overriding must be, too. */
8317 if (old_target
->attr
.pure
&& !proc_target
->attr
.pure
)
8319 gfc_error ("'%s' at %L overrides a PURE procedure and must also be PURE",
8320 proc
->name
, &where
);
8324 /* If the overridden binding is ELEMENTAL, the overriding must be, too. If it
8325 is not, the overriding must not be either. */
8326 if (old_target
->attr
.elemental
&& !proc_target
->attr
.elemental
)
8328 gfc_error ("'%s' at %L overrides an ELEMENTAL procedure and must also be"
8329 " ELEMENTAL", proc
->name
, &where
);
8332 if (!old_target
->attr
.elemental
&& proc_target
->attr
.elemental
)
8334 gfc_error ("'%s' at %L overrides a non-ELEMENTAL procedure and must not"
8335 " be ELEMENTAL, either", proc
->name
, &where
);
8339 /* If the overridden binding is a SUBROUTINE, the overriding must also be a
8341 if (old_target
->attr
.subroutine
&& !proc_target
->attr
.subroutine
)
8343 gfc_error ("'%s' at %L overrides a SUBROUTINE and must also be a"
8344 " SUBROUTINE", proc
->name
, &where
);
8348 /* If the overridden binding is a FUNCTION, the overriding must also be a
8349 FUNCTION and have the same characteristics. */
8350 if (old_target
->attr
.function
)
8352 if (!proc_target
->attr
.function
)
8354 gfc_error ("'%s' at %L overrides a FUNCTION and must also be a"
8355 " FUNCTION", proc
->name
, &where
);
8359 /* FIXME: Do more comprehensive checking (including, for instance, the
8360 rank and array-shape). */
8361 gcc_assert (proc_target
->result
&& old_target
->result
);
8362 if (!gfc_compare_types (&proc_target
->result
->ts
,
8363 &old_target
->result
->ts
))
8365 gfc_error ("'%s' at %L and the overridden FUNCTION should have"
8366 " matching result types", proc
->name
, &where
);
8371 /* If the overridden binding is PUBLIC, the overriding one must not be
8373 if (old
->n
.tb
->access
== ACCESS_PUBLIC
8374 && proc
->n
.tb
->access
== ACCESS_PRIVATE
)
8376 gfc_error ("'%s' at %L overrides a PUBLIC procedure and must not be"
8377 " PRIVATE", proc
->name
, &where
);
8381 /* Compare the formal argument lists of both procedures. This is also abused
8382 to find the position of the passed-object dummy arguments of both
8383 bindings as at least the overridden one might not yet be resolved and we
8384 need those positions in the check below. */
8385 proc_pass_arg
= old_pass_arg
= 0;
8386 if (!proc
->n
.tb
->nopass
&& !proc
->n
.tb
->pass_arg
)
8388 if (!old
->n
.tb
->nopass
&& !old
->n
.tb
->pass_arg
)
8391 for (proc_formal
= proc_target
->formal
, old_formal
= old_target
->formal
;
8392 proc_formal
&& old_formal
;
8393 proc_formal
= proc_formal
->next
, old_formal
= old_formal
->next
)
8395 if (proc
->n
.tb
->pass_arg
8396 && !strcmp (proc
->n
.tb
->pass_arg
, proc_formal
->sym
->name
))
8397 proc_pass_arg
= argpos
;
8398 if (old
->n
.tb
->pass_arg
8399 && !strcmp (old
->n
.tb
->pass_arg
, old_formal
->sym
->name
))
8400 old_pass_arg
= argpos
;
8402 /* Check that the names correspond. */
8403 if (strcmp (proc_formal
->sym
->name
, old_formal
->sym
->name
))
8405 gfc_error ("Dummy argument '%s' of '%s' at %L should be named '%s' as"
8406 " to match the corresponding argument of the overridden"
8407 " procedure", proc_formal
->sym
->name
, proc
->name
, &where
,
8408 old_formal
->sym
->name
);
8412 /* Check that the types correspond if neither is the passed-object
8414 /* FIXME: Do more comprehensive testing here. */
8415 if (proc_pass_arg
!= argpos
&& old_pass_arg
!= argpos
8416 && !gfc_compare_types (&proc_formal
->sym
->ts
, &old_formal
->sym
->ts
))
8418 gfc_error ("Types mismatch for dummy argument '%s' of '%s' %L in"
8419 " in respect to the overridden procedure",
8420 proc_formal
->sym
->name
, proc
->name
, &where
);
8426 if (proc_formal
|| old_formal
)
8428 gfc_error ("'%s' at %L must have the same number of formal arguments as"
8429 " the overridden procedure", proc
->name
, &where
);
8433 /* If the overridden binding is NOPASS, the overriding one must also be
8435 if (old
->n
.tb
->nopass
&& !proc
->n
.tb
->nopass
)
8437 gfc_error ("'%s' at %L overrides a NOPASS binding and must also be"
8438 " NOPASS", proc
->name
, &where
);
8442 /* If the overridden binding is PASS(x), the overriding one must also be
8443 PASS and the passed-object dummy arguments must correspond. */
8444 if (!old
->n
.tb
->nopass
)
8446 if (proc
->n
.tb
->nopass
)
8448 gfc_error ("'%s' at %L overrides a binding with PASS and must also be"
8449 " PASS", proc
->name
, &where
);
8453 if (proc_pass_arg
!= old_pass_arg
)
8455 gfc_error ("Passed-object dummy argument of '%s' at %L must be at"
8456 " the same position as the passed-object dummy argument of"
8457 " the overridden procedure", proc
->name
, &where
);
8466 /* Check if two GENERIC targets are ambiguous and emit an error is they are. */
8469 check_generic_tbp_ambiguity (gfc_tbp_generic
* t1
, gfc_tbp_generic
* t2
,
8470 const char* generic_name
, locus where
)
8475 gcc_assert (t1
->specific
&& t2
->specific
);
8476 gcc_assert (!t1
->specific
->is_generic
);
8477 gcc_assert (!t2
->specific
->is_generic
);
8479 sym1
= t1
->specific
->u
.specific
->n
.sym
;
8480 sym2
= t2
->specific
->u
.specific
->n
.sym
;
8482 /* Both must be SUBROUTINEs or both must be FUNCTIONs. */
8483 if (sym1
->attr
.subroutine
!= sym2
->attr
.subroutine
8484 || sym1
->attr
.function
!= sym2
->attr
.function
)
8486 gfc_error ("'%s' and '%s' can't be mixed FUNCTION/SUBROUTINE for"
8487 " GENERIC '%s' at %L",
8488 sym1
->name
, sym2
->name
, generic_name
, &where
);
8492 /* Compare the interfaces. */
8493 if (gfc_compare_interfaces (sym1
, sym2
, 1))
8495 gfc_error ("'%s' and '%s' for GENERIC '%s' at %L are ambiguous",
8496 sym1
->name
, sym2
->name
, generic_name
, &where
);
8504 /* Resolve a GENERIC procedure binding for a derived type. */
8507 resolve_typebound_generic (gfc_symbol
* derived
, gfc_symtree
* st
)
8509 gfc_tbp_generic
* target
;
8510 gfc_symtree
* first_target
;
8511 gfc_symbol
* super_type
;
8512 gfc_symtree
* inherited
;
8515 gcc_assert (st
->n
.tb
);
8516 gcc_assert (st
->n
.tb
->is_generic
);
8518 where
= st
->n
.tb
->where
;
8519 super_type
= gfc_get_derived_super_type (derived
);
8521 /* Find the overridden binding if any. */
8522 st
->n
.tb
->overridden
= NULL
;
8525 gfc_symtree
* overridden
;
8526 overridden
= gfc_find_typebound_proc (super_type
, NULL
, st
->name
, true);
8528 if (overridden
&& overridden
->n
.tb
)
8529 st
->n
.tb
->overridden
= overridden
->n
.tb
;
8532 /* Try to find the specific bindings for the symtrees in our target-list. */
8533 gcc_assert (st
->n
.tb
->u
.generic
);
8534 for (target
= st
->n
.tb
->u
.generic
; target
; target
= target
->next
)
8535 if (!target
->specific
)
8537 gfc_typebound_proc
* overridden_tbp
;
8539 const char* target_name
;
8541 target_name
= target
->specific_st
->name
;
8543 /* Defined for this type directly. */
8544 if (target
->specific_st
->n
.tb
)
8546 target
->specific
= target
->specific_st
->n
.tb
;
8547 goto specific_found
;
8550 /* Look for an inherited specific binding. */
8553 inherited
= gfc_find_typebound_proc (super_type
, NULL
,
8558 gcc_assert (inherited
->n
.tb
);
8559 target
->specific
= inherited
->n
.tb
;
8560 goto specific_found
;
8564 gfc_error ("Undefined specific binding '%s' as target of GENERIC '%s'"
8565 " at %L", target_name
, st
->name
, &where
);
8568 /* Once we've found the specific binding, check it is not ambiguous with
8569 other specifics already found or inherited for the same GENERIC. */
8571 gcc_assert (target
->specific
);
8573 /* This must really be a specific binding! */
8574 if (target
->specific
->is_generic
)
8576 gfc_error ("GENERIC '%s' at %L must target a specific binding,"
8577 " '%s' is GENERIC, too", st
->name
, &where
, target_name
);
8581 /* Check those already resolved on this type directly. */
8582 for (g
= st
->n
.tb
->u
.generic
; g
; g
= g
->next
)
8583 if (g
!= target
&& g
->specific
8584 && check_generic_tbp_ambiguity (target
, g
, st
->name
, where
)
8588 /* Check for ambiguity with inherited specific targets. */
8589 for (overridden_tbp
= st
->n
.tb
->overridden
; overridden_tbp
;
8590 overridden_tbp
= overridden_tbp
->overridden
)
8591 if (overridden_tbp
->is_generic
)
8593 for (g
= overridden_tbp
->u
.generic
; g
; g
= g
->next
)
8595 gcc_assert (g
->specific
);
8596 if (check_generic_tbp_ambiguity (target
, g
,
8597 st
->name
, where
) == FAILURE
)
8603 /* If we attempt to "overwrite" a specific binding, this is an error. */
8604 if (st
->n
.tb
->overridden
&& !st
->n
.tb
->overridden
->is_generic
)
8606 gfc_error ("GENERIC '%s' at %L can't overwrite specific binding with"
8607 " the same name", st
->name
, &where
);
8611 /* Take the SUBROUTINE/FUNCTION attributes of the first specific target, as
8612 all must have the same attributes here. */
8613 first_target
= st
->n
.tb
->u
.generic
->specific
->u
.specific
;
8614 gcc_assert (first_target
);
8615 st
->n
.tb
->subroutine
= first_target
->n
.sym
->attr
.subroutine
;
8616 st
->n
.tb
->function
= first_target
->n
.sym
->attr
.function
;
8622 /* Resolve the type-bound procedures for a derived type. */
8624 static gfc_symbol
* resolve_bindings_derived
;
8625 static gfc_try resolve_bindings_result
;
8628 resolve_typebound_procedure (gfc_symtree
* stree
)
8633 gfc_symbol
* super_type
;
8634 gfc_component
* comp
;
8638 /* Undefined specific symbol from GENERIC target definition. */
8642 if (stree
->n
.tb
->error
)
8645 /* If this is a GENERIC binding, use that routine. */
8646 if (stree
->n
.tb
->is_generic
)
8648 if (resolve_typebound_generic (resolve_bindings_derived
, stree
)
8654 /* Get the target-procedure to check it. */
8655 gcc_assert (!stree
->n
.tb
->is_generic
);
8656 gcc_assert (stree
->n
.tb
->u
.specific
);
8657 proc
= stree
->n
.tb
->u
.specific
->n
.sym
;
8658 where
= stree
->n
.tb
->where
;
8660 /* Default access should already be resolved from the parser. */
8661 gcc_assert (stree
->n
.tb
->access
!= ACCESS_UNKNOWN
);
8663 /* It should be a module procedure or an external procedure with explicit
8664 interface. For DEFERRED bindings, abstract interfaces are ok as well. */
8665 if ((!proc
->attr
.subroutine
&& !proc
->attr
.function
)
8666 || (proc
->attr
.proc
!= PROC_MODULE
8667 && proc
->attr
.if_source
!= IFSRC_IFBODY
)
8668 || (proc
->attr
.abstract
&& !stree
->n
.tb
->deferred
))
8670 gfc_error ("'%s' must be a module procedure or an external procedure with"
8671 " an explicit interface at %L", proc
->name
, &where
);
8674 stree
->n
.tb
->subroutine
= proc
->attr
.subroutine
;
8675 stree
->n
.tb
->function
= proc
->attr
.function
;
8677 /* Find the super-type of the current derived type. We could do this once and
8678 store in a global if speed is needed, but as long as not I believe this is
8679 more readable and clearer. */
8680 super_type
= gfc_get_derived_super_type (resolve_bindings_derived
);
8682 /* If PASS, resolve and check arguments if not already resolved / loaded
8683 from a .mod file. */
8684 if (!stree
->n
.tb
->nopass
&& stree
->n
.tb
->pass_arg_num
== 0)
8686 if (stree
->n
.tb
->pass_arg
)
8688 gfc_formal_arglist
* i
;
8690 /* If an explicit passing argument name is given, walk the arg-list
8694 stree
->n
.tb
->pass_arg_num
= 1;
8695 for (i
= proc
->formal
; i
; i
= i
->next
)
8697 if (!strcmp (i
->sym
->name
, stree
->n
.tb
->pass_arg
))
8702 ++stree
->n
.tb
->pass_arg_num
;
8707 gfc_error ("Procedure '%s' with PASS(%s) at %L has no"
8709 proc
->name
, stree
->n
.tb
->pass_arg
, &where
,
8710 stree
->n
.tb
->pass_arg
);
8716 /* Otherwise, take the first one; there should in fact be at least
8718 stree
->n
.tb
->pass_arg_num
= 1;
8721 gfc_error ("Procedure '%s' with PASS at %L must have at"
8722 " least one argument", proc
->name
, &where
);
8725 me_arg
= proc
->formal
->sym
;
8728 /* Now check that the argument-type matches. */
8729 gcc_assert (me_arg
);
8730 if (me_arg
->ts
.type
!= BT_DERIVED
8731 || me_arg
->ts
.derived
!= resolve_bindings_derived
)
8733 gfc_error ("Argument '%s' of '%s' with PASS(%s) at %L must be of"
8734 " the derived-type '%s'", me_arg
->name
, proc
->name
,
8735 me_arg
->name
, &where
, resolve_bindings_derived
->name
);
8739 gfc_warning ("Polymorphic entities are not yet implemented,"
8740 " non-polymorphic passed-object dummy argument of '%s'"
8741 " at %L accepted", proc
->name
, &where
);
8744 /* If we are extending some type, check that we don't override a procedure
8745 flagged NON_OVERRIDABLE. */
8746 stree
->n
.tb
->overridden
= NULL
;
8749 gfc_symtree
* overridden
;
8750 overridden
= gfc_find_typebound_proc (super_type
, NULL
,
8753 if (overridden
&& overridden
->n
.tb
)
8754 stree
->n
.tb
->overridden
= overridden
->n
.tb
;
8756 if (overridden
&& check_typebound_override (stree
, overridden
) == FAILURE
)
8760 /* See if there's a name collision with a component directly in this type. */
8761 for (comp
= resolve_bindings_derived
->components
; comp
; comp
= comp
->next
)
8762 if (!strcmp (comp
->name
, stree
->name
))
8764 gfc_error ("Procedure '%s' at %L has the same name as a component of"
8766 stree
->name
, &where
, resolve_bindings_derived
->name
);
8770 /* Try to find a name collision with an inherited component. */
8771 if (super_type
&& gfc_find_component (super_type
, stree
->name
, true, true))
8773 gfc_error ("Procedure '%s' at %L has the same name as an inherited"
8774 " component of '%s'",
8775 stree
->name
, &where
, resolve_bindings_derived
->name
);
8779 stree
->n
.tb
->error
= 0;
8783 resolve_bindings_result
= FAILURE
;
8784 stree
->n
.tb
->error
= 1;
8788 resolve_typebound_procedures (gfc_symbol
* derived
)
8790 if (!derived
->f2k_derived
|| !derived
->f2k_derived
->tb_sym_root
)
8793 resolve_bindings_derived
= derived
;
8794 resolve_bindings_result
= SUCCESS
;
8795 gfc_traverse_symtree (derived
->f2k_derived
->tb_sym_root
,
8796 &resolve_typebound_procedure
);
8798 return resolve_bindings_result
;
8802 /* Add a derived type to the dt_list. The dt_list is used in trans-types.c
8803 to give all identical derived types the same backend_decl. */
8805 add_dt_to_dt_list (gfc_symbol
*derived
)
8807 gfc_dt_list
*dt_list
;
8809 for (dt_list
= gfc_derived_types
; dt_list
; dt_list
= dt_list
->next
)
8810 if (derived
== dt_list
->derived
)
8813 if (dt_list
== NULL
)
8815 dt_list
= gfc_get_dt_list ();
8816 dt_list
->next
= gfc_derived_types
;
8817 dt_list
->derived
= derived
;
8818 gfc_derived_types
= dt_list
;
8823 /* Ensure that a derived-type is really not abstract, meaning that every
8824 inherited DEFERRED binding is overridden by a non-DEFERRED one. */
8827 ensure_not_abstract_walker (gfc_symbol
* sub
, gfc_symtree
* st
)
8832 if (ensure_not_abstract_walker (sub
, st
->left
) == FAILURE
)
8834 if (ensure_not_abstract_walker (sub
, st
->right
) == FAILURE
)
8837 if (st
->n
.tb
&& st
->n
.tb
->deferred
)
8839 gfc_symtree
* overriding
;
8840 overriding
= gfc_find_typebound_proc (sub
, NULL
, st
->name
, true);
8841 gcc_assert (overriding
&& overriding
->n
.tb
);
8842 if (overriding
->n
.tb
->deferred
)
8844 gfc_error ("Derived-type '%s' declared at %L must be ABSTRACT because"
8845 " '%s' is DEFERRED and not overridden",
8846 sub
->name
, &sub
->declared_at
, st
->name
);
8855 ensure_not_abstract (gfc_symbol
* sub
, gfc_symbol
* ancestor
)
8857 /* The algorithm used here is to recursively travel up the ancestry of sub
8858 and for each ancestor-type, check all bindings. If any of them is
8859 DEFERRED, look it up starting from sub and see if the found (overriding)
8860 binding is not DEFERRED.
8861 This is not the most efficient way to do this, but it should be ok and is
8862 clearer than something sophisticated. */
8864 gcc_assert (ancestor
&& ancestor
->attr
.abstract
&& !sub
->attr
.abstract
);
8866 /* Walk bindings of this ancestor. */
8867 if (ancestor
->f2k_derived
)
8870 t
= ensure_not_abstract_walker (sub
, ancestor
->f2k_derived
->tb_sym_root
);
8875 /* Find next ancestor type and recurse on it. */
8876 ancestor
= gfc_get_derived_super_type (ancestor
);
8878 return ensure_not_abstract (sub
, ancestor
);
8884 /* Resolve the components of a derived type. */
8887 resolve_fl_derived (gfc_symbol
*sym
)
8889 gfc_symbol
* super_type
;
8893 super_type
= gfc_get_derived_super_type (sym
);
8895 /* Ensure the extended type gets resolved before we do. */
8896 if (super_type
&& resolve_fl_derived (super_type
) == FAILURE
)
8899 /* An ABSTRACT type must be extensible. */
8900 if (sym
->attr
.abstract
&& (sym
->attr
.is_bind_c
|| sym
->attr
.sequence
))
8902 gfc_error ("Non-extensible derived-type '%s' at %L must not be ABSTRACT",
8903 sym
->name
, &sym
->declared_at
);
8907 for (c
= sym
->components
; c
!= NULL
; c
= c
->next
)
8909 /* Check type-spec if this is not the parent-type component. */
8910 if ((!sym
->attr
.extension
|| c
!= sym
->components
)
8911 && resolve_typespec_used (&c
->ts
, &c
->loc
, c
->name
) == FAILURE
)
8914 /* If this type is an extension, see if this component has the same name
8915 as an inherited type-bound procedure. */
8917 && gfc_find_typebound_proc (super_type
, NULL
, c
->name
, true))
8919 gfc_error ("Component '%s' of '%s' at %L has the same name as an"
8920 " inherited type-bound procedure",
8921 c
->name
, sym
->name
, &c
->loc
);
8925 if (c
->ts
.type
== BT_CHARACTER
)
8927 if (c
->ts
.cl
->length
== NULL
8928 || (resolve_charlen (c
->ts
.cl
) == FAILURE
)
8929 || !gfc_is_constant_expr (c
->ts
.cl
->length
))
8931 gfc_error ("Character length of component '%s' needs to "
8932 "be a constant specification expression at %L",
8934 c
->ts
.cl
->length
? &c
->ts
.cl
->length
->where
: &c
->loc
);
8939 if (c
->ts
.type
== BT_DERIVED
8940 && sym
->component_access
!= ACCESS_PRIVATE
8941 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
)
8942 && !is_sym_host_assoc (c
->ts
.derived
, sym
->ns
)
8943 && !c
->ts
.derived
->attr
.use_assoc
8944 && !gfc_check_access (c
->ts
.derived
->attr
.access
,
8945 c
->ts
.derived
->ns
->default_access
))
8947 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: the component '%s' "
8948 "is a PRIVATE type and cannot be a component of "
8949 "'%s', which is PUBLIC at %L", c
->name
,
8950 sym
->name
, &sym
->declared_at
);
8954 if (sym
->attr
.sequence
)
8956 if (c
->ts
.type
== BT_DERIVED
&& c
->ts
.derived
->attr
.sequence
== 0)
8958 gfc_error ("Component %s of SEQUENCE type declared at %L does "
8959 "not have the SEQUENCE attribute",
8960 c
->ts
.derived
->name
, &sym
->declared_at
);
8965 if (c
->ts
.type
== BT_DERIVED
&& c
->attr
.pointer
8966 && c
->ts
.derived
->components
== NULL
8967 && !c
->ts
.derived
->attr
.zero_comp
)
8969 gfc_error ("The pointer component '%s' of '%s' at %L is a type "
8970 "that has not been declared", c
->name
, sym
->name
,
8975 /* Ensure that all the derived type components are put on the
8976 derived type list; even in formal namespaces, where derived type
8977 pointer components might not have been declared. */
8978 if (c
->ts
.type
== BT_DERIVED
8980 && c
->ts
.derived
->components
8982 && sym
!= c
->ts
.derived
)
8983 add_dt_to_dt_list (c
->ts
.derived
);
8985 if (c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->as
== NULL
)
8988 for (i
= 0; i
< c
->as
->rank
; i
++)
8990 if (c
->as
->lower
[i
] == NULL
8991 || (resolve_index_expr (c
->as
->lower
[i
]) == FAILURE
)
8992 || !gfc_is_constant_expr (c
->as
->lower
[i
])
8993 || c
->as
->upper
[i
] == NULL
8994 || (resolve_index_expr (c
->as
->upper
[i
]) == FAILURE
)
8995 || !gfc_is_constant_expr (c
->as
->upper
[i
]))
8997 gfc_error ("Component '%s' of '%s' at %L must have "
8998 "constant array bounds",
8999 c
->name
, sym
->name
, &c
->loc
);
9005 /* Resolve the type-bound procedures. */
9006 if (resolve_typebound_procedures (sym
) == FAILURE
)
9009 /* Resolve the finalizer procedures. */
9010 if (gfc_resolve_finalizers (sym
) == FAILURE
)
9013 /* If this is a non-ABSTRACT type extending an ABSTRACT one, ensure that
9014 all DEFERRED bindings are overridden. */
9015 if (super_type
&& super_type
->attr
.abstract
&& !sym
->attr
.abstract
9016 && ensure_not_abstract (sym
, super_type
) == FAILURE
)
9019 /* Add derived type to the derived type list. */
9020 add_dt_to_dt_list (sym
);
9027 resolve_fl_namelist (gfc_symbol
*sym
)
9032 /* Reject PRIVATE objects in a PUBLIC namelist. */
9033 if (gfc_check_access(sym
->attr
.access
, sym
->ns
->default_access
))
9035 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
9037 if (!nl
->sym
->attr
.use_assoc
9038 && !is_sym_host_assoc (nl
->sym
, sym
->ns
)
9039 && !gfc_check_access(nl
->sym
->attr
.access
,
9040 nl
->sym
->ns
->default_access
))
9042 gfc_error ("NAMELIST object '%s' was declared PRIVATE and "
9043 "cannot be member of PUBLIC namelist '%s' at %L",
9044 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
9048 /* Types with private components that came here by USE-association. */
9049 if (nl
->sym
->ts
.type
== BT_DERIVED
9050 && derived_inaccessible (nl
->sym
->ts
.derived
))
9052 gfc_error ("NAMELIST object '%s' has use-associated PRIVATE "
9053 "components and cannot be member of namelist '%s' at %L",
9054 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
9058 /* Types with private components that are defined in the same module. */
9059 if (nl
->sym
->ts
.type
== BT_DERIVED
9060 && !is_sym_host_assoc (nl
->sym
->ts
.derived
, sym
->ns
)
9061 && !gfc_check_access (nl
->sym
->ts
.derived
->attr
.private_comp
9062 ? ACCESS_PRIVATE
: ACCESS_UNKNOWN
,
9063 nl
->sym
->ns
->default_access
))
9065 gfc_error ("NAMELIST object '%s' has PRIVATE components and "
9066 "cannot be a member of PUBLIC namelist '%s' at %L",
9067 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
9073 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
9075 /* Reject namelist arrays of assumed shape. */
9076 if (nl
->sym
->as
&& nl
->sym
->as
->type
== AS_ASSUMED_SHAPE
9077 && gfc_notify_std (GFC_STD_F2003
, "NAMELIST array object '%s' "
9078 "must not have assumed shape in namelist "
9079 "'%s' at %L", nl
->sym
->name
, sym
->name
,
9080 &sym
->declared_at
) == FAILURE
)
9083 /* Reject namelist arrays that are not constant shape. */
9084 if (is_non_constant_shape_array (nl
->sym
))
9086 gfc_error ("NAMELIST array object '%s' must have constant "
9087 "shape in namelist '%s' at %L", nl
->sym
->name
,
9088 sym
->name
, &sym
->declared_at
);
9092 /* Namelist objects cannot have allocatable or pointer components. */
9093 if (nl
->sym
->ts
.type
!= BT_DERIVED
)
9096 if (nl
->sym
->ts
.derived
->attr
.alloc_comp
)
9098 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L cannot "
9099 "have ALLOCATABLE components",
9100 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
9104 if (nl
->sym
->ts
.derived
->attr
.pointer_comp
)
9106 gfc_error ("NAMELIST object '%s' in namelist '%s' at %L cannot "
9107 "have POINTER components",
9108 nl
->sym
->name
, sym
->name
, &sym
->declared_at
);
9114 /* 14.1.2 A module or internal procedure represent local entities
9115 of the same type as a namelist member and so are not allowed. */
9116 for (nl
= sym
->namelist
; nl
; nl
= nl
->next
)
9118 if (nl
->sym
->ts
.kind
!= 0 && nl
->sym
->attr
.flavor
== FL_VARIABLE
)
9121 if (nl
->sym
->attr
.function
&& nl
->sym
== nl
->sym
->result
)
9122 if ((nl
->sym
== sym
->ns
->proc_name
)
9124 (sym
->ns
->parent
&& nl
->sym
== sym
->ns
->parent
->proc_name
))
9128 if (nl
->sym
&& nl
->sym
->name
)
9129 gfc_find_symbol (nl
->sym
->name
, sym
->ns
, 1, &nlsym
);
9130 if (nlsym
&& nlsym
->attr
.flavor
== FL_PROCEDURE
)
9132 gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
9133 "attribute in '%s' at %L", nlsym
->name
,
9144 resolve_fl_parameter (gfc_symbol
*sym
)
9146 /* A parameter array's shape needs to be constant. */
9148 && (sym
->as
->type
== AS_DEFERRED
9149 || is_non_constant_shape_array (sym
)))
9151 gfc_error ("Parameter array '%s' at %L cannot be automatic "
9152 "or of deferred shape", sym
->name
, &sym
->declared_at
);
9156 /* Make sure a parameter that has been implicitly typed still
9157 matches the implicit type, since PARAMETER statements can precede
9158 IMPLICIT statements. */
9159 if (sym
->attr
.implicit_type
9160 && !gfc_compare_types (&sym
->ts
, gfc_get_default_type (sym
, sym
->ns
)))
9162 gfc_error ("Implicitly typed PARAMETER '%s' at %L doesn't match a "
9163 "later IMPLICIT type", sym
->name
, &sym
->declared_at
);
9167 /* Make sure the types of derived parameters are consistent. This
9168 type checking is deferred until resolution because the type may
9169 refer to a derived type from the host. */
9170 if (sym
->ts
.type
== BT_DERIVED
9171 && !gfc_compare_types (&sym
->ts
, &sym
->value
->ts
))
9173 gfc_error ("Incompatible derived type in PARAMETER at %L",
9174 &sym
->value
->where
);
9181 /* Do anything necessary to resolve a symbol. Right now, we just
9182 assume that an otherwise unknown symbol is a variable. This sort
9183 of thing commonly happens for symbols in module. */
9186 resolve_symbol (gfc_symbol
*sym
)
9188 int check_constant
, mp_flag
;
9189 gfc_symtree
*symtree
;
9190 gfc_symtree
*this_symtree
;
9194 if (sym
->attr
.flavor
== FL_UNKNOWN
)
9197 /* If we find that a flavorless symbol is an interface in one of the
9198 parent namespaces, find its symtree in this namespace, free the
9199 symbol and set the symtree to point to the interface symbol. */
9200 for (ns
= gfc_current_ns
->parent
; ns
; ns
= ns
->parent
)
9202 symtree
= gfc_find_symtree (ns
->sym_root
, sym
->name
);
9203 if (symtree
&& symtree
->n
.sym
->generic
)
9205 this_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
,
9209 gfc_free_symbol (sym
);
9210 symtree
->n
.sym
->refs
++;
9211 this_symtree
->n
.sym
= symtree
->n
.sym
;
9216 /* Otherwise give it a flavor according to such attributes as
9218 if (sym
->attr
.external
== 0 && sym
->attr
.intrinsic
== 0)
9219 sym
->attr
.flavor
= FL_VARIABLE
;
9222 sym
->attr
.flavor
= FL_PROCEDURE
;
9223 if (sym
->attr
.dimension
)
9224 sym
->attr
.function
= 1;
9228 if (sym
->attr
.external
&& sym
->ts
.type
!= BT_UNKNOWN
&& !sym
->attr
.function
)
9229 gfc_add_function (&sym
->attr
, sym
->name
, &sym
->declared_at
);
9231 if (sym
->attr
.procedure
&& sym
->ts
.interface
9232 && sym
->attr
.if_source
!= IFSRC_DECL
)
9234 if (sym
->ts
.interface
->attr
.procedure
)
9235 gfc_error ("Interface '%s', used by procedure '%s' at %L, is declared "
9236 "in a later PROCEDURE statement", sym
->ts
.interface
->name
,
9237 sym
->name
,&sym
->declared_at
);
9239 /* Get the attributes from the interface (now resolved). */
9240 if (sym
->ts
.interface
->attr
.if_source
|| sym
->ts
.interface
->attr
.intrinsic
)
9242 gfc_symbol
*ifc
= sym
->ts
.interface
;
9244 if (ifc
->attr
.intrinsic
)
9245 resolve_intrinsic (ifc
, &ifc
->declared_at
);
9248 sym
->ts
.interface
= ifc
;
9249 sym
->attr
.function
= ifc
->attr
.function
;
9250 sym
->attr
.subroutine
= ifc
->attr
.subroutine
;
9251 gfc_copy_formal_args (sym
, ifc
);
9253 sym
->attr
.allocatable
= ifc
->attr
.allocatable
;
9254 sym
->attr
.pointer
= ifc
->attr
.pointer
;
9255 sym
->attr
.pure
= ifc
->attr
.pure
;
9256 sym
->attr
.elemental
= ifc
->attr
.elemental
;
9257 sym
->attr
.dimension
= ifc
->attr
.dimension
;
9258 sym
->attr
.recursive
= ifc
->attr
.recursive
;
9259 sym
->attr
.always_explicit
= ifc
->attr
.always_explicit
;
9260 /* Copy array spec. */
9261 sym
->as
= gfc_copy_array_spec (ifc
->as
);
9265 for (i
= 0; i
< sym
->as
->rank
; i
++)
9267 gfc_expr_replace_symbols (sym
->as
->lower
[i
], sym
);
9268 gfc_expr_replace_symbols (sym
->as
->upper
[i
], sym
);
9271 /* Copy char length. */
9274 sym
->ts
.cl
= gfc_get_charlen();
9275 sym
->ts
.cl
->resolved
= ifc
->ts
.cl
->resolved
;
9276 sym
->ts
.cl
->length
= gfc_copy_expr (ifc
->ts
.cl
->length
);
9277 gfc_expr_replace_symbols (sym
->ts
.cl
->length
, sym
);
9278 /* Add charlen to namespace. */
9281 sym
->ts
.cl
->next
= sym
->formal_ns
->cl_list
;
9282 sym
->formal_ns
->cl_list
= sym
->ts
.cl
;
9286 else if (sym
->ts
.interface
->name
[0] != '\0')
9288 gfc_error ("Interface '%s' of procedure '%s' at %L must be explicit",
9289 sym
->ts
.interface
->name
, sym
->name
, &sym
->declared_at
);
9294 if (sym
->attr
.flavor
== FL_DERIVED
&& resolve_fl_derived (sym
) == FAILURE
)
9297 /* Symbols that are module procedures with results (functions) have
9298 the types and array specification copied for type checking in
9299 procedures that call them, as well as for saving to a module
9300 file. These symbols can't stand the scrutiny that their results
9302 mp_flag
= (sym
->result
!= NULL
&& sym
->result
!= sym
);
9305 /* Make sure that the intrinsic is consistent with its internal
9306 representation. This needs to be done before assigning a default
9307 type to avoid spurious warnings. */
9308 if (sym
->attr
.flavor
!= FL_MODULE
&& sym
->attr
.intrinsic
)
9310 gfc_intrinsic_sym
* isym
;
9313 /* We already know this one is an intrinsic, so we don't call
9314 gfc_is_intrinsic for full checking but rather use gfc_find_function and
9315 gfc_find_subroutine directly to check whether it is a function or
9318 if ((isym
= gfc_find_function (sym
->name
)))
9320 if (sym
->ts
.type
!= BT_UNKNOWN
&& gfc_option
.warn_surprising
)
9321 gfc_warning ("Type specified for intrinsic function '%s' at %L is"
9322 " ignored", sym
->name
, &sym
->declared_at
);
9324 else if ((isym
= gfc_find_subroutine (sym
->name
)))
9326 if (sym
->ts
.type
!= BT_UNKNOWN
)
9328 gfc_error ("Intrinsic subroutine '%s' at %L shall not have a type"
9329 " specifier", sym
->name
, &sym
->declared_at
);
9335 gfc_error ("'%s' declared INTRINSIC at %L does not exist",
9336 sym
->name
, &sym
->declared_at
);
9340 /* Check it is actually available in the standard settings. */
9341 if (gfc_check_intrinsic_standard (isym
, &symstd
, false, sym
->declared_at
)
9344 gfc_error ("The intrinsic '%s' declared INTRINSIC at %L is not"
9345 " available in the current standard settings but %s. Use"
9346 " an appropriate -std=* option or enable -fall-intrinsics"
9347 " in order to use it.",
9348 sym
->name
, &sym
->declared_at
, symstd
);
9353 /* Assign default type to symbols that need one and don't have one. */
9354 if (sym
->ts
.type
== BT_UNKNOWN
)
9356 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
)
9357 gfc_set_default_type (sym
, 1, NULL
);
9359 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
)
9361 /* The specific case of an external procedure should emit an error
9362 in the case that there is no implicit type. */
9364 gfc_set_default_type (sym
, sym
->attr
.external
, NULL
);
9367 /* Result may be in another namespace. */
9368 resolve_symbol (sym
->result
);
9370 if (!sym
->result
->attr
.proc_pointer
)
9372 sym
->ts
= sym
->result
->ts
;
9373 sym
->as
= gfc_copy_array_spec (sym
->result
->as
);
9374 sym
->attr
.dimension
= sym
->result
->attr
.dimension
;
9375 sym
->attr
.pointer
= sym
->result
->attr
.pointer
;
9376 sym
->attr
.allocatable
= sym
->result
->attr
.allocatable
;
9382 /* Assumed size arrays and assumed shape arrays must be dummy
9386 && (sym
->as
->type
== AS_ASSUMED_SIZE
9387 || sym
->as
->type
== AS_ASSUMED_SHAPE
)
9388 && sym
->attr
.dummy
== 0)
9390 if (sym
->as
->type
== AS_ASSUMED_SIZE
)
9391 gfc_error ("Assumed size array at %L must be a dummy argument",
9394 gfc_error ("Assumed shape array at %L must be a dummy argument",
9399 /* Make sure symbols with known intent or optional are really dummy
9400 variable. Because of ENTRY statement, this has to be deferred
9401 until resolution time. */
9403 if (!sym
->attr
.dummy
9404 && (sym
->attr
.optional
|| sym
->attr
.intent
!= INTENT_UNKNOWN
))
9406 gfc_error ("Symbol at %L is not a DUMMY variable", &sym
->declared_at
);
9410 if (sym
->attr
.value
&& !sym
->attr
.dummy
)
9412 gfc_error ("'%s' at %L cannot have the VALUE attribute because "
9413 "it is not a dummy argument", sym
->name
, &sym
->declared_at
);
9417 if (sym
->attr
.value
&& sym
->ts
.type
== BT_CHARACTER
)
9419 gfc_charlen
*cl
= sym
->ts
.cl
;
9420 if (!cl
|| !cl
->length
|| cl
->length
->expr_type
!= EXPR_CONSTANT
)
9422 gfc_error ("Character dummy variable '%s' at %L with VALUE "
9423 "attribute must have constant length",
9424 sym
->name
, &sym
->declared_at
);
9428 if (sym
->ts
.is_c_interop
9429 && mpz_cmp_si (cl
->length
->value
.integer
, 1) != 0)
9431 gfc_error ("C interoperable character dummy variable '%s' at %L "
9432 "with VALUE attribute must have length one",
9433 sym
->name
, &sym
->declared_at
);
9438 /* If the symbol is marked as bind(c), verify it's type and kind. Do not
9439 do this for something that was implicitly typed because that is handled
9440 in gfc_set_default_type. Handle dummy arguments and procedure
9441 definitions separately. Also, anything that is use associated is not
9442 handled here but instead is handled in the module it is declared in.
9443 Finally, derived type definitions are allowed to be BIND(C) since that
9444 only implies that they're interoperable, and they are checked fully for
9445 interoperability when a variable is declared of that type. */
9446 if (sym
->attr
.is_bind_c
&& sym
->attr
.implicit_type
== 0 &&
9447 sym
->attr
.use_assoc
== 0 && sym
->attr
.dummy
== 0 &&
9448 sym
->attr
.flavor
!= FL_PROCEDURE
&& sym
->attr
.flavor
!= FL_DERIVED
)
9450 gfc_try t
= SUCCESS
;
9452 /* First, make sure the variable is declared at the
9453 module-level scope (J3/04-007, Section 15.3). */
9454 if (sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
&&
9455 sym
->attr
.in_common
== 0)
9457 gfc_error ("Variable '%s' at %L cannot be BIND(C) because it "
9458 "is neither a COMMON block nor declared at the "
9459 "module level scope", sym
->name
, &(sym
->declared_at
));
9462 else if (sym
->common_head
!= NULL
)
9464 t
= verify_com_block_vars_c_interop (sym
->common_head
);
9468 /* If type() declaration, we need to verify that the components
9469 of the given type are all C interoperable, etc. */
9470 if (sym
->ts
.type
== BT_DERIVED
&&
9471 sym
->ts
.derived
->attr
.is_c_interop
!= 1)
9473 /* Make sure the user marked the derived type as BIND(C). If
9474 not, call the verify routine. This could print an error
9475 for the derived type more than once if multiple variables
9476 of that type are declared. */
9477 if (sym
->ts
.derived
->attr
.is_bind_c
!= 1)
9478 verify_bind_c_derived_type (sym
->ts
.derived
);
9482 /* Verify the variable itself as C interoperable if it
9483 is BIND(C). It is not possible for this to succeed if
9484 the verify_bind_c_derived_type failed, so don't have to handle
9485 any error returned by verify_bind_c_derived_type. */
9486 t
= verify_bind_c_sym (sym
, &(sym
->ts
), sym
->attr
.in_common
,
9492 /* clear the is_bind_c flag to prevent reporting errors more than
9493 once if something failed. */
9494 sym
->attr
.is_bind_c
= 0;
9499 /* If a derived type symbol has reached this point, without its
9500 type being declared, we have an error. Notice that most
9501 conditions that produce undefined derived types have already
9502 been dealt with. However, the likes of:
9503 implicit type(t) (t) ..... call foo (t) will get us here if
9504 the type is not declared in the scope of the implicit
9505 statement. Change the type to BT_UNKNOWN, both because it is so
9506 and to prevent an ICE. */
9507 if (sym
->ts
.type
== BT_DERIVED
&& sym
->ts
.derived
->components
== NULL
9508 && !sym
->ts
.derived
->attr
.zero_comp
)
9510 gfc_error ("The derived type '%s' at %L is of type '%s', "
9511 "which has not been defined", sym
->name
,
9512 &sym
->declared_at
, sym
->ts
.derived
->name
);
9513 sym
->ts
.type
= BT_UNKNOWN
;
9517 /* Make sure that the derived type has been resolved and that the
9518 derived type is visible in the symbol's namespace, if it is a
9519 module function and is not PRIVATE. */
9520 if (sym
->ts
.type
== BT_DERIVED
9521 && sym
->ts
.derived
->attr
.use_assoc
9522 && sym
->ns
->proc_name
9523 && sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
9527 if (resolve_fl_derived (sym
->ts
.derived
) == FAILURE
)
9530 gfc_find_symbol (sym
->ts
.derived
->name
, sym
->ns
, 1, &ds
);
9531 if (!ds
&& sym
->attr
.function
9532 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
))
9534 symtree
= gfc_new_symtree (&sym
->ns
->sym_root
,
9535 sym
->ts
.derived
->name
);
9536 symtree
->n
.sym
= sym
->ts
.derived
;
9537 sym
->ts
.derived
->refs
++;
9541 /* Unless the derived-type declaration is use associated, Fortran 95
9542 does not allow public entries of private derived types.
9543 See 4.4.1 (F95) and 4.5.1.1 (F2003); and related interpretation
9545 if (sym
->ts
.type
== BT_DERIVED
9546 && sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.flavor
== FL_MODULE
9547 && !sym
->ts
.derived
->attr
.use_assoc
9548 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
)
9549 && !gfc_check_access (sym
->ts
.derived
->attr
.access
,
9550 sym
->ts
.derived
->ns
->default_access
)
9551 && gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC %s '%s' at %L "
9552 "of PRIVATE derived type '%s'",
9553 (sym
->attr
.flavor
== FL_PARAMETER
) ? "parameter"
9554 : "variable", sym
->name
, &sym
->declared_at
,
9555 sym
->ts
.derived
->name
) == FAILURE
)
9558 /* An assumed-size array with INTENT(OUT) shall not be of a type for which
9559 default initialization is defined (5.1.2.4.4). */
9560 if (sym
->ts
.type
== BT_DERIVED
9562 && sym
->attr
.intent
== INTENT_OUT
9564 && sym
->as
->type
== AS_ASSUMED_SIZE
)
9566 for (c
= sym
->ts
.derived
->components
; c
; c
= c
->next
)
9570 gfc_error ("The INTENT(OUT) dummy argument '%s' at %L is "
9571 "ASSUMED SIZE and so cannot have a default initializer",
9572 sym
->name
, &sym
->declared_at
);
9578 switch (sym
->attr
.flavor
)
9581 if (resolve_fl_variable (sym
, mp_flag
) == FAILURE
)
9586 if (resolve_fl_procedure (sym
, mp_flag
) == FAILURE
)
9591 if (resolve_fl_namelist (sym
) == FAILURE
)
9596 if (resolve_fl_parameter (sym
) == FAILURE
)
9604 /* Resolve array specifier. Check as well some constraints
9605 on COMMON blocks. */
9607 check_constant
= sym
->attr
.in_common
&& !sym
->attr
.pointer
;
9609 /* Set the formal_arg_flag so that check_conflict will not throw
9610 an error for host associated variables in the specification
9611 expression for an array_valued function. */
9612 if (sym
->attr
.function
&& sym
->as
)
9613 formal_arg_flag
= 1;
9615 gfc_resolve_array_spec (sym
->as
, check_constant
);
9617 formal_arg_flag
= 0;
9619 /* Resolve formal namespaces. */
9620 if (sym
->formal_ns
&& sym
->formal_ns
!= gfc_current_ns
)
9621 gfc_resolve (sym
->formal_ns
);
9623 /* Check threadprivate restrictions. */
9624 if (sym
->attr
.threadprivate
&& !sym
->attr
.save
&& !sym
->ns
->save_all
9625 && (!sym
->attr
.in_common
9626 && sym
->module
== NULL
9627 && (sym
->ns
->proc_name
== NULL
9628 || sym
->ns
->proc_name
->attr
.flavor
!= FL_MODULE
)))
9629 gfc_error ("Threadprivate at %L isn't SAVEd", &sym
->declared_at
);
9631 /* If we have come this far we can apply default-initializers, as
9632 described in 14.7.5, to those variables that have not already
9633 been assigned one. */
9634 if (sym
->ts
.type
== BT_DERIVED
9635 && sym
->attr
.referenced
9636 && sym
->ns
== gfc_current_ns
9638 && !sym
->attr
.allocatable
9639 && !sym
->attr
.alloc_comp
)
9641 symbol_attribute
*a
= &sym
->attr
;
9643 if ((!a
->save
&& !a
->dummy
&& !a
->pointer
9644 && !a
->in_common
&& !a
->use_assoc
9645 && !(a
->function
&& sym
!= sym
->result
))
9646 || (a
->dummy
&& a
->intent
== INTENT_OUT
))
9647 apply_default_init (sym
);
9650 /* If this symbol has a type-spec, check it. */
9651 if (sym
->attr
.flavor
== FL_VARIABLE
|| sym
->attr
.flavor
== FL_PARAMETER
9652 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.function
))
9653 if (resolve_typespec_used (&sym
->ts
, &sym
->declared_at
, sym
->name
)
9659 /************* Resolve DATA statements *************/
9663 gfc_data_value
*vnode
;
9669 /* Advance the values structure to point to the next value in the data list. */
9672 next_data_value (void)
9675 while (mpz_cmp_ui (values
.left
, 0) == 0)
9677 if (values
.vnode
->next
== NULL
)
9680 values
.vnode
= values
.vnode
->next
;
9681 mpz_set (values
.left
, values
.vnode
->repeat
);
9689 check_data_variable (gfc_data_variable
*var
, locus
*where
)
9695 ar_type mark
= AR_UNKNOWN
;
9697 mpz_t section_index
[GFC_MAX_DIMENSIONS
];
9703 if (gfc_resolve_expr (var
->expr
) == FAILURE
)
9707 mpz_init_set_si (offset
, 0);
9710 if (e
->expr_type
!= EXPR_VARIABLE
)
9711 gfc_internal_error ("check_data_variable(): Bad expression");
9713 sym
= e
->symtree
->n
.sym
;
9715 if (sym
->ns
->is_block_data
&& !sym
->attr
.in_common
)
9717 gfc_error ("BLOCK DATA element '%s' at %L must be in COMMON",
9718 sym
->name
, &sym
->declared_at
);
9721 if (e
->ref
== NULL
&& sym
->as
)
9723 gfc_error ("DATA array '%s' at %L must be specified in a previous"
9724 " declaration", sym
->name
, where
);
9728 has_pointer
= sym
->attr
.pointer
;
9730 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9732 if (ref
->type
== REF_COMPONENT
&& ref
->u
.c
.component
->attr
.pointer
)
9736 && ref
->type
== REF_ARRAY
9737 && ref
->u
.ar
.type
!= AR_FULL
)
9739 gfc_error ("DATA element '%s' at %L is a pointer and so must "
9740 "be a full array", sym
->name
, where
);
9745 if (e
->rank
== 0 || has_pointer
)
9747 mpz_init_set_ui (size
, 1);
9754 /* Find the array section reference. */
9755 for (ref
= e
->ref
; ref
; ref
= ref
->next
)
9757 if (ref
->type
!= REF_ARRAY
)
9759 if (ref
->u
.ar
.type
== AR_ELEMENT
)
9765 /* Set marks according to the reference pattern. */
9766 switch (ref
->u
.ar
.type
)
9774 /* Get the start position of array section. */
9775 gfc_get_section_index (ar
, section_index
, &offset
);
9783 if (gfc_array_size (e
, &size
) == FAILURE
)
9785 gfc_error ("Nonconstant array section at %L in DATA statement",
9794 while (mpz_cmp_ui (size
, 0) > 0)
9796 if (next_data_value () == FAILURE
)
9798 gfc_error ("DATA statement at %L has more variables than values",
9804 t
= gfc_check_assign (var
->expr
, values
.vnode
->expr
, 0);
9808 /* If we have more than one element left in the repeat count,
9809 and we have more than one element left in the target variable,
9810 then create a range assignment. */
9811 /* FIXME: Only done for full arrays for now, since array sections
9813 if (mark
== AR_FULL
&& ref
&& ref
->next
== NULL
9814 && mpz_cmp_ui (values
.left
, 1) > 0 && mpz_cmp_ui (size
, 1) > 0)
9818 if (mpz_cmp (size
, values
.left
) >= 0)
9820 mpz_init_set (range
, values
.left
);
9821 mpz_sub (size
, size
, values
.left
);
9822 mpz_set_ui (values
.left
, 0);
9826 mpz_init_set (range
, size
);
9827 mpz_sub (values
.left
, values
.left
, size
);
9828 mpz_set_ui (size
, 0);
9831 gfc_assign_data_value_range (var
->expr
, values
.vnode
->expr
,
9834 mpz_add (offset
, offset
, range
);
9838 /* Assign initial value to symbol. */
9841 mpz_sub_ui (values
.left
, values
.left
, 1);
9842 mpz_sub_ui (size
, size
, 1);
9844 t
= gfc_assign_data_value (var
->expr
, values
.vnode
->expr
, offset
);
9848 if (mark
== AR_FULL
)
9849 mpz_add_ui (offset
, offset
, 1);
9851 /* Modify the array section indexes and recalculate the offset
9852 for next element. */
9853 else if (mark
== AR_SECTION
)
9854 gfc_advance_section (section_index
, ar
, &offset
);
9858 if (mark
== AR_SECTION
)
9860 for (i
= 0; i
< ar
->dimen
; i
++)
9861 mpz_clear (section_index
[i
]);
9871 static gfc_try
traverse_data_var (gfc_data_variable
*, locus
*);
9873 /* Iterate over a list of elements in a DATA statement. */
9876 traverse_data_list (gfc_data_variable
*var
, locus
*where
)
9879 iterator_stack frame
;
9880 gfc_expr
*e
, *start
, *end
, *step
;
9881 gfc_try retval
= SUCCESS
;
9883 mpz_init (frame
.value
);
9885 start
= gfc_copy_expr (var
->iter
.start
);
9886 end
= gfc_copy_expr (var
->iter
.end
);
9887 step
= gfc_copy_expr (var
->iter
.step
);
9889 if (gfc_simplify_expr (start
, 1) == FAILURE
9890 || start
->expr_type
!= EXPR_CONSTANT
)
9892 gfc_error ("iterator start at %L does not simplify", &start
->where
);
9896 if (gfc_simplify_expr (end
, 1) == FAILURE
9897 || end
->expr_type
!= EXPR_CONSTANT
)
9899 gfc_error ("iterator end at %L does not simplify", &end
->where
);
9903 if (gfc_simplify_expr (step
, 1) == FAILURE
9904 || step
->expr_type
!= EXPR_CONSTANT
)
9906 gfc_error ("iterator step at %L does not simplify", &step
->where
);
9911 mpz_init_set (trip
, end
->value
.integer
);
9912 mpz_sub (trip
, trip
, start
->value
.integer
);
9913 mpz_add (trip
, trip
, step
->value
.integer
);
9915 mpz_div (trip
, trip
, step
->value
.integer
);
9917 mpz_set (frame
.value
, start
->value
.integer
);
9919 frame
.prev
= iter_stack
;
9920 frame
.variable
= var
->iter
.var
->symtree
;
9921 iter_stack
= &frame
;
9923 while (mpz_cmp_ui (trip
, 0) > 0)
9925 if (traverse_data_var (var
->list
, where
) == FAILURE
)
9932 e
= gfc_copy_expr (var
->expr
);
9933 if (gfc_simplify_expr (e
, 1) == FAILURE
)
9941 mpz_add (frame
.value
, frame
.value
, step
->value
.integer
);
9943 mpz_sub_ui (trip
, trip
, 1);
9948 mpz_clear (frame
.value
);
9950 gfc_free_expr (start
);
9951 gfc_free_expr (end
);
9952 gfc_free_expr (step
);
9954 iter_stack
= frame
.prev
;
9959 /* Type resolve variables in the variable list of a DATA statement. */
9962 traverse_data_var (gfc_data_variable
*var
, locus
*where
)
9966 for (; var
; var
= var
->next
)
9968 if (var
->expr
== NULL
)
9969 t
= traverse_data_list (var
, where
);
9971 t
= check_data_variable (var
, where
);
9981 /* Resolve the expressions and iterators associated with a data statement.
9982 This is separate from the assignment checking because data lists should
9983 only be resolved once. */
9986 resolve_data_variables (gfc_data_variable
*d
)
9988 for (; d
; d
= d
->next
)
9990 if (d
->list
== NULL
)
9992 if (gfc_resolve_expr (d
->expr
) == FAILURE
)
9997 if (gfc_resolve_iterator (&d
->iter
, false) == FAILURE
)
10000 if (resolve_data_variables (d
->list
) == FAILURE
)
10009 /* Resolve a single DATA statement. We implement this by storing a pointer to
10010 the value list into static variables, and then recursively traversing the
10011 variables list, expanding iterators and such. */
10014 resolve_data (gfc_data
*d
)
10017 if (resolve_data_variables (d
->var
) == FAILURE
)
10020 values
.vnode
= d
->value
;
10021 if (d
->value
== NULL
)
10022 mpz_set_ui (values
.left
, 0);
10024 mpz_set (values
.left
, d
->value
->repeat
);
10026 if (traverse_data_var (d
->var
, &d
->where
) == FAILURE
)
10029 /* At this point, we better not have any values left. */
10031 if (next_data_value () == SUCCESS
)
10032 gfc_error ("DATA statement at %L has more values than variables",
10037 /* 12.6 Constraint: In a pure subprogram any variable which is in common or
10038 accessed by host or use association, is a dummy argument to a pure function,
10039 is a dummy argument with INTENT (IN) to a pure subroutine, or an object that
10040 is storage associated with any such variable, shall not be used in the
10041 following contexts: (clients of this function). */
10043 /* Determines if a variable is not 'pure', i.e., not assignable within a pure
10044 procedure. Returns zero if assignment is OK, nonzero if there is a
10047 gfc_impure_variable (gfc_symbol
*sym
)
10051 if (sym
->attr
.use_assoc
|| sym
->attr
.in_common
)
10054 if (sym
->ns
!= gfc_current_ns
)
10055 return !sym
->attr
.function
;
10057 proc
= sym
->ns
->proc_name
;
10058 if (sym
->attr
.dummy
&& gfc_pure (proc
)
10059 && ((proc
->attr
.subroutine
&& sym
->attr
.intent
== INTENT_IN
)
10061 proc
->attr
.function
))
10064 /* TODO: Sort out what can be storage associated, if anything, and include
10065 it here. In principle equivalences should be scanned but it does not
10066 seem to be possible to storage associate an impure variable this way. */
10071 /* Test whether a symbol is pure or not. For a NULL pointer, checks the
10072 symbol of the current procedure. */
10075 gfc_pure (gfc_symbol
*sym
)
10077 symbol_attribute attr
;
10080 sym
= gfc_current_ns
->proc_name
;
10086 return attr
.flavor
== FL_PROCEDURE
&& (attr
.pure
|| attr
.elemental
);
10090 /* Test whether the current procedure is elemental or not. */
10093 gfc_elemental (gfc_symbol
*sym
)
10095 symbol_attribute attr
;
10098 sym
= gfc_current_ns
->proc_name
;
10103 return attr
.flavor
== FL_PROCEDURE
&& attr
.elemental
;
10107 /* Warn about unused labels. */
10110 warn_unused_fortran_label (gfc_st_label
*label
)
10115 warn_unused_fortran_label (label
->left
);
10117 if (label
->defined
== ST_LABEL_UNKNOWN
)
10120 switch (label
->referenced
)
10122 case ST_LABEL_UNKNOWN
:
10123 gfc_warning ("Label %d at %L defined but not used", label
->value
,
10127 case ST_LABEL_BAD_TARGET
:
10128 gfc_warning ("Label %d at %L defined but cannot be used",
10129 label
->value
, &label
->where
);
10136 warn_unused_fortran_label (label
->right
);
10140 /* Returns the sequence type of a symbol or sequence. */
10143 sequence_type (gfc_typespec ts
)
10152 if (ts
.derived
->components
== NULL
)
10153 return SEQ_NONDEFAULT
;
10155 result
= sequence_type (ts
.derived
->components
->ts
);
10156 for (c
= ts
.derived
->components
->next
; c
; c
= c
->next
)
10157 if (sequence_type (c
->ts
) != result
)
10163 if (ts
.kind
!= gfc_default_character_kind
)
10164 return SEQ_NONDEFAULT
;
10166 return SEQ_CHARACTER
;
10169 if (ts
.kind
!= gfc_default_integer_kind
)
10170 return SEQ_NONDEFAULT
;
10172 return SEQ_NUMERIC
;
10175 if (!(ts
.kind
== gfc_default_real_kind
10176 || ts
.kind
== gfc_default_double_kind
))
10177 return SEQ_NONDEFAULT
;
10179 return SEQ_NUMERIC
;
10182 if (ts
.kind
!= gfc_default_complex_kind
)
10183 return SEQ_NONDEFAULT
;
10185 return SEQ_NUMERIC
;
10188 if (ts
.kind
!= gfc_default_logical_kind
)
10189 return SEQ_NONDEFAULT
;
10191 return SEQ_NUMERIC
;
10194 return SEQ_NONDEFAULT
;
10199 /* Resolve derived type EQUIVALENCE object. */
10202 resolve_equivalence_derived (gfc_symbol
*derived
, gfc_symbol
*sym
, gfc_expr
*e
)
10205 gfc_component
*c
= derived
->components
;
10210 /* Shall not be an object of nonsequence derived type. */
10211 if (!derived
->attr
.sequence
)
10213 gfc_error ("Derived type variable '%s' at %L must have SEQUENCE "
10214 "attribute to be an EQUIVALENCE object", sym
->name
,
10219 /* Shall not have allocatable components. */
10220 if (derived
->attr
.alloc_comp
)
10222 gfc_error ("Derived type variable '%s' at %L cannot have ALLOCATABLE "
10223 "components to be an EQUIVALENCE object",sym
->name
,
10228 if (sym
->attr
.in_common
&& has_default_initializer (sym
->ts
.derived
))
10230 gfc_error ("Derived type variable '%s' at %L with default "
10231 "initialization cannot be in EQUIVALENCE with a variable "
10232 "in COMMON", sym
->name
, &e
->where
);
10236 for (; c
; c
= c
->next
)
10240 && (resolve_equivalence_derived (c
->ts
.derived
, sym
, e
) == FAILURE
))
10243 /* Shall not be an object of sequence derived type containing a pointer
10244 in the structure. */
10245 if (c
->attr
.pointer
)
10247 gfc_error ("Derived type variable '%s' at %L with pointer "
10248 "component(s) cannot be an EQUIVALENCE object",
10249 sym
->name
, &e
->where
);
10257 /* Resolve equivalence object.
10258 An EQUIVALENCE object shall not be a dummy argument, a pointer, a target,
10259 an allocatable array, an object of nonsequence derived type, an object of
10260 sequence derived type containing a pointer at any level of component
10261 selection, an automatic object, a function name, an entry name, a result
10262 name, a named constant, a structure component, or a subobject of any of
10263 the preceding objects. A substring shall not have length zero. A
10264 derived type shall not have components with default initialization nor
10265 shall two objects of an equivalence group be initialized.
10266 Either all or none of the objects shall have an protected attribute.
10267 The simple constraints are done in symbol.c(check_conflict) and the rest
10268 are implemented here. */
10271 resolve_equivalence (gfc_equiv
*eq
)
10274 gfc_symbol
*derived
;
10275 gfc_symbol
*first_sym
;
10278 locus
*last_where
= NULL
;
10279 seq_type eq_type
, last_eq_type
;
10280 gfc_typespec
*last_ts
;
10281 int object
, cnt_protected
;
10282 const char *value_name
;
10286 last_ts
= &eq
->expr
->symtree
->n
.sym
->ts
;
10288 first_sym
= eq
->expr
->symtree
->n
.sym
;
10292 for (object
= 1; eq
; eq
= eq
->eq
, object
++)
10296 e
->ts
= e
->symtree
->n
.sym
->ts
;
10297 /* match_varspec might not know yet if it is seeing
10298 array reference or substring reference, as it doesn't
10300 if (e
->ref
&& e
->ref
->type
== REF_ARRAY
)
10302 gfc_ref
*ref
= e
->ref
;
10303 sym
= e
->symtree
->n
.sym
;
10305 if (sym
->attr
.dimension
)
10307 ref
->u
.ar
.as
= sym
->as
;
10311 /* For substrings, convert REF_ARRAY into REF_SUBSTRING. */
10312 if (e
->ts
.type
== BT_CHARACTER
10314 && ref
->type
== REF_ARRAY
10315 && ref
->u
.ar
.dimen
== 1
10316 && ref
->u
.ar
.dimen_type
[0] == DIMEN_RANGE
10317 && ref
->u
.ar
.stride
[0] == NULL
)
10319 gfc_expr
*start
= ref
->u
.ar
.start
[0];
10320 gfc_expr
*end
= ref
->u
.ar
.end
[0];
10323 /* Optimize away the (:) reference. */
10324 if (start
== NULL
&& end
== NULL
)
10327 e
->ref
= ref
->next
;
10329 e
->ref
->next
= ref
->next
;
10334 ref
->type
= REF_SUBSTRING
;
10336 start
= gfc_int_expr (1);
10337 ref
->u
.ss
.start
= start
;
10338 if (end
== NULL
&& e
->ts
.cl
)
10339 end
= gfc_copy_expr (e
->ts
.cl
->length
);
10340 ref
->u
.ss
.end
= end
;
10341 ref
->u
.ss
.length
= e
->ts
.cl
;
10348 /* Any further ref is an error. */
10351 gcc_assert (ref
->type
== REF_ARRAY
);
10352 gfc_error ("Syntax error in EQUIVALENCE statement at %L",
10358 if (gfc_resolve_expr (e
) == FAILURE
)
10361 sym
= e
->symtree
->n
.sym
;
10363 if (sym
->attr
.is_protected
)
10365 if (cnt_protected
> 0 && cnt_protected
!= object
)
10367 gfc_error ("Either all or none of the objects in the "
10368 "EQUIVALENCE set at %L shall have the "
10369 "PROTECTED attribute",
10374 /* Shall not equivalence common block variables in a PURE procedure. */
10375 if (sym
->ns
->proc_name
10376 && sym
->ns
->proc_name
->attr
.pure
10377 && sym
->attr
.in_common
)
10379 gfc_error ("Common block member '%s' at %L cannot be an EQUIVALENCE "
10380 "object in the pure procedure '%s'",
10381 sym
->name
, &e
->where
, sym
->ns
->proc_name
->name
);
10385 /* Shall not be a named constant. */
10386 if (e
->expr_type
== EXPR_CONSTANT
)
10388 gfc_error ("Named constant '%s' at %L cannot be an EQUIVALENCE "
10389 "object", sym
->name
, &e
->where
);
10393 derived
= e
->ts
.derived
;
10394 if (derived
&& resolve_equivalence_derived (derived
, sym
, e
) == FAILURE
)
10397 /* Check that the types correspond correctly:
10399 A numeric sequence structure may be equivalenced to another sequence
10400 structure, an object of default integer type, default real type, double
10401 precision real type, default logical type such that components of the
10402 structure ultimately only become associated to objects of the same
10403 kind. A character sequence structure may be equivalenced to an object
10404 of default character kind or another character sequence structure.
10405 Other objects may be equivalenced only to objects of the same type and
10406 kind parameters. */
10408 /* Identical types are unconditionally OK. */
10409 if (object
== 1 || gfc_compare_types (last_ts
, &sym
->ts
))
10410 goto identical_types
;
10412 last_eq_type
= sequence_type (*last_ts
);
10413 eq_type
= sequence_type (sym
->ts
);
10415 /* Since the pair of objects is not of the same type, mixed or
10416 non-default sequences can be rejected. */
10418 msg
= "Sequence %s with mixed components in EQUIVALENCE "
10419 "statement at %L with different type objects";
10421 && last_eq_type
== SEQ_MIXED
10422 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
, last_where
)
10424 || (eq_type
== SEQ_MIXED
10425 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
10426 &e
->where
) == FAILURE
))
10429 msg
= "Non-default type object or sequence %s in EQUIVALENCE "
10430 "statement at %L with objects of different type";
10432 && last_eq_type
== SEQ_NONDEFAULT
10433 && gfc_notify_std (GFC_STD_GNU
, msg
, first_sym
->name
,
10434 last_where
) == FAILURE
)
10435 || (eq_type
== SEQ_NONDEFAULT
10436 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
10437 &e
->where
) == FAILURE
))
10440 msg
="Non-CHARACTER object '%s' in default CHARACTER "
10441 "EQUIVALENCE statement at %L";
10442 if (last_eq_type
== SEQ_CHARACTER
10443 && eq_type
!= SEQ_CHARACTER
10444 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
10445 &e
->where
) == FAILURE
)
10448 msg
="Non-NUMERIC object '%s' in default NUMERIC "
10449 "EQUIVALENCE statement at %L";
10450 if (last_eq_type
== SEQ_NUMERIC
10451 && eq_type
!= SEQ_NUMERIC
10452 && gfc_notify_std (GFC_STD_GNU
, msg
, sym
->name
,
10453 &e
->where
) == FAILURE
)
10458 last_where
= &e
->where
;
10463 /* Shall not be an automatic array. */
10464 if (e
->ref
->type
== REF_ARRAY
10465 && gfc_resolve_array_spec (e
->ref
->u
.ar
.as
, 1) == FAILURE
)
10467 gfc_error ("Array '%s' at %L with non-constant bounds cannot be "
10468 "an EQUIVALENCE object", sym
->name
, &e
->where
);
10475 /* Shall not be a structure component. */
10476 if (r
->type
== REF_COMPONENT
)
10478 gfc_error ("Structure component '%s' at %L cannot be an "
10479 "EQUIVALENCE object",
10480 r
->u
.c
.component
->name
, &e
->where
);
10484 /* A substring shall not have length zero. */
10485 if (r
->type
== REF_SUBSTRING
)
10487 if (compare_bound (r
->u
.ss
.start
, r
->u
.ss
.end
) == CMP_GT
)
10489 gfc_error ("Substring at %L has length zero",
10490 &r
->u
.ss
.start
->where
);
10500 /* Resolve function and ENTRY types, issue diagnostics if needed. */
10503 resolve_fntype (gfc_namespace
*ns
)
10505 gfc_entry_list
*el
;
10508 if (ns
->proc_name
== NULL
|| !ns
->proc_name
->attr
.function
)
10511 /* If there are any entries, ns->proc_name is the entry master
10512 synthetic symbol and ns->entries->sym actual FUNCTION symbol. */
10514 sym
= ns
->entries
->sym
;
10516 sym
= ns
->proc_name
;
10517 if (sym
->result
== sym
10518 && sym
->ts
.type
== BT_UNKNOWN
10519 && gfc_set_default_type (sym
, 0, NULL
) == FAILURE
10520 && !sym
->attr
.untyped
)
10522 gfc_error ("Function '%s' at %L has no IMPLICIT type",
10523 sym
->name
, &sym
->declared_at
);
10524 sym
->attr
.untyped
= 1;
10527 if (sym
->ts
.type
== BT_DERIVED
&& !sym
->ts
.derived
->attr
.use_assoc
10528 && !sym
->attr
.contained
10529 && !gfc_check_access (sym
->ts
.derived
->attr
.access
,
10530 sym
->ts
.derived
->ns
->default_access
)
10531 && gfc_check_access (sym
->attr
.access
, sym
->ns
->default_access
))
10533 gfc_notify_std (GFC_STD_F2003
, "Fortran 2003: PUBLIC function '%s' at "
10534 "%L of PRIVATE type '%s'", sym
->name
,
10535 &sym
->declared_at
, sym
->ts
.derived
->name
);
10539 for (el
= ns
->entries
->next
; el
; el
= el
->next
)
10541 if (el
->sym
->result
== el
->sym
10542 && el
->sym
->ts
.type
== BT_UNKNOWN
10543 && gfc_set_default_type (el
->sym
, 0, NULL
) == FAILURE
10544 && !el
->sym
->attr
.untyped
)
10546 gfc_error ("ENTRY '%s' at %L has no IMPLICIT type",
10547 el
->sym
->name
, &el
->sym
->declared_at
);
10548 el
->sym
->attr
.untyped
= 1;
10553 /* 12.3.2.1.1 Defined operators. */
10556 gfc_resolve_uops (gfc_symtree
*symtree
)
10558 gfc_interface
*itr
;
10560 gfc_formal_arglist
*formal
;
10562 if (symtree
== NULL
)
10565 gfc_resolve_uops (symtree
->left
);
10566 gfc_resolve_uops (symtree
->right
);
10568 for (itr
= symtree
->n
.uop
->op
; itr
; itr
= itr
->next
)
10571 if (!sym
->attr
.function
)
10572 gfc_error ("User operator procedure '%s' at %L must be a FUNCTION",
10573 sym
->name
, &sym
->declared_at
);
10575 if (sym
->ts
.type
== BT_CHARACTER
10576 && !(sym
->ts
.cl
&& sym
->ts
.cl
->length
)
10577 && !(sym
->result
&& sym
->result
->ts
.cl
10578 && sym
->result
->ts
.cl
->length
))
10579 gfc_error ("User operator procedure '%s' at %L cannot be assumed "
10580 "character length", sym
->name
, &sym
->declared_at
);
10582 formal
= sym
->formal
;
10583 if (!formal
|| !formal
->sym
)
10585 gfc_error ("User operator procedure '%s' at %L must have at least "
10586 "one argument", sym
->name
, &sym
->declared_at
);
10590 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
10591 gfc_error ("First argument of operator interface at %L must be "
10592 "INTENT(IN)", &sym
->declared_at
);
10594 if (formal
->sym
->attr
.optional
)
10595 gfc_error ("First argument of operator interface at %L cannot be "
10596 "optional", &sym
->declared_at
);
10598 formal
= formal
->next
;
10599 if (!formal
|| !formal
->sym
)
10602 if (formal
->sym
->attr
.intent
!= INTENT_IN
)
10603 gfc_error ("Second argument of operator interface at %L must be "
10604 "INTENT(IN)", &sym
->declared_at
);
10606 if (formal
->sym
->attr
.optional
)
10607 gfc_error ("Second argument of operator interface at %L cannot be "
10608 "optional", &sym
->declared_at
);
10611 gfc_error ("Operator interface at %L must have, at most, two "
10612 "arguments", &sym
->declared_at
);
10617 /* Examine all of the expressions associated with a program unit,
10618 assign types to all intermediate expressions, make sure that all
10619 assignments are to compatible types and figure out which names
10620 refer to which functions or subroutines. It doesn't check code
10621 block, which is handled by resolve_code. */
10624 resolve_types (gfc_namespace
*ns
)
10630 gfc_namespace
* old_ns
= gfc_current_ns
;
10632 /* Check that all IMPLICIT types are ok. */
10633 if (!ns
->seen_implicit_none
)
10636 for (letter
= 0; letter
!= GFC_LETTERS
; ++letter
)
10637 if (ns
->set_flag
[letter
]
10638 && resolve_typespec_used (&ns
->default_type
[letter
],
10639 &ns
->implicit_loc
[letter
],
10644 gfc_current_ns
= ns
;
10646 resolve_entries (ns
);
10648 resolve_common_vars (ns
->blank_common
.head
, false);
10649 resolve_common_blocks (ns
->common_root
);
10651 resolve_contained_functions (ns
);
10653 gfc_traverse_ns (ns
, resolve_bind_c_derived_types
);
10655 for (cl
= ns
->cl_list
; cl
; cl
= cl
->next
)
10656 resolve_charlen (cl
);
10658 gfc_traverse_ns (ns
, resolve_symbol
);
10660 resolve_fntype (ns
);
10662 for (n
= ns
->contained
; n
; n
= n
->sibling
)
10664 if (gfc_pure (ns
->proc_name
) && !gfc_pure (n
->proc_name
))
10665 gfc_error ("Contained procedure '%s' at %L of a PURE procedure must "
10666 "also be PURE", n
->proc_name
->name
,
10667 &n
->proc_name
->declared_at
);
10673 gfc_check_interfaces (ns
);
10675 gfc_traverse_ns (ns
, resolve_values
);
10681 for (d
= ns
->data
; d
; d
= d
->next
)
10685 gfc_traverse_ns (ns
, gfc_formalize_init_value
);
10687 gfc_traverse_ns (ns
, gfc_verify_binding_labels
);
10689 if (ns
->common_root
!= NULL
)
10690 gfc_traverse_symtree (ns
->common_root
, resolve_bind_c_comms
);
10692 for (eq
= ns
->equiv
; eq
; eq
= eq
->next
)
10693 resolve_equivalence (eq
);
10695 /* Warn about unused labels. */
10696 if (warn_unused_label
)
10697 warn_unused_fortran_label (ns
->st_labels
);
10699 gfc_resolve_uops (ns
->uop_root
);
10701 gfc_current_ns
= old_ns
;
10705 /* Call resolve_code recursively. */
10708 resolve_codes (gfc_namespace
*ns
)
10711 bitmap_obstack old_obstack
;
10713 for (n
= ns
->contained
; n
; n
= n
->sibling
)
10716 gfc_current_ns
= ns
;
10718 /* Set to an out of range value. */
10719 current_entry_id
= -1;
10721 old_obstack
= labels_obstack
;
10722 bitmap_obstack_initialize (&labels_obstack
);
10724 resolve_code (ns
->code
, ns
);
10726 bitmap_obstack_release (&labels_obstack
);
10727 labels_obstack
= old_obstack
;
10731 /* This function is called after a complete program unit has been compiled.
10732 Its purpose is to examine all of the expressions associated with a program
10733 unit, assign types to all intermediate expressions, make sure that all
10734 assignments are to compatible types and figure out which names refer to
10735 which functions or subroutines. */
10738 gfc_resolve (gfc_namespace
*ns
)
10740 gfc_namespace
*old_ns
;
10745 old_ns
= gfc_current_ns
;
10747 resolve_types (ns
);
10748 resolve_codes (ns
);
10750 gfc_current_ns
= old_ns
;