1 /* Handle modules, which amounts to loading and saving symbols and
2 their attendant structures.
3 Copyright (C) 2000-2024 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/>. */
22 /* The syntax of gfortran modules resembles that of lisp lists, i.e. a
23 sequence of atoms, which can be left or right parenthesis, names,
24 integers or strings. Parenthesis are always matched which allows
25 us to skip over sections at high speed without having to know
26 anything about the internal structure of the lists. A "name" is
27 usually a fortran 95 identifier, but can also start with '@' in
28 order to reference a hidden symbol.
30 The first line of a module is an informational message about what
31 created the module, the file it came from and when it was created.
32 The second line is a warning for people not to edit the module.
33 The rest of the module looks like:
35 ( ( <Interface info for UPLUS> )
36 ( <Interface info for UMINUS> )
39 ( ( <name of operator interface> <module of op interface> <i/f1> ... )
42 ( ( <name of generic interface> <module of generic interface> <i/f1> ... )
45 ( ( <common name> <symbol> <saved flag>)
51 ( <Symbol Number (in no particular order)>
53 <Module name of symbol>
54 ( <symbol information> )
63 In general, symbols refer to other symbols by their symbol number,
64 which are zero based. Symbols are written to the module in no
69 #include "coretypes.h"
73 #include "stringpool.h"
76 #include "parse.h" /* FIXME */
77 #include "constructor.h"
82 #define MODULE_EXTENSION ".mod"
83 #define SUBMODULE_EXTENSION ".smod"
85 /* Don't put any single quote (') in MOD_VERSION, if you want it to be
87 #define MOD_VERSION "15"
90 /* Structure that describes a position within a module file. */
99 /* Structure for list of symbols of intrinsic modules. */
112 P_UNKNOWN
= 0, P_OTHER
, P_NAMESPACE
, P_COMPONENT
, P_SYMBOL
116 /* The fixup structure lists pointers to pointers that have to
117 be updated when a pointer value becomes known. */
119 typedef struct fixup_t
122 struct fixup_t
*next
;
127 /* Structure for holding extra info needed for pointers being read. */
143 typedef struct pointer_info
145 BBT_HEADER (pointer_info
);
146 HOST_WIDE_INT integer
;
149 /* The first component of each member of the union is the pointer
156 void *pointer
; /* Member for doing pointer searches. */
161 char *true_name
, *module
, *binding_label
;
163 gfc_symtree
*symtree
;
164 enum gfc_rsym_state state
;
165 int ns
, referenced
, renamed
;
173 enum gfc_wsym_state state
;
182 #define gfc_get_pointer_info() XCNEW (pointer_info)
185 /* Local variables */
187 /* The gzFile for the module we're reading or writing. */
188 static gzFile module_fp
;
190 /* Fully qualified module path */
191 static char *module_fullpath
= NULL
;
193 /* The name of the module we're reading (USE'ing) or writing. */
194 static const char *module_name
;
195 /* The name of the .smod file that the submodule will write to. */
196 static const char *submodule_name
;
198 /* The list of use statements to apply to the current namespace
199 before parsing the non-use statements. */
200 static gfc_use_list
*module_list
;
201 /* The end of the MODULE_LIST list above at the time the recognition
202 of the current statement started. */
203 static gfc_use_list
**old_module_list_tail
;
205 /* If we're reading an intrinsic module, this is its ID. */
206 static intmod_id current_intmod
;
208 /* Content of module. */
209 static char* module_content
;
211 static long module_pos
;
212 static int module_line
, module_column
, only_flag
;
213 static int prev_module_line
, prev_module_column
;
216 { IO_INPUT
, IO_OUTPUT
}
219 static gfc_use_rename
*gfc_rename_list
;
220 static pointer_info
*pi_root
;
221 static int symbol_number
; /* Counter for assigning symbol numbers */
223 /* Tells mio_expr_ref to make symbols for unused equivalence members. */
224 static bool in_load_equiv
;
228 /*****************************************************************/
230 /* Pointer/integer conversion. Pointers between structures are stored
231 as integers in the module file. The next couple of subroutines
232 handle this translation for reading and writing. */
234 /* Recursively free the tree of pointer structures. */
237 free_pi_tree (pointer_info
*p
)
242 if (p
->fixup
!= NULL
)
243 gfc_internal_error ("free_pi_tree(): Unresolved fixup");
245 free_pi_tree (p
->left
);
246 free_pi_tree (p
->right
);
248 if (iomode
== IO_INPUT
)
250 XDELETEVEC (p
->u
.rsym
.true_name
);
251 XDELETEVEC (p
->u
.rsym
.module
);
252 XDELETEVEC (p
->u
.rsym
.binding_label
);
259 /* Compare pointers when searching by pointer. Used when writing a
263 compare_pointers (void *_sn1
, void *_sn2
)
265 pointer_info
*sn1
, *sn2
;
267 sn1
= (pointer_info
*) _sn1
;
268 sn2
= (pointer_info
*) _sn2
;
270 if (sn1
->u
.pointer
< sn2
->u
.pointer
)
272 if (sn1
->u
.pointer
> sn2
->u
.pointer
)
279 /* Compare integers when searching by integer. Used when reading a
283 compare_integers (void *_sn1
, void *_sn2
)
285 pointer_info
*sn1
, *sn2
;
287 sn1
= (pointer_info
*) _sn1
;
288 sn2
= (pointer_info
*) _sn2
;
290 if (sn1
->integer
< sn2
->integer
)
292 if (sn1
->integer
> sn2
->integer
)
299 /* Initialize the pointer_info tree. */
308 compare
= (iomode
== IO_INPUT
) ? compare_integers
: compare_pointers
;
310 /* Pointer 0 is the NULL pointer. */
311 p
= gfc_get_pointer_info ();
316 gfc_insert_bbt (&pi_root
, p
, compare
);
318 /* Pointer 1 is the current namespace. */
319 p
= gfc_get_pointer_info ();
320 p
->u
.pointer
= gfc_current_ns
;
322 p
->type
= P_NAMESPACE
;
324 gfc_insert_bbt (&pi_root
, p
, compare
);
330 /* During module writing, call here with a pointer to something,
331 returning the pointer_info node. */
333 static pointer_info
*
334 find_pointer (void *gp
)
341 if (p
->u
.pointer
== gp
)
343 p
= (gp
< p
->u
.pointer
) ? p
->left
: p
->right
;
350 /* Given a pointer while writing, returns the pointer_info tree node,
351 creating it if it doesn't exist. */
353 static pointer_info
*
354 get_pointer (void *gp
)
358 p
= find_pointer (gp
);
362 /* Pointer doesn't have an integer. Give it one. */
363 p
= gfc_get_pointer_info ();
366 p
->integer
= symbol_number
++;
368 gfc_insert_bbt (&pi_root
, p
, compare_pointers
);
374 /* Given an integer during reading, find it in the pointer_info tree,
375 creating the node if not found. */
377 static pointer_info
*
378 get_integer (HOST_WIDE_INT integer
)
388 c
= compare_integers (&t
, p
);
392 p
= (c
< 0) ? p
->left
: p
->right
;
398 p
= gfc_get_pointer_info ();
399 p
->integer
= integer
;
402 gfc_insert_bbt (&pi_root
, p
, compare_integers
);
408 /* Resolve any fixups using a known pointer. */
411 resolve_fixups (fixup_t
*f
, void *gp
)
424 /* Convert a string such that it starts with a lower-case character. Used
425 to convert the symtree name of a derived-type to the symbol name or to
426 the name of the associated generic function. */
429 gfc_dt_lower_string (const char *name
)
431 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
432 return gfc_get_string ("%c%s", (char) TOLOWER ((unsigned char) name
[0]),
434 return gfc_get_string ("%s", name
);
438 /* Convert a string such that it starts with an upper-case character. Used to
439 return the symtree-name for a derived type; the symbol name itself and the
440 symtree/symbol name of the associated generic function start with a lower-
444 gfc_dt_upper_string (const char *name
)
446 if (name
[0] != (char) TOUPPER ((unsigned char) name
[0]))
447 return gfc_get_string ("%c%s", (char) TOUPPER ((unsigned char) name
[0]),
449 return gfc_get_string ("%s", name
);
452 /* Call here during module reading when we know what pointer to
453 associate with an integer. Any fixups that exist are resolved at
457 associate_integer_pointer (pointer_info
*p
, void *gp
)
459 if (p
->u
.pointer
!= NULL
)
460 gfc_internal_error ("associate_integer_pointer(): Already associated");
464 resolve_fixups (p
->fixup
, gp
);
470 /* During module reading, given an integer and a pointer to a pointer,
471 either store the pointer from an already-known value or create a
472 fixup structure in order to store things later. Returns zero if
473 the reference has been actually stored, or nonzero if the reference
474 must be fixed later (i.e., associate_integer_pointer must be called
475 sometime later. Returns the pointer_info structure. */
477 static pointer_info
*
478 add_fixup (HOST_WIDE_INT integer
, void *gp
)
484 p
= get_integer (integer
);
486 if (p
->integer
== 0 || p
->u
.pointer
!= NULL
)
489 *cp
= (char *) p
->u
.pointer
;
498 f
->pointer
= (void **) gp
;
505 /*****************************************************************/
507 /* Parser related subroutines */
509 /* Free the rename list left behind by a USE statement. */
512 free_rename (gfc_use_rename
*list
)
514 gfc_use_rename
*next
;
516 for (; list
; list
= next
)
524 /* Match a USE statement. */
529 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module_nature
[GFC_MAX_SYMBOL_LEN
+ 1];
530 gfc_use_rename
*tail
= NULL
, *new_use
;
531 interface_type type
, type2
;
534 gfc_use_list
*use_list
;
538 use_list
= gfc_get_use_list ();
540 if (gfc_match (" , ") == MATCH_YES
)
542 if ((m
= gfc_match (" %n ::", module_nature
)) == MATCH_YES
)
544 if (!gfc_notify_std (GFC_STD_F2003
, "module "
545 "nature in USE statement at %C"))
548 if (strcmp (module_nature
, "intrinsic") == 0)
549 use_list
->intrinsic
= true;
552 if (strcmp (module_nature
, "non_intrinsic") == 0)
553 use_list
->non_intrinsic
= true;
556 gfc_error ("Module nature in USE statement at %C shall "
557 "be either INTRINSIC or NON_INTRINSIC");
564 /* Help output a better error message than "Unclassifiable
566 gfc_match (" %n", module_nature
);
567 if (strcmp (module_nature
, "intrinsic") == 0
568 || strcmp (module_nature
, "non_intrinsic") == 0)
569 gfc_error ("\"::\" was expected after module nature at %C "
570 "but was not found");
577 m
= gfc_match (" ::");
578 if (m
== MATCH_YES
&&
579 !gfc_notify_std(GFC_STD_F2003
, "\"USE :: module\" at %C"))
584 m
= gfc_match ("% ");
593 use_list
->where
= gfc_current_locus
;
595 m
= gfc_match_name (name
);
602 use_list
->module_name
= gfc_get_string ("%s", name
);
604 if (gfc_match_eos () == MATCH_YES
)
607 if (gfc_match_char (',') != MATCH_YES
)
610 if (gfc_match (" only :") == MATCH_YES
)
611 use_list
->only_flag
= true;
613 if (gfc_match_eos () == MATCH_YES
)
618 /* Get a new rename struct and add it to the rename list. */
619 new_use
= gfc_get_use_rename ();
620 new_use
->where
= gfc_current_locus
;
623 if (use_list
->rename
== NULL
)
624 use_list
->rename
= new_use
;
626 tail
->next
= new_use
;
629 /* See what kind of interface we're dealing with. Assume it is
631 new_use
->op
= INTRINSIC_NONE
;
632 if (gfc_match_generic_spec (&type
, name
, &op
) == MATCH_ERROR
)
637 case INTERFACE_NAMELESS
:
638 gfc_error ("Missing generic specification in USE statement at %C");
641 case INTERFACE_USER_OP
:
642 case INTERFACE_GENERIC
:
644 loc
= gfc_current_locus
;
646 m
= gfc_match (" =>");
648 if (type
== INTERFACE_USER_OP
&& m
== MATCH_YES
649 && (!gfc_notify_std(GFC_STD_F2003
, "Renaming "
650 "operators in USE statements at %C")))
653 if (type
== INTERFACE_USER_OP
)
654 new_use
->op
= INTRINSIC_USER
;
656 if (use_list
->only_flag
)
659 strcpy (new_use
->use_name
, name
);
662 strcpy (new_use
->local_name
, name
);
663 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
668 if (m
== MATCH_ERROR
)
676 strcpy (new_use
->local_name
, name
);
678 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
683 if (m
== MATCH_ERROR
)
687 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
688 if (st
&& type
!= INTERFACE_USER_OP
689 && (st
->n
.sym
->module
!= use_list
->module_name
690 || strcmp (st
->n
.sym
->name
, new_use
->use_name
) != 0))
693 gfc_error ("Symbol %qs at %L conflicts with the rename symbol "
694 "at %L", name
, &st
->n
.sym
->declared_at
, &loc
);
696 gfc_error ("Symbol %qs at %L conflicts with the symbol "
697 "at %L", name
, &st
->n
.sym
->declared_at
, &loc
);
701 if (strcmp (new_use
->use_name
, use_list
->module_name
) == 0
702 || strcmp (new_use
->local_name
, use_list
->module_name
) == 0)
704 gfc_error ("The name %qs at %C has already been used as "
705 "an external module name", use_list
->module_name
);
710 case INTERFACE_INTRINSIC_OP
:
718 if (gfc_match_eos () == MATCH_YES
)
720 if (gfc_match_char (',') != MATCH_YES
)
727 gfc_use_list
*last
= module_list
;
730 last
->next
= use_list
;
733 module_list
= use_list
;
738 gfc_syntax_error (ST_USE
);
741 free_rename (use_list
->rename
);
747 /* Match a SUBMODULE statement.
749 According to F2008:11.2.3.2, "The submodule identifier is the
750 ordered pair whose first element is the ancestor module name and
751 whose second element is the submodule name. 'Submodule_name' is
752 used for the submodule filename and uses '@' as a separator, whilst
753 the name of the symbol for the module uses '.' as a separator.
754 The reasons for these choices are:
755 (i) To follow another leading brand in the submodule filenames;
756 (ii) Since '.' is not particularly visible in the filenames; and
757 (iii) The linker does not permit '@' in mnemonics. */
760 gfc_match_submodule (void)
763 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
764 gfc_use_list
*use_list
;
765 bool seen_colon
= false;
767 if (!gfc_notify_std (GFC_STD_F2008
, "SUBMODULE declaration at %C"))
770 if (gfc_current_state () != COMP_NONE
)
772 gfc_error ("SUBMODULE declaration at %C cannot appear within "
773 "another scoping unit");
777 gfc_new_block
= NULL
;
778 gcc_assert (module_list
== NULL
);
780 if (gfc_match_char ('(') != MATCH_YES
)
785 m
= gfc_match (" %n", name
);
789 use_list
= gfc_get_use_list ();
790 use_list
->where
= gfc_current_locus
;
794 gfc_use_list
*last
= module_list
;
797 last
->next
= use_list
;
798 use_list
->module_name
799 = gfc_get_string ("%s.%s", module_list
->module_name
, name
);
800 use_list
->submodule_name
801 = gfc_get_string ("%s@%s", module_list
->module_name
, name
);
805 module_list
= use_list
;
806 use_list
->module_name
= gfc_get_string ("%s", name
);
807 use_list
->submodule_name
= use_list
->module_name
;
810 if (gfc_match_char (')') == MATCH_YES
)
813 if (gfc_match_char (':') != MATCH_YES
820 m
= gfc_match (" %s%t", &gfc_new_block
);
824 submodule_name
= gfc_get_string ("%s@%s", module_list
->module_name
,
825 gfc_new_block
->name
);
827 gfc_new_block
->name
= gfc_get_string ("%s.%s",
828 module_list
->module_name
,
829 gfc_new_block
->name
);
831 if (!gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
832 gfc_new_block
->name
, NULL
))
835 /* Just retain the ultimate .(s)mod file for reading, since it
836 contains all the information in its ancestors. */
837 use_list
= module_list
;
838 for (; module_list
->next
; use_list
= module_list
)
840 module_list
= use_list
->next
;
847 gfc_error ("Syntax error in SUBMODULE statement at %C");
852 /* Given a name and a number, inst, return the inst name
853 under which to load this symbol. Returns NULL if this
854 symbol shouldn't be loaded. If inst is zero, returns
855 the number of instances of this name. If interface is
856 true, a user-defined operator is sought, otherwise only
857 non-operators are sought. */
860 find_use_name_n (const char *name
, int *inst
, bool interface
)
863 const char *low_name
= NULL
;
866 /* For derived types. */
867 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
868 low_name
= gfc_dt_lower_string (name
);
871 for (u
= gfc_rename_list
; u
; u
= u
->next
)
873 if ((!low_name
&& strcmp (u
->use_name
, name
) != 0)
874 || (low_name
&& strcmp (u
->use_name
, low_name
) != 0)
875 || (u
->op
== INTRINSIC_USER
&& !interface
)
876 || (u
->op
!= INTRINSIC_USER
&& interface
))
889 return only_flag
? NULL
: name
;
895 if (u
->local_name
[0] == '\0')
897 return gfc_dt_upper_string (u
->local_name
);
900 return (u
->local_name
[0] != '\0') ? u
->local_name
: name
;
904 /* Given a name, return the name under which to load this symbol.
905 Returns NULL if this symbol shouldn't be loaded. */
908 find_use_name (const char *name
, bool interface
)
911 return find_use_name_n (name
, &i
, interface
);
915 /* Given a real name, return the number of use names associated with it. */
918 number_use_names (const char *name
, bool interface
)
921 find_use_name_n (name
, &i
, interface
);
926 /* Try to find the operator in the current list. */
928 static gfc_use_rename
*
929 find_use_operator (gfc_intrinsic_op op
)
933 for (u
= gfc_rename_list
; u
; u
= u
->next
)
941 /*****************************************************************/
943 /* The next couple of subroutines maintain a tree used to avoid a
944 brute-force search for a combination of true name and module name.
945 While symtree names, the name that a particular symbol is known by
946 can changed with USE statements, we still have to keep track of the
947 true names to generate the correct reference, and also avoid
948 loading the same real symbol twice in a program unit.
950 When we start reading, the true name tree is built and maintained
951 as symbols are read. The tree is searched as we load new symbols
952 to see if it already exists someplace in the namespace. */
954 typedef struct true_name
956 BBT_HEADER (true_name
);
962 static true_name
*true_name_root
;
965 /* Compare two true_name structures. */
968 compare_true_names (void *_t1
, void *_t2
)
973 t1
= (true_name
*) _t1
;
974 t2
= (true_name
*) _t2
;
976 c
= ((t1
->sym
->module
> t2
->sym
->module
)
977 - (t1
->sym
->module
< t2
->sym
->module
));
981 return strcmp (t1
->name
, t2
->name
);
985 /* Given a true name, search the true name tree to see if it exists
986 within the main namespace. */
989 find_true_name (const char *name
, const char *module
)
995 t
.name
= gfc_get_string ("%s", name
);
997 sym
.module
= gfc_get_string ("%s", module
);
1005 c
= compare_true_names ((void *) (&t
), (void *) p
);
1009 p
= (c
< 0) ? p
->left
: p
->right
;
1016 /* Given a gfc_symbol pointer that is not in the true name tree, add it. */
1019 add_true_name (gfc_symbol
*sym
)
1023 t
= XCNEW (true_name
);
1025 if (gfc_fl_struct (sym
->attr
.flavor
))
1026 t
->name
= gfc_dt_upper_string (sym
->name
);
1028 t
->name
= sym
->name
;
1030 gfc_insert_bbt (&true_name_root
, t
, compare_true_names
);
1034 /* Recursive function to build the initial true name tree by
1035 recursively traversing the current namespace. */
1038 build_tnt (gfc_symtree
*st
)
1044 build_tnt (st
->left
);
1045 build_tnt (st
->right
);
1047 if (gfc_fl_struct (st
->n
.sym
->attr
.flavor
))
1048 name
= gfc_dt_upper_string (st
->n
.sym
->name
);
1050 name
= st
->n
.sym
->name
;
1052 if (find_true_name (name
, st
->n
.sym
->module
) != NULL
)
1055 add_true_name (st
->n
.sym
);
1059 /* Initialize the true name tree with the current namespace. */
1062 init_true_name_tree (void)
1064 true_name_root
= NULL
;
1065 build_tnt (gfc_current_ns
->sym_root
);
1069 /* Recursively free a true name tree node. */
1072 free_true_name (true_name
*t
)
1076 free_true_name (t
->left
);
1077 free_true_name (t
->right
);
1083 /*****************************************************************/
1085 /* Module reading and writing. */
1087 /* The following are versions similar to the ones in scanner.cc, but
1088 for dealing with compressed module files. */
1091 gzopen_included_file_1 (const char *name
, gfc_directorylist
*list
,
1092 bool module
, bool system
)
1095 gfc_directorylist
*p
;
1098 for (p
= list
; p
; p
= p
->next
)
1100 if (module
&& !p
->use_for_modules
)
1103 fullname
= (char *) alloca(strlen (p
->path
) + strlen (name
) + 2);
1104 strcpy (fullname
, p
->path
);
1105 strcat (fullname
, "/");
1106 strcat (fullname
, name
);
1108 f
= gzopen (fullname
, "r");
1111 if (gfc_cpp_makedep ())
1112 gfc_cpp_add_dep (fullname
, system
);
1114 free (module_fullpath
);
1115 module_fullpath
= xstrdup (fullname
);
1124 gzopen_included_file (const char *name
, bool include_cwd
, bool module
)
1128 if (IS_ABSOLUTE_PATH (name
) || include_cwd
)
1130 f
= gzopen (name
, "r");
1133 if (gfc_cpp_makedep ())
1134 gfc_cpp_add_dep (name
, false);
1136 free (module_fullpath
);
1137 module_fullpath
= xstrdup (name
);
1142 f
= gzopen_included_file_1 (name
, include_dirs
, module
, false);
1148 gzopen_intrinsic_module (const char* name
)
1152 if (IS_ABSOLUTE_PATH (name
))
1154 f
= gzopen (name
, "r");
1157 if (gfc_cpp_makedep ())
1158 gfc_cpp_add_dep (name
, true);
1160 free (module_fullpath
);
1161 module_fullpath
= xstrdup (name
);
1166 f
= gzopen_included_file_1 (name
, intrinsic_modules_dirs
, true, true);
1174 ATOM_NAME
, ATOM_LPAREN
, ATOM_RPAREN
, ATOM_INTEGER
, ATOM_STRING
1177 static atom_type last_atom
;
1180 /* The name buffer must be at least as long as a symbol name. Right
1181 now it's not clear how we're going to store numeric constants--
1182 probably as a hexadecimal string, since this will allow the exact
1183 number to be preserved (this can't be done by a decimal
1184 representation). Worry about that later. TODO! */
1186 #define MAX_ATOM_SIZE 100
1188 static HOST_WIDE_INT atom_int
;
1189 static char *atom_string
, atom_name
[MAX_ATOM_SIZE
];
1192 /* Report problems with a module. Error reporting is not very
1193 elaborate, since this sorts of errors shouldn't really happen.
1194 This subroutine never returns. */
1196 static void bad_module (const char *) ATTRIBUTE_NORETURN
;
1199 bad_module (const char *msgid
)
1201 XDELETEVEC (module_content
);
1202 module_content
= NULL
;
1207 gfc_fatal_error ("Reading module %qs at line %d column %d: %s",
1208 module_fullpath
, module_line
, module_column
, msgid
);
1211 gfc_fatal_error ("Writing module %qs at line %d column %d: %s",
1212 module_name
, module_line
, module_column
, msgid
);
1215 gfc_fatal_error ("Module %qs at line %d column %d: %s",
1216 module_name
, module_line
, module_column
, msgid
);
1222 /* Set the module's input pointer. */
1225 set_module_locus (module_locus
*m
)
1227 module_column
= m
->column
;
1228 module_line
= m
->line
;
1229 module_pos
= m
->pos
;
1233 /* Get the module's input pointer so that we can restore it later. */
1236 get_module_locus (module_locus
*m
)
1238 m
->column
= module_column
;
1239 m
->line
= module_line
;
1240 m
->pos
= module_pos
;
1243 /* Peek at the next character in the module. */
1246 module_peek_char (void)
1248 return module_content
[module_pos
];
1251 /* Get the next character in the module, updating our reckoning of
1257 const char c
= module_content
[module_pos
++];
1259 bad_module ("Unexpected EOF");
1261 prev_module_line
= module_line
;
1262 prev_module_column
= module_column
;
1274 /* Unget a character while remembering the line and column. Works for
1275 a single character only. */
1278 module_unget_char (void)
1280 module_line
= prev_module_line
;
1281 module_column
= prev_module_column
;
1285 /* Parse a string constant. The delimiter is guaranteed to be a
1295 atom_string
= XNEWVEC (char, cursz
);
1303 int c2
= module_char ();
1306 module_unget_char ();
1314 atom_string
= XRESIZEVEC (char, atom_string
, cursz
);
1316 atom_string
[len
] = c
;
1320 atom_string
= XRESIZEVEC (char, atom_string
, len
+ 1);
1321 atom_string
[len
] = '\0'; /* C-style string for debug purposes. */
1325 /* Parse an integer. Should fit in a HOST_WIDE_INT. */
1328 parse_integer (int c
)
1349 module_unget_char ();
1353 atom_int
= 10 * atom_int
+ c
- '0';
1376 if (!ISALNUM (c
) && c
!= '_' && c
!= '-')
1378 module_unget_char ();
1383 if (++len
> GFC_MAX_SYMBOL_LEN
)
1384 bad_module ("Name too long");
1392 /* Read the next atom in the module's input stream. */
1403 while (c
== ' ' || c
== '\r' || c
== '\n');
1428 return ATOM_INTEGER
;
1432 if (ISDIGIT (module_peek_char ()))
1435 return ATOM_INTEGER
;
1438 bad_module ("Bad name");
1496 bad_module ("Bad name");
1503 /* Peek at the next atom on the input. */
1514 while (c
== ' ' || c
== '\r' || c
== '\n');
1519 module_unget_char ();
1523 module_unget_char ();
1527 module_unget_char ();
1540 module_unget_char ();
1541 return ATOM_INTEGER
;
1545 if (ISDIGIT (module_peek_char ()))
1547 module_unget_char ();
1548 return ATOM_INTEGER
;
1551 bad_module ("Bad name");
1605 module_unget_char ();
1609 bad_module ("Bad name");
1614 /* Read the next atom from the input, requiring that it be a
1618 require_atom (atom_type type
)
1624 column
= module_column
;
1633 p
= _("Expected name");
1636 p
= _("Expected left parenthesis");
1639 p
= _("Expected right parenthesis");
1642 p
= _("Expected integer");
1645 p
= _("Expected string");
1648 gfc_internal_error ("require_atom(): bad atom type required");
1651 module_column
= column
;
1658 /* Given a pointer to an mstring array, require that the current input
1659 be one of the strings in the array. We return the enum value. */
1662 find_enum (const mstring
*m
)
1666 i
= gfc_string2code (m
, atom_name
);
1670 bad_module ("find_enum(): Enum not found");
1676 /* Read a string. The caller is responsible for freeing. */
1682 require_atom (ATOM_STRING
);
1689 /**************** Module output subroutines ***************************/
1691 /* Output a character to a module file. */
1694 write_char (char out
)
1696 if (gzputc (module_fp
, out
) == EOF
)
1697 gfc_fatal_error ("Error writing modules file: %s", xstrerror (errno
));
1709 /* Write an atom to a module. The line wrapping isn't perfect, but it
1710 should work most of the time. This isn't that big of a deal, since
1711 the file really isn't meant to be read by people anyway. */
1714 write_atom (atom_type atom
, const void *v
)
1718 /* Workaround -Wmaybe-uninitialized false positive during
1719 profiledbootstrap by initializing them. */
1721 HOST_WIDE_INT i
= 0;
1728 p
= (const char *) v
;
1740 i
= *((const HOST_WIDE_INT
*) v
);
1742 snprintf (buffer
, sizeof (buffer
), HOST_WIDE_INT_PRINT_DEC
, i
);
1747 gfc_internal_error ("write_atom(): Trying to write dab atom");
1751 if(p
== NULL
|| *p
== '\0')
1756 if (atom
!= ATOM_RPAREN
)
1758 if (module_column
+ len
> 72)
1763 if (last_atom
!= ATOM_LPAREN
&& module_column
!= 1)
1768 if (atom
== ATOM_STRING
)
1771 while (p
!= NULL
&& *p
)
1773 if (atom
== ATOM_STRING
&& *p
== '\'')
1778 if (atom
== ATOM_STRING
)
1786 /***************** Mid-level I/O subroutines *****************/
1788 /* These subroutines let their caller read or write atoms without
1789 caring about which of the two is actually happening. This lets a
1790 subroutine concentrate on the actual format of the data being
1793 static void mio_expr (gfc_expr
**);
1794 pointer_info
*mio_symbol_ref (gfc_symbol
**);
1795 pointer_info
*mio_interface_rest (gfc_interface
**);
1796 static void mio_symtree_ref (gfc_symtree
**);
1798 /* Read or write an enumerated value. On writing, we return the input
1799 value for the convenience of callers. We avoid using an integer
1800 pointer because enums are sometimes inside bitfields. */
1803 mio_name (int t
, const mstring
*m
)
1805 if (iomode
== IO_OUTPUT
)
1806 write_atom (ATOM_NAME
, gfc_code2string (m
, t
));
1809 require_atom (ATOM_NAME
);
1816 /* Specialization of mio_name. */
1818 #define DECL_MIO_NAME(TYPE) \
1819 static inline TYPE \
1820 MIO_NAME(TYPE) (TYPE t, const mstring *m) \
1822 return (TYPE) mio_name ((int) t, m); \
1824 #define MIO_NAME(TYPE) mio_name_##TYPE
1829 if (iomode
== IO_OUTPUT
)
1830 write_atom (ATOM_LPAREN
, NULL
);
1832 require_atom (ATOM_LPAREN
);
1839 if (iomode
== IO_OUTPUT
)
1840 write_atom (ATOM_RPAREN
, NULL
);
1842 require_atom (ATOM_RPAREN
);
1847 mio_integer (int *ip
)
1849 if (iomode
== IO_OUTPUT
)
1851 HOST_WIDE_INT hwi
= *ip
;
1852 write_atom (ATOM_INTEGER
, &hwi
);
1856 require_atom (ATOM_INTEGER
);
1862 mio_hwi (HOST_WIDE_INT
*hwi
)
1864 if (iomode
== IO_OUTPUT
)
1865 write_atom (ATOM_INTEGER
, hwi
);
1868 require_atom (ATOM_INTEGER
);
1874 /* Read or write a gfc_intrinsic_op value. */
1877 mio_intrinsic_op (gfc_intrinsic_op
* op
)
1879 /* FIXME: Would be nicer to do this via the operators symbolic name. */
1880 if (iomode
== IO_OUTPUT
)
1882 HOST_WIDE_INT converted
= (HOST_WIDE_INT
) *op
;
1883 write_atom (ATOM_INTEGER
, &converted
);
1887 require_atom (ATOM_INTEGER
);
1888 *op
= (gfc_intrinsic_op
) atom_int
;
1893 /* Read or write a character pointer that points to a string on the heap. */
1896 mio_allocated_string (const char *s
)
1898 if (iomode
== IO_OUTPUT
)
1900 write_atom (ATOM_STRING
, s
);
1905 require_atom (ATOM_STRING
);
1911 /* Functions for quoting and unquoting strings. */
1914 quote_string (const gfc_char_t
*s
, const size_t slength
)
1916 const gfc_char_t
*p
;
1920 /* Calculate the length we'll need: a backslash takes two ("\\"),
1921 non-printable characters take 10 ("\Uxxxxxxxx") and others take 1. */
1922 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1926 else if (!gfc_wide_is_printable (*p
))
1932 q
= res
= XCNEWVEC (char, len
+ 1);
1933 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1936 *q
++ = '\\', *q
++ = '\\';
1937 else if (!gfc_wide_is_printable (*p
))
1939 sprintf (q
, "\\U%08" HOST_WIDE_INT_PRINT
"x",
1940 (unsigned HOST_WIDE_INT
) *p
);
1944 *q
++ = (unsigned char) *p
;
1952 unquote_string (const char *s
)
1958 for (p
= s
, len
= 0; *p
; p
++, len
++)
1965 else if (p
[1] == 'U')
1966 p
+= 9; /* That is a "\U????????". */
1968 gfc_internal_error ("unquote_string(): got bad string");
1971 res
= gfc_get_wide_string (len
+ 1);
1972 for (i
= 0, p
= s
; i
< len
; i
++, p
++)
1977 res
[i
] = (unsigned char) *p
;
1978 else if (p
[1] == '\\')
1980 res
[i
] = (unsigned char) '\\';
1985 /* We read the 8-digits hexadecimal constant that follows. */
1990 gcc_assert (p
[1] == 'U');
1991 for (j
= 0; j
< 8; j
++)
1994 gcc_assert (sscanf (&p
[j
+2], "%01x", &n
) == 1);
2008 /* Read or write a character pointer that points to a wide string on the
2009 heap, performing quoting/unquoting of nonprintable characters using the
2010 form \U???????? (where each ? is a hexadecimal digit).
2011 Length is the length of the string, only known and used in output mode. */
2013 static const gfc_char_t
*
2014 mio_allocated_wide_string (const gfc_char_t
*s
, const size_t length
)
2016 if (iomode
== IO_OUTPUT
)
2018 char *quoted
= quote_string (s
, length
);
2019 write_atom (ATOM_STRING
, quoted
);
2025 gfc_char_t
*unquoted
;
2027 require_atom (ATOM_STRING
);
2028 unquoted
= unquote_string (atom_string
);
2035 /* Read or write a string that is in static memory. */
2038 mio_pool_string (const char **stringp
)
2040 /* TODO: one could write the string only once, and refer to it via a
2043 /* As a special case we have to deal with a NULL string. This
2044 happens for the 'module' member of 'gfc_symbol's that are not in a
2045 module. We read / write these as the empty string. */
2046 if (iomode
== IO_OUTPUT
)
2048 const char *p
= *stringp
== NULL
? "" : *stringp
;
2049 write_atom (ATOM_STRING
, p
);
2053 require_atom (ATOM_STRING
);
2054 *stringp
= (atom_string
[0] == '\0'
2055 ? NULL
: gfc_get_string ("%s", atom_string
));
2061 /* Read or write a string that is inside of some already-allocated
2065 mio_internal_string (char *string
)
2067 if (iomode
== IO_OUTPUT
)
2068 write_atom (ATOM_STRING
, string
);
2071 require_atom (ATOM_STRING
);
2072 strcpy (string
, atom_string
);
2079 { AB_ALLOCATABLE
, AB_DIMENSION
, AB_EXTERNAL
, AB_INTRINSIC
, AB_OPTIONAL
,
2080 AB_POINTER
, AB_TARGET
, AB_DUMMY
, AB_RESULT
, AB_DATA
,
2081 AB_IN_NAMELIST
, AB_IN_COMMON
, AB_FUNCTION
, AB_SUBROUTINE
, AB_SEQUENCE
,
2082 AB_ELEMENTAL
, AB_PURE
, AB_RECURSIVE
, AB_GENERIC
, AB_ALWAYS_EXPLICIT
,
2083 AB_CRAY_POINTER
, AB_CRAY_POINTEE
, AB_THREADPRIVATE
,
2084 AB_ALLOC_COMP
, AB_POINTER_COMP
, AB_PROC_POINTER_COMP
, AB_PRIVATE_COMP
,
2085 AB_VALUE
, AB_VOLATILE
, AB_PROTECTED
, AB_LOCK_COMP
, AB_EVENT_COMP
,
2086 AB_IS_BIND_C
, AB_IS_C_INTEROP
, AB_IS_ISO_C
, AB_ABSTRACT
, AB_ZERO_COMP
,
2087 AB_IS_CLASS
, AB_PROCEDURE
, AB_PROC_POINTER
, AB_ASYNCHRONOUS
, AB_CODIMENSION
,
2088 AB_COARRAY_COMP
, AB_VTYPE
, AB_VTAB
, AB_CONTIGUOUS
, AB_CLASS_POINTER
,
2089 AB_IMPLICIT_PURE
, AB_ARTIFICIAL
, AB_UNLIMITED_POLY
, AB_OMP_DECLARE_TARGET
,
2090 AB_ARRAY_OUTER_DEPENDENCY
, AB_MODULE_PROCEDURE
, AB_OACC_DECLARE_CREATE
,
2091 AB_OACC_DECLARE_COPYIN
, AB_OACC_DECLARE_DEVICEPTR
,
2092 AB_OACC_DECLARE_DEVICE_RESIDENT
, AB_OACC_DECLARE_LINK
,
2093 AB_OMP_DECLARE_TARGET_LINK
, AB_PDT_KIND
, AB_PDT_LEN
, AB_PDT_TYPE
,
2094 AB_PDT_TEMPLATE
, AB_PDT_ARRAY
, AB_PDT_STRING
,
2095 AB_OACC_ROUTINE_LOP_GANG
, AB_OACC_ROUTINE_LOP_WORKER
,
2096 AB_OACC_ROUTINE_LOP_VECTOR
, AB_OACC_ROUTINE_LOP_SEQ
,
2097 AB_OACC_ROUTINE_NOHOST
,
2098 AB_OMP_REQ_REVERSE_OFFLOAD
, AB_OMP_REQ_UNIFIED_ADDRESS
, AB_OMP_REQ_SELF_MAPS
,
2099 AB_OMP_REQ_UNIFIED_SHARED_MEMORY
, AB_OMP_REQ_DYNAMIC_ALLOCATORS
,
2100 AB_OMP_REQ_MEM_ORDER_SEQ_CST
, AB_OMP_REQ_MEM_ORDER_ACQ_REL
,
2101 AB_OMP_REQ_MEM_ORDER_ACQUIRE
, AB_OMP_REQ_MEM_ORDER_RELEASE
,
2102 AB_OMP_REQ_MEM_ORDER_RELAXED
, AB_OMP_DEVICE_TYPE_NOHOST
,
2103 AB_OMP_DEVICE_TYPE_HOST
, AB_OMP_DEVICE_TYPE_ANY
2106 static const mstring attr_bits
[] =
2108 minit ("ALLOCATABLE", AB_ALLOCATABLE
),
2109 minit ("ARTIFICIAL", AB_ARTIFICIAL
),
2110 minit ("ASYNCHRONOUS", AB_ASYNCHRONOUS
),
2111 minit ("DIMENSION", AB_DIMENSION
),
2112 minit ("CODIMENSION", AB_CODIMENSION
),
2113 minit ("CONTIGUOUS", AB_CONTIGUOUS
),
2114 minit ("EXTERNAL", AB_EXTERNAL
),
2115 minit ("INTRINSIC", AB_INTRINSIC
),
2116 minit ("OPTIONAL", AB_OPTIONAL
),
2117 minit ("POINTER", AB_POINTER
),
2118 minit ("VOLATILE", AB_VOLATILE
),
2119 minit ("TARGET", AB_TARGET
),
2120 minit ("THREADPRIVATE", AB_THREADPRIVATE
),
2121 minit ("DUMMY", AB_DUMMY
),
2122 minit ("RESULT", AB_RESULT
),
2123 minit ("DATA", AB_DATA
),
2124 minit ("IN_NAMELIST", AB_IN_NAMELIST
),
2125 minit ("IN_COMMON", AB_IN_COMMON
),
2126 minit ("FUNCTION", AB_FUNCTION
),
2127 minit ("SUBROUTINE", AB_SUBROUTINE
),
2128 minit ("SEQUENCE", AB_SEQUENCE
),
2129 minit ("ELEMENTAL", AB_ELEMENTAL
),
2130 minit ("PURE", AB_PURE
),
2131 minit ("RECURSIVE", AB_RECURSIVE
),
2132 minit ("GENERIC", AB_GENERIC
),
2133 minit ("ALWAYS_EXPLICIT", AB_ALWAYS_EXPLICIT
),
2134 minit ("CRAY_POINTER", AB_CRAY_POINTER
),
2135 minit ("CRAY_POINTEE", AB_CRAY_POINTEE
),
2136 minit ("IS_BIND_C", AB_IS_BIND_C
),
2137 minit ("IS_C_INTEROP", AB_IS_C_INTEROP
),
2138 minit ("IS_ISO_C", AB_IS_ISO_C
),
2139 minit ("VALUE", AB_VALUE
),
2140 minit ("ALLOC_COMP", AB_ALLOC_COMP
),
2141 minit ("COARRAY_COMP", AB_COARRAY_COMP
),
2142 minit ("LOCK_COMP", AB_LOCK_COMP
),
2143 minit ("EVENT_COMP", AB_EVENT_COMP
),
2144 minit ("POINTER_COMP", AB_POINTER_COMP
),
2145 minit ("PROC_POINTER_COMP", AB_PROC_POINTER_COMP
),
2146 minit ("PRIVATE_COMP", AB_PRIVATE_COMP
),
2147 minit ("ZERO_COMP", AB_ZERO_COMP
),
2148 minit ("PROTECTED", AB_PROTECTED
),
2149 minit ("ABSTRACT", AB_ABSTRACT
),
2150 minit ("IS_CLASS", AB_IS_CLASS
),
2151 minit ("PROCEDURE", AB_PROCEDURE
),
2152 minit ("PROC_POINTER", AB_PROC_POINTER
),
2153 minit ("VTYPE", AB_VTYPE
),
2154 minit ("VTAB", AB_VTAB
),
2155 minit ("CLASS_POINTER", AB_CLASS_POINTER
),
2156 minit ("IMPLICIT_PURE", AB_IMPLICIT_PURE
),
2157 minit ("UNLIMITED_POLY", AB_UNLIMITED_POLY
),
2158 minit ("OMP_DECLARE_TARGET", AB_OMP_DECLARE_TARGET
),
2159 minit ("ARRAY_OUTER_DEPENDENCY", AB_ARRAY_OUTER_DEPENDENCY
),
2160 minit ("MODULE_PROCEDURE", AB_MODULE_PROCEDURE
),
2161 minit ("OACC_DECLARE_CREATE", AB_OACC_DECLARE_CREATE
),
2162 minit ("OACC_DECLARE_COPYIN", AB_OACC_DECLARE_COPYIN
),
2163 minit ("OACC_DECLARE_DEVICEPTR", AB_OACC_DECLARE_DEVICEPTR
),
2164 minit ("OACC_DECLARE_DEVICE_RESIDENT", AB_OACC_DECLARE_DEVICE_RESIDENT
),
2165 minit ("OACC_DECLARE_LINK", AB_OACC_DECLARE_LINK
),
2166 minit ("OMP_DECLARE_TARGET_LINK", AB_OMP_DECLARE_TARGET_LINK
),
2167 minit ("PDT_KIND", AB_PDT_KIND
),
2168 minit ("PDT_LEN", AB_PDT_LEN
),
2169 minit ("PDT_TYPE", AB_PDT_TYPE
),
2170 minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE
),
2171 minit ("PDT_ARRAY", AB_PDT_ARRAY
),
2172 minit ("PDT_STRING", AB_PDT_STRING
),
2173 minit ("OACC_ROUTINE_LOP_GANG", AB_OACC_ROUTINE_LOP_GANG
),
2174 minit ("OACC_ROUTINE_LOP_WORKER", AB_OACC_ROUTINE_LOP_WORKER
),
2175 minit ("OACC_ROUTINE_LOP_VECTOR", AB_OACC_ROUTINE_LOP_VECTOR
),
2176 minit ("OACC_ROUTINE_LOP_SEQ", AB_OACC_ROUTINE_LOP_SEQ
),
2177 minit ("OACC_ROUTINE_NOHOST", AB_OACC_ROUTINE_NOHOST
),
2178 minit ("OMP_REQ_REVERSE_OFFLOAD", AB_OMP_REQ_REVERSE_OFFLOAD
),
2179 minit ("OMP_REQ_UNIFIED_ADDRESS", AB_OMP_REQ_UNIFIED_ADDRESS
),
2180 minit ("OMP_REQ_UNIFIED_SHARED_MEMORY", AB_OMP_REQ_UNIFIED_SHARED_MEMORY
),
2181 minit ("OMP_REQ_SELF_MAPS", AB_OMP_REQ_SELF_MAPS
),
2182 minit ("OMP_REQ_DYNAMIC_ALLOCATORS", AB_OMP_REQ_DYNAMIC_ALLOCATORS
),
2183 minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST
),
2184 minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL
),
2185 minit ("OMP_REQ_MEM_ORDER_ACQUIRE", AB_OMP_REQ_MEM_ORDER_ACQUIRE
),
2186 minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED
),
2187 minit ("OMP_REQ_MEM_ORDER_RELEASE", AB_OMP_REQ_MEM_ORDER_RELEASE
),
2188 minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST
),
2189 minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST
),
2190 minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY
),
2194 /* For binding attributes. */
2195 static const mstring binding_passing
[] =
2198 minit ("NOPASS", 1),
2201 static const mstring binding_overriding
[] =
2203 minit ("OVERRIDABLE", 0),
2204 minit ("NON_OVERRIDABLE", 1),
2205 minit ("DEFERRED", 2),
2208 static const mstring binding_generic
[] =
2210 minit ("SPECIFIC", 0),
2211 minit ("GENERIC", 1),
2214 static const mstring binding_ppc
[] =
2216 minit ("NO_PPC", 0),
2221 /* Specialization of mio_name. */
2222 DECL_MIO_NAME (ab_attribute
)
2223 DECL_MIO_NAME (ar_type
)
2224 DECL_MIO_NAME (array_type
)
2226 DECL_MIO_NAME (expr_t
)
2227 DECL_MIO_NAME (gfc_access
)
2228 DECL_MIO_NAME (gfc_intrinsic_op
)
2229 DECL_MIO_NAME (ifsrc
)
2230 DECL_MIO_NAME (save_state
)
2231 DECL_MIO_NAME (procedure_type
)
2232 DECL_MIO_NAME (ref_type
)
2233 DECL_MIO_NAME (sym_flavor
)
2234 DECL_MIO_NAME (sym_intent
)
2235 DECL_MIO_NAME (inquiry_type
)
2236 #undef DECL_MIO_NAME
2238 /* Verify OACC_ROUTINE_LOP_NONE. */
2241 verify_OACC_ROUTINE_LOP_NONE (enum oacc_routine_lop lop
)
2243 if (lop
!= OACC_ROUTINE_LOP_NONE
)
2244 bad_module ("Unsupported: multiple OpenACC 'routine' levels of parallelism");
2247 /* Symbol attributes are stored in list with the first three elements
2248 being the enumerated fields, while the remaining elements (if any)
2249 indicate the individual attribute bits. The access field is not
2250 saved-- it controls what symbols are exported when a module is
2254 mio_symbol_attribute (symbol_attribute
*attr
)
2257 unsigned ext_attr
,extension_level
;
2261 attr
->flavor
= MIO_NAME (sym_flavor
) (attr
->flavor
, flavors
);
2262 attr
->intent
= MIO_NAME (sym_intent
) (attr
->intent
, intents
);
2263 attr
->proc
= MIO_NAME (procedure_type
) (attr
->proc
, procedures
);
2264 attr
->if_source
= MIO_NAME (ifsrc
) (attr
->if_source
, ifsrc_types
);
2265 attr
->save
= MIO_NAME (save_state
) (attr
->save
, save_status
);
2267 ext_attr
= attr
->ext_attr
;
2268 mio_integer ((int *) &ext_attr
);
2269 attr
->ext_attr
= ext_attr
;
2271 extension_level
= attr
->extension
;
2272 mio_integer ((int *) &extension_level
);
2273 attr
->extension
= extension_level
;
2275 if (iomode
== IO_OUTPUT
)
2277 if (attr
->allocatable
)
2278 MIO_NAME (ab_attribute
) (AB_ALLOCATABLE
, attr_bits
);
2279 if (attr
->artificial
)
2280 MIO_NAME (ab_attribute
) (AB_ARTIFICIAL
, attr_bits
);
2281 if (attr
->asynchronous
)
2282 MIO_NAME (ab_attribute
) (AB_ASYNCHRONOUS
, attr_bits
);
2283 if (attr
->dimension
)
2284 MIO_NAME (ab_attribute
) (AB_DIMENSION
, attr_bits
);
2285 if (attr
->codimension
)
2286 MIO_NAME (ab_attribute
) (AB_CODIMENSION
, attr_bits
);
2287 if (attr
->contiguous
)
2288 MIO_NAME (ab_attribute
) (AB_CONTIGUOUS
, attr_bits
);
2290 MIO_NAME (ab_attribute
) (AB_EXTERNAL
, attr_bits
);
2291 if (attr
->intrinsic
)
2292 MIO_NAME (ab_attribute
) (AB_INTRINSIC
, attr_bits
);
2294 MIO_NAME (ab_attribute
) (AB_OPTIONAL
, attr_bits
);
2296 MIO_NAME (ab_attribute
) (AB_POINTER
, attr_bits
);
2297 if (attr
->class_pointer
)
2298 MIO_NAME (ab_attribute
) (AB_CLASS_POINTER
, attr_bits
);
2299 if (attr
->is_protected
)
2300 MIO_NAME (ab_attribute
) (AB_PROTECTED
, attr_bits
);
2302 MIO_NAME (ab_attribute
) (AB_VALUE
, attr_bits
);
2303 if (attr
->volatile_
)
2304 MIO_NAME (ab_attribute
) (AB_VOLATILE
, attr_bits
);
2306 MIO_NAME (ab_attribute
) (AB_TARGET
, attr_bits
);
2307 if (attr
->threadprivate
)
2308 MIO_NAME (ab_attribute
) (AB_THREADPRIVATE
, attr_bits
);
2310 MIO_NAME (ab_attribute
) (AB_DUMMY
, attr_bits
);
2312 MIO_NAME (ab_attribute
) (AB_RESULT
, attr_bits
);
2313 /* We deliberately don't preserve the "entry" flag. */
2316 MIO_NAME (ab_attribute
) (AB_DATA
, attr_bits
);
2317 if (attr
->in_namelist
)
2318 MIO_NAME (ab_attribute
) (AB_IN_NAMELIST
, attr_bits
);
2319 if (attr
->in_common
)
2320 MIO_NAME (ab_attribute
) (AB_IN_COMMON
, attr_bits
);
2323 MIO_NAME (ab_attribute
) (AB_FUNCTION
, attr_bits
);
2324 if (attr
->subroutine
)
2325 MIO_NAME (ab_attribute
) (AB_SUBROUTINE
, attr_bits
);
2327 MIO_NAME (ab_attribute
) (AB_GENERIC
, attr_bits
);
2329 MIO_NAME (ab_attribute
) (AB_ABSTRACT
, attr_bits
);
2332 MIO_NAME (ab_attribute
) (AB_SEQUENCE
, attr_bits
);
2333 if (attr
->elemental
)
2334 MIO_NAME (ab_attribute
) (AB_ELEMENTAL
, attr_bits
);
2336 MIO_NAME (ab_attribute
) (AB_PURE
, attr_bits
);
2337 if (attr
->implicit_pure
)
2338 MIO_NAME (ab_attribute
) (AB_IMPLICIT_PURE
, attr_bits
);
2339 if (attr
->unlimited_polymorphic
)
2340 MIO_NAME (ab_attribute
) (AB_UNLIMITED_POLY
, attr_bits
);
2341 if (attr
->recursive
)
2342 MIO_NAME (ab_attribute
) (AB_RECURSIVE
, attr_bits
);
2343 if (attr
->always_explicit
)
2344 MIO_NAME (ab_attribute
) (AB_ALWAYS_EXPLICIT
, attr_bits
);
2345 if (attr
->cray_pointer
)
2346 MIO_NAME (ab_attribute
) (AB_CRAY_POINTER
, attr_bits
);
2347 if (attr
->cray_pointee
)
2348 MIO_NAME (ab_attribute
) (AB_CRAY_POINTEE
, attr_bits
);
2349 if (attr
->is_bind_c
)
2350 MIO_NAME(ab_attribute
) (AB_IS_BIND_C
, attr_bits
);
2351 if (attr
->is_c_interop
)
2352 MIO_NAME(ab_attribute
) (AB_IS_C_INTEROP
, attr_bits
);
2354 MIO_NAME(ab_attribute
) (AB_IS_ISO_C
, attr_bits
);
2355 if (attr
->alloc_comp
)
2356 MIO_NAME (ab_attribute
) (AB_ALLOC_COMP
, attr_bits
);
2357 if (attr
->pointer_comp
)
2358 MIO_NAME (ab_attribute
) (AB_POINTER_COMP
, attr_bits
);
2359 if (attr
->proc_pointer_comp
)
2360 MIO_NAME (ab_attribute
) (AB_PROC_POINTER_COMP
, attr_bits
);
2361 if (attr
->private_comp
)
2362 MIO_NAME (ab_attribute
) (AB_PRIVATE_COMP
, attr_bits
);
2363 if (attr
->coarray_comp
)
2364 MIO_NAME (ab_attribute
) (AB_COARRAY_COMP
, attr_bits
);
2365 if (attr
->lock_comp
)
2366 MIO_NAME (ab_attribute
) (AB_LOCK_COMP
, attr_bits
);
2367 if (attr
->event_comp
)
2368 MIO_NAME (ab_attribute
) (AB_EVENT_COMP
, attr_bits
);
2369 if (attr
->zero_comp
)
2370 MIO_NAME (ab_attribute
) (AB_ZERO_COMP
, attr_bits
);
2372 MIO_NAME (ab_attribute
) (AB_IS_CLASS
, attr_bits
);
2373 if (attr
->procedure
)
2374 MIO_NAME (ab_attribute
) (AB_PROCEDURE
, attr_bits
);
2375 if (attr
->proc_pointer
)
2376 MIO_NAME (ab_attribute
) (AB_PROC_POINTER
, attr_bits
);
2378 MIO_NAME (ab_attribute
) (AB_VTYPE
, attr_bits
);
2380 MIO_NAME (ab_attribute
) (AB_VTAB
, attr_bits
);
2381 if (attr
->omp_declare_target
)
2382 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET
, attr_bits
);
2383 if (attr
->array_outer_dependency
)
2384 MIO_NAME (ab_attribute
) (AB_ARRAY_OUTER_DEPENDENCY
, attr_bits
);
2385 if (attr
->module_procedure
)
2386 MIO_NAME (ab_attribute
) (AB_MODULE_PROCEDURE
, attr_bits
);
2387 if (attr
->oacc_declare_create
)
2388 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_CREATE
, attr_bits
);
2389 if (attr
->oacc_declare_copyin
)
2390 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_COPYIN
, attr_bits
);
2391 if (attr
->oacc_declare_deviceptr
)
2392 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICEPTR
, attr_bits
);
2393 if (attr
->oacc_declare_device_resident
)
2394 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICE_RESIDENT
, attr_bits
);
2395 if (attr
->oacc_declare_link
)
2396 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_LINK
, attr_bits
);
2397 if (attr
->omp_declare_target_link
)
2398 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET_LINK
, attr_bits
);
2400 MIO_NAME (ab_attribute
) (AB_PDT_KIND
, attr_bits
);
2402 MIO_NAME (ab_attribute
) (AB_PDT_LEN
, attr_bits
);
2404 MIO_NAME (ab_attribute
) (AB_PDT_TYPE
, attr_bits
);
2405 if (attr
->pdt_template
)
2406 MIO_NAME (ab_attribute
) (AB_PDT_TEMPLATE
, attr_bits
);
2407 if (attr
->pdt_array
)
2408 MIO_NAME (ab_attribute
) (AB_PDT_ARRAY
, attr_bits
);
2409 if (attr
->pdt_string
)
2410 MIO_NAME (ab_attribute
) (AB_PDT_STRING
, attr_bits
);
2411 switch (attr
->oacc_routine_lop
)
2413 case OACC_ROUTINE_LOP_NONE
:
2414 /* This is the default anyway, and for maintaining compatibility with
2415 the current MOD_VERSION, we're not emitting anything in that
2418 case OACC_ROUTINE_LOP_GANG
:
2419 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_GANG
, attr_bits
);
2421 case OACC_ROUTINE_LOP_WORKER
:
2422 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_WORKER
, attr_bits
);
2424 case OACC_ROUTINE_LOP_VECTOR
:
2425 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_VECTOR
, attr_bits
);
2427 case OACC_ROUTINE_LOP_SEQ
:
2428 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_SEQ
, attr_bits
);
2430 case OACC_ROUTINE_LOP_ERROR
:
2431 /* ... intentionally omitted here; it's only used internally. */
2435 if (attr
->oacc_routine_nohost
)
2436 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_NOHOST
, attr_bits
);
2438 if (attr
->flavor
== FL_MODULE
&& gfc_current_ns
->omp_requires
)
2440 if (gfc_current_ns
->omp_requires
& OMP_REQ_REVERSE_OFFLOAD
)
2441 MIO_NAME (ab_attribute
) (AB_OMP_REQ_REVERSE_OFFLOAD
, attr_bits
);
2442 if (gfc_current_ns
->omp_requires
& OMP_REQ_UNIFIED_ADDRESS
)
2443 MIO_NAME (ab_attribute
) (AB_OMP_REQ_UNIFIED_ADDRESS
, attr_bits
);
2444 if (gfc_current_ns
->omp_requires
& OMP_REQ_UNIFIED_SHARED_MEMORY
)
2445 MIO_NAME (ab_attribute
) (AB_OMP_REQ_UNIFIED_SHARED_MEMORY
, attr_bits
);
2446 if (gfc_current_ns
->omp_requires
& OMP_REQ_SELF_MAPS
)
2447 MIO_NAME (ab_attribute
) (AB_OMP_REQ_SELF_MAPS
, attr_bits
);
2448 if (gfc_current_ns
->omp_requires
& OMP_REQ_DYNAMIC_ALLOCATORS
)
2449 MIO_NAME (ab_attribute
) (AB_OMP_REQ_DYNAMIC_ALLOCATORS
, attr_bits
);
2450 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2451 == OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
)
2452 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_SEQ_CST
, attr_bits
);
2453 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2454 == OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
)
2455 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_ACQ_REL
, attr_bits
);
2456 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2457 == OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE
)
2458 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_ACQUIRE
, attr_bits
);
2459 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2460 == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
)
2461 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_RELAXED
, attr_bits
);
2462 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2463 == OMP_REQ_ATOMIC_MEM_ORDER_RELEASE
)
2464 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_RELEASE
, attr_bits
);
2466 switch (attr
->omp_device_type
)
2468 case OMP_DEVICE_TYPE_UNSET
:
2470 case OMP_DEVICE_TYPE_HOST
:
2471 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_HOST
, attr_bits
);
2473 case OMP_DEVICE_TYPE_NOHOST
:
2474 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_NOHOST
, attr_bits
);
2476 case OMP_DEVICE_TYPE_ANY
:
2477 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_ANY
, attr_bits
);
2489 if (t
== ATOM_RPAREN
)
2492 bad_module ("Expected attribute bit name");
2494 switch ((ab_attribute
) find_enum (attr_bits
))
2496 case AB_ALLOCATABLE
:
2497 attr
->allocatable
= 1;
2500 attr
->artificial
= 1;
2502 case AB_ASYNCHRONOUS
:
2503 attr
->asynchronous
= 1;
2506 attr
->dimension
= 1;
2508 case AB_CODIMENSION
:
2509 attr
->codimension
= 1;
2512 attr
->contiguous
= 1;
2518 attr
->intrinsic
= 1;
2526 case AB_CLASS_POINTER
:
2527 attr
->class_pointer
= 1;
2530 attr
->is_protected
= 1;
2536 attr
->volatile_
= 1;
2541 case AB_THREADPRIVATE
:
2542 attr
->threadprivate
= 1;
2553 case AB_IN_NAMELIST
:
2554 attr
->in_namelist
= 1;
2557 attr
->in_common
= 1;
2563 attr
->subroutine
= 1;
2575 attr
->elemental
= 1;
2580 case AB_IMPLICIT_PURE
:
2581 attr
->implicit_pure
= 1;
2583 case AB_UNLIMITED_POLY
:
2584 attr
->unlimited_polymorphic
= 1;
2587 attr
->recursive
= 1;
2589 case AB_ALWAYS_EXPLICIT
:
2590 attr
->always_explicit
= 1;
2592 case AB_CRAY_POINTER
:
2593 attr
->cray_pointer
= 1;
2595 case AB_CRAY_POINTEE
:
2596 attr
->cray_pointee
= 1;
2599 attr
->is_bind_c
= 1;
2601 case AB_IS_C_INTEROP
:
2602 attr
->is_c_interop
= 1;
2608 attr
->alloc_comp
= 1;
2610 case AB_COARRAY_COMP
:
2611 attr
->coarray_comp
= 1;
2614 attr
->lock_comp
= 1;
2617 attr
->event_comp
= 1;
2619 case AB_POINTER_COMP
:
2620 attr
->pointer_comp
= 1;
2622 case AB_PROC_POINTER_COMP
:
2623 attr
->proc_pointer_comp
= 1;
2625 case AB_PRIVATE_COMP
:
2626 attr
->private_comp
= 1;
2629 attr
->zero_comp
= 1;
2635 attr
->procedure
= 1;
2637 case AB_PROC_POINTER
:
2638 attr
->proc_pointer
= 1;
2646 case AB_OMP_DECLARE_TARGET
:
2647 attr
->omp_declare_target
= 1;
2649 case AB_OMP_DECLARE_TARGET_LINK
:
2650 attr
->omp_declare_target_link
= 1;
2652 case AB_ARRAY_OUTER_DEPENDENCY
:
2653 attr
->array_outer_dependency
=1;
2655 case AB_MODULE_PROCEDURE
:
2656 attr
->module_procedure
=1;
2658 case AB_OACC_DECLARE_CREATE
:
2659 attr
->oacc_declare_create
= 1;
2661 case AB_OACC_DECLARE_COPYIN
:
2662 attr
->oacc_declare_copyin
= 1;
2664 case AB_OACC_DECLARE_DEVICEPTR
:
2665 attr
->oacc_declare_deviceptr
= 1;
2667 case AB_OACC_DECLARE_DEVICE_RESIDENT
:
2668 attr
->oacc_declare_device_resident
= 1;
2670 case AB_OACC_DECLARE_LINK
:
2671 attr
->oacc_declare_link
= 1;
2682 case AB_PDT_TEMPLATE
:
2683 attr
->pdt_template
= 1;
2686 attr
->pdt_array
= 1;
2689 attr
->pdt_string
= 1;
2691 case AB_OACC_ROUTINE_LOP_GANG
:
2692 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2693 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_GANG
;
2695 case AB_OACC_ROUTINE_LOP_WORKER
:
2696 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2697 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_WORKER
;
2699 case AB_OACC_ROUTINE_LOP_VECTOR
:
2700 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2701 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_VECTOR
;
2703 case AB_OACC_ROUTINE_LOP_SEQ
:
2704 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2705 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_SEQ
;
2707 case AB_OACC_ROUTINE_NOHOST
:
2708 attr
->oacc_routine_nohost
= 1;
2710 case AB_OMP_REQ_REVERSE_OFFLOAD
:
2711 gfc_omp_requires_add_clause (OMP_REQ_REVERSE_OFFLOAD
,
2716 case AB_OMP_REQ_UNIFIED_ADDRESS
:
2717 gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_ADDRESS
,
2722 case AB_OMP_REQ_UNIFIED_SHARED_MEMORY
:
2723 gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_SHARED_MEMORY
,
2724 "unified_shared_memory",
2728 case AB_OMP_REQ_SELF_MAPS
:
2729 gfc_omp_requires_add_clause (OMP_REQ_SELF_MAPS
,
2734 case AB_OMP_REQ_DYNAMIC_ALLOCATORS
:
2735 gfc_omp_requires_add_clause (OMP_REQ_DYNAMIC_ALLOCATORS
,
2736 "dynamic_allocators",
2740 case AB_OMP_REQ_MEM_ORDER_SEQ_CST
:
2741 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
,
2742 "seq_cst", &gfc_current_locus
,
2745 case AB_OMP_REQ_MEM_ORDER_ACQ_REL
:
2746 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
,
2747 "acq_rel", &gfc_current_locus
,
2750 case AB_OMP_REQ_MEM_ORDER_ACQUIRE
:
2751 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE
,
2752 "acquires", &gfc_current_locus
,
2755 case AB_OMP_REQ_MEM_ORDER_RELAXED
:
2756 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
,
2757 "relaxed", &gfc_current_locus
,
2760 case AB_OMP_REQ_MEM_ORDER_RELEASE
:
2761 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELEASE
,
2762 "release", &gfc_current_locus
,
2765 case AB_OMP_DEVICE_TYPE_HOST
:
2766 attr
->omp_device_type
= OMP_DEVICE_TYPE_HOST
;
2768 case AB_OMP_DEVICE_TYPE_NOHOST
:
2769 attr
->omp_device_type
= OMP_DEVICE_TYPE_NOHOST
;
2771 case AB_OMP_DEVICE_TYPE_ANY
:
2772 attr
->omp_device_type
= OMP_DEVICE_TYPE_ANY
;
2780 static const mstring bt_types
[] = {
2781 minit ("INTEGER", BT_INTEGER
),
2782 minit ("REAL", BT_REAL
),
2783 minit ("COMPLEX", BT_COMPLEX
),
2784 minit ("LOGICAL", BT_LOGICAL
),
2785 minit ("CHARACTER", BT_CHARACTER
),
2786 minit ("UNION", BT_UNION
),
2787 minit ("DERIVED", BT_DERIVED
),
2788 minit ("CLASS", BT_CLASS
),
2789 minit ("PROCEDURE", BT_PROCEDURE
),
2790 minit ("UNKNOWN", BT_UNKNOWN
),
2791 minit ("VOID", BT_VOID
),
2792 minit ("ASSUMED", BT_ASSUMED
),
2793 minit ("UNSIGNED", BT_UNSIGNED
),
2799 mio_charlen (gfc_charlen
**clp
)
2805 if (iomode
== IO_OUTPUT
)
2809 mio_expr (&cl
->length
);
2813 if (peek_atom () != ATOM_RPAREN
)
2815 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2816 mio_expr (&cl
->length
);
2825 /* See if a name is a generated name. */
2828 check_unique_name (const char *name
)
2830 return *name
== '@';
2835 mio_typespec (gfc_typespec
*ts
)
2839 ts
->type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2841 if (!gfc_bt_struct (ts
->type
) && ts
->type
!= BT_CLASS
)
2842 mio_integer (&ts
->kind
);
2844 mio_symbol_ref (&ts
->u
.derived
);
2846 mio_symbol_ref (&ts
->interface
);
2848 /* Add info for C interop and is_iso_c. */
2849 mio_integer (&ts
->is_c_interop
);
2850 mio_integer (&ts
->is_iso_c
);
2852 /* If the typespec is for an identifier either from iso_c_binding, or
2853 a constant that was initialized to an identifier from it, use the
2854 f90_type. Otherwise, use the ts->type, since it shouldn't matter. */
2856 ts
->f90_type
= MIO_NAME (bt
) (ts
->f90_type
, bt_types
);
2858 ts
->f90_type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2860 if (ts
->type
!= BT_CHARACTER
)
2862 /* ts->u.cl is only valid for BT_CHARACTER. */
2867 mio_charlen (&ts
->u
.cl
);
2869 /* So as not to disturb the existing API, use an ATOM_NAME to
2870 transmit deferred characteristic for characters (F2003). */
2871 if (iomode
== IO_OUTPUT
)
2873 if (ts
->type
== BT_CHARACTER
&& ts
->deferred
)
2874 write_atom (ATOM_NAME
, "DEFERRED_CL");
2876 else if (peek_atom () != ATOM_RPAREN
)
2878 if (parse_atom () != ATOM_NAME
)
2879 bad_module ("Expected string");
2887 static const mstring array_spec_types
[] = {
2888 minit ("EXPLICIT", AS_EXPLICIT
),
2889 minit ("ASSUMED_RANK", AS_ASSUMED_RANK
),
2890 minit ("ASSUMED_SHAPE", AS_ASSUMED_SHAPE
),
2891 minit ("DEFERRED", AS_DEFERRED
),
2892 minit ("ASSUMED_SIZE", AS_ASSUMED_SIZE
),
2898 mio_array_spec (gfc_array_spec
**asp
)
2905 if (iomode
== IO_OUTPUT
)
2913 /* mio_integer expects nonnegative values. */
2914 rank
= as
->rank
> 0 ? as
->rank
: 0;
2915 mio_integer (&rank
);
2919 if (peek_atom () == ATOM_RPAREN
)
2925 *asp
= as
= gfc_get_array_spec ();
2926 mio_integer (&as
->rank
);
2929 mio_integer (&as
->corank
);
2930 as
->type
= MIO_NAME (array_type
) (as
->type
, array_spec_types
);
2932 if (iomode
== IO_INPUT
&& as
->type
== AS_ASSUMED_RANK
)
2934 if (iomode
== IO_INPUT
&& as
->corank
)
2935 as
->cotype
= (as
->type
== AS_DEFERRED
) ? AS_DEFERRED
: AS_EXPLICIT
;
2937 if (as
->rank
+ as
->corank
> 0)
2938 for (i
= 0; i
< as
->rank
+ as
->corank
; i
++)
2940 mio_expr (&as
->lower
[i
]);
2941 mio_expr (&as
->upper
[i
]);
2949 /* Given a pointer to an array reference structure (which lives in a
2950 gfc_ref structure), find the corresponding array specification
2951 structure. Storing the pointer in the ref structure doesn't quite
2952 work when loading from a module. Generating code for an array
2953 reference also needs more information than just the array spec. */
2955 static const mstring array_ref_types
[] = {
2956 minit ("FULL", AR_FULL
),
2957 minit ("ELEMENT", AR_ELEMENT
),
2958 minit ("SECTION", AR_SECTION
),
2964 mio_array_ref (gfc_array_ref
*ar
)
2969 ar
->type
= MIO_NAME (ar_type
) (ar
->type
, array_ref_types
);
2970 mio_integer (&ar
->dimen
);
2978 for (i
= 0; i
< ar
->dimen
; i
++)
2979 mio_expr (&ar
->start
[i
]);
2984 for (i
= 0; i
< ar
->dimen
; i
++)
2986 mio_expr (&ar
->start
[i
]);
2987 mio_expr (&ar
->end
[i
]);
2988 mio_expr (&ar
->stride
[i
]);
2994 gfc_internal_error ("mio_array_ref(): Unknown array ref");
2997 /* Unfortunately, ar->dimen_type is an anonymous enumerated type so
2998 we can't call mio_integer directly. Instead loop over each element
2999 and cast it to/from an integer. */
3000 if (iomode
== IO_OUTPUT
)
3002 for (i
= 0; i
< ar
->dimen
; i
++)
3004 HOST_WIDE_INT tmp
= (HOST_WIDE_INT
)ar
->dimen_type
[i
];
3005 write_atom (ATOM_INTEGER
, &tmp
);
3010 for (i
= 0; i
< ar
->dimen
; i
++)
3012 require_atom (ATOM_INTEGER
);
3013 ar
->dimen_type
[i
] = (enum gfc_array_ref_dimen_type
) atom_int
;
3017 if (iomode
== IO_INPUT
)
3019 ar
->where
= gfc_current_locus
;
3021 for (i
= 0; i
< ar
->dimen
; i
++)
3022 ar
->c_where
[i
] = gfc_current_locus
;
3029 /* Saves or restores a pointer. The pointer is converted back and
3030 forth from an integer. We return the pointer_info pointer so that
3031 the caller can take additional action based on the pointer type. */
3033 static pointer_info
*
3034 mio_pointer_ref (void *gp
)
3038 if (iomode
== IO_OUTPUT
)
3040 p
= get_pointer (*((char **) gp
));
3041 HOST_WIDE_INT hwi
= p
->integer
;
3042 write_atom (ATOM_INTEGER
, &hwi
);
3046 require_atom (ATOM_INTEGER
);
3047 p
= add_fixup (atom_int
, gp
);
3054 /* Save and load references to components that occur within
3055 expressions. We have to describe these references by a number and
3056 by name. The number is necessary for forward references during
3057 reading, and the name is necessary if the symbol already exists in
3058 the namespace and is not loaded again. */
3061 mio_component_ref (gfc_component
**cp
)
3065 p
= mio_pointer_ref (cp
);
3066 if (p
->type
== P_UNKNOWN
)
3067 p
->type
= P_COMPONENT
;
3071 static void mio_namespace_ref (gfc_namespace
**nsp
);
3072 static void mio_formal_arglist (gfc_formal_arglist
**formal
);
3073 static void mio_typebound_proc (gfc_typebound_proc
** proc
);
3074 static void mio_actual_arglist (gfc_actual_arglist
**ap
, bool pdt
);
3077 mio_component (gfc_component
*c
, int vtype
)
3083 if (iomode
== IO_OUTPUT
)
3085 p
= get_pointer (c
);
3086 mio_hwi (&p
->integer
);
3092 p
= get_integer (n
);
3093 associate_integer_pointer (p
, c
);
3096 if (p
->type
== P_UNKNOWN
)
3097 p
->type
= P_COMPONENT
;
3099 mio_pool_string (&c
->name
);
3100 mio_typespec (&c
->ts
);
3101 mio_array_spec (&c
->as
);
3103 /* PDT templates store the expression for the kind of a component here. */
3104 mio_expr (&c
->kind_expr
);
3106 /* PDT types store the component specification list here. */
3107 mio_actual_arglist (&c
->param_list
, true);
3109 mio_symbol_attribute (&c
->attr
);
3110 if (c
->ts
.type
== BT_CLASS
)
3111 c
->attr
.class_ok
= 1;
3112 c
->attr
.access
= MIO_NAME (gfc_access
) (c
->attr
.access
, access_types
);
3114 if (!vtype
|| strcmp (c
->name
, "_final") == 0
3115 || strcmp (c
->name
, "_hash") == 0)
3116 mio_expr (&c
->initializer
);
3118 if (c
->attr
.proc_pointer
)
3119 mio_typebound_proc (&c
->tb
);
3121 c
->loc
= gfc_current_locus
;
3128 mio_component_list (gfc_component
**cp
, int vtype
)
3130 gfc_component
*c
, *tail
;
3134 if (iomode
== IO_OUTPUT
)
3136 for (c
= *cp
; c
; c
= c
->next
)
3137 mio_component (c
, vtype
);
3146 if (peek_atom () == ATOM_RPAREN
)
3149 c
= gfc_get_component ();
3150 mio_component (c
, vtype
);
3166 mio_actual_arg (gfc_actual_arglist
*a
, bool pdt
)
3169 mio_pool_string (&a
->name
);
3170 mio_expr (&a
->expr
);
3172 mio_integer ((int *)&a
->spec_type
);
3178 mio_actual_arglist (gfc_actual_arglist
**ap
, bool pdt
)
3180 gfc_actual_arglist
*a
, *tail
;
3184 if (iomode
== IO_OUTPUT
)
3186 for (a
= *ap
; a
; a
= a
->next
)
3187 mio_actual_arg (a
, pdt
);
3196 if (peek_atom () != ATOM_LPAREN
)
3199 a
= gfc_get_actual_arglist ();
3207 mio_actual_arg (a
, pdt
);
3215 /* Read and write formal argument lists. */
3218 mio_formal_arglist (gfc_formal_arglist
**formal
)
3220 gfc_formal_arglist
*f
, *tail
;
3224 if (iomode
== IO_OUTPUT
)
3226 for (f
= *formal
; f
; f
= f
->next
)
3227 mio_symbol_ref (&f
->sym
);
3231 *formal
= tail
= NULL
;
3233 while (peek_atom () != ATOM_RPAREN
)
3235 f
= gfc_get_formal_arglist ();
3236 mio_symbol_ref (&f
->sym
);
3238 if (*formal
== NULL
)
3251 /* Save or restore a reference to a symbol node. */
3254 mio_symbol_ref (gfc_symbol
**symp
)
3258 p
= mio_pointer_ref (symp
);
3259 if (p
->type
== P_UNKNOWN
)
3262 if (iomode
== IO_OUTPUT
)
3264 if (p
->u
.wsym
.state
== UNREFERENCED
)
3265 p
->u
.wsym
.state
= NEEDS_WRITE
;
3269 if (p
->u
.rsym
.state
== UNUSED
)
3270 p
->u
.rsym
.state
= NEEDED
;
3276 /* Save or restore a reference to a symtree node. */
3279 mio_symtree_ref (gfc_symtree
**stp
)
3284 if (iomode
== IO_OUTPUT
)
3285 mio_symbol_ref (&(*stp
)->n
.sym
);
3288 require_atom (ATOM_INTEGER
);
3289 p
= get_integer (atom_int
);
3291 /* An unused equivalence member; make a symbol and a symtree
3293 if (in_load_equiv
&& p
->u
.rsym
.symtree
== NULL
)
3295 /* Since this is not used, it must have a unique name. */
3296 p
->u
.rsym
.symtree
= gfc_get_unique_symtree (gfc_current_ns
);
3298 /* Make the symbol. */
3299 if (p
->u
.rsym
.sym
== NULL
)
3301 p
->u
.rsym
.sym
= gfc_new_symbol (p
->u
.rsym
.true_name
,
3303 p
->u
.rsym
.sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
3306 p
->u
.rsym
.symtree
->n
.sym
= p
->u
.rsym
.sym
;
3307 p
->u
.rsym
.symtree
->n
.sym
->refs
++;
3308 p
->u
.rsym
.referenced
= 1;
3310 /* If the symbol is PRIVATE and in COMMON, load_commons will
3311 generate a fixup symbol, which must be associated. */
3313 resolve_fixups (p
->fixup
, p
->u
.rsym
.sym
);
3317 if (p
->type
== P_UNKNOWN
)
3320 if (p
->u
.rsym
.state
== UNUSED
)
3321 p
->u
.rsym
.state
= NEEDED
;
3323 if (p
->u
.rsym
.symtree
!= NULL
)
3325 *stp
= p
->u
.rsym
.symtree
;
3329 f
= XCNEW (fixup_t
);
3331 f
->next
= p
->u
.rsym
.stfixup
;
3332 p
->u
.rsym
.stfixup
= f
;
3334 f
->pointer
= (void **) stp
;
3341 mio_iterator (gfc_iterator
**ip
)
3347 if (iomode
== IO_OUTPUT
)
3354 if (peek_atom () == ATOM_RPAREN
)
3360 *ip
= gfc_get_iterator ();
3365 mio_expr (&iter
->var
);
3366 mio_expr (&iter
->start
);
3367 mio_expr (&iter
->end
);
3368 mio_expr (&iter
->step
);
3376 mio_constructor (gfc_constructor_base
*cp
)
3382 if (iomode
== IO_OUTPUT
)
3384 for (c
= gfc_constructor_first (*cp
); c
; c
= gfc_constructor_next (c
))
3387 mio_expr (&c
->expr
);
3388 mio_iterator (&c
->iterator
);
3394 while (peek_atom () != ATOM_RPAREN
)
3396 c
= gfc_constructor_append_expr (cp
, NULL
, NULL
);
3399 mio_expr (&c
->expr
);
3400 mio_iterator (&c
->iterator
);
3409 static const mstring ref_types
[] = {
3410 minit ("ARRAY", REF_ARRAY
),
3411 minit ("COMPONENT", REF_COMPONENT
),
3412 minit ("SUBSTRING", REF_SUBSTRING
),
3413 minit ("INQUIRY", REF_INQUIRY
),
3417 static const mstring inquiry_types
[] = {
3418 minit ("RE", INQUIRY_RE
),
3419 minit ("IM", INQUIRY_IM
),
3420 minit ("KIND", INQUIRY_KIND
),
3421 minit ("LEN", INQUIRY_LEN
),
3427 mio_ref (gfc_ref
**rp
)
3434 r
->type
= MIO_NAME (ref_type
) (r
->type
, ref_types
);
3439 mio_array_ref (&r
->u
.ar
);
3443 mio_symbol_ref (&r
->u
.c
.sym
);
3444 mio_component_ref (&r
->u
.c
.component
);
3448 mio_expr (&r
->u
.ss
.start
);
3449 mio_expr (&r
->u
.ss
.end
);
3450 mio_charlen (&r
->u
.ss
.length
);
3454 r
->u
.i
= MIO_NAME (inquiry_type
) (r
->u
.i
, inquiry_types
);
3463 mio_ref_list (gfc_ref
**rp
)
3465 gfc_ref
*ref
, *head
, *tail
;
3469 if (iomode
== IO_OUTPUT
)
3471 for (ref
= *rp
; ref
; ref
= ref
->next
)
3478 while (peek_atom () != ATOM_RPAREN
)
3481 head
= tail
= gfc_get_ref ();
3484 tail
->next
= gfc_get_ref ();
3498 /* Read and write an integer value. */
3501 mio_gmp_integer (mpz_t
*integer
)
3505 if (iomode
== IO_INPUT
)
3507 if (parse_atom () != ATOM_STRING
)
3508 bad_module ("Expected integer string");
3510 mpz_init (*integer
);
3511 if (mpz_set_str (*integer
, atom_string
, 10))
3512 bad_module ("Error converting integer");
3518 p
= mpz_get_str (NULL
, 10, *integer
);
3519 write_atom (ATOM_STRING
, p
);
3526 mio_gmp_real (mpfr_t
*real
)
3528 mpfr_exp_t exponent
;
3531 if (iomode
== IO_INPUT
)
3533 if (parse_atom () != ATOM_STRING
)
3534 bad_module ("Expected real string");
3537 mpfr_set_str (*real
, atom_string
, 16, GFC_RND_MODE
);
3542 p
= mpfr_get_str (NULL
, &exponent
, 16, 0, *real
, GFC_RND_MODE
);
3544 if (mpfr_nan_p (*real
) || mpfr_inf_p (*real
))
3546 write_atom (ATOM_STRING
, p
);
3551 atom_string
= XCNEWVEC (char, strlen (p
) + 20);
3553 sprintf (atom_string
, "0.%s@%ld", p
, exponent
);
3555 /* Fix negative numbers. */
3556 if (atom_string
[2] == '-')
3558 atom_string
[0] = '-';
3559 atom_string
[1] = '0';
3560 atom_string
[2] = '.';
3563 write_atom (ATOM_STRING
, atom_string
);
3571 /* Save and restore the shape of an array constructor. */
3574 mio_shape (mpz_t
**pshape
, int rank
)
3580 /* A NULL shape is represented by (). */
3583 if (iomode
== IO_OUTPUT
)
3595 if (t
== ATOM_RPAREN
)
3602 shape
= gfc_get_shape (rank
);
3606 for (n
= 0; n
< rank
; n
++)
3607 mio_gmp_integer (&shape
[n
]);
3613 static const mstring expr_types
[] = {
3614 minit ("OP", EXPR_OP
),
3615 minit ("FUNCTION", EXPR_FUNCTION
),
3616 minit ("CONSTANT", EXPR_CONSTANT
),
3617 minit ("VARIABLE", EXPR_VARIABLE
),
3618 minit ("SUBSTRING", EXPR_SUBSTRING
),
3619 minit ("STRUCTURE", EXPR_STRUCTURE
),
3620 minit ("ARRAY", EXPR_ARRAY
),
3621 minit ("NULL", EXPR_NULL
),
3622 minit ("COMPCALL", EXPR_COMPCALL
),
3626 /* INTRINSIC_ASSIGN is missing because it is used as an index for
3627 generic operators, not in expressions. INTRINSIC_USER is also
3628 replaced by the correct function name by the time we see it. */
3630 static const mstring intrinsics
[] =
3632 minit ("UPLUS", INTRINSIC_UPLUS
),
3633 minit ("UMINUS", INTRINSIC_UMINUS
),
3634 minit ("PLUS", INTRINSIC_PLUS
),
3635 minit ("MINUS", INTRINSIC_MINUS
),
3636 minit ("TIMES", INTRINSIC_TIMES
),
3637 minit ("DIVIDE", INTRINSIC_DIVIDE
),
3638 minit ("POWER", INTRINSIC_POWER
),
3639 minit ("CONCAT", INTRINSIC_CONCAT
),
3640 minit ("AND", INTRINSIC_AND
),
3641 minit ("OR", INTRINSIC_OR
),
3642 minit ("EQV", INTRINSIC_EQV
),
3643 minit ("NEQV", INTRINSIC_NEQV
),
3644 minit ("EQ_SIGN", INTRINSIC_EQ
),
3645 minit ("EQ", INTRINSIC_EQ_OS
),
3646 minit ("NE_SIGN", INTRINSIC_NE
),
3647 minit ("NE", INTRINSIC_NE_OS
),
3648 minit ("GT_SIGN", INTRINSIC_GT
),
3649 minit ("GT", INTRINSIC_GT_OS
),
3650 minit ("GE_SIGN", INTRINSIC_GE
),
3651 minit ("GE", INTRINSIC_GE_OS
),
3652 minit ("LT_SIGN", INTRINSIC_LT
),
3653 minit ("LT", INTRINSIC_LT_OS
),
3654 minit ("LE_SIGN", INTRINSIC_LE
),
3655 minit ("LE", INTRINSIC_LE_OS
),
3656 minit ("NOT", INTRINSIC_NOT
),
3657 minit ("PARENTHESES", INTRINSIC_PARENTHESES
),
3658 minit ("USER", INTRINSIC_USER
),
3663 /* Remedy a couple of situations where the gfc_expr's can be defective. */
3666 fix_mio_expr (gfc_expr
*e
)
3668 gfc_symtree
*ns_st
= NULL
;
3671 if (iomode
!= IO_OUTPUT
)
3676 /* If this is a symtree for a symbol that came from a contained module
3677 namespace, it has a unique name and we should look in the current
3678 namespace to see if the required, non-contained symbol is available
3679 yet. If so, the latter should be written. */
3680 if (e
->symtree
->n
.sym
&& check_unique_name (e
->symtree
->name
))
3682 const char *name
= e
->symtree
->n
.sym
->name
;
3683 if (gfc_fl_struct (e
->symtree
->n
.sym
->attr
.flavor
))
3684 name
= gfc_dt_upper_string (name
);
3685 ns_st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
3688 /* On the other hand, if the existing symbol is the module name or the
3689 new symbol is a dummy argument, do not do the promotion. */
3690 if (ns_st
&& ns_st
->n
.sym
3691 && ns_st
->n
.sym
->attr
.flavor
!= FL_MODULE
3692 && !e
->symtree
->n
.sym
->attr
.dummy
)
3695 else if (e
->expr_type
== EXPR_FUNCTION
3696 && (e
->value
.function
.name
|| e
->value
.function
.isym
))
3700 /* In some circumstances, a function used in an initialization
3701 expression, in one use associated module, can fail to be
3702 coupled to its symtree when used in a specification
3703 expression in another module. */
3704 fname
= e
->value
.function
.esym
? e
->value
.function
.esym
->name
3705 : e
->value
.function
.isym
->name
;
3706 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3711 /* This is probably a reference to a private procedure from another
3712 module. To prevent a segfault, make a generic with no specific
3713 instances. If this module is used, without the required
3714 specific coming from somewhere, the appropriate error message
3716 gfc_get_symbol (fname
, gfc_current_ns
, &sym
);
3717 sym
->attr
.flavor
= FL_PROCEDURE
;
3718 sym
->attr
.generic
= 1;
3719 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3720 gfc_commit_symbol (sym
);
3725 /* Read and write expressions. The form "()" is allowed to indicate a
3729 mio_expr (gfc_expr
**ep
)
3738 if (iomode
== IO_OUTPUT
)
3747 MIO_NAME (expr_t
) (e
->expr_type
, expr_types
);
3752 if (t
== ATOM_RPAREN
)
3759 bad_module ("Expected expression type");
3761 e
= *ep
= gfc_get_expr ();
3762 e
->where
= gfc_current_locus
;
3763 e
->expr_type
= (expr_t
) find_enum (expr_types
);
3766 mio_typespec (&e
->ts
);
3767 mio_integer (&e
->rank
);
3771 switch (e
->expr_type
)
3775 = MIO_NAME (gfc_intrinsic_op
) (e
->value
.op
.op
, intrinsics
);
3777 switch (e
->value
.op
.op
)
3779 case INTRINSIC_UPLUS
:
3780 case INTRINSIC_UMINUS
:
3782 case INTRINSIC_PARENTHESES
:
3783 mio_expr (&e
->value
.op
.op1
);
3786 case INTRINSIC_PLUS
:
3787 case INTRINSIC_MINUS
:
3788 case INTRINSIC_TIMES
:
3789 case INTRINSIC_DIVIDE
:
3790 case INTRINSIC_POWER
:
3791 case INTRINSIC_CONCAT
:
3795 case INTRINSIC_NEQV
:
3797 case INTRINSIC_EQ_OS
:
3799 case INTRINSIC_NE_OS
:
3801 case INTRINSIC_GT_OS
:
3803 case INTRINSIC_GE_OS
:
3805 case INTRINSIC_LT_OS
:
3807 case INTRINSIC_LE_OS
:
3808 mio_expr (&e
->value
.op
.op1
);
3809 mio_expr (&e
->value
.op
.op2
);
3812 case INTRINSIC_USER
:
3813 /* INTRINSIC_USER should not appear in resolved expressions,
3814 though for UDRs we need to stream unresolved ones. */
3815 if (iomode
== IO_OUTPUT
)
3816 write_atom (ATOM_STRING
, e
->value
.op
.uop
->name
);
3819 char *name
= read_string ();
3820 const char *uop_name
= find_use_name (name
, true);
3821 if (uop_name
== NULL
)
3823 size_t len
= strlen (name
);
3824 char *name2
= XCNEWVEC (char, len
+ 2);
3825 memcpy (name2
, name
, len
);
3827 name2
[len
+ 1] = '\0';
3829 uop_name
= name
= name2
;
3831 e
->value
.op
.uop
= gfc_get_uop (uop_name
);
3834 mio_expr (&e
->value
.op
.op1
);
3835 mio_expr (&e
->value
.op
.op2
);
3839 bad_module ("Bad operator");
3845 mio_symtree_ref (&e
->symtree
);
3846 mio_actual_arglist (&e
->value
.function
.actual
, false);
3848 if (iomode
== IO_OUTPUT
)
3850 e
->value
.function
.name
3851 = mio_allocated_string (e
->value
.function
.name
);
3852 if (e
->value
.function
.esym
)
3856 else if (e
->value
.function
.isym
== NULL
)
3860 mio_integer (&flag
);
3864 mio_symbol_ref (&e
->value
.function
.esym
);
3867 mio_ref_list (&e
->ref
);
3872 write_atom (ATOM_STRING
, e
->value
.function
.isym
->name
);
3877 require_atom (ATOM_STRING
);
3878 if (atom_string
[0] == '\0')
3879 e
->value
.function
.name
= NULL
;
3881 e
->value
.function
.name
= gfc_get_string ("%s", atom_string
);
3884 mio_integer (&flag
);
3888 mio_symbol_ref (&e
->value
.function
.esym
);
3891 mio_ref_list (&e
->ref
);
3896 require_atom (ATOM_STRING
);
3897 e
->value
.function
.isym
= gfc_find_function (atom_string
);
3905 mio_symtree_ref (&e
->symtree
);
3906 mio_ref_list (&e
->ref
);
3909 case EXPR_SUBSTRING
:
3910 e
->value
.character
.string
3911 = CONST_CAST (gfc_char_t
*,
3912 mio_allocated_wide_string (e
->value
.character
.string
,
3913 e
->value
.character
.length
));
3914 mio_ref_list (&e
->ref
);
3917 case EXPR_STRUCTURE
:
3919 mio_constructor (&e
->value
.constructor
);
3920 mio_shape (&e
->shape
, e
->rank
);
3927 mio_gmp_integer (&e
->value
.integer
);
3931 gfc_set_model_kind (e
->ts
.kind
);
3932 mio_gmp_real (&e
->value
.real
);
3936 gfc_set_model_kind (e
->ts
.kind
);
3937 mio_gmp_real (&mpc_realref (e
->value
.complex));
3938 mio_gmp_real (&mpc_imagref (e
->value
.complex));
3942 mio_integer (&e
->value
.logical
);
3946 hwi
= e
->value
.character
.length
;
3948 e
->value
.character
.length
= hwi
;
3949 e
->value
.character
.string
3950 = CONST_CAST (gfc_char_t
*,
3951 mio_allocated_wide_string (e
->value
.character
.string
,
3952 e
->value
.character
.length
));
3956 bad_module ("Bad type in constant expression");
3971 /* PDT types store the expression specification list here. */
3972 mio_actual_arglist (&e
->param_list
, true);
3978 /* Read and write namelists. */
3981 mio_namelist (gfc_symbol
*sym
)
3983 gfc_namelist
*n
, *m
;
3987 if (iomode
== IO_OUTPUT
)
3989 for (n
= sym
->namelist
; n
; n
= n
->next
)
3990 mio_symbol_ref (&n
->sym
);
3995 while (peek_atom () != ATOM_RPAREN
)
3997 n
= gfc_get_namelist ();
3998 mio_symbol_ref (&n
->sym
);
4000 if (sym
->namelist
== NULL
)
4007 sym
->namelist_tail
= m
;
4014 /* Save/restore lists of gfc_interface structures. When loading an
4015 interface, we are really appending to the existing list of
4016 interfaces. Checking for duplicate and ambiguous interfaces has to
4017 be done later when all symbols have been loaded. */
4020 mio_interface_rest (gfc_interface
**ip
)
4022 gfc_interface
*tail
, *p
;
4023 pointer_info
*pi
= NULL
;
4025 if (iomode
== IO_OUTPUT
)
4028 for (p
= *ip
; p
; p
= p
->next
)
4029 mio_symbol_ref (&p
->sym
);
4044 if (peek_atom () == ATOM_RPAREN
)
4047 p
= gfc_get_interface ();
4048 p
->where
= gfc_current_locus
;
4049 pi
= mio_symbol_ref (&p
->sym
);
4065 /* Save/restore a nameless operator interface. */
4068 mio_interface (gfc_interface
**ip
)
4071 mio_interface_rest (ip
);
4075 /* Save/restore a named operator interface. */
4078 mio_symbol_interface (const char **name
, const char **module
,
4082 mio_pool_string (name
);
4083 mio_pool_string (module
);
4084 mio_interface_rest (ip
);
4089 mio_namespace_ref (gfc_namespace
**nsp
)
4094 p
= mio_pointer_ref (nsp
);
4096 if (p
->type
== P_UNKNOWN
)
4097 p
->type
= P_NAMESPACE
;
4099 if (iomode
== IO_INPUT
&& p
->integer
!= 0)
4101 ns
= (gfc_namespace
*) p
->u
.pointer
;
4104 ns
= gfc_get_namespace (NULL
, 0);
4105 associate_integer_pointer (p
, ns
);
4113 /* Save/restore the f2k_derived namespace of a derived-type symbol. */
4115 static gfc_namespace
* current_f2k_derived
;
4118 mio_typebound_proc (gfc_typebound_proc
** proc
)
4121 int overriding_flag
;
4123 if (iomode
== IO_INPUT
)
4125 *proc
= gfc_get_typebound_proc (NULL
);
4126 (*proc
)->where
= gfc_current_locus
;
4132 (*proc
)->access
= MIO_NAME (gfc_access
) ((*proc
)->access
, access_types
);
4134 /* IO the NON_OVERRIDABLE/DEFERRED combination. */
4135 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
4136 overriding_flag
= ((*proc
)->deferred
<< 1) | (*proc
)->non_overridable
;
4137 overriding_flag
= mio_name (overriding_flag
, binding_overriding
);
4138 (*proc
)->deferred
= ((overriding_flag
& 2) != 0);
4139 (*proc
)->non_overridable
= ((overriding_flag
& 1) != 0);
4140 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
4142 (*proc
)->nopass
= mio_name ((*proc
)->nopass
, binding_passing
);
4143 (*proc
)->is_generic
= mio_name ((*proc
)->is_generic
, binding_generic
);
4144 (*proc
)->ppc
= mio_name((*proc
)->ppc
, binding_ppc
);
4146 mio_pool_string (&((*proc
)->pass_arg
));
4148 flag
= (int) (*proc
)->pass_arg_num
;
4149 mio_integer (&flag
);
4150 (*proc
)->pass_arg_num
= (unsigned) flag
;
4152 if ((*proc
)->is_generic
)
4159 if (iomode
== IO_OUTPUT
)
4160 for (g
= (*proc
)->u
.generic
; g
; g
= g
->next
)
4162 iop
= (int) g
->is_operator
;
4164 mio_allocated_string (g
->specific_st
->name
);
4168 (*proc
)->u
.generic
= NULL
;
4169 while (peek_atom () != ATOM_RPAREN
)
4171 gfc_symtree
** sym_root
;
4173 g
= gfc_get_tbp_generic ();
4177 g
->is_operator
= (bool) iop
;
4179 require_atom (ATOM_STRING
);
4180 sym_root
= ¤t_f2k_derived
->tb_sym_root
;
4181 g
->specific_st
= gfc_get_tbp_symtree (sym_root
, atom_string
);
4184 g
->next
= (*proc
)->u
.generic
;
4185 (*proc
)->u
.generic
= g
;
4191 else if (!(*proc
)->ppc
)
4192 mio_symtree_ref (&(*proc
)->u
.specific
);
4197 /* Walker-callback function for this purpose. */
4199 mio_typebound_symtree (gfc_symtree
* st
)
4201 if (iomode
== IO_OUTPUT
&& !st
->n
.tb
)
4204 if (iomode
== IO_OUTPUT
)
4207 mio_allocated_string (st
->name
);
4209 /* For IO_INPUT, the above is done in mio_f2k_derived. */
4211 mio_typebound_proc (&st
->n
.tb
);
4215 /* IO a full symtree (in all depth). */
4217 mio_full_typebound_tree (gfc_symtree
** root
)
4221 if (iomode
== IO_OUTPUT
)
4222 gfc_traverse_symtree (*root
, &mio_typebound_symtree
);
4225 while (peek_atom () == ATOM_LPAREN
)
4231 require_atom (ATOM_STRING
);
4232 st
= gfc_get_tbp_symtree (root
, atom_string
);
4235 mio_typebound_symtree (st
);
4243 mio_finalizer (gfc_finalizer
**f
)
4245 if (iomode
== IO_OUTPUT
)
4248 gcc_assert ((*f
)->proc_tree
); /* Should already be resolved. */
4249 mio_symtree_ref (&(*f
)->proc_tree
);
4253 *f
= gfc_get_finalizer ();
4254 (*f
)->where
= gfc_current_locus
; /* Value should not matter. */
4257 mio_symtree_ref (&(*f
)->proc_tree
);
4258 (*f
)->proc_sym
= NULL
;
4263 mio_f2k_derived (gfc_namespace
*f2k
)
4265 current_f2k_derived
= f2k
;
4267 /* Handle the list of finalizer procedures. */
4269 if (iomode
== IO_OUTPUT
)
4272 for (f
= f2k
->finalizers
; f
; f
= f
->next
)
4277 f2k
->finalizers
= NULL
;
4278 while (peek_atom () != ATOM_RPAREN
)
4280 gfc_finalizer
*cur
= NULL
;
4281 mio_finalizer (&cur
);
4282 cur
->next
= f2k
->finalizers
;
4283 f2k
->finalizers
= cur
;
4288 /* Handle type-bound procedures. */
4289 mio_full_typebound_tree (&f2k
->tb_sym_root
);
4291 /* Type-bound user operators. */
4292 mio_full_typebound_tree (&f2k
->tb_uop_root
);
4294 /* Type-bound intrinsic operators. */
4296 if (iomode
== IO_OUTPUT
)
4299 for (op
= GFC_INTRINSIC_BEGIN
; op
!= GFC_INTRINSIC_END
; ++op
)
4301 gfc_intrinsic_op realop
;
4303 if (op
== INTRINSIC_USER
|| !f2k
->tb_op
[op
])
4307 realop
= (gfc_intrinsic_op
) op
;
4308 mio_intrinsic_op (&realop
);
4309 mio_typebound_proc (&f2k
->tb_op
[op
]);
4314 while (peek_atom () != ATOM_RPAREN
)
4316 gfc_intrinsic_op op
= GFC_INTRINSIC_BEGIN
; /* Silence GCC. */
4319 mio_intrinsic_op (&op
);
4320 mio_typebound_proc (&f2k
->tb_op
[op
]);
4327 mio_full_f2k_derived (gfc_symbol
*sym
)
4331 if (iomode
== IO_OUTPUT
)
4333 if (sym
->f2k_derived
)
4334 mio_f2k_derived (sym
->f2k_derived
);
4338 if (peek_atom () != ATOM_RPAREN
)
4342 sym
->f2k_derived
= gfc_get_namespace (NULL
, 0);
4344 /* PDT templates make use of the mechanisms for formal args
4345 and so the parameter symbols are stored in the formal
4346 namespace. Transfer the sym_root to f2k_derived and then
4347 free the formal namespace since it is uneeded. */
4348 if (sym
->attr
.pdt_template
&& sym
->formal
&& sym
->formal
->sym
)
4350 ns
= sym
->formal
->sym
->ns
;
4351 sym
->f2k_derived
->sym_root
= ns
->sym_root
;
4352 ns
->sym_root
= NULL
;
4354 gfc_free_namespace (ns
);
4358 mio_f2k_derived (sym
->f2k_derived
);
4361 gcc_assert (!sym
->f2k_derived
);
4367 static const mstring omp_declare_simd_clauses
[] =
4369 minit ("INBRANCH", 0),
4370 minit ("NOTINBRANCH", 1),
4371 minit ("SIMDLEN", 2),
4372 minit ("UNIFORM", 3),
4373 minit ("LINEAR", 4),
4374 minit ("ALIGNED", 5),
4375 minit ("LINEAR_REF", 33),
4376 minit ("LINEAR_VAL", 34),
4377 minit ("LINEAR_UVAL", 35),
4381 /* Handle !$omp declare simd. */
4384 mio_omp_declare_simd (gfc_namespace
*ns
, gfc_omp_declare_simd
**odsp
)
4386 if (iomode
== IO_OUTPUT
)
4391 else if (peek_atom () != ATOM_LPAREN
)
4394 gfc_omp_declare_simd
*ods
= *odsp
;
4397 if (iomode
== IO_OUTPUT
)
4399 write_atom (ATOM_NAME
, "OMP_DECLARE_SIMD");
4402 gfc_omp_namelist
*n
;
4404 if (ods
->clauses
->inbranch
)
4405 mio_name (0, omp_declare_simd_clauses
);
4406 if (ods
->clauses
->notinbranch
)
4407 mio_name (1, omp_declare_simd_clauses
);
4408 if (ods
->clauses
->simdlen_expr
)
4410 mio_name (2, omp_declare_simd_clauses
);
4411 mio_expr (&ods
->clauses
->simdlen_expr
);
4413 for (n
= ods
->clauses
->lists
[OMP_LIST_UNIFORM
]; n
; n
= n
->next
)
4415 mio_name (3, omp_declare_simd_clauses
);
4416 mio_symbol_ref (&n
->sym
);
4418 for (n
= ods
->clauses
->lists
[OMP_LIST_LINEAR
]; n
; n
= n
->next
)
4420 if (n
->u
.linear
.op
== OMP_LINEAR_DEFAULT
)
4421 mio_name (4, omp_declare_simd_clauses
);
4423 mio_name (32 + n
->u
.linear
.op
, omp_declare_simd_clauses
);
4424 mio_symbol_ref (&n
->sym
);
4425 mio_expr (&n
->expr
);
4427 for (n
= ods
->clauses
->lists
[OMP_LIST_ALIGNED
]; n
; n
= n
->next
)
4429 mio_name (5, omp_declare_simd_clauses
);
4430 mio_symbol_ref (&n
->sym
);
4431 mio_expr (&n
->expr
);
4437 gfc_omp_namelist
**ptrs
[3] = { NULL
, NULL
, NULL
};
4439 require_atom (ATOM_NAME
);
4440 *odsp
= ods
= gfc_get_omp_declare_simd ();
4441 ods
->where
= gfc_current_locus
;
4442 ods
->proc_name
= ns
->proc_name
;
4443 if (peek_atom () == ATOM_NAME
)
4445 ods
->clauses
= gfc_get_omp_clauses ();
4446 ptrs
[0] = &ods
->clauses
->lists
[OMP_LIST_UNIFORM
];
4447 ptrs
[1] = &ods
->clauses
->lists
[OMP_LIST_LINEAR
];
4448 ptrs
[2] = &ods
->clauses
->lists
[OMP_LIST_ALIGNED
];
4450 while (peek_atom () == ATOM_NAME
)
4452 gfc_omp_namelist
*n
;
4453 int t
= mio_name (0, omp_declare_simd_clauses
);
4457 case 0: ods
->clauses
->inbranch
= true; break;
4458 case 1: ods
->clauses
->notinbranch
= true; break;
4459 case 2: mio_expr (&ods
->clauses
->simdlen_expr
); break;
4463 *ptrs
[t
- 3] = n
= gfc_get_omp_namelist ();
4465 n
->where
= gfc_current_locus
;
4466 ptrs
[t
- 3] = &n
->next
;
4467 mio_symbol_ref (&n
->sym
);
4469 mio_expr (&n
->expr
);
4474 *ptrs
[1] = n
= gfc_get_omp_namelist ();
4475 n
->u
.linear
.op
= (enum gfc_omp_linear_op
) (t
- 32);
4477 goto finish_namelist
;
4482 mio_omp_declare_simd (ns
, &ods
->next
);
4488 static const mstring omp_declare_reduction_stmt
[] =
4490 minit ("ASSIGN", 0),
4497 mio_omp_udr_expr (gfc_omp_udr
*udr
, gfc_symbol
**sym1
, gfc_symbol
**sym2
,
4498 gfc_namespace
*ns
, bool is_initializer
)
4500 if (iomode
== IO_OUTPUT
)
4502 if ((*sym1
)->module
== NULL
)
4504 (*sym1
)->module
= module_name
;
4505 (*sym2
)->module
= module_name
;
4507 mio_symbol_ref (sym1
);
4508 mio_symbol_ref (sym2
);
4509 if (ns
->code
->op
== EXEC_ASSIGN
)
4511 mio_name (0, omp_declare_reduction_stmt
);
4512 mio_expr (&ns
->code
->expr1
);
4513 mio_expr (&ns
->code
->expr2
);
4518 mio_name (1, omp_declare_reduction_stmt
);
4519 mio_symtree_ref (&ns
->code
->symtree
);
4520 mio_actual_arglist (&ns
->code
->ext
.actual
, false);
4522 flag
= ns
->code
->resolved_isym
!= NULL
;
4523 mio_integer (&flag
);
4525 write_atom (ATOM_STRING
, ns
->code
->resolved_isym
->name
);
4527 mio_symbol_ref (&ns
->code
->resolved_sym
);
4532 pointer_info
*p1
= mio_symbol_ref (sym1
);
4533 pointer_info
*p2
= mio_symbol_ref (sym2
);
4535 gcc_assert (p1
->u
.rsym
.ns
== p2
->u
.rsym
.ns
);
4536 gcc_assert (p1
->u
.rsym
.sym
== NULL
);
4537 /* Add hidden symbols to the symtree. */
4538 pointer_info
*q
= get_integer (p1
->u
.rsym
.ns
);
4539 q
->u
.pointer
= (void *) ns
;
4540 sym
= gfc_new_symbol (is_initializer
? "omp_priv" : "omp_out", ns
);
4542 sym
->module
= gfc_get_string ("%s", p1
->u
.rsym
.module
);
4543 associate_integer_pointer (p1
, sym
);
4544 sym
->attr
.omp_udr_artificial_var
= 1;
4545 gcc_assert (p2
->u
.rsym
.sym
== NULL
);
4546 sym
= gfc_new_symbol (is_initializer
? "omp_orig" : "omp_in", ns
);
4548 sym
->module
= gfc_get_string ("%s", p2
->u
.rsym
.module
);
4549 associate_integer_pointer (p2
, sym
);
4550 sym
->attr
.omp_udr_artificial_var
= 1;
4551 if (mio_name (0, omp_declare_reduction_stmt
) == 0)
4553 ns
->code
= gfc_get_code (EXEC_ASSIGN
);
4554 mio_expr (&ns
->code
->expr1
);
4555 mio_expr (&ns
->code
->expr2
);
4560 ns
->code
= gfc_get_code (EXEC_CALL
);
4561 mio_symtree_ref (&ns
->code
->symtree
);
4562 mio_actual_arglist (&ns
->code
->ext
.actual
, false);
4564 mio_integer (&flag
);
4567 require_atom (ATOM_STRING
);
4568 ns
->code
->resolved_isym
= gfc_find_subroutine (atom_string
);
4572 mio_symbol_ref (&ns
->code
->resolved_sym
);
4574 ns
->code
->loc
= gfc_current_locus
;
4580 /* Unlike most other routines, the address of the symbol node is already
4581 fixed on input and the name/module has already been filled in.
4582 If you update the symbol format here, don't forget to update read_module
4583 as well (look for "seek to the symbol's component list"). */
4586 mio_symbol (gfc_symbol
*sym
)
4588 int intmod
= INTMOD_NONE
;
4592 mio_symbol_attribute (&sym
->attr
);
4594 if (sym
->attr
.pdt_type
)
4595 sym
->name
= gfc_dt_upper_string (sym
->name
);
4597 /* Note that components are always saved, even if they are supposed
4598 to be private. Component access is checked during searching. */
4599 mio_component_list (&sym
->components
, sym
->attr
.vtype
);
4600 if (sym
->components
!= NULL
)
4601 sym
->component_access
4602 = MIO_NAME (gfc_access
) (sym
->component_access
, access_types
);
4604 mio_typespec (&sym
->ts
);
4605 if (sym
->ts
.type
== BT_CLASS
)
4606 sym
->attr
.class_ok
= 1;
4608 if (iomode
== IO_OUTPUT
)
4609 mio_namespace_ref (&sym
->formal_ns
);
4612 mio_namespace_ref (&sym
->formal_ns
);
4614 sym
->formal_ns
->proc_name
= sym
;
4617 /* Save/restore common block links. */
4618 mio_symbol_ref (&sym
->common_next
);
4620 mio_formal_arglist (&sym
->formal
);
4622 if (sym
->attr
.flavor
== FL_PARAMETER
)
4623 mio_expr (&sym
->value
);
4625 mio_array_spec (&sym
->as
);
4627 mio_symbol_ref (&sym
->result
);
4629 if (sym
->attr
.cray_pointee
)
4630 mio_symbol_ref (&sym
->cp_pointer
);
4632 /* Load/save the f2k_derived namespace of a derived-type symbol. */
4633 mio_full_f2k_derived (sym
);
4635 /* PDT types store the symbol specification list here. */
4636 mio_actual_arglist (&sym
->param_list
, true);
4640 /* Add the fields that say whether this is from an intrinsic module,
4641 and if so, what symbol it is within the module. */
4642 /* mio_integer (&(sym->from_intmod)); */
4643 if (iomode
== IO_OUTPUT
)
4645 intmod
= sym
->from_intmod
;
4646 mio_integer (&intmod
);
4650 mio_integer (&intmod
);
4652 sym
->from_intmod
= current_intmod
;
4654 sym
->from_intmod
= (intmod_id
) intmod
;
4657 mio_integer (&(sym
->intmod_sym_id
));
4659 if (gfc_fl_struct (sym
->attr
.flavor
))
4660 mio_integer (&(sym
->hash_value
));
4663 && sym
->formal_ns
->proc_name
== sym
4664 && sym
->formal_ns
->entries
== NULL
)
4665 mio_omp_declare_simd (sym
->formal_ns
, &sym
->formal_ns
->omp_declare_simd
);
4671 /************************* Top level subroutines *************************/
4673 /* A recursive function to look for a specific symbol by name and by
4674 module. Whilst several symtrees might point to one symbol, its
4675 is sufficient for the purposes here than one exist. Note that
4676 generic interfaces are distinguished as are symbols that have been
4677 renamed in another module. */
4678 static gfc_symtree
*
4679 find_symbol (gfc_symtree
*st
, const char *name
,
4680 const char *module
, int generic
)
4683 gfc_symtree
*retval
, *s
;
4685 if (st
== NULL
|| st
->n
.sym
== NULL
)
4688 c
= strcmp (name
, st
->n
.sym
->name
);
4689 if (c
== 0 && st
->n
.sym
->module
4690 && strcmp (module
, st
->n
.sym
->module
) == 0
4691 && !check_unique_name (st
->name
))
4693 s
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
4695 /* Detect symbols that are renamed by use association in another
4696 module by the absence of a symtree and null attr.use_rename,
4697 since the latter is not transmitted in the module file. */
4698 if (((!generic
&& !st
->n
.sym
->attr
.generic
)
4699 || (generic
&& st
->n
.sym
->attr
.generic
))
4700 && !(s
== NULL
&& !st
->n
.sym
->attr
.use_rename
))
4704 retval
= find_symbol (st
->left
, name
, module
, generic
);
4707 retval
= find_symbol (st
->right
, name
, module
, generic
);
4713 /* Skip a list between balanced left and right parens.
4714 By setting NEST_LEVEL one assumes that a number of NEST_LEVEL opening parens
4715 have been already parsed by hand, and the remaining of the content is to be
4716 skipped here. The default value is 0 (balanced parens). */
4719 skip_list (int nest_level
= 0)
4726 switch (parse_atom ())
4749 /* Load operator interfaces from the module. Interfaces are unusual
4750 in that they attach themselves to existing symbols. */
4753 load_operator_interfaces (void)
4756 /* "module" must be large enough for the case of submodules in which the name
4757 has the form module.submodule */
4758 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
4760 pointer_info
*pi
= NULL
;
4765 while (peek_atom () != ATOM_RPAREN
)
4769 mio_internal_string (name
);
4770 mio_internal_string (module
);
4772 n
= number_use_names (name
, true);
4775 for (i
= 1; i
<= n
; i
++)
4777 /* Decide if we need to load this one or not. */
4778 p
= find_use_name_n (name
, &i
, true);
4782 while (parse_atom () != ATOM_RPAREN
);
4788 uop
= gfc_get_uop (p
);
4789 pi
= mio_interface_rest (&uop
->op
);
4793 if (gfc_find_uop (p
, NULL
))
4795 uop
= gfc_get_uop (p
);
4796 uop
->op
= gfc_get_interface ();
4797 uop
->op
->where
= gfc_current_locus
;
4798 add_fixup (pi
->integer
, &uop
->op
->sym
);
4807 /* Load interfaces from the module. Interfaces are unusual in that
4808 they attach themselves to existing symbols. */
4811 load_generic_interfaces (void)
4814 /* "module" must be large enough for the case of submodules in which the name
4815 has the form module.submodule */
4816 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
4818 gfc_interface
*generic
= NULL
, *gen
= NULL
;
4820 bool ambiguous_set
= false;
4824 while (peek_atom () != ATOM_RPAREN
)
4828 mio_internal_string (name
);
4829 mio_internal_string (module
);
4831 n
= number_use_names (name
, false);
4832 renamed
= n
? 1 : 0;
4835 for (i
= 1; i
<= n
; i
++)
4838 /* Decide if we need to load this one or not. */
4839 p
= find_use_name_n (name
, &i
, false);
4841 if (!p
|| gfc_find_symbol (p
, NULL
, 0, &sym
))
4843 /* Skip the specific names for these cases. */
4844 while (i
== 1 && parse_atom () != ATOM_RPAREN
);
4849 st
= find_symbol (gfc_current_ns
->sym_root
,
4850 name
, module_name
, 1);
4852 /* If the symbol exists already and is being USEd without being
4853 in an ONLY clause, do not load a new symtree(11.3.2). */
4854 if (!only_flag
&& st
)
4862 if (strcmp (st
->name
, p
) != 0)
4864 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
4870 /* Since we haven't found a valid generic interface, we had
4874 gfc_get_symbol (p
, NULL
, &sym
);
4875 sym
->name
= gfc_get_string ("%s", name
);
4876 sym
->module
= module_name
;
4877 sym
->attr
.flavor
= FL_PROCEDURE
;
4878 sym
->attr
.generic
= 1;
4879 sym
->attr
.use_assoc
= 1;
4884 /* Unless sym is a generic interface, this reference
4887 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
4891 if (st
&& !sym
->attr
.generic
4894 && strcmp (module
, sym
->module
))
4896 ambiguous_set
= true;
4901 sym
->attr
.use_only
= only_flag
;
4902 sym
->attr
.use_rename
= renamed
;
4906 mio_interface_rest (&sym
->generic
);
4907 generic
= sym
->generic
;
4909 else if (!sym
->generic
)
4911 sym
->generic
= generic
;
4912 sym
->attr
.generic_copy
= 1;
4915 /* If a procedure that is not generic has generic interfaces
4916 that include itself, it is generic! We need to take care
4917 to retain symbols ambiguous that were already so. */
4918 if (sym
->attr
.use_assoc
4919 && !sym
->attr
.generic
4920 && sym
->attr
.flavor
== FL_PROCEDURE
)
4922 for (gen
= generic
; gen
; gen
= gen
->next
)
4924 if (gen
->sym
== sym
)
4926 sym
->attr
.generic
= 1;
4941 /* Load common blocks. */
4946 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4951 while (peek_atom () != ATOM_RPAREN
)
4956 mio_internal_string (name
);
4958 p
= gfc_get_common (name
, 1);
4960 mio_symbol_ref (&p
->head
);
4961 mio_integer (&flags
);
4965 p
->threadprivate
= 1;
4966 p
->omp_device_type
= (gfc_omp_device_type
) ((flags
>> 2) & 3);
4969 /* Get whether this was a bind(c) common or not. */
4970 mio_integer (&p
->is_bind_c
);
4971 /* Get the binding label. */
4972 label
= read_string ();
4974 p
->binding_label
= IDENTIFIER_POINTER (get_identifier (label
));
4984 /* Load equivalences. The flag in_load_equiv informs mio_expr_ref of this
4985 so that unused variables are not loaded and so that the expression can
4991 gfc_equiv
*head
, *tail
, *end
, *eq
, *equiv
;
4995 in_load_equiv
= true;
4997 end
= gfc_current_ns
->equiv
;
4998 while (end
!= NULL
&& end
->next
!= NULL
)
5001 while (peek_atom () != ATOM_RPAREN
) {
5005 while(peek_atom () != ATOM_RPAREN
)
5008 head
= tail
= gfc_get_equiv ();
5011 tail
->eq
= gfc_get_equiv ();
5015 mio_pool_string (&tail
->module
);
5016 mio_expr (&tail
->expr
);
5019 /* Check for duplicate equivalences being loaded from different modules */
5021 for (equiv
= gfc_current_ns
->equiv
; equiv
; equiv
= equiv
->next
)
5023 if (equiv
->module
&& head
->module
5024 && strcmp (equiv
->module
, head
->module
) == 0)
5033 for (eq
= head
; eq
; eq
= head
)
5036 gfc_free_expr (eq
->expr
);
5042 gfc_current_ns
->equiv
= head
;
5053 in_load_equiv
= false;
5057 /* This function loads OpenMP user defined reductions. */
5059 load_omp_udrs (void)
5062 while (peek_atom () != ATOM_RPAREN
)
5064 const char *name
= NULL
, *newname
;
5068 gfc_omp_reduction_op rop
= OMP_REDUCTION_USER
;
5071 mio_pool_string (&name
);
5074 if (startswith (name
, "operator "))
5076 const char *p
= name
+ sizeof ("operator ") - 1;
5077 if (strcmp (p
, "+") == 0)
5078 rop
= OMP_REDUCTION_PLUS
;
5079 else if (strcmp (p
, "*") == 0)
5080 rop
= OMP_REDUCTION_TIMES
;
5081 else if (strcmp (p
, "-") == 0)
5082 rop
= OMP_REDUCTION_MINUS
;
5083 else if (strcmp (p
, ".and.") == 0)
5084 rop
= OMP_REDUCTION_AND
;
5085 else if (strcmp (p
, ".or.") == 0)
5086 rop
= OMP_REDUCTION_OR
;
5087 else if (strcmp (p
, ".eqv.") == 0)
5088 rop
= OMP_REDUCTION_EQV
;
5089 else if (strcmp (p
, ".neqv.") == 0)
5090 rop
= OMP_REDUCTION_NEQV
;
5093 if (rop
== OMP_REDUCTION_USER
&& name
[0] == '.')
5095 size_t len
= strlen (name
+ 1);
5096 altname
= XALLOCAVEC (char, len
);
5097 gcc_assert (name
[len
] == '.');
5098 memcpy (altname
, name
+ 1, len
- 1);
5099 altname
[len
- 1] = '\0';
5102 if (rop
== OMP_REDUCTION_USER
)
5103 newname
= find_use_name (altname
? altname
: name
, !!altname
);
5104 else if (only_flag
&& find_use_operator ((gfc_intrinsic_op
) rop
) == NULL
)
5106 if (newname
== NULL
)
5111 if (altname
&& newname
!= altname
)
5113 size_t len
= strlen (newname
);
5114 altname
= XALLOCAVEC (char, len
+ 3);
5116 memcpy (altname
+ 1, newname
, len
);
5117 altname
[len
+ 1] = '.';
5118 altname
[len
+ 2] = '\0';
5119 name
= gfc_get_string ("%s", altname
);
5121 st
= gfc_find_symtree (gfc_current_ns
->omp_udr_root
, name
);
5122 gfc_omp_udr
*udr
= gfc_omp_udr_find (st
, &ts
);
5125 require_atom (ATOM_INTEGER
);
5126 pointer_info
*p
= get_integer (atom_int
);
5127 if (strcmp (p
->u
.rsym
.module
, udr
->omp_out
->module
))
5129 gfc_error ("Ambiguous !$OMP DECLARE REDUCTION from "
5131 p
->u
.rsym
.module
, &gfc_current_locus
);
5132 gfc_error ("Previous !$OMP DECLARE REDUCTION from module "
5134 udr
->omp_out
->module
, &udr
->where
);
5139 udr
= gfc_get_omp_udr ();
5143 udr
->where
= gfc_current_locus
;
5144 udr
->combiner_ns
= gfc_get_namespace (gfc_current_ns
, 1);
5145 udr
->combiner_ns
->proc_name
= gfc_current_ns
->proc_name
;
5146 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
,
5148 if (peek_atom () != ATOM_RPAREN
)
5150 udr
->initializer_ns
= gfc_get_namespace (gfc_current_ns
, 1);
5151 udr
->initializer_ns
->proc_name
= gfc_current_ns
->proc_name
;
5152 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
5153 udr
->initializer_ns
, true);
5157 udr
->next
= st
->n
.omp_udr
;
5158 st
->n
.omp_udr
= udr
;
5162 st
= gfc_new_symtree (&gfc_current_ns
->omp_udr_root
, name
);
5163 st
->n
.omp_udr
= udr
;
5171 /* Recursive function to traverse the pointer_info tree and load a
5172 needed symbol. We return nonzero if we load a symbol and stop the
5173 traversal, because the act of loading can alter the tree. */
5176 load_needed (pointer_info
*p
)
5187 rv
|= load_needed (p
->left
);
5188 rv
|= load_needed (p
->right
);
5190 if (p
->type
!= P_SYMBOL
|| p
->u
.rsym
.state
!= NEEDED
)
5193 p
->u
.rsym
.state
= USED
;
5195 set_module_locus (&p
->u
.rsym
.where
);
5197 sym
= p
->u
.rsym
.sym
;
5200 q
= get_integer (p
->u
.rsym
.ns
);
5202 ns
= (gfc_namespace
*) q
->u
.pointer
;
5205 /* Create an interface namespace if necessary. These are
5206 the namespaces that hold the formal parameters of module
5209 ns
= gfc_get_namespace (NULL
, 0);
5210 associate_integer_pointer (q
, ns
);
5213 /* Use the module sym as 'proc_name' so that gfc_get_symbol_decl
5214 doesn't go pear-shaped if the symbol is used. */
5216 gfc_find_symbol (p
->u
.rsym
.module
, gfc_current_ns
,
5219 sym
= gfc_new_symbol (p
->u
.rsym
.true_name
, ns
);
5220 sym
->name
= gfc_dt_lower_string (p
->u
.rsym
.true_name
);
5221 sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
5222 if (p
->u
.rsym
.binding_label
)
5223 sym
->binding_label
= IDENTIFIER_POINTER (get_identifier
5224 (p
->u
.rsym
.binding_label
));
5226 associate_integer_pointer (p
, sym
);
5230 sym
->attr
.use_assoc
= 1;
5232 /* Unliked derived types, a STRUCTURE may share names with other symbols.
5233 We greedily converted the symbol name to lowercase before we knew its
5234 type, so now we must fix it. */
5235 if (sym
->attr
.flavor
== FL_STRUCT
)
5236 sym
->name
= gfc_dt_upper_string (sym
->name
);
5238 /* Mark as only or rename for later diagnosis for explicitly imported
5239 but not used warnings; don't mark internal symbols such as __vtab,
5240 __def_init etc. Only mark them if they have been explicitly loaded. */
5242 if (only_flag
&& sym
->name
[0] != '_' && sym
->name
[1] != '_')
5246 /* Search the use/rename list for the variable; if the variable is
5248 for (u
= gfc_rename_list
; u
; u
= u
->next
)
5250 if (strcmp (u
->use_name
, sym
->name
) == 0)
5252 sym
->attr
.use_only
= 1;
5258 if (p
->u
.rsym
.renamed
)
5259 sym
->attr
.use_rename
= 1;
5265 /* Recursive function for cleaning up things after a module has been read. */
5268 read_cleanup (pointer_info
*p
)
5276 read_cleanup (p
->left
);
5277 read_cleanup (p
->right
);
5279 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== USED
&& !p
->u
.rsym
.referenced
)
5282 /* Add hidden symbols to the symtree. */
5283 q
= get_integer (p
->u
.rsym
.ns
);
5284 ns
= (gfc_namespace
*) q
->u
.pointer
;
5286 if (!p
->u
.rsym
.sym
->attr
.vtype
5287 && !p
->u
.rsym
.sym
->attr
.vtab
)
5288 st
= gfc_get_unique_symtree (ns
);
5291 /* There is no reason to use 'unique_symtrees' for vtabs or
5292 vtypes - their name is fine for a symtree and reduces the
5293 namespace pollution. */
5294 st
= gfc_find_symtree (ns
->sym_root
, p
->u
.rsym
.sym
->name
);
5296 st
= gfc_new_symtree (&ns
->sym_root
, p
->u
.rsym
.sym
->name
);
5299 st
->n
.sym
= p
->u
.rsym
.sym
;
5302 /* Fixup any symtree references. */
5303 p
->u
.rsym
.symtree
= st
;
5304 resolve_fixups (p
->u
.rsym
.stfixup
, st
);
5305 p
->u
.rsym
.stfixup
= NULL
;
5308 /* Free unused symbols. */
5309 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== UNUSED
)
5310 gfc_free_symbol (p
->u
.rsym
.sym
);
5314 /* It is not quite enough to check for ambiguity in the symbols by
5315 the loaded symbol and the new symbol not being identical. */
5317 check_for_ambiguous (gfc_symtree
*st
, pointer_info
*info
)
5321 symbol_attribute attr
;
5324 if (gfc_current_ns
->proc_name
&& st
->name
== gfc_current_ns
->proc_name
->name
)
5326 gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
5327 "current program unit", st
->name
, module_name
);
5332 rsym
= info
->u
.rsym
.sym
;
5336 if (st_sym
->attr
.vtab
|| st_sym
->attr
.vtype
)
5339 /* If the existing symbol is generic from a different module and
5340 the new symbol is generic there can be no ambiguity. */
5341 if (st_sym
->attr
.generic
5343 && st_sym
->module
!= module_name
)
5345 /* The new symbol's attributes have not yet been read. Since
5346 we need attr.generic, read it directly. */
5347 get_module_locus (&locus
);
5348 set_module_locus (&info
->u
.rsym
.where
);
5351 mio_symbol_attribute (&attr
);
5352 set_module_locus (&locus
);
5361 /* Read a module file. */
5366 module_locus operator_interfaces
, user_operators
, omp_udrs
;
5368 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5370 /* Workaround -Wmaybe-uninitialized false positive during
5371 profiledbootstrap by initializing them. */
5372 int ambiguous
= 0, j
, nuse
, symbol
= 0;
5373 pointer_info
*info
, *q
;
5374 gfc_use_rename
*u
= NULL
;
5378 get_module_locus (&operator_interfaces
); /* Skip these for now. */
5381 get_module_locus (&user_operators
);
5385 /* Skip commons and equivalences for now. */
5389 /* Skip OpenMP UDRs. */
5390 get_module_locus (&omp_udrs
);
5395 /* Create the fixup nodes for all the symbols. */
5397 while (peek_atom () != ATOM_RPAREN
)
5400 require_atom (ATOM_INTEGER
);
5401 info
= get_integer (atom_int
);
5403 info
->type
= P_SYMBOL
;
5404 info
->u
.rsym
.state
= UNUSED
;
5406 info
->u
.rsym
.true_name
= read_string ();
5407 info
->u
.rsym
.module
= read_string ();
5408 bind_label
= read_string ();
5409 if (strlen (bind_label
))
5410 info
->u
.rsym
.binding_label
= bind_label
;
5412 XDELETEVEC (bind_label
);
5414 require_atom (ATOM_INTEGER
);
5415 info
->u
.rsym
.ns
= atom_int
;
5417 get_module_locus (&info
->u
.rsym
.where
);
5419 /* See if the symbol has already been loaded by a previous module.
5420 If so, we reference the existing symbol and prevent it from
5421 being loaded again. This should not happen if the symbol being
5422 read is an index for an assumed shape dummy array (ns != 1). */
5424 sym
= find_true_name (info
->u
.rsym
.true_name
, info
->u
.rsym
.module
);
5427 || (sym
->attr
.flavor
== FL_VARIABLE
&& info
->u
.rsym
.ns
!=1))
5433 info
->u
.rsym
.state
= USED
;
5434 info
->u
.rsym
.sym
= sym
;
5435 /* The current symbol has already been loaded, so we can avoid loading
5436 it again. However, if it is a derived type, some of its components
5437 can be used in expressions in the module. To avoid the module loading
5438 failing, we need to associate the module's component pointer indexes
5439 with the existing symbol's component pointers. */
5440 if (gfc_fl_struct (sym
->attr
.flavor
))
5444 /* First seek to the symbol's component list. */
5445 mio_lparen (); /* symbol opening. */
5446 skip_list (); /* skip symbol attribute. */
5448 mio_lparen (); /* component list opening. */
5449 for (c
= sym
->components
; c
; c
= c
->next
)
5452 const char *comp_name
= NULL
;
5455 mio_lparen (); /* component opening. */
5457 p
= get_integer (n
);
5458 if (p
->u
.pointer
== NULL
)
5459 associate_integer_pointer (p
, c
);
5460 mio_pool_string (&comp_name
);
5461 if (comp_name
!= c
->name
)
5463 gfc_fatal_error ("Mismatch in components of derived type "
5464 "%qs from %qs at %C: expecting %qs, "
5465 "but got %qs", sym
->name
, sym
->module
,
5466 c
->name
, comp_name
);
5468 skip_list (1); /* component end. */
5470 mio_rparen (); /* component list closing. */
5472 skip_list (1); /* symbol end. */
5477 /* Some symbols do not have a namespace (eg. formal arguments),
5478 so the automatic "unique symtree" mechanism must be suppressed
5479 by marking them as referenced. */
5480 q
= get_integer (info
->u
.rsym
.ns
);
5481 if (q
->u
.pointer
== NULL
)
5483 info
->u
.rsym
.referenced
= 1;
5490 /* Parse the symtree lists. This lets us mark which symbols need to
5491 be loaded. Renaming is also done at this point by replacing the
5496 while (peek_atom () != ATOM_RPAREN
)
5498 mio_internal_string (name
);
5499 mio_integer (&ambiguous
);
5500 mio_integer (&symbol
);
5502 info
= get_integer (symbol
);
5504 /* See how many use names there are. If none, go through the start
5505 of the loop at least once. */
5506 nuse
= number_use_names (name
, false);
5507 info
->u
.rsym
.renamed
= nuse
? 1 : 0;
5512 for (j
= 1; j
<= nuse
; j
++)
5514 /* Get the jth local name for this symbol. */
5515 p
= find_use_name_n (name
, &j
, false);
5517 if (p
== NULL
&& strcmp (name
, module_name
) == 0)
5520 /* Exception: Always import vtabs & vtypes. */
5521 if (p
== NULL
&& name
[0] == '_'
5522 && (startswith (name
, "__vtab_")
5523 || startswith (name
, "__vtype_")))
5526 /* Skip symtree nodes not in an ONLY clause, unless there
5527 is an existing symtree loaded from another USE statement. */
5530 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
5532 && strcmp (st
->n
.sym
->name
, info
->u
.rsym
.true_name
) == 0
5533 && st
->n
.sym
->module
!= NULL
5534 && strcmp (st
->n
.sym
->module
, info
->u
.rsym
.module
) == 0)
5536 info
->u
.rsym
.symtree
= st
;
5537 info
->u
.rsym
.sym
= st
->n
.sym
;
5542 /* If a symbol of the same name and module exists already,
5543 this symbol, which is not in an ONLY clause, must not be
5544 added to the namespace(11.3.2). Note that find_symbol
5545 only returns the first occurrence that it finds. */
5546 if (!only_flag
&& !info
->u
.rsym
.renamed
5547 && strcmp (name
, module_name
) != 0
5548 && find_symbol (gfc_current_ns
->sym_root
, name
,
5552 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
5555 && !(st
->n
.sym
&& st
->n
.sym
->attr
.used_in_submodule
))
5557 /* Check for ambiguous symbols. */
5558 if (check_for_ambiguous (st
, info
))
5561 info
->u
.rsym
.symtree
= st
;
5567 /* This symbol is host associated from a module in a
5568 submodule. Hide it with a unique symtree. */
5569 gfc_symtree
*s
= gfc_get_unique_symtree (gfc_current_ns
);
5570 s
->n
.sym
= st
->n
.sym
;
5575 /* Create a symtree node in the current namespace for this
5577 st
= check_unique_name (p
)
5578 ? gfc_get_unique_symtree (gfc_current_ns
)
5579 : gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
5580 st
->ambiguous
= ambiguous
;
5583 sym
= info
->u
.rsym
.sym
;
5585 /* Create a symbol node if it doesn't already exist. */
5588 info
->u
.rsym
.sym
= gfc_new_symbol (info
->u
.rsym
.true_name
,
5590 info
->u
.rsym
.sym
->name
= gfc_dt_lower_string (info
->u
.rsym
.true_name
);
5591 sym
= info
->u
.rsym
.sym
;
5592 sym
->module
= gfc_get_string ("%s", info
->u
.rsym
.module
);
5594 if (info
->u
.rsym
.binding_label
)
5596 tree id
= get_identifier (info
->u
.rsym
.binding_label
);
5597 sym
->binding_label
= IDENTIFIER_POINTER (id
);
5604 if (strcmp (name
, p
) != 0)
5605 sym
->attr
.use_rename
= 1;
5608 || (!startswith (name
, "__vtab_")
5609 && !startswith (name
, "__vtype_")))
5610 sym
->attr
.use_only
= only_flag
;
5612 /* Store the symtree pointing to this symbol. */
5613 info
->u
.rsym
.symtree
= st
;
5615 if (info
->u
.rsym
.state
== UNUSED
)
5616 info
->u
.rsym
.state
= NEEDED
;
5617 info
->u
.rsym
.referenced
= 1;
5624 /* Load intrinsic operator interfaces. */
5625 set_module_locus (&operator_interfaces
);
5628 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
5630 gfc_use_rename
*u
= NULL
, *v
= NULL
;
5633 if (i
== INTRINSIC_USER
)
5638 u
= find_use_operator ((gfc_intrinsic_op
) i
);
5640 /* F2018:10.1.5.5.1 requires same interpretation of old and new-style
5641 relational operators. Special handling for USE, ONLY. */
5645 j
= INTRINSIC_EQ_OS
;
5647 case INTRINSIC_EQ_OS
:
5651 j
= INTRINSIC_NE_OS
;
5653 case INTRINSIC_NE_OS
:
5657 j
= INTRINSIC_GT_OS
;
5659 case INTRINSIC_GT_OS
:
5663 j
= INTRINSIC_GE_OS
;
5665 case INTRINSIC_GE_OS
:
5669 j
= INTRINSIC_LT_OS
;
5671 case INTRINSIC_LT_OS
:
5675 j
= INTRINSIC_LE_OS
;
5677 case INTRINSIC_LE_OS
:
5685 v
= find_use_operator ((gfc_intrinsic_op
) j
);
5687 if (u
== NULL
&& v
== NULL
)
5699 mio_interface (&gfc_current_ns
->op
[i
]);
5700 if (!gfc_current_ns
->op
[i
] && !gfc_current_ns
->op
[j
])
5711 /* Load generic and user operator interfaces. These must follow the
5712 loading of symtree because otherwise symbols can be marked as
5715 set_module_locus (&user_operators
);
5717 load_operator_interfaces ();
5718 load_generic_interfaces ();
5723 /* Load OpenMP user defined reductions. */
5724 set_module_locus (&omp_udrs
);
5727 /* At this point, we read those symbols that are needed but haven't
5728 been loaded yet. If one symbol requires another, the other gets
5729 marked as NEEDED if its previous state was UNUSED. */
5731 while (load_needed (pi_root
));
5733 /* Make sure all elements of the rename-list were found in the module. */
5735 for (u
= gfc_rename_list
; u
; u
= u
->next
)
5740 if (u
->op
== INTRINSIC_NONE
)
5742 gfc_error ("Symbol %qs referenced at %L not found in module %qs",
5743 u
->use_name
, &u
->where
, module_name
);
5747 if (u
->op
== INTRINSIC_USER
)
5749 gfc_error ("User operator %qs referenced at %L not found "
5750 "in module %qs", u
->use_name
, &u
->where
, module_name
);
5754 gfc_error ("Intrinsic operator %qs referenced at %L not found "
5755 "in module %qs", gfc_op2string (u
->op
), &u
->where
,
5759 /* Clean up symbol nodes that were never loaded, create references
5760 to hidden symbols. */
5762 read_cleanup (pi_root
);
5766 /* Given an access type that is specific to an entity and the default
5767 access, return nonzero if the entity is publicly accessible. If the
5768 element is declared as PUBLIC, then it is public; if declared
5769 PRIVATE, then private, and otherwise it is public unless the default
5770 access in this context has been declared PRIVATE. */
5772 static bool dump_smod
= false;
5775 check_access (gfc_access specific_access
, gfc_access default_access
)
5780 if (specific_access
== ACCESS_PUBLIC
)
5782 if (specific_access
== ACCESS_PRIVATE
)
5785 if (flag_module_private
)
5786 return default_access
== ACCESS_PUBLIC
;
5788 return default_access
!= ACCESS_PRIVATE
;
5793 gfc_check_symbol_access (gfc_symbol
*sym
)
5795 if (sym
->attr
.vtab
|| sym
->attr
.vtype
)
5798 return check_access (sym
->attr
.access
, sym
->ns
->default_access
);
5802 /* A structure to remember which commons we've already written. */
5804 struct written_common
5806 BBT_HEADER(written_common
);
5807 const char *name
, *label
;
5810 static struct written_common
*written_commons
= NULL
;
5812 /* Comparison function used for balancing the binary tree. */
5815 compare_written_commons (void *a1
, void *b1
)
5817 const char *aname
= ((struct written_common
*) a1
)->name
;
5818 const char *alabel
= ((struct written_common
*) a1
)->label
;
5819 const char *bname
= ((struct written_common
*) b1
)->name
;
5820 const char *blabel
= ((struct written_common
*) b1
)->label
;
5821 int c
= strcmp (aname
, bname
);
5823 return (c
!= 0 ? c
: strcmp (alabel
, blabel
));
5826 /* Free a list of written commons. */
5829 free_written_common (struct written_common
*w
)
5835 free_written_common (w
->left
);
5837 free_written_common (w
->right
);
5842 /* Write a common block to the module -- recursive helper function. */
5845 write_common_0 (gfc_symtree
*st
, bool this_module
)
5851 struct written_common
*w
;
5852 bool write_me
= true;
5857 write_common_0 (st
->left
, this_module
);
5859 /* We will write out the binding label, or "" if no label given. */
5860 name
= st
->n
.common
->name
;
5862 label
= (p
->is_bind_c
&& p
->binding_label
) ? p
->binding_label
: "";
5864 /* Check if we've already output this common. */
5865 w
= written_commons
;
5868 int c
= strcmp (name
, w
->name
);
5869 c
= (c
!= 0 ? c
: strcmp (label
, w
->label
));
5873 w
= (c
< 0) ? w
->left
: w
->right
;
5876 if (this_module
&& p
->use_assoc
)
5881 /* Write the common to the module. */
5883 mio_pool_string (&name
);
5885 mio_symbol_ref (&p
->head
);
5886 flags
= p
->saved
? 1 : 0;
5887 if (p
->threadprivate
)
5889 flags
|= p
->omp_device_type
<< 2;
5890 mio_integer (&flags
);
5892 /* Write out whether the common block is bind(c) or not. */
5893 mio_integer (&(p
->is_bind_c
));
5895 mio_pool_string (&label
);
5898 /* Record that we have written this common. */
5899 w
= XCNEW (struct written_common
);
5902 gfc_insert_bbt (&written_commons
, w
, compare_written_commons
);
5905 write_common_0 (st
->right
, this_module
);
5909 /* Write a common, by initializing the list of written commons, calling
5910 the recursive function write_common_0() and cleaning up afterwards. */
5913 write_common (gfc_symtree
*st
)
5915 written_commons
= NULL
;
5916 write_common_0 (st
, true);
5917 write_common_0 (st
, false);
5918 free_written_common (written_commons
);
5919 written_commons
= NULL
;
5923 /* Write the blank common block to the module. */
5926 write_blank_common (void)
5928 const char * name
= BLANK_COMMON_NAME
;
5930 /* TODO: Blank commons are not bind(c). The F2003 standard probably says
5931 this, but it hasn't been checked. Just making it so for now. */
5934 if (gfc_current_ns
->blank_common
.head
== NULL
)
5939 mio_pool_string (&name
);
5941 mio_symbol_ref (&gfc_current_ns
->blank_common
.head
);
5942 saved
= gfc_current_ns
->blank_common
.saved
;
5943 mio_integer (&saved
);
5945 /* Write out whether the common block is bind(c) or not. */
5946 mio_integer (&is_bind_c
);
5948 /* Write out an empty binding label. */
5949 write_atom (ATOM_STRING
, "");
5955 /* Write equivalences to the module. */
5964 for (eq
= gfc_current_ns
->equiv
; eq
; eq
= eq
->next
)
5968 for (e
= eq
; e
; e
= e
->eq
)
5970 if (e
->module
== NULL
)
5971 e
->module
= gfc_get_string ("%s.eq.%d", module_name
, num
);
5972 mio_allocated_string (e
->module
);
5973 mio_expr (&e
->expr
);
5982 /* Write a symbol to the module. */
5985 write_symbol (int n
, gfc_symbol
*sym
)
5989 if (sym
->attr
.flavor
== FL_UNKNOWN
|| sym
->attr
.flavor
== FL_LABEL
)
5990 gfc_internal_error ("write_symbol(): bad module symbol %qs", sym
->name
);
5994 if (gfc_fl_struct (sym
->attr
.flavor
))
5997 name
= gfc_dt_upper_string (sym
->name
);
5998 mio_pool_string (&name
);
6001 mio_pool_string (&sym
->name
);
6003 mio_pool_string (&sym
->module
);
6004 if ((sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
) && sym
->binding_label
)
6006 label
= sym
->binding_label
;
6007 mio_pool_string (&label
);
6010 write_atom (ATOM_STRING
, "");
6012 mio_pointer_ref (&sym
->ns
);
6019 /* Recursive traversal function to write the initial set of symbols to
6020 the module. We check to see if the symbol should be written
6021 according to the access specification. */
6024 write_symbol0 (gfc_symtree
*st
)
6028 bool dont_write
= false;
6033 write_symbol0 (st
->left
);
6036 if (sym
->module
== NULL
)
6037 sym
->module
= module_name
;
6039 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
6040 && !sym
->attr
.subroutine
&& !sym
->attr
.function
)
6043 if (!gfc_check_symbol_access (sym
))
6048 p
= get_pointer (sym
);
6049 if (p
->type
== P_UNKNOWN
)
6052 if (p
->u
.wsym
.state
!= WRITTEN
)
6054 write_symbol (p
->integer
, sym
);
6055 p
->u
.wsym
.state
= WRITTEN
;
6059 write_symbol0 (st
->right
);
6064 write_omp_udr (gfc_omp_udr
*udr
)
6068 case OMP_REDUCTION_USER
:
6069 /* Non-operators can't be used outside of the module. */
6070 if (udr
->name
[0] != '.')
6075 size_t len
= strlen (udr
->name
+ 1);
6076 char *name
= XALLOCAVEC (char, len
);
6077 memcpy (name
, udr
->name
, len
- 1);
6078 name
[len
- 1] = '\0';
6079 st
= gfc_find_symtree (gfc_current_ns
->uop_root
, name
);
6080 /* If corresponding user operator is private, don't write
6084 gfc_user_op
*uop
= st
->n
.uop
;
6085 if (!check_access (uop
->access
, uop
->ns
->default_access
))
6090 case OMP_REDUCTION_PLUS
:
6091 case OMP_REDUCTION_MINUS
:
6092 case OMP_REDUCTION_TIMES
:
6093 case OMP_REDUCTION_AND
:
6094 case OMP_REDUCTION_OR
:
6095 case OMP_REDUCTION_EQV
:
6096 case OMP_REDUCTION_NEQV
:
6097 /* If corresponding operator is private, don't write the UDR. */
6098 if (!check_access (gfc_current_ns
->operator_access
[udr
->rop
],
6099 gfc_current_ns
->default_access
))
6105 if (udr
->ts
.type
== BT_DERIVED
|| udr
->ts
.type
== BT_CLASS
)
6107 /* If derived type is private, don't write the UDR. */
6108 if (!gfc_check_symbol_access (udr
->ts
.u
.derived
))
6113 mio_pool_string (&udr
->name
);
6114 mio_typespec (&udr
->ts
);
6115 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
, false);
6116 if (udr
->initializer_ns
)
6117 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
6118 udr
->initializer_ns
, true);
6124 write_omp_udrs (gfc_symtree
*st
)
6129 write_omp_udrs (st
->left
);
6131 for (udr
= st
->n
.omp_udr
; udr
; udr
= udr
->next
)
6132 write_omp_udr (udr
);
6133 write_omp_udrs (st
->right
);
6137 /* Type for the temporary tree used when writing secondary symbols. */
6139 struct sorted_pointer_info
6141 BBT_HEADER (sorted_pointer_info
);
6146 #define gfc_get_sorted_pointer_info() XCNEW (sorted_pointer_info)
6148 /* Recursively traverse the temporary tree, free its contents. */
6151 free_sorted_pointer_info_tree (sorted_pointer_info
*p
)
6156 free_sorted_pointer_info_tree (p
->left
);
6157 free_sorted_pointer_info_tree (p
->right
);
6162 /* Comparison function for the temporary tree. */
6165 compare_sorted_pointer_info (void *_spi1
, void *_spi2
)
6167 sorted_pointer_info
*spi1
, *spi2
;
6168 spi1
= (sorted_pointer_info
*)_spi1
;
6169 spi2
= (sorted_pointer_info
*)_spi2
;
6171 if (spi1
->p
->integer
< spi2
->p
->integer
)
6173 if (spi1
->p
->integer
> spi2
->p
->integer
)
6179 /* Finds the symbols that need to be written and collects them in the
6180 sorted_pi tree so that they can be traversed in an order
6181 independent of memory addresses. */
6184 find_symbols_to_write(sorted_pointer_info
**tree
, pointer_info
*p
)
6189 if (p
->type
== P_SYMBOL
&& p
->u
.wsym
.state
== NEEDS_WRITE
)
6191 sorted_pointer_info
*sp
= gfc_get_sorted_pointer_info();
6194 gfc_insert_bbt (tree
, sp
, compare_sorted_pointer_info
);
6197 find_symbols_to_write (tree
, p
->left
);
6198 find_symbols_to_write (tree
, p
->right
);
6202 /* Recursive function that traverses the tree of symbols that need to be
6203 written and writes them in order. */
6206 write_symbol1_recursion (sorted_pointer_info
*sp
)
6211 write_symbol1_recursion (sp
->left
);
6213 pointer_info
*p1
= sp
->p
;
6214 gcc_assert (p1
->type
== P_SYMBOL
&& p1
->u
.wsym
.state
== NEEDS_WRITE
);
6216 p1
->u
.wsym
.state
= WRITTEN
;
6217 write_symbol (p1
->integer
, p1
->u
.wsym
.sym
);
6218 p1
->u
.wsym
.sym
->attr
.public_used
= 1;
6220 write_symbol1_recursion (sp
->right
);
6224 /* Write the secondary set of symbols to the module file. These are
6225 symbols that were not public yet are needed by the public symbols
6226 or another dependent symbol. The act of writing a symbol can add
6227 symbols to the pointer_info tree, so we return nonzero if a symbol
6228 was written and pass that information upwards. The caller will
6229 then call this function again until nothing was written. It uses
6230 the utility functions and a temporary tree to ensure a reproducible
6231 ordering of the symbol output and thus the module file. */
6234 write_symbol1 (pointer_info
*p
)
6239 /* Put symbols that need to be written into a tree sorted on the
6242 sorted_pointer_info
*spi_root
= NULL
;
6243 find_symbols_to_write (&spi_root
, p
);
6245 /* No symbols to write, return. */
6249 /* Otherwise, write and free the tree again. */
6250 write_symbol1_recursion (spi_root
);
6251 free_sorted_pointer_info_tree (spi_root
);
6257 /* Write operator interfaces associated with a symbol. */
6260 write_operator (gfc_user_op
*uop
)
6262 static char nullstring
[] = "";
6263 const char *p
= nullstring
;
6265 if (uop
->op
== NULL
|| !check_access (uop
->access
, uop
->ns
->default_access
))
6268 mio_symbol_interface (&uop
->name
, &p
, &uop
->op
);
6272 /* Write generic interfaces from the namespace sym_root. */
6275 write_generic (gfc_symtree
*st
)
6282 write_generic (st
->left
);
6285 if (sym
&& !check_unique_name (st
->name
)
6286 && sym
->generic
&& gfc_check_symbol_access (sym
))
6289 sym
->module
= module_name
;
6291 mio_symbol_interface (&st
->name
, &sym
->module
, &sym
->generic
);
6294 write_generic (st
->right
);
6299 write_symtree (gfc_symtree
*st
)
6306 /* A symbol in an interface body must not be visible in the
6308 if (sym
->ns
!= gfc_current_ns
6309 && sym
->ns
->proc_name
6310 && sym
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
6313 if (!gfc_check_symbol_access (sym
)
6314 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
6315 && !sym
->attr
.subroutine
&& !sym
->attr
.function
))
6318 if (check_unique_name (st
->name
))
6321 /* From F2003 onwards, intrinsic procedures are no longer subject to
6322 the restriction, "that an elemental intrinsic function here be of
6323 type integer or character and each argument must be an initialization
6324 expr of type integer or character" is lifted so that intrinsic
6325 procedures can be over-ridden. This requires that the intrinsic
6326 symbol not appear in the module file, thereby preventing ambiguity
6328 if (strcmp (sym
->module
, "(intrinsic)") == 0
6329 && (gfc_option
.allow_std
& GFC_STD_F2003
))
6332 p
= find_pointer (sym
);
6334 gfc_internal_error ("write_symtree(): Symbol not written");
6336 mio_pool_string (&st
->name
);
6337 mio_integer (&st
->ambiguous
);
6338 mio_hwi (&p
->integer
);
6347 /* Initialize the column counter. */
6350 /* Write the operator interfaces. */
6353 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
6355 if (i
== INTRINSIC_USER
)
6358 mio_interface (check_access (gfc_current_ns
->operator_access
[i
],
6359 gfc_current_ns
->default_access
)
6360 ? &gfc_current_ns
->op
[i
] : NULL
);
6368 gfc_traverse_user_op (gfc_current_ns
, write_operator
);
6374 write_generic (gfc_current_ns
->sym_root
);
6380 write_blank_common ();
6381 write_common (gfc_current_ns
->common_root
);
6393 write_omp_udrs (gfc_current_ns
->omp_udr_root
);
6398 /* Write symbol information. First we traverse all symbols in the
6399 primary namespace, writing those that need to be written.
6400 Sometimes writing one symbol will cause another to need to be
6401 written. A list of these symbols ends up on the write stack, and
6402 we end by popping the bottom of the stack and writing the symbol
6403 until the stack is empty. */
6407 write_symbol0 (gfc_current_ns
->sym_root
);
6408 while (write_symbol1 (pi_root
))
6417 gfc_traverse_symtree (gfc_current_ns
->sym_root
, write_symtree
);
6422 /* Read a CRC32 sum from the gzip trailer of a module file. Returns
6423 true on success, false on failure. */
6426 read_crc32_from_module_file (const char* filename
, uLong
* crc
)
6432 /* Open the file in binary mode. */
6433 if ((file
= fopen (filename
, "rb")) == NULL
)
6436 /* The gzip crc32 value is found in the [END-8, END-4] bytes of the
6437 file. See RFC 1952. */
6438 if (fseek (file
, -8, SEEK_END
) != 0)
6444 /* Read the CRC32. */
6445 if (fread (buf
, 1, 4, file
) != 4)
6451 /* Close the file. */
6454 val
= (buf
[0] & 0xFF) + ((buf
[1] & 0xFF) << 8) + ((buf
[2] & 0xFF) << 16)
6455 + ((buf
[3] & 0xFF) << 24);
6458 /* For debugging, the CRC value printed in hexadecimal should match
6459 the CRC printed by "zcat -l -v filename".
6460 printf("CRC of file %s is %x\n", filename, val); */
6466 /* Given module, dump it to disk. If there was an error while
6467 processing the module, dump_flag will be set to zero and we delete
6468 the module file, even if it was already there. */
6471 dump_module (const char *name
, int dump_flag
)
6474 char *filename
, *filename_tmp
;
6477 module_name
= gfc_get_string ("%s", name
);
6481 name
= submodule_name
;
6482 n
= strlen (name
) + strlen (SUBMODULE_EXTENSION
) + 1;
6485 n
= strlen (name
) + strlen (MODULE_EXTENSION
) + 1;
6487 if (gfc_option
.module_dir
!= NULL
)
6489 n
+= strlen (gfc_option
.module_dir
);
6490 filename
= (char *) alloca (n
);
6491 strcpy (filename
, gfc_option
.module_dir
);
6492 strcat (filename
, name
);
6496 filename
= (char *) alloca (n
);
6497 strcpy (filename
, name
);
6501 strcat (filename
, SUBMODULE_EXTENSION
);
6503 strcat (filename
, MODULE_EXTENSION
);
6505 /* Name of the temporary file used to write the module. */
6506 filename_tmp
= (char *) alloca (n
+ 1);
6507 strcpy (filename_tmp
, filename
);
6508 strcat (filename_tmp
, "0");
6510 /* There was an error while processing the module. We delete the
6511 module file, even if it was already there. */
6518 if (gfc_cpp_makedep ())
6519 gfc_cpp_add_target (filename
);
6521 /* Write the module to the temporary file. */
6522 module_fp
= gzopen (filename_tmp
, "w");
6523 if (module_fp
== NULL
)
6524 gfc_fatal_error ("Cannot open module file %qs for writing at %C: %s",
6525 filename_tmp
, xstrerror (errno
));
6527 /* Use lbasename to ensure module files are reproducible regardless
6528 of the build path (see the reproducible builds project). */
6529 gzprintf (module_fp
, "GFORTRAN module version '%s' created from %s\n",
6530 MOD_VERSION
, lbasename (gfc_source_file
));
6532 /* Write the module itself. */
6539 free_pi_tree (pi_root
);
6544 if (gzclose (module_fp
))
6545 gfc_fatal_error ("Error writing module file %qs for writing: %s",
6546 filename_tmp
, xstrerror (errno
));
6548 /* Read the CRC32 from the gzip trailers of the module files and
6550 if (!read_crc32_from_module_file (filename_tmp
, &crc
)
6551 || !read_crc32_from_module_file (filename
, &crc_old
)
6554 /* Module file have changed, replace the old one. */
6555 if (remove (filename
) && errno
!= ENOENT
)
6556 gfc_fatal_error ("Cannot delete module file %qs: %s", filename
,
6558 if (rename (filename_tmp
, filename
))
6559 gfc_fatal_error ("Cannot rename module file %qs to %qs: %s",
6560 filename_tmp
, filename
, xstrerror (errno
));
6564 if (remove (filename_tmp
))
6565 gfc_fatal_error ("Cannot delete temporary module file %qs: %s",
6566 filename_tmp
, xstrerror (errno
));
6571 /* Suppress the output of a .smod file by module, if no module
6572 procedures have been seen. */
6573 static bool no_module_procedures
;
6576 check_for_module_procedures (gfc_symbol
*sym
)
6578 if (sym
&& sym
->attr
.module_procedure
)
6579 no_module_procedures
= false;
6584 gfc_dump_module (const char *name
, int dump_flag
)
6586 if (gfc_state_stack
->state
== COMP_SUBMODULE
)
6591 no_module_procedures
= true;
6592 gfc_traverse_ns (gfc_current_ns
, check_for_module_procedures
);
6594 dump_module (name
, dump_flag
);
6596 if (no_module_procedures
|| dump_smod
)
6599 /* Write a submodule file from a module. The 'dump_smod' flag switches
6600 off the check for PRIVATE entities. */
6602 submodule_name
= module_name
;
6603 dump_module (name
, dump_flag
);
6608 create_intrinsic_function (const char *name
, int id
,
6609 const char *modname
, intmod_id module
,
6610 bool subroutine
, gfc_symbol
*result_type
)
6612 gfc_intrinsic_sym
*isym
;
6613 gfc_symtree
*tmp_symtree
;
6616 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6619 if (tmp_symtree
->n
.sym
&& tmp_symtree
->n
.sym
->module
6620 && strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6622 gfc_error ("Symbol %qs at %C already declared", name
);
6626 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6627 sym
= tmp_symtree
->n
.sym
;
6631 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6632 isym
= gfc_intrinsic_subroutine_by_id (isym_id
);
6633 sym
->attr
.subroutine
= 1;
6637 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6638 isym
= gfc_intrinsic_function_by_id (isym_id
);
6640 sym
->attr
.function
= 1;
6643 sym
->ts
.type
= BT_DERIVED
;
6644 sym
->ts
.u
.derived
= result_type
;
6645 sym
->ts
.is_c_interop
= 1;
6646 isym
->ts
.f90_type
= BT_VOID
;
6647 isym
->ts
.type
= BT_DERIVED
;
6648 isym
->ts
.f90_type
= BT_VOID
;
6649 isym
->ts
.u
.derived
= result_type
;
6650 isym
->ts
.is_c_interop
= 1;
6655 sym
->attr
.flavor
= FL_PROCEDURE
;
6656 sym
->attr
.intrinsic
= 1;
6658 sym
->module
= gfc_get_string ("%s", modname
);
6659 sym
->attr
.use_assoc
= 1;
6660 sym
->from_intmod
= module
;
6661 sym
->intmod_sym_id
= id
;
6665 /* Import the intrinsic ISO_C_BINDING module, generating symbols in
6666 the current namespace for all named constants, pointer types, and
6667 procedures in the module unless the only clause was used or a rename
6668 list was provided. */
6671 import_iso_c_binding_module (void)
6673 gfc_symbol
*mod_sym
= NULL
, *return_type
;
6674 gfc_symtree
*mod_symtree
= NULL
, *tmp_symtree
;
6675 gfc_symtree
*c_ptr
= NULL
, *c_funptr
= NULL
;
6676 const char *iso_c_module_name
= "__iso_c_binding";
6679 bool want_c_ptr
= false, want_c_funptr
= false;
6681 /* Look only in the current namespace. */
6682 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, iso_c_module_name
);
6684 if (mod_symtree
== NULL
)
6686 /* symtree doesn't already exist in current namespace. */
6687 gfc_get_sym_tree (iso_c_module_name
, gfc_current_ns
, &mod_symtree
,
6690 if (mod_symtree
!= NULL
)
6691 mod_sym
= mod_symtree
->n
.sym
;
6693 gfc_internal_error ("import_iso_c_binding_module(): Unable to "
6694 "create symbol for %s", iso_c_module_name
);
6696 mod_sym
->attr
.flavor
= FL_MODULE
;
6697 mod_sym
->attr
.intrinsic
= 1;
6698 mod_sym
->module
= gfc_get_string ("%s", iso_c_module_name
);
6699 mod_sym
->from_intmod
= INTMOD_ISO_C_BINDING
;
6702 /* Check whether C_PTR or C_FUNPTR are in the include list, if so, load it;
6703 check also whether C_NULL_(FUN)PTR or C_(FUN)LOC are requested, which
6705 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6707 if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_PTR
].name
,
6710 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_LOC
].name
,
6713 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_FUNPTR
].name
,
6715 want_c_funptr
= true;
6716 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNLOC
].name
,
6718 want_c_funptr
= true;
6719 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_PTR
].name
,
6722 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6723 (iso_c_binding_symbol
)
6725 u
->local_name
[0] ? u
->local_name
6729 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNPTR
].name
,
6733 = generate_isocbinding_symbol (iso_c_module_name
,
6734 (iso_c_binding_symbol
)
6736 u
->local_name
[0] ? u
->local_name
6742 if ((want_c_ptr
|| !only_flag
) && !c_ptr
)
6743 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6744 (iso_c_binding_symbol
)
6746 NULL
, NULL
, only_flag
);
6747 if ((want_c_funptr
|| !only_flag
) && !c_funptr
)
6748 c_funptr
= generate_isocbinding_symbol (iso_c_module_name
,
6749 (iso_c_binding_symbol
)
6751 NULL
, NULL
, only_flag
);
6753 /* Generate the symbols for the named constants representing
6754 the kinds for intrinsic data types. */
6755 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
6758 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6759 if (strcmp (c_interop_kinds_table
[i
].name
, u
->use_name
) == 0)
6768 #define NAMED_FUNCTION(a,b,c,d) \
6770 not_in_std = (gfc_option.allow_std & d) == 0; \
6773 #define NAMED_SUBROUTINE(a,b,c,d) \
6775 not_in_std = (gfc_option.allow_std & d) == 0; \
6778 #define NAMED_INTCST(a,b,c,d) \
6780 not_in_std = (gfc_option.allow_std & d) == 0; \
6783 #define NAMED_UINTCST(a,b,c,d) \
6785 not_in_std = (gfc_option.allow_std & d) == 0; \
6788 #define NAMED_REALCST(a,b,c,d) \
6790 not_in_std = (gfc_option.allow_std & d) == 0; \
6793 #define NAMED_CMPXCST(a,b,c,d) \
6795 not_in_std = (gfc_option.allow_std & d) == 0; \
6798 #include "iso-c-binding.def"
6806 gfc_error ("The symbol %qs, referenced at %L, is not "
6807 "in the selected standard", name
, &u
->where
);
6813 #define NAMED_FUNCTION(a,b,c,d) \
6815 if (a == ISOCBINDING_LOC) \
6816 return_type = c_ptr->n.sym; \
6817 else if (a == ISOCBINDING_FUNLOC) \
6818 return_type = c_funptr->n.sym; \
6820 return_type = NULL; \
6821 create_intrinsic_function (u->local_name[0] \
6822 ? u->local_name : u->use_name, \
6823 a, iso_c_module_name, \
6824 INTMOD_ISO_C_BINDING, false, \
6827 #define NAMED_SUBROUTINE(a,b,c,d) \
6829 create_intrinsic_function (u->local_name[0] ? u->local_name \
6831 a, iso_c_module_name, \
6832 INTMOD_ISO_C_BINDING, true, NULL); \
6834 #include "iso-c-binding.def"
6836 case ISOCBINDING_PTR
:
6837 case ISOCBINDING_FUNPTR
:
6838 /* Already handled above. */
6841 if (i
== ISOCBINDING_NULL_PTR
)
6842 tmp_symtree
= c_ptr
;
6843 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6844 tmp_symtree
= c_funptr
;
6847 generate_isocbinding_symbol (iso_c_module_name
,
6848 (iso_c_binding_symbol
) i
,
6850 ? u
->local_name
: u
->use_name
,
6851 tmp_symtree
, false);
6855 if (!found
&& !only_flag
)
6857 /* Skip, if the symbol is not in the enabled standard. */
6860 #define NAMED_FUNCTION(a,b,c,d) \
6862 if ((gfc_option.allow_std & d) == 0) \
6865 #define NAMED_SUBROUTINE(a,b,c,d) \
6867 if ((gfc_option.allow_std & d) == 0) \
6870 #define NAMED_INTCST(a,b,c,d) \
6872 if ((gfc_option.allow_std & d) == 0) \
6875 #define NAMED_UINTCST(a,b,c,d) \
6877 if ((gfc_option.allow_std & d) == 0) \
6880 #define NAMED_REALCST(a,b,c,d) \
6882 if ((gfc_option.allow_std & d) == 0) \
6885 #define NAMED_CMPXCST(a,b,c,d) \
6887 if ((gfc_option.allow_std & d) == 0) \
6890 #include "iso-c-binding.def"
6892 ; /* Not GFC_STD_* versioned. */
6897 #define NAMED_FUNCTION(a,b,c,d) \
6899 if (a == ISOCBINDING_LOC) \
6900 return_type = c_ptr->n.sym; \
6901 else if (a == ISOCBINDING_FUNLOC) \
6902 return_type = c_funptr->n.sym; \
6904 return_type = NULL; \
6905 create_intrinsic_function (b, a, iso_c_module_name, \
6906 INTMOD_ISO_C_BINDING, false, \
6909 #define NAMED_SUBROUTINE(a,b,c,d) \
6911 create_intrinsic_function (b, a, iso_c_module_name, \
6912 INTMOD_ISO_C_BINDING, true, NULL); \
6914 #include "iso-c-binding.def"
6916 case ISOCBINDING_PTR
:
6917 case ISOCBINDING_FUNPTR
:
6918 /* Already handled above. */
6921 if (i
== ISOCBINDING_NULL_PTR
)
6922 tmp_symtree
= c_ptr
;
6923 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6924 tmp_symtree
= c_funptr
;
6927 generate_isocbinding_symbol (iso_c_module_name
,
6928 (iso_c_binding_symbol
) i
, NULL
,
6929 tmp_symtree
, false);
6934 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6939 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
6940 "module ISO_C_BINDING", u
->use_name
, &u
->where
);
6945 /* Add an integer named constant from a given module. */
6948 create_int_parameter (const char *name
, int value
, const char *modname
,
6949 intmod_id module
, int id
)
6951 gfc_symtree
*tmp_symtree
;
6954 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6955 if (tmp_symtree
!= NULL
)
6957 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6960 gfc_error ("Symbol %qs already declared", name
);
6963 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6964 sym
= tmp_symtree
->n
.sym
;
6966 sym
->module
= gfc_get_string ("%s", modname
);
6967 sym
->attr
.flavor
= FL_PARAMETER
;
6968 sym
->ts
.type
= BT_INTEGER
;
6969 sym
->ts
.kind
= gfc_default_integer_kind
;
6970 sym
->value
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, value
);
6971 sym
->attr
.use_assoc
= 1;
6972 sym
->from_intmod
= module
;
6973 sym
->intmod_sym_id
= id
;
6977 /* Value is already contained by the array constructor, but not
6981 create_int_parameter_array (const char *name
, int size
, gfc_expr
*value
,
6982 const char *modname
, intmod_id module
, int id
)
6984 gfc_symtree
*tmp_symtree
;
6987 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6988 if (tmp_symtree
!= NULL
)
6990 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6993 gfc_error ("Symbol %qs already declared", name
);
6996 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6997 sym
= tmp_symtree
->n
.sym
;
6999 sym
->module
= gfc_get_string ("%s", modname
);
7000 sym
->attr
.flavor
= FL_PARAMETER
;
7001 sym
->ts
.type
= BT_INTEGER
;
7002 sym
->ts
.kind
= gfc_default_integer_kind
;
7003 sym
->attr
.use_assoc
= 1;
7004 sym
->from_intmod
= module
;
7005 sym
->intmod_sym_id
= id
;
7006 sym
->attr
.dimension
= 1;
7007 sym
->as
= gfc_get_array_spec ();
7009 sym
->as
->type
= AS_EXPLICIT
;
7010 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
7011 sym
->as
->upper
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, size
);
7014 sym
->value
->shape
= gfc_get_shape (1);
7015 mpz_init_set_ui (sym
->value
->shape
[0], size
);
7019 /* Add an derived type for a given module. */
7022 create_derived_type (const char *name
, const char *modname
,
7023 intmod_id module
, int id
)
7025 gfc_symtree
*tmp_symtree
;
7026 gfc_symbol
*sym
, *dt_sym
;
7027 gfc_interface
*intr
, *head
;
7029 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
7030 if (tmp_symtree
!= NULL
)
7032 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
7035 gfc_error ("Symbol %qs already declared", name
);
7038 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
7039 sym
= tmp_symtree
->n
.sym
;
7040 sym
->module
= gfc_get_string ("%s", modname
);
7041 sym
->from_intmod
= module
;
7042 sym
->intmod_sym_id
= id
;
7043 sym
->attr
.flavor
= FL_PROCEDURE
;
7044 sym
->attr
.function
= 1;
7045 sym
->attr
.generic
= 1;
7047 gfc_get_sym_tree (gfc_dt_upper_string (sym
->name
),
7048 gfc_current_ns
, &tmp_symtree
, false);
7049 dt_sym
= tmp_symtree
->n
.sym
;
7050 dt_sym
->name
= gfc_get_string ("%s", sym
->name
);
7051 dt_sym
->attr
.flavor
= FL_DERIVED
;
7052 dt_sym
->attr
.private_comp
= 1;
7053 dt_sym
->attr
.zero_comp
= 1;
7054 dt_sym
->attr
.use_assoc
= 1;
7055 dt_sym
->module
= gfc_get_string ("%s", modname
);
7056 dt_sym
->from_intmod
= module
;
7057 dt_sym
->intmod_sym_id
= id
;
7059 head
= sym
->generic
;
7060 intr
= gfc_get_interface ();
7062 intr
->where
= gfc_current_locus
;
7064 sym
->generic
= intr
;
7065 sym
->attr
.if_source
= IFSRC_DECL
;
7069 /* Read the contents of the module file into a temporary buffer. */
7072 read_module_to_tmpbuf ()
7074 /* We don't know the uncompressed size, so enlarge the buffer as
7080 module_content
= XNEWVEC (char, cursz
);
7084 int nread
= gzread (module_fp
, module_content
+ len
, rsize
);
7089 module_content
= XRESIZEVEC (char, module_content
, cursz
);
7090 rsize
= cursz
- len
;
7093 module_content
= XRESIZEVEC (char, module_content
, len
+ 1);
7094 module_content
[len
] = '\0';
7100 /* USE the ISO_FORTRAN_ENV intrinsic module. */
7103 use_iso_fortran_env_module (void)
7105 static char mod
[] = "iso_fortran_env";
7107 gfc_symbol
*mod_sym
;
7108 gfc_symtree
*mod_symtree
;
7112 intmod_sym symbol
[] = {
7113 #define NAMED_INTCST(a,b,c,d) { a, b, 0, d },
7114 #define NAMED_UINTCST(a,b,c,d) { a, b, 0, d },
7115 #define NAMED_KINDARRAY(a,b,c,d) { a, b, 0, d },
7116 #define NAMED_DERIVED_TYPE(a,b,c,d) { a, b, 0, d },
7117 #define NAMED_FUNCTION(a,b,c,d) { a, b, c, d },
7118 #define NAMED_SUBROUTINE(a,b,c,d) { a, b, c, d },
7119 #include "iso-fortran-env.def"
7120 { ISOFORTRANENV_INVALID
, NULL
, -1234, 0 } };
7123 #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c;
7124 #include "iso-fortran-env.def"
7126 #define NAMED_UINTCST(a,b,c,d) symbol[i++].value = c;
7127 #include "iso-fortran-env.def"
7129 /* Generate the symbol for the module itself. */
7130 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, mod
);
7131 if (mod_symtree
== NULL
)
7133 gfc_get_sym_tree (mod
, gfc_current_ns
, &mod_symtree
, false);
7134 gcc_assert (mod_symtree
);
7135 mod_sym
= mod_symtree
->n
.sym
;
7137 mod_sym
->attr
.flavor
= FL_MODULE
;
7138 mod_sym
->attr
.intrinsic
= 1;
7139 mod_sym
->module
= gfc_get_string ("%s", mod
);
7140 mod_sym
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
7143 if (!mod_symtree
->n
.sym
->attr
.intrinsic
)
7144 gfc_error ("Use of intrinsic module %qs at %C conflicts with "
7145 "non-intrinsic module name used previously", mod
);
7147 /* Generate the symbols for the module integer named constants. */
7149 for (i
= 0; symbol
[i
].name
; i
++)
7152 for (u
= gfc_rename_list
; u
; u
= u
->next
)
7154 if (strcmp (symbol
[i
].name
, u
->use_name
) == 0)
7159 if (!gfc_notify_std (symbol
[i
].standard
, "The symbol %qs, "
7160 "referenced at %L, is not in the selected "
7161 "standard", symbol
[i
].name
, &u
->where
))
7164 if ((flag_default_integer
|| flag_default_real_8
)
7165 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
7166 gfc_warning_now (0, "Use of the NUMERIC_STORAGE_SIZE named "
7167 "constant from intrinsic module "
7168 "ISO_FORTRAN_ENV at %L is incompatible with "
7169 "option %qs", &u
->where
,
7170 flag_default_integer
7171 ? "-fdefault-integer-8"
7172 : "-fdefault-real-8");
7173 switch (symbol
[i
].id
)
7175 #define NAMED_INTCST(a,b,c,d) \
7177 #include "iso-fortran-env.def"
7178 create_int_parameter (u
->local_name
[0] ? u
->local_name
7180 symbol
[i
].value
, mod
,
7181 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7184 #define NAMED_UINTCST(a,b,c,d) \
7186 #include "iso-fortran-env.def"
7187 create_int_parameter (u
->local_name
[0] ? u
->local_name
7189 symbol
[i
].value
, mod
,
7190 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7193 #define NAMED_KINDARRAY(a,b,KINDS,d) \
7195 expr = gfc_get_array_expr (BT_INTEGER, \
7196 gfc_default_integer_kind,\
7198 for (j = 0; KINDS[j].kind != 0; j++) \
7199 gfc_constructor_append_expr (&expr->value.constructor, \
7200 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7201 KINDS[j].kind), NULL); \
7202 create_int_parameter_array (u->local_name[0] ? u->local_name \
7205 INTMOD_ISO_FORTRAN_ENV, \
7208 #include "iso-fortran-env.def"
7210 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7212 #include "iso-fortran-env.def"
7213 create_derived_type (u
->local_name
[0] ? u
->local_name
7215 mod
, INTMOD_ISO_FORTRAN_ENV
,
7219 #define NAMED_FUNCTION(a,b,c,d) \
7221 #include "iso-fortran-env.def"
7222 create_intrinsic_function (u
->local_name
[0] ? u
->local_name
7225 INTMOD_ISO_FORTRAN_ENV
, false,
7235 if (!found
&& !only_flag
)
7237 if ((gfc_option
.allow_std
& symbol
[i
].standard
) == 0)
7240 if ((flag_default_integer
|| flag_default_real_8
)
7241 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
7243 "Use of the NUMERIC_STORAGE_SIZE named constant "
7244 "from intrinsic module ISO_FORTRAN_ENV at %C is "
7245 "incompatible with option %s",
7246 flag_default_integer
7247 ? "-fdefault-integer-8" : "-fdefault-real-8");
7249 switch (symbol
[i
].id
)
7251 #define NAMED_INTCST(a,b,c,d) \
7253 #include "iso-fortran-env.def"
7254 create_int_parameter (symbol
[i
].name
, symbol
[i
].value
, mod
,
7255 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7258 #define NAMED_UINTCST(a,b,c,d) \
7260 #include "iso-fortran-env.def"
7261 create_int_parameter (symbol
[i
].name
, symbol
[i
].value
, mod
,
7262 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7265 #define NAMED_KINDARRAY(a,b,KINDS,d) \
7267 expr = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind, \
7269 for (j = 0; KINDS[j].kind != 0; j++) \
7270 gfc_constructor_append_expr (&expr->value.constructor, \
7271 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7272 KINDS[j].kind), NULL); \
7273 create_int_parameter_array (symbol[i].name, j, expr, mod, \
7274 INTMOD_ISO_FORTRAN_ENV, symbol[i].id);\
7276 #include "iso-fortran-env.def"
7278 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7280 #include "iso-fortran-env.def"
7281 create_derived_type (symbol
[i
].name
, mod
, INTMOD_ISO_FORTRAN_ENV
,
7285 #define NAMED_FUNCTION(a,b,c,d) \
7287 #include "iso-fortran-env.def"
7288 create_intrinsic_function (symbol
[i
].name
, symbol
[i
].id
, mod
,
7289 INTMOD_ISO_FORTRAN_ENV
, false,
7299 for (u
= gfc_rename_list
; u
; u
= u
->next
)
7304 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
7305 "module ISO_FORTRAN_ENV", u
->use_name
, &u
->where
);
7310 /* Process a USE directive. */
7313 gfc_use_module (gfc_use_list
*module
)
7318 gfc_symtree
*mod_symtree
;
7319 gfc_use_list
*use_stmt
;
7320 locus old_locus
= gfc_current_locus
;
7322 gfc_current_locus
= module
->where
;
7323 module_name
= module
->module_name
;
7324 gfc_rename_list
= module
->rename
;
7325 only_flag
= module
->only_flag
;
7326 current_intmod
= INTMOD_NONE
;
7329 gfc_warning_now (OPT_Wuse_without_only
,
7330 "USE statement at %C has no ONLY qualifier");
7332 if (gfc_state_stack
->state
== COMP_MODULE
7333 || module
->submodule_name
== NULL
)
7335 filename
= XALLOCAVEC (char, strlen (module_name
)
7336 + strlen (MODULE_EXTENSION
) + 1);
7337 strcpy (filename
, module_name
);
7338 strcat (filename
, MODULE_EXTENSION
);
7342 filename
= XALLOCAVEC (char, strlen (module
->submodule_name
)
7343 + strlen (SUBMODULE_EXTENSION
) + 1);
7344 strcpy (filename
, module
->submodule_name
);
7345 strcat (filename
, SUBMODULE_EXTENSION
);
7348 /* First, try to find an non-intrinsic module, unless the USE statement
7349 specified that the module is intrinsic. */
7351 if (!module
->intrinsic
)
7352 module_fp
= gzopen_included_file (filename
, true, true);
7354 /* Then, see if it's an intrinsic one, unless the USE statement
7355 specified that the module is non-intrinsic. */
7356 if (module_fp
== NULL
&& !module
->non_intrinsic
)
7358 if (strcmp (module_name
, "iso_fortran_env") == 0
7359 && gfc_notify_std (GFC_STD_F2003
, "ISO_FORTRAN_ENV "
7360 "intrinsic module at %C"))
7362 use_iso_fortran_env_module ();
7363 free_rename (module
->rename
);
7364 module
->rename
= NULL
;
7365 gfc_current_locus
= old_locus
;
7366 module
->intrinsic
= true;
7370 if (strcmp (module_name
, "iso_c_binding") == 0
7371 && gfc_notify_std (GFC_STD_F2003
, "ISO_C_BINDING module at %C"))
7373 import_iso_c_binding_module();
7374 free_rename (module
->rename
);
7375 module
->rename
= NULL
;
7376 gfc_current_locus
= old_locus
;
7377 module
->intrinsic
= true;
7381 module_fp
= gzopen_intrinsic_module (filename
);
7383 if (module_fp
== NULL
&& module
->intrinsic
)
7384 gfc_fatal_error ("Cannot find an intrinsic module named %qs at %C",
7387 /* Check for the IEEE modules, so we can mark their symbols
7388 accordingly when we read them. */
7389 if (strcmp (module_name
, "ieee_features") == 0
7390 && gfc_notify_std (GFC_STD_F2003
, "IEEE_FEATURES module at %C"))
7392 current_intmod
= INTMOD_IEEE_FEATURES
;
7394 else if (strcmp (module_name
, "ieee_exceptions") == 0
7395 && gfc_notify_std (GFC_STD_F2003
,
7396 "IEEE_EXCEPTIONS module at %C"))
7398 current_intmod
= INTMOD_IEEE_EXCEPTIONS
;
7400 else if (strcmp (module_name
, "ieee_arithmetic") == 0
7401 && gfc_notify_std (GFC_STD_F2003
,
7402 "IEEE_ARITHMETIC module at %C"))
7404 current_intmod
= INTMOD_IEEE_ARITHMETIC
;
7408 if (module_fp
== NULL
)
7410 if (gfc_state_stack
->state
!= COMP_SUBMODULE
7411 && module
->submodule_name
== NULL
)
7412 gfc_fatal_error ("Cannot open module file %qs for reading at %C: %s",
7413 filename
, xstrerror (errno
));
7415 gfc_fatal_error ("Module file %qs has not been generated, either "
7416 "because the module does not contain a MODULE "
7417 "PROCEDURE or there is an error in the module.",
7421 /* Check that we haven't already USEd an intrinsic module with the
7424 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, module_name
);
7425 if (mod_symtree
&& mod_symtree
->n
.sym
->attr
.intrinsic
)
7426 gfc_error ("Use of non-intrinsic module %qs at %C conflicts with "
7427 "intrinsic module name used previously", module_name
);
7434 read_module_to_tmpbuf ();
7435 gzclose (module_fp
);
7437 /* Skip the first line of the module, after checking that this is
7438 a gfortran module file. */
7444 bad_module ("Unexpected end of module");
7447 if ((start
== 1 && strcmp (atom_name
, "GFORTRAN") != 0)
7448 || (start
== 2 && strcmp (atom_name
, " module") != 0))
7449 gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran"
7450 " module file", module_fullpath
);
7453 if (strcmp (atom_name
, " version") != 0
7454 || module_char () != ' '
7455 || parse_atom () != ATOM_STRING
7456 || strcmp (atom_string
, MOD_VERSION
))
7457 gfc_fatal_error ("Cannot read module file %qs opened at %C,"
7458 " because it was created by a different"
7459 " version of GNU Fortran", module_fullpath
);
7468 /* Make sure we're not reading the same module that we may be building. */
7469 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
7470 if ((p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
)
7471 && strcmp (p
->sym
->name
, module_name
) == 0)
7473 if (p
->state
== COMP_SUBMODULE
)
7474 gfc_fatal_error ("Cannot USE a submodule that is currently built");
7476 gfc_fatal_error ("Cannot USE a module that is currently built");
7480 init_true_name_tree ();
7484 free_true_name (true_name_root
);
7485 true_name_root
= NULL
;
7487 free_pi_tree (pi_root
);
7490 XDELETEVEC (module_content
);
7491 module_content
= NULL
;
7493 use_stmt
= gfc_get_use_list ();
7494 *use_stmt
= *module
;
7495 use_stmt
->next
= gfc_current_ns
->use_stmts
;
7496 gfc_current_ns
->use_stmts
= use_stmt
;
7498 gfc_current_locus
= old_locus
;
7502 /* Remove duplicated intrinsic operators from the rename list. */
7505 rename_list_remove_duplicate (gfc_use_rename
*list
)
7507 gfc_use_rename
*seek
, *last
;
7509 for (; list
; list
= list
->next
)
7510 if (list
->op
!= INTRINSIC_USER
&& list
->op
!= INTRINSIC_NONE
)
7513 for (seek
= list
->next
; seek
; seek
= last
->next
)
7515 if (list
->op
== seek
->op
)
7517 last
->next
= seek
->next
;
7527 /* Process all USE directives. */
7530 gfc_use_modules (void)
7532 gfc_use_list
*next
, *seek
, *last
;
7534 for (next
= module_list
; next
; next
= next
->next
)
7536 bool non_intrinsic
= next
->non_intrinsic
;
7537 bool intrinsic
= next
->intrinsic
;
7538 bool neither
= !non_intrinsic
&& !intrinsic
;
7540 for (seek
= next
->next
; seek
; seek
= seek
->next
)
7542 if (next
->module_name
!= seek
->module_name
)
7545 if (seek
->non_intrinsic
)
7546 non_intrinsic
= true;
7547 else if (seek
->intrinsic
)
7553 if (intrinsic
&& neither
&& !non_intrinsic
)
7558 filename
= XALLOCAVEC (char,
7559 strlen (next
->module_name
)
7560 + strlen (MODULE_EXTENSION
) + 1);
7561 strcpy (filename
, next
->module_name
);
7562 strcat (filename
, MODULE_EXTENSION
);
7563 fp
= gfc_open_included_file (filename
, true, true);
7566 non_intrinsic
= true;
7572 for (seek
= next
->next
; seek
; seek
= last
->next
)
7574 if (next
->module_name
!= seek
->module_name
)
7580 if ((!next
->intrinsic
&& !seek
->intrinsic
)
7581 || (next
->intrinsic
&& seek
->intrinsic
)
7584 if (!seek
->only_flag
)
7585 next
->only_flag
= false;
7588 gfc_use_rename
*r
= seek
->rename
;
7591 r
->next
= next
->rename
;
7592 next
->rename
= seek
->rename
;
7594 last
->next
= seek
->next
;
7602 for (; module_list
; module_list
= next
)
7604 next
= module_list
->next
;
7605 rename_list_remove_duplicate (module_list
->rename
);
7606 gfc_use_module (module_list
);
7610 old_module_list_tail
= &module_list
;
7611 gfc_rename_list
= NULL
;
7616 gfc_free_use_stmts (gfc_use_list
*use_stmts
)
7619 for (; use_stmts
; use_stmts
= next
)
7621 gfc_use_rename
*next_rename
;
7623 for (; use_stmts
->rename
; use_stmts
->rename
= next_rename
)
7625 next_rename
= use_stmts
->rename
->next
;
7626 free (use_stmts
->rename
);
7628 next
= use_stmts
->next
;
7634 /* Remember the end of the MODULE_LIST list, so that the list can be restored
7635 to its previous state if the current statement is erroneous. */
7638 gfc_save_module_list ()
7640 gfc_use_list
**tail
= &module_list
;
7641 while (*tail
!= NULL
)
7642 tail
= &(*tail
)->next
;
7643 old_module_list_tail
= tail
;
7647 /* Restore the MODULE_LIST list to its previous value and free the use
7648 statements that are no longer part of the list. */
7651 gfc_restore_old_module_list ()
7653 gfc_free_use_stmts (*old_module_list_tail
);
7654 *old_module_list_tail
= NULL
;
7659 gfc_module_init_2 (void)
7661 last_atom
= ATOM_LPAREN
;
7662 gfc_rename_list
= NULL
;
7668 gfc_module_done_2 (void)
7670 free_rename (gfc_rename_list
);
7671 gfc_rename_list
= NULL
;