1 /* Handle modules, which amounts to loading and saving symbols and
2 their attendant structures.
3 Copyright (C) 2000-2025 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 "16"
88 /* Older mod versions we can still parse. */
89 #define COMPAT_MOD_VERSIONS { "15" }
92 /* Structure that describes a position within a module file. */
101 /* Structure for list of symbols of intrinsic modules. */
114 P_UNKNOWN
= 0, P_OTHER
, P_NAMESPACE
, P_COMPONENT
, P_SYMBOL
118 /* The fixup structure lists pointers to pointers that have to
119 be updated when a pointer value becomes known. */
121 typedef struct fixup_t
124 struct fixup_t
*next
;
129 /* Structure for holding extra info needed for pointers being read. */
145 typedef struct pointer_info
147 BBT_HEADER (pointer_info
);
148 HOST_WIDE_INT integer
;
151 /* The first component of each member of the union is the pointer
158 void *pointer
; /* Member for doing pointer searches. */
163 char *true_name
, *module
, *binding_label
;
165 gfc_symtree
*symtree
;
166 enum gfc_rsym_state state
;
167 int ns
, referenced
, renamed
;
175 enum gfc_wsym_state state
;
184 #define gfc_get_pointer_info() XCNEW (pointer_info)
187 /* Local variables */
189 /* The gzFile for the module we're reading or writing. */
190 static gzFile module_fp
;
192 /* Fully qualified module path */
193 static char *module_fullpath
= NULL
;
195 /* The name of the module we're reading (USE'ing) or writing. */
196 static const char *module_name
;
197 /* The name of the .smod file that the submodule will write to. */
198 static const char *submodule_name
;
200 /* The list of use statements to apply to the current namespace
201 before parsing the non-use statements. */
202 static gfc_use_list
*module_list
;
203 /* The end of the MODULE_LIST list above at the time the recognition
204 of the current statement started. */
205 static gfc_use_list
**old_module_list_tail
;
207 /* If we're reading an intrinsic module, this is its ID. */
208 static intmod_id current_intmod
;
210 /* Content of module. */
211 static char* module_content
;
213 static long module_pos
;
214 static int module_line
, module_column
, only_flag
;
215 static int prev_module_line
, prev_module_column
;
218 { IO_INPUT
, IO_OUTPUT
}
221 static gfc_use_rename
*gfc_rename_list
;
222 static pointer_info
*pi_root
;
223 static int symbol_number
; /* Counter for assigning symbol numbers */
225 /* Tells mio_expr_ref to make symbols for unused equivalence members. */
226 static bool in_load_equiv
;
230 /*****************************************************************/
232 /* Pointer/integer conversion. Pointers between structures are stored
233 as integers in the module file. The next couple of subroutines
234 handle this translation for reading and writing. */
236 /* Recursively free the tree of pointer structures. */
239 free_pi_tree (pointer_info
*p
)
244 if (p
->fixup
!= NULL
)
245 gfc_internal_error ("free_pi_tree(): Unresolved fixup");
247 free_pi_tree (p
->left
);
248 free_pi_tree (p
->right
);
250 if (iomode
== IO_INPUT
)
252 XDELETEVEC (p
->u
.rsym
.true_name
);
253 XDELETEVEC (p
->u
.rsym
.module
);
254 XDELETEVEC (p
->u
.rsym
.binding_label
);
261 /* Compare pointers when searching by pointer. Used when writing a
265 compare_pointers (void *_sn1
, void *_sn2
)
267 pointer_info
*sn1
, *sn2
;
269 sn1
= (pointer_info
*) _sn1
;
270 sn2
= (pointer_info
*) _sn2
;
272 if (sn1
->u
.pointer
< sn2
->u
.pointer
)
274 if (sn1
->u
.pointer
> sn2
->u
.pointer
)
281 /* Compare integers when searching by integer. Used when reading a
285 compare_integers (void *_sn1
, void *_sn2
)
287 pointer_info
*sn1
, *sn2
;
289 sn1
= (pointer_info
*) _sn1
;
290 sn2
= (pointer_info
*) _sn2
;
292 if (sn1
->integer
< sn2
->integer
)
294 if (sn1
->integer
> sn2
->integer
)
301 /* Initialize the pointer_info tree. */
310 compare
= (iomode
== IO_INPUT
) ? compare_integers
: compare_pointers
;
312 /* Pointer 0 is the NULL pointer. */
313 p
= gfc_get_pointer_info ();
318 gfc_insert_bbt (&pi_root
, p
, compare
);
320 /* Pointer 1 is the current namespace. */
321 p
= gfc_get_pointer_info ();
322 p
->u
.pointer
= gfc_current_ns
;
324 p
->type
= P_NAMESPACE
;
326 gfc_insert_bbt (&pi_root
, p
, compare
);
332 /* During module writing, call here with a pointer to something,
333 returning the pointer_info node. */
335 static pointer_info
*
336 find_pointer (void *gp
)
343 if (p
->u
.pointer
== gp
)
345 p
= (gp
< p
->u
.pointer
) ? p
->left
: p
->right
;
352 /* Given a pointer while writing, returns the pointer_info tree node,
353 creating it if it doesn't exist. */
355 static pointer_info
*
356 get_pointer (void *gp
)
360 p
= find_pointer (gp
);
364 /* Pointer doesn't have an integer. Give it one. */
365 p
= gfc_get_pointer_info ();
368 p
->integer
= symbol_number
++;
370 gfc_insert_bbt (&pi_root
, p
, compare_pointers
);
376 /* Given an integer during reading, find it in the pointer_info tree,
377 creating the node if not found. */
379 static pointer_info
*
380 get_integer (HOST_WIDE_INT integer
)
390 c
= compare_integers (&t
, p
);
394 p
= (c
< 0) ? p
->left
: p
->right
;
400 p
= gfc_get_pointer_info ();
401 p
->integer
= integer
;
404 gfc_insert_bbt (&pi_root
, p
, compare_integers
);
410 /* Resolve any fixups using a known pointer. */
413 resolve_fixups (fixup_t
*f
, void *gp
)
426 /* Convert a string such that it starts with a lower-case character. Used
427 to convert the symtree name of a derived-type to the symbol name or to
428 the name of the associated generic function. */
431 gfc_dt_lower_string (const char *name
)
433 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
434 return gfc_get_string ("%c%s", (char) TOLOWER ((unsigned char) name
[0]),
436 return gfc_get_string ("%s", name
);
440 /* Convert a string such that it starts with an upper-case character. Used to
441 return the symtree-name for a derived type; the symbol name itself and the
442 symtree/symbol name of the associated generic function start with a lower-
446 gfc_dt_upper_string (const char *name
)
448 if (name
[0] != (char) TOUPPER ((unsigned char) name
[0]))
449 return gfc_get_string ("%c%s", (char) TOUPPER ((unsigned char) name
[0]),
451 return gfc_get_string ("%s", name
);
454 /* Call here during module reading when we know what pointer to
455 associate with an integer. Any fixups that exist are resolved at
459 associate_integer_pointer (pointer_info
*p
, void *gp
)
461 if (p
->u
.pointer
!= NULL
)
462 gfc_internal_error ("associate_integer_pointer(): Already associated");
466 resolve_fixups (p
->fixup
, gp
);
472 /* During module reading, given an integer and a pointer to a pointer,
473 either store the pointer from an already-known value or create a
474 fixup structure in order to store things later. Returns zero if
475 the reference has been actually stored, or nonzero if the reference
476 must be fixed later (i.e., associate_integer_pointer must be called
477 sometime later. Returns the pointer_info structure. */
479 static pointer_info
*
480 add_fixup (HOST_WIDE_INT integer
, void *gp
)
486 p
= get_integer (integer
);
488 if (p
->integer
== 0 || p
->u
.pointer
!= NULL
)
491 *cp
= (char *) p
->u
.pointer
;
500 f
->pointer
= (void **) gp
;
507 /*****************************************************************/
509 /* Parser related subroutines */
511 /* Free the rename list left behind by a USE statement. */
514 free_rename (gfc_use_rename
*list
)
516 gfc_use_rename
*next
;
518 for (; list
; list
= next
)
526 /* Match a USE statement. */
531 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module_nature
[GFC_MAX_SYMBOL_LEN
+ 1];
532 gfc_use_rename
*tail
= NULL
, *new_use
;
533 interface_type type
, type2
;
536 gfc_use_list
*use_list
;
540 use_list
= gfc_get_use_list ();
542 if (gfc_match (" , ") == MATCH_YES
)
544 if ((m
= gfc_match (" %n ::", module_nature
)) == MATCH_YES
)
546 if (!gfc_notify_std (GFC_STD_F2003
, "module "
547 "nature in USE statement at %C"))
550 if (strcmp (module_nature
, "intrinsic") == 0)
551 use_list
->intrinsic
= true;
554 if (strcmp (module_nature
, "non_intrinsic") == 0)
555 use_list
->non_intrinsic
= true;
558 gfc_error ("Module nature in USE statement at %C shall "
559 "be either INTRINSIC or NON_INTRINSIC");
566 /* Help output a better error message than "Unclassifiable
568 gfc_match (" %n", module_nature
);
569 if (strcmp (module_nature
, "intrinsic") == 0
570 || strcmp (module_nature
, "non_intrinsic") == 0)
571 gfc_error ("\"::\" was expected after module nature at %C "
572 "but was not found");
579 m
= gfc_match (" ::");
580 if (m
== MATCH_YES
&&
581 !gfc_notify_std(GFC_STD_F2003
, "\"USE :: module\" at %C"))
586 m
= gfc_match ("% ");
595 use_list
->where
= gfc_current_locus
;
597 m
= gfc_match_name (name
);
604 use_list
->module_name
= gfc_get_string ("%s", name
);
606 if (gfc_match_eos () == MATCH_YES
)
609 if (gfc_match_char (',') != MATCH_YES
)
612 if (gfc_match (" only :") == MATCH_YES
)
613 use_list
->only_flag
= true;
615 if (gfc_match_eos () == MATCH_YES
)
620 /* Get a new rename struct and add it to the rename list. */
621 new_use
= gfc_get_use_rename ();
622 new_use
->where
= gfc_current_locus
;
625 if (use_list
->rename
== NULL
)
626 use_list
->rename
= new_use
;
628 tail
->next
= new_use
;
631 /* See what kind of interface we're dealing with. Assume it is
633 new_use
->op
= INTRINSIC_NONE
;
634 if (gfc_match_generic_spec (&type
, name
, &op
) == MATCH_ERROR
)
639 case INTERFACE_NAMELESS
:
640 gfc_error ("Missing generic specification in USE statement at %C");
643 case INTERFACE_USER_OP
:
644 case INTERFACE_GENERIC
:
646 loc
= gfc_current_locus
;
648 m
= gfc_match (" =>");
650 if (type
== INTERFACE_USER_OP
&& m
== MATCH_YES
651 && (!gfc_notify_std(GFC_STD_F2003
, "Renaming "
652 "operators in USE statements at %C")))
655 if (type
== INTERFACE_USER_OP
)
656 new_use
->op
= INTRINSIC_USER
;
658 if (use_list
->only_flag
)
661 strcpy (new_use
->use_name
, name
);
664 strcpy (new_use
->local_name
, name
);
665 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
670 if (m
== MATCH_ERROR
)
678 strcpy (new_use
->local_name
, name
);
680 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
685 if (m
== MATCH_ERROR
)
689 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
690 if (st
&& type
!= INTERFACE_USER_OP
691 && (st
->n
.sym
->module
!= use_list
->module_name
692 || strcmp (st
->n
.sym
->name
, new_use
->use_name
) != 0))
695 gfc_error ("Symbol %qs at %L conflicts with the rename symbol "
696 "at %L", name
, &st
->n
.sym
->declared_at
, &loc
);
698 gfc_error ("Symbol %qs at %L conflicts with the symbol "
699 "at %L", name
, &st
->n
.sym
->declared_at
, &loc
);
703 if (strcmp (new_use
->use_name
, use_list
->module_name
) == 0
704 || strcmp (new_use
->local_name
, use_list
->module_name
) == 0)
706 gfc_error ("The name %qs at %C has already been used as "
707 "an external module name", use_list
->module_name
);
712 case INTERFACE_INTRINSIC_OP
:
720 if (gfc_match_eos () == MATCH_YES
)
722 if (gfc_match_char (',') != MATCH_YES
)
729 gfc_use_list
*last
= module_list
;
732 last
->next
= use_list
;
735 module_list
= use_list
;
740 gfc_syntax_error (ST_USE
);
743 free_rename (use_list
->rename
);
749 /* Match a SUBMODULE statement.
751 According to F2008:11.2.3.2, "The submodule identifier is the
752 ordered pair whose first element is the ancestor module name and
753 whose second element is the submodule name. 'Submodule_name' is
754 used for the submodule filename and uses '@' as a separator, whilst
755 the name of the symbol for the module uses '.' as a separator.
756 The reasons for these choices are:
757 (i) To follow another leading brand in the submodule filenames;
758 (ii) Since '.' is not particularly visible in the filenames; and
759 (iii) The linker does not permit '@' in mnemonics. */
762 gfc_match_submodule (void)
765 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
766 gfc_use_list
*use_list
;
767 bool seen_colon
= false;
769 if (!gfc_notify_std (GFC_STD_F2008
, "SUBMODULE declaration at %C"))
772 if (gfc_current_state () != COMP_NONE
)
774 gfc_error ("SUBMODULE declaration at %C cannot appear within "
775 "another scoping unit");
779 gfc_new_block
= NULL
;
780 gcc_assert (module_list
== NULL
);
782 if (gfc_match_char ('(') != MATCH_YES
)
787 m
= gfc_match (" %n", name
);
791 use_list
= gfc_get_use_list ();
792 use_list
->where
= gfc_current_locus
;
796 gfc_use_list
*last
= module_list
;
799 last
->next
= use_list
;
800 use_list
->module_name
801 = gfc_get_string ("%s.%s", module_list
->module_name
, name
);
802 use_list
->submodule_name
803 = gfc_get_string ("%s@%s", module_list
->module_name
, name
);
807 module_list
= use_list
;
808 use_list
->module_name
= gfc_get_string ("%s", name
);
809 use_list
->submodule_name
= use_list
->module_name
;
812 if (gfc_match_char (')') == MATCH_YES
)
815 if (gfc_match_char (':') != MATCH_YES
822 m
= gfc_match (" %s%t", &gfc_new_block
);
826 submodule_name
= gfc_get_string ("%s@%s", module_list
->module_name
,
827 gfc_new_block
->name
);
829 gfc_new_block
->name
= gfc_get_string ("%s.%s",
830 module_list
->module_name
,
831 gfc_new_block
->name
);
833 if (!gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
834 gfc_new_block
->name
, NULL
))
837 /* Just retain the ultimate .(s)mod file for reading, since it
838 contains all the information in its ancestors. */
839 use_list
= module_list
;
840 for (; module_list
->next
; use_list
= module_list
)
842 module_list
= use_list
->next
;
849 gfc_error ("Syntax error in SUBMODULE statement at %C");
854 /* Given a name and a number, inst, return the inst name
855 under which to load this symbol. Returns NULL if this
856 symbol shouldn't be loaded. If inst is zero, returns
857 the number of instances of this name. If interface is
858 true, a user-defined operator is sought, otherwise only
859 non-operators are sought. */
862 find_use_name_n (const char *name
, int *inst
, bool interface
)
865 const char *low_name
= NULL
;
868 /* For derived types. */
869 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
870 low_name
= gfc_dt_lower_string (name
);
873 for (u
= gfc_rename_list
; u
; u
= u
->next
)
875 if ((!low_name
&& strcmp (u
->use_name
, name
) != 0)
876 || (low_name
&& strcmp (u
->use_name
, low_name
) != 0)
877 || (u
->op
== INTRINSIC_USER
&& !interface
)
878 || (u
->op
!= INTRINSIC_USER
&& interface
))
891 return only_flag
? NULL
: name
;
897 if (u
->local_name
[0] == '\0')
899 return gfc_dt_upper_string (u
->local_name
);
902 return (u
->local_name
[0] != '\0') ? u
->local_name
: name
;
906 /* Given a name, return the name under which to load this symbol.
907 Returns NULL if this symbol shouldn't be loaded. */
910 find_use_name (const char *name
, bool interface
)
913 return find_use_name_n (name
, &i
, interface
);
917 /* Given a real name, return the number of use names associated with it. */
920 number_use_names (const char *name
, bool interface
)
923 find_use_name_n (name
, &i
, interface
);
928 /* Try to find the operator in the current list. */
930 static gfc_use_rename
*
931 find_use_operator (gfc_intrinsic_op op
)
935 for (u
= gfc_rename_list
; u
; u
= u
->next
)
943 /*****************************************************************/
945 /* The next couple of subroutines maintain a tree used to avoid a
946 brute-force search for a combination of true name and module name.
947 While symtree names, the name that a particular symbol is known by
948 can changed with USE statements, we still have to keep track of the
949 true names to generate the correct reference, and also avoid
950 loading the same real symbol twice in a program unit.
952 When we start reading, the true name tree is built and maintained
953 as symbols are read. The tree is searched as we load new symbols
954 to see if it already exists someplace in the namespace. */
956 typedef struct true_name
958 BBT_HEADER (true_name
);
964 static true_name
*true_name_root
;
967 /* Compare two true_name structures. */
970 compare_true_names (void *_t1
, void *_t2
)
975 t1
= (true_name
*) _t1
;
976 t2
= (true_name
*) _t2
;
978 c
= ((t1
->sym
->module
> t2
->sym
->module
)
979 - (t1
->sym
->module
< t2
->sym
->module
));
983 return strcmp (t1
->name
, t2
->name
);
987 /* Given a true name, search the true name tree to see if it exists
988 within the main namespace. */
991 find_true_name (const char *name
, const char *module
)
997 t
.name
= gfc_get_string ("%s", name
);
999 sym
.module
= gfc_get_string ("%s", module
);
1007 c
= compare_true_names ((void *) (&t
), (void *) p
);
1011 p
= (c
< 0) ? p
->left
: p
->right
;
1018 /* Given a gfc_symbol pointer that is not in the true name tree, add it. */
1021 add_true_name (gfc_symbol
*sym
)
1025 t
= XCNEW (true_name
);
1027 if (gfc_fl_struct (sym
->attr
.flavor
))
1028 t
->name
= gfc_dt_upper_string (sym
->name
);
1030 t
->name
= sym
->name
;
1032 gfc_insert_bbt (&true_name_root
, t
, compare_true_names
);
1036 /* Recursive function to build the initial true name tree by
1037 recursively traversing the current namespace. */
1040 build_tnt (gfc_symtree
*st
)
1046 build_tnt (st
->left
);
1047 build_tnt (st
->right
);
1049 if (gfc_fl_struct (st
->n
.sym
->attr
.flavor
))
1050 name
= gfc_dt_upper_string (st
->n
.sym
->name
);
1052 name
= st
->n
.sym
->name
;
1054 if (find_true_name (name
, st
->n
.sym
->module
) != NULL
)
1057 add_true_name (st
->n
.sym
);
1061 /* Initialize the true name tree with the current namespace. */
1064 init_true_name_tree (void)
1066 true_name_root
= NULL
;
1067 build_tnt (gfc_current_ns
->sym_root
);
1071 /* Recursively free a true name tree node. */
1074 free_true_name (true_name
*t
)
1078 free_true_name (t
->left
);
1079 free_true_name (t
->right
);
1085 /*****************************************************************/
1087 /* Module reading and writing. */
1089 /* The following are versions similar to the ones in scanner.cc, but
1090 for dealing with compressed module files. */
1093 gzopen_included_file_1 (const char *name
, gfc_directorylist
*list
,
1094 bool module
, bool system
)
1097 gfc_directorylist
*p
;
1100 for (p
= list
; p
; p
= p
->next
)
1102 if (module
&& !p
->use_for_modules
)
1105 fullname
= (char *) alloca(strlen (p
->path
) + strlen (name
) + 2);
1106 strcpy (fullname
, p
->path
);
1107 strcat (fullname
, "/");
1108 strcat (fullname
, name
);
1110 f
= gzopen (fullname
, "r");
1113 if (gfc_cpp_makedep ())
1114 gfc_cpp_add_dep (fullname
, system
);
1116 free (module_fullpath
);
1117 module_fullpath
= xstrdup (fullname
);
1126 gzopen_included_file (const char *name
, bool include_cwd
, bool module
)
1130 if (IS_ABSOLUTE_PATH (name
) || include_cwd
)
1132 f
= gzopen (name
, "r");
1135 if (gfc_cpp_makedep ())
1136 gfc_cpp_add_dep (name
, false);
1138 free (module_fullpath
);
1139 module_fullpath
= xstrdup (name
);
1144 f
= gzopen_included_file_1 (name
, include_dirs
, module
, false);
1150 gzopen_intrinsic_module (const char* name
)
1154 if (IS_ABSOLUTE_PATH (name
))
1156 f
= gzopen (name
, "r");
1159 if (gfc_cpp_makedep ())
1160 gfc_cpp_add_dep (name
, true);
1162 free (module_fullpath
);
1163 module_fullpath
= xstrdup (name
);
1168 f
= gzopen_included_file_1 (name
, intrinsic_modules_dirs
, true, true);
1176 ATOM_NAME
, ATOM_LPAREN
, ATOM_RPAREN
, ATOM_INTEGER
, ATOM_STRING
1179 static atom_type last_atom
;
1182 /* The name buffer must be at least as long as a symbol name. Right
1183 now it's not clear how we're going to store numeric constants--
1184 probably as a hexadecimal string, since this will allow the exact
1185 number to be preserved (this can't be done by a decimal
1186 representation). Worry about that later. TODO! */
1188 #define MAX_ATOM_SIZE 100
1190 static HOST_WIDE_INT atom_int
;
1191 static char *atom_string
, atom_name
[MAX_ATOM_SIZE
];
1194 /* Report problems with a module. Error reporting is not very
1195 elaborate, since this sorts of errors shouldn't really happen.
1196 This subroutine never returns. */
1198 static void bad_module (const char *) ATTRIBUTE_NORETURN
;
1201 bad_module (const char *msgid
)
1203 XDELETEVEC (module_content
);
1204 module_content
= NULL
;
1209 gfc_fatal_error ("Reading module %qs at line %d column %d: %s",
1210 module_fullpath
, module_line
, module_column
, msgid
);
1213 gfc_fatal_error ("Writing module %qs at line %d column %d: %s",
1214 module_name
, module_line
, module_column
, msgid
);
1217 gfc_fatal_error ("Module %qs at line %d column %d: %s",
1218 module_name
, module_line
, module_column
, msgid
);
1224 /* Set the module's input pointer. */
1227 set_module_locus (module_locus
*m
)
1229 module_column
= m
->column
;
1230 module_line
= m
->line
;
1231 module_pos
= m
->pos
;
1235 /* Get the module's input pointer so that we can restore it later. */
1238 get_module_locus (module_locus
*m
)
1240 m
->column
= module_column
;
1241 m
->line
= module_line
;
1242 m
->pos
= module_pos
;
1245 /* Peek at the next character in the module. */
1248 module_peek_char (void)
1250 return module_content
[module_pos
];
1253 /* Get the next character in the module, updating our reckoning of
1259 const char c
= module_content
[module_pos
++];
1261 bad_module ("Unexpected EOF");
1263 prev_module_line
= module_line
;
1264 prev_module_column
= module_column
;
1276 /* Unget a character while remembering the line and column. Works for
1277 a single character only. */
1280 module_unget_char (void)
1282 module_line
= prev_module_line
;
1283 module_column
= prev_module_column
;
1287 /* Parse a string constant. The delimiter is guaranteed to be a
1297 atom_string
= XNEWVEC (char, cursz
);
1305 int c2
= module_char ();
1308 module_unget_char ();
1316 atom_string
= XRESIZEVEC (char, atom_string
, cursz
);
1318 atom_string
[len
] = c
;
1322 atom_string
= XRESIZEVEC (char, atom_string
, len
+ 1);
1323 atom_string
[len
] = '\0'; /* C-style string for debug purposes. */
1327 /* Parse an integer. Should fit in a HOST_WIDE_INT. */
1330 parse_integer (int c
)
1351 module_unget_char ();
1355 atom_int
= 10 * atom_int
+ c
- '0';
1378 if (!ISALNUM (c
) && c
!= '_' && c
!= '-')
1380 module_unget_char ();
1385 if (++len
> GFC_MAX_SYMBOL_LEN
)
1386 bad_module ("Name too long");
1394 /* Read the next atom in the module's input stream. */
1405 while (c
== ' ' || c
== '\r' || c
== '\n');
1430 return ATOM_INTEGER
;
1434 if (ISDIGIT (module_peek_char ()))
1437 return ATOM_INTEGER
;
1440 bad_module ("Bad name");
1498 bad_module ("Bad name");
1505 /* Peek at the next atom on the input. */
1516 while (c
== ' ' || c
== '\r' || c
== '\n');
1521 module_unget_char ();
1525 module_unget_char ();
1529 module_unget_char ();
1542 module_unget_char ();
1543 return ATOM_INTEGER
;
1547 if (ISDIGIT (module_peek_char ()))
1549 module_unget_char ();
1550 return ATOM_INTEGER
;
1553 bad_module ("Bad name");
1607 module_unget_char ();
1611 bad_module ("Bad name");
1616 /* Read the next atom from the input, requiring that it be a
1620 require_atom (atom_type type
)
1626 column
= module_column
;
1635 p
= _("Expected name");
1638 p
= _("Expected left parenthesis");
1641 p
= _("Expected right parenthesis");
1644 p
= _("Expected integer");
1647 p
= _("Expected string");
1650 gfc_internal_error ("require_atom(): bad atom type required");
1653 module_column
= column
;
1660 /* Given a pointer to an mstring array, require that the current input
1661 be one of the strings in the array. We return the enum value. */
1664 find_enum (const mstring
*m
)
1668 i
= gfc_string2code (m
, atom_name
);
1672 bad_module ("find_enum(): Enum not found");
1678 /* Read a string. The caller is responsible for freeing. */
1684 require_atom (ATOM_STRING
);
1691 /**************** Module output subroutines ***************************/
1693 /* Output a character to a module file. */
1696 write_char (char out
)
1698 if (gzputc (module_fp
, out
) == EOF
)
1699 gfc_fatal_error ("Error writing modules file: %s", xstrerror (errno
));
1711 /* Write an atom to a module. The line wrapping isn't perfect, but it
1712 should work most of the time. This isn't that big of a deal, since
1713 the file really isn't meant to be read by people anyway. */
1716 write_atom (atom_type atom
, const void *v
)
1720 /* Workaround -Wmaybe-uninitialized false positive during
1721 profiledbootstrap by initializing them. */
1723 HOST_WIDE_INT i
= 0;
1730 p
= (const char *) v
;
1742 i
= *((const HOST_WIDE_INT
*) v
);
1744 snprintf (buffer
, sizeof (buffer
), HOST_WIDE_INT_PRINT_DEC
, i
);
1749 gfc_internal_error ("write_atom(): Trying to write dab atom");
1753 if(p
== NULL
|| *p
== '\0')
1758 if (atom
!= ATOM_RPAREN
)
1760 if (module_column
+ len
> 72)
1765 if (last_atom
!= ATOM_LPAREN
&& module_column
!= 1)
1770 if (atom
== ATOM_STRING
)
1773 while (p
!= NULL
&& *p
)
1775 if (atom
== ATOM_STRING
&& *p
== '\'')
1780 if (atom
== ATOM_STRING
)
1788 /***************** Mid-level I/O subroutines *****************/
1790 /* These subroutines let their caller read or write atoms without
1791 caring about which of the two is actually happening. This lets a
1792 subroutine concentrate on the actual format of the data being
1795 static void mio_expr (gfc_expr
**);
1796 pointer_info
*mio_symbol_ref (gfc_symbol
**);
1797 pointer_info
*mio_interface_rest (gfc_interface
**);
1798 static void mio_symtree_ref (gfc_symtree
**);
1800 /* Read or write an enumerated value. On writing, we return the input
1801 value for the convenience of callers. We avoid using an integer
1802 pointer because enums are sometimes inside bitfields. */
1805 mio_name (int t
, const mstring
*m
)
1807 if (iomode
== IO_OUTPUT
)
1808 write_atom (ATOM_NAME
, gfc_code2string (m
, t
));
1811 require_atom (ATOM_NAME
);
1818 /* Specialization of mio_name. */
1820 #define DECL_MIO_NAME(TYPE) \
1821 static inline TYPE \
1822 MIO_NAME(TYPE) (TYPE t, const mstring *m) \
1824 return (TYPE) mio_name ((int) t, m); \
1826 #define MIO_NAME(TYPE) mio_name_##TYPE
1831 if (iomode
== IO_OUTPUT
)
1832 write_atom (ATOM_LPAREN
, NULL
);
1834 require_atom (ATOM_LPAREN
);
1841 if (iomode
== IO_OUTPUT
)
1842 write_atom (ATOM_RPAREN
, NULL
);
1844 require_atom (ATOM_RPAREN
);
1849 mio_integer (int *ip
)
1851 if (iomode
== IO_OUTPUT
)
1853 HOST_WIDE_INT hwi
= *ip
;
1854 write_atom (ATOM_INTEGER
, &hwi
);
1858 require_atom (ATOM_INTEGER
);
1864 mio_hwi (HOST_WIDE_INT
*hwi
)
1866 if (iomode
== IO_OUTPUT
)
1867 write_atom (ATOM_INTEGER
, hwi
);
1870 require_atom (ATOM_INTEGER
);
1876 /* Read or write a gfc_intrinsic_op value. */
1879 mio_intrinsic_op (gfc_intrinsic_op
* op
)
1881 /* FIXME: Would be nicer to do this via the operators symbolic name. */
1882 if (iomode
== IO_OUTPUT
)
1884 HOST_WIDE_INT converted
= (HOST_WIDE_INT
) *op
;
1885 write_atom (ATOM_INTEGER
, &converted
);
1889 require_atom (ATOM_INTEGER
);
1890 *op
= (gfc_intrinsic_op
) atom_int
;
1895 /* Read or write a character pointer that points to a string on the heap. */
1898 mio_allocated_string (const char *s
)
1900 if (iomode
== IO_OUTPUT
)
1902 write_atom (ATOM_STRING
, s
);
1907 require_atom (ATOM_STRING
);
1913 /* Functions for quoting and unquoting strings. */
1916 quote_string (const gfc_char_t
*s
, const size_t slength
)
1918 const gfc_char_t
*p
;
1922 /* Calculate the length we'll need: a backslash takes two ("\\"),
1923 non-printable characters take 10 ("\Uxxxxxxxx") and others take 1. */
1924 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1928 else if (!gfc_wide_is_printable (*p
))
1934 q
= res
= XCNEWVEC (char, len
+ 1);
1935 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1938 *q
++ = '\\', *q
++ = '\\';
1939 else if (!gfc_wide_is_printable (*p
))
1941 sprintf (q
, "\\U%08" HOST_WIDE_INT_PRINT
"x",
1942 (unsigned HOST_WIDE_INT
) *p
);
1946 *q
++ = (unsigned char) *p
;
1954 unquote_string (const char *s
)
1960 for (p
= s
, len
= 0; *p
; p
++, len
++)
1967 else if (p
[1] == 'U')
1968 p
+= 9; /* That is a "\U????????". */
1970 gfc_internal_error ("unquote_string(): got bad string");
1973 res
= gfc_get_wide_string (len
+ 1);
1974 for (i
= 0, p
= s
; i
< len
; i
++, p
++)
1979 res
[i
] = (unsigned char) *p
;
1980 else if (p
[1] == '\\')
1982 res
[i
] = (unsigned char) '\\';
1987 /* We read the 8-digits hexadecimal constant that follows. */
1992 gcc_assert (p
[1] == 'U');
1993 for (j
= 0; j
< 8; j
++)
1996 gcc_assert (sscanf (&p
[j
+2], "%01x", &n
) == 1);
2010 /* Read or write a character pointer that points to a wide string on the
2011 heap, performing quoting/unquoting of nonprintable characters using the
2012 form \U???????? (where each ? is a hexadecimal digit).
2013 Length is the length of the string, only known and used in output mode. */
2015 static const gfc_char_t
*
2016 mio_allocated_wide_string (const gfc_char_t
*s
, const size_t length
)
2018 if (iomode
== IO_OUTPUT
)
2020 char *quoted
= quote_string (s
, length
);
2021 write_atom (ATOM_STRING
, quoted
);
2027 gfc_char_t
*unquoted
;
2029 require_atom (ATOM_STRING
);
2030 unquoted
= unquote_string (atom_string
);
2037 /* Read or write a string that is in static memory. */
2040 mio_pool_string (const char **stringp
)
2042 /* TODO: one could write the string only once, and refer to it via a
2045 /* As a special case we have to deal with a NULL string. This
2046 happens for the 'module' member of 'gfc_symbol's that are not in a
2047 module. We read / write these as the empty string. */
2048 if (iomode
== IO_OUTPUT
)
2050 const char *p
= *stringp
== NULL
? "" : *stringp
;
2051 write_atom (ATOM_STRING
, p
);
2055 require_atom (ATOM_STRING
);
2056 *stringp
= (atom_string
[0] == '\0'
2057 ? NULL
: gfc_get_string ("%s", atom_string
));
2063 /* Read or write a string that is inside of some already-allocated
2067 mio_internal_string (char *string
)
2069 if (iomode
== IO_OUTPUT
)
2070 write_atom (ATOM_STRING
, string
);
2073 require_atom (ATOM_STRING
);
2074 strcpy (string
, atom_string
);
2081 { AB_ALLOCATABLE
, AB_DIMENSION
, AB_EXTERNAL
, AB_INTRINSIC
, AB_OPTIONAL
,
2082 AB_POINTER
, AB_TARGET
, AB_DUMMY
, AB_RESULT
, AB_DATA
,
2083 AB_IN_NAMELIST
, AB_IN_COMMON
, AB_FUNCTION
, AB_SUBROUTINE
, AB_SEQUENCE
,
2084 AB_ELEMENTAL
, AB_PURE
, AB_RECURSIVE
, AB_GENERIC
, AB_ALWAYS_EXPLICIT
,
2085 AB_CRAY_POINTER
, AB_CRAY_POINTEE
, AB_THREADPRIVATE
,
2086 AB_ALLOC_COMP
, AB_POINTER_COMP
, AB_PROC_POINTER_COMP
, AB_PRIVATE_COMP
,
2087 AB_VALUE
, AB_VOLATILE
, AB_PROTECTED
, AB_LOCK_COMP
, AB_EVENT_COMP
,
2088 AB_IS_BIND_C
, AB_IS_C_INTEROP
, AB_IS_ISO_C
, AB_ABSTRACT
, AB_ZERO_COMP
,
2089 AB_IS_CLASS
, AB_PROCEDURE
, AB_PROC_POINTER
, AB_ASYNCHRONOUS
, AB_CODIMENSION
,
2090 AB_COARRAY_COMP
, AB_VTYPE
, AB_VTAB
, AB_CONTIGUOUS
, AB_CLASS_POINTER
,
2091 AB_IMPLICIT_PURE
, AB_ARTIFICIAL
, AB_UNLIMITED_POLY
, AB_OMP_DECLARE_TARGET
,
2092 AB_ARRAY_OUTER_DEPENDENCY
, AB_MODULE_PROCEDURE
, AB_OACC_DECLARE_CREATE
,
2093 AB_OACC_DECLARE_COPYIN
, AB_OACC_DECLARE_DEVICEPTR
,
2094 AB_OACC_DECLARE_DEVICE_RESIDENT
, AB_OACC_DECLARE_LINK
,
2095 AB_OMP_DECLARE_TARGET_LINK
, AB_PDT_KIND
, AB_PDT_LEN
, AB_PDT_TYPE
,
2096 AB_PDT_TEMPLATE
, AB_PDT_ARRAY
, AB_PDT_STRING
,
2097 AB_OACC_ROUTINE_LOP_GANG
, AB_OACC_ROUTINE_LOP_WORKER
,
2098 AB_OACC_ROUTINE_LOP_VECTOR
, AB_OACC_ROUTINE_LOP_SEQ
,
2099 AB_OACC_ROUTINE_NOHOST
,
2100 AB_OMP_REQ_REVERSE_OFFLOAD
, AB_OMP_REQ_UNIFIED_ADDRESS
, AB_OMP_REQ_SELF_MAPS
,
2101 AB_OMP_REQ_UNIFIED_SHARED_MEMORY
, AB_OMP_REQ_DYNAMIC_ALLOCATORS
,
2102 AB_OMP_REQ_MEM_ORDER_SEQ_CST
, AB_OMP_REQ_MEM_ORDER_ACQ_REL
,
2103 AB_OMP_REQ_MEM_ORDER_ACQUIRE
, AB_OMP_REQ_MEM_ORDER_RELEASE
,
2104 AB_OMP_REQ_MEM_ORDER_RELAXED
, AB_OMP_DEVICE_TYPE_NOHOST
,
2105 AB_OMP_DEVICE_TYPE_HOST
, AB_OMP_DEVICE_TYPE_ANY
2108 static const mstring attr_bits
[] =
2110 minit ("ALLOCATABLE", AB_ALLOCATABLE
),
2111 minit ("ARTIFICIAL", AB_ARTIFICIAL
),
2112 minit ("ASYNCHRONOUS", AB_ASYNCHRONOUS
),
2113 minit ("DIMENSION", AB_DIMENSION
),
2114 minit ("CODIMENSION", AB_CODIMENSION
),
2115 minit ("CONTIGUOUS", AB_CONTIGUOUS
),
2116 minit ("EXTERNAL", AB_EXTERNAL
),
2117 minit ("INTRINSIC", AB_INTRINSIC
),
2118 minit ("OPTIONAL", AB_OPTIONAL
),
2119 minit ("POINTER", AB_POINTER
),
2120 minit ("VOLATILE", AB_VOLATILE
),
2121 minit ("TARGET", AB_TARGET
),
2122 minit ("THREADPRIVATE", AB_THREADPRIVATE
),
2123 minit ("DUMMY", AB_DUMMY
),
2124 minit ("RESULT", AB_RESULT
),
2125 minit ("DATA", AB_DATA
),
2126 minit ("IN_NAMELIST", AB_IN_NAMELIST
),
2127 minit ("IN_COMMON", AB_IN_COMMON
),
2128 minit ("FUNCTION", AB_FUNCTION
),
2129 minit ("SUBROUTINE", AB_SUBROUTINE
),
2130 minit ("SEQUENCE", AB_SEQUENCE
),
2131 minit ("ELEMENTAL", AB_ELEMENTAL
),
2132 minit ("PURE", AB_PURE
),
2133 minit ("RECURSIVE", AB_RECURSIVE
),
2134 minit ("GENERIC", AB_GENERIC
),
2135 minit ("ALWAYS_EXPLICIT", AB_ALWAYS_EXPLICIT
),
2136 minit ("CRAY_POINTER", AB_CRAY_POINTER
),
2137 minit ("CRAY_POINTEE", AB_CRAY_POINTEE
),
2138 minit ("IS_BIND_C", AB_IS_BIND_C
),
2139 minit ("IS_C_INTEROP", AB_IS_C_INTEROP
),
2140 minit ("IS_ISO_C", AB_IS_ISO_C
),
2141 minit ("VALUE", AB_VALUE
),
2142 minit ("ALLOC_COMP", AB_ALLOC_COMP
),
2143 minit ("COARRAY_COMP", AB_COARRAY_COMP
),
2144 minit ("LOCK_COMP", AB_LOCK_COMP
),
2145 minit ("EVENT_COMP", AB_EVENT_COMP
),
2146 minit ("POINTER_COMP", AB_POINTER_COMP
),
2147 minit ("PROC_POINTER_COMP", AB_PROC_POINTER_COMP
),
2148 minit ("PRIVATE_COMP", AB_PRIVATE_COMP
),
2149 minit ("ZERO_COMP", AB_ZERO_COMP
),
2150 minit ("PROTECTED", AB_PROTECTED
),
2151 minit ("ABSTRACT", AB_ABSTRACT
),
2152 minit ("IS_CLASS", AB_IS_CLASS
),
2153 minit ("PROCEDURE", AB_PROCEDURE
),
2154 minit ("PROC_POINTER", AB_PROC_POINTER
),
2155 minit ("VTYPE", AB_VTYPE
),
2156 minit ("VTAB", AB_VTAB
),
2157 minit ("CLASS_POINTER", AB_CLASS_POINTER
),
2158 minit ("IMPLICIT_PURE", AB_IMPLICIT_PURE
),
2159 minit ("UNLIMITED_POLY", AB_UNLIMITED_POLY
),
2160 minit ("OMP_DECLARE_TARGET", AB_OMP_DECLARE_TARGET
),
2161 minit ("ARRAY_OUTER_DEPENDENCY", AB_ARRAY_OUTER_DEPENDENCY
),
2162 minit ("MODULE_PROCEDURE", AB_MODULE_PROCEDURE
),
2163 minit ("OACC_DECLARE_CREATE", AB_OACC_DECLARE_CREATE
),
2164 minit ("OACC_DECLARE_COPYIN", AB_OACC_DECLARE_COPYIN
),
2165 minit ("OACC_DECLARE_DEVICEPTR", AB_OACC_DECLARE_DEVICEPTR
),
2166 minit ("OACC_DECLARE_DEVICE_RESIDENT", AB_OACC_DECLARE_DEVICE_RESIDENT
),
2167 minit ("OACC_DECLARE_LINK", AB_OACC_DECLARE_LINK
),
2168 minit ("OMP_DECLARE_TARGET_LINK", AB_OMP_DECLARE_TARGET_LINK
),
2169 minit ("PDT_KIND", AB_PDT_KIND
),
2170 minit ("PDT_LEN", AB_PDT_LEN
),
2171 minit ("PDT_TYPE", AB_PDT_TYPE
),
2172 minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE
),
2173 minit ("PDT_ARRAY", AB_PDT_ARRAY
),
2174 minit ("PDT_STRING", AB_PDT_STRING
),
2175 minit ("OACC_ROUTINE_LOP_GANG", AB_OACC_ROUTINE_LOP_GANG
),
2176 minit ("OACC_ROUTINE_LOP_WORKER", AB_OACC_ROUTINE_LOP_WORKER
),
2177 minit ("OACC_ROUTINE_LOP_VECTOR", AB_OACC_ROUTINE_LOP_VECTOR
),
2178 minit ("OACC_ROUTINE_LOP_SEQ", AB_OACC_ROUTINE_LOP_SEQ
),
2179 minit ("OACC_ROUTINE_NOHOST", AB_OACC_ROUTINE_NOHOST
),
2180 minit ("OMP_REQ_REVERSE_OFFLOAD", AB_OMP_REQ_REVERSE_OFFLOAD
),
2181 minit ("OMP_REQ_UNIFIED_ADDRESS", AB_OMP_REQ_UNIFIED_ADDRESS
),
2182 minit ("OMP_REQ_UNIFIED_SHARED_MEMORY", AB_OMP_REQ_UNIFIED_SHARED_MEMORY
),
2183 minit ("OMP_REQ_SELF_MAPS", AB_OMP_REQ_SELF_MAPS
),
2184 minit ("OMP_REQ_DYNAMIC_ALLOCATORS", AB_OMP_REQ_DYNAMIC_ALLOCATORS
),
2185 minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST
),
2186 minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL
),
2187 minit ("OMP_REQ_MEM_ORDER_ACQUIRE", AB_OMP_REQ_MEM_ORDER_ACQUIRE
),
2188 minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED
),
2189 minit ("OMP_REQ_MEM_ORDER_RELEASE", AB_OMP_REQ_MEM_ORDER_RELEASE
),
2190 minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST
),
2191 minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST
),
2192 minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY
),
2196 /* For binding attributes. */
2197 static const mstring binding_passing
[] =
2200 minit ("NOPASS", 1),
2203 static const mstring binding_overriding
[] =
2205 minit ("OVERRIDABLE", 0),
2206 minit ("NON_OVERRIDABLE", 1),
2207 minit ("DEFERRED", 2),
2210 static const mstring binding_generic
[] =
2212 minit ("SPECIFIC", 0),
2213 minit ("GENERIC", 1),
2216 static const mstring binding_ppc
[] =
2218 minit ("NO_PPC", 0),
2223 /* Specialization of mio_name. */
2224 DECL_MIO_NAME (ab_attribute
)
2225 DECL_MIO_NAME (ar_type
)
2226 DECL_MIO_NAME (array_type
)
2228 DECL_MIO_NAME (expr_t
)
2229 DECL_MIO_NAME (gfc_access
)
2230 DECL_MIO_NAME (gfc_intrinsic_op
)
2231 DECL_MIO_NAME (ifsrc
)
2232 DECL_MIO_NAME (save_state
)
2233 DECL_MIO_NAME (procedure_type
)
2234 DECL_MIO_NAME (ref_type
)
2235 DECL_MIO_NAME (sym_flavor
)
2236 DECL_MIO_NAME (sym_intent
)
2237 DECL_MIO_NAME (inquiry_type
)
2238 #undef DECL_MIO_NAME
2240 /* Verify OACC_ROUTINE_LOP_NONE. */
2243 verify_OACC_ROUTINE_LOP_NONE (enum oacc_routine_lop lop
)
2245 if (lop
!= OACC_ROUTINE_LOP_NONE
)
2246 bad_module ("Unsupported: multiple OpenACC 'routine' levels of parallelism");
2249 /* Symbol attributes are stored in list with the first three elements
2250 being the enumerated fields, while the remaining elements (if any)
2251 indicate the individual attribute bits. The access field is not
2252 saved-- it controls what symbols are exported when a module is
2256 mio_symbol_attribute (symbol_attribute
*attr
)
2259 unsigned ext_attr
,extension_level
;
2263 attr
->flavor
= MIO_NAME (sym_flavor
) (attr
->flavor
, flavors
);
2264 attr
->intent
= MIO_NAME (sym_intent
) (attr
->intent
, intents
);
2265 attr
->proc
= MIO_NAME (procedure_type
) (attr
->proc
, procedures
);
2266 attr
->if_source
= MIO_NAME (ifsrc
) (attr
->if_source
, ifsrc_types
);
2267 attr
->save
= MIO_NAME (save_state
) (attr
->save
, save_status
);
2269 ext_attr
= attr
->ext_attr
;
2270 mio_integer ((int *) &ext_attr
);
2271 attr
->ext_attr
= ext_attr
;
2273 extension_level
= attr
->extension
;
2274 mio_integer ((int *) &extension_level
);
2275 attr
->extension
= extension_level
;
2277 if (iomode
== IO_OUTPUT
)
2279 if (attr
->allocatable
)
2280 MIO_NAME (ab_attribute
) (AB_ALLOCATABLE
, attr_bits
);
2281 if (attr
->artificial
)
2282 MIO_NAME (ab_attribute
) (AB_ARTIFICIAL
, attr_bits
);
2283 if (attr
->asynchronous
)
2284 MIO_NAME (ab_attribute
) (AB_ASYNCHRONOUS
, attr_bits
);
2285 if (attr
->dimension
)
2286 MIO_NAME (ab_attribute
) (AB_DIMENSION
, attr_bits
);
2287 if (attr
->codimension
)
2288 MIO_NAME (ab_attribute
) (AB_CODIMENSION
, attr_bits
);
2289 if (attr
->contiguous
)
2290 MIO_NAME (ab_attribute
) (AB_CONTIGUOUS
, attr_bits
);
2292 MIO_NAME (ab_attribute
) (AB_EXTERNAL
, attr_bits
);
2293 if (attr
->intrinsic
)
2294 MIO_NAME (ab_attribute
) (AB_INTRINSIC
, attr_bits
);
2296 MIO_NAME (ab_attribute
) (AB_OPTIONAL
, attr_bits
);
2298 MIO_NAME (ab_attribute
) (AB_POINTER
, attr_bits
);
2299 if (attr
->class_pointer
)
2300 MIO_NAME (ab_attribute
) (AB_CLASS_POINTER
, attr_bits
);
2301 if (attr
->is_protected
)
2302 MIO_NAME (ab_attribute
) (AB_PROTECTED
, attr_bits
);
2304 MIO_NAME (ab_attribute
) (AB_VALUE
, attr_bits
);
2305 if (attr
->volatile_
)
2306 MIO_NAME (ab_attribute
) (AB_VOLATILE
, attr_bits
);
2308 MIO_NAME (ab_attribute
) (AB_TARGET
, attr_bits
);
2309 if (attr
->threadprivate
)
2310 MIO_NAME (ab_attribute
) (AB_THREADPRIVATE
, attr_bits
);
2312 MIO_NAME (ab_attribute
) (AB_DUMMY
, attr_bits
);
2314 MIO_NAME (ab_attribute
) (AB_RESULT
, attr_bits
);
2315 /* We deliberately don't preserve the "entry" flag. */
2318 MIO_NAME (ab_attribute
) (AB_DATA
, attr_bits
);
2319 if (attr
->in_namelist
)
2320 MIO_NAME (ab_attribute
) (AB_IN_NAMELIST
, attr_bits
);
2321 if (attr
->in_common
)
2322 MIO_NAME (ab_attribute
) (AB_IN_COMMON
, attr_bits
);
2325 MIO_NAME (ab_attribute
) (AB_FUNCTION
, attr_bits
);
2326 if (attr
->subroutine
)
2327 MIO_NAME (ab_attribute
) (AB_SUBROUTINE
, attr_bits
);
2329 MIO_NAME (ab_attribute
) (AB_GENERIC
, attr_bits
);
2331 MIO_NAME (ab_attribute
) (AB_ABSTRACT
, attr_bits
);
2334 MIO_NAME (ab_attribute
) (AB_SEQUENCE
, attr_bits
);
2335 if (attr
->elemental
)
2336 MIO_NAME (ab_attribute
) (AB_ELEMENTAL
, attr_bits
);
2338 MIO_NAME (ab_attribute
) (AB_PURE
, attr_bits
);
2339 if (attr
->implicit_pure
)
2340 MIO_NAME (ab_attribute
) (AB_IMPLICIT_PURE
, attr_bits
);
2341 if (attr
->unlimited_polymorphic
)
2342 MIO_NAME (ab_attribute
) (AB_UNLIMITED_POLY
, attr_bits
);
2343 if (attr
->recursive
)
2344 MIO_NAME (ab_attribute
) (AB_RECURSIVE
, attr_bits
);
2345 if (attr
->always_explicit
)
2346 MIO_NAME (ab_attribute
) (AB_ALWAYS_EXPLICIT
, attr_bits
);
2347 if (attr
->cray_pointer
)
2348 MIO_NAME (ab_attribute
) (AB_CRAY_POINTER
, attr_bits
);
2349 if (attr
->cray_pointee
)
2350 MIO_NAME (ab_attribute
) (AB_CRAY_POINTEE
, attr_bits
);
2351 if (attr
->is_bind_c
)
2352 MIO_NAME(ab_attribute
) (AB_IS_BIND_C
, attr_bits
);
2353 if (attr
->is_c_interop
)
2354 MIO_NAME(ab_attribute
) (AB_IS_C_INTEROP
, attr_bits
);
2356 MIO_NAME(ab_attribute
) (AB_IS_ISO_C
, attr_bits
);
2357 if (attr
->alloc_comp
)
2358 MIO_NAME (ab_attribute
) (AB_ALLOC_COMP
, attr_bits
);
2359 if (attr
->pointer_comp
)
2360 MIO_NAME (ab_attribute
) (AB_POINTER_COMP
, attr_bits
);
2361 if (attr
->proc_pointer_comp
)
2362 MIO_NAME (ab_attribute
) (AB_PROC_POINTER_COMP
, attr_bits
);
2363 if (attr
->private_comp
)
2364 MIO_NAME (ab_attribute
) (AB_PRIVATE_COMP
, attr_bits
);
2365 if (attr
->coarray_comp
)
2366 MIO_NAME (ab_attribute
) (AB_COARRAY_COMP
, attr_bits
);
2367 if (attr
->lock_comp
)
2368 MIO_NAME (ab_attribute
) (AB_LOCK_COMP
, attr_bits
);
2369 if (attr
->event_comp
)
2370 MIO_NAME (ab_attribute
) (AB_EVENT_COMP
, attr_bits
);
2371 if (attr
->zero_comp
)
2372 MIO_NAME (ab_attribute
) (AB_ZERO_COMP
, attr_bits
);
2374 MIO_NAME (ab_attribute
) (AB_IS_CLASS
, attr_bits
);
2375 if (attr
->procedure
)
2376 MIO_NAME (ab_attribute
) (AB_PROCEDURE
, attr_bits
);
2377 if (attr
->proc_pointer
)
2378 MIO_NAME (ab_attribute
) (AB_PROC_POINTER
, attr_bits
);
2380 MIO_NAME (ab_attribute
) (AB_VTYPE
, attr_bits
);
2382 MIO_NAME (ab_attribute
) (AB_VTAB
, attr_bits
);
2383 if (attr
->omp_declare_target
)
2384 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET
, attr_bits
);
2385 if (attr
->array_outer_dependency
)
2386 MIO_NAME (ab_attribute
) (AB_ARRAY_OUTER_DEPENDENCY
, attr_bits
);
2387 if (attr
->module_procedure
)
2388 MIO_NAME (ab_attribute
) (AB_MODULE_PROCEDURE
, attr_bits
);
2389 if (attr
->oacc_declare_create
)
2390 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_CREATE
, attr_bits
);
2391 if (attr
->oacc_declare_copyin
)
2392 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_COPYIN
, attr_bits
);
2393 if (attr
->oacc_declare_deviceptr
)
2394 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICEPTR
, attr_bits
);
2395 if (attr
->oacc_declare_device_resident
)
2396 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICE_RESIDENT
, attr_bits
);
2397 if (attr
->oacc_declare_link
)
2398 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_LINK
, attr_bits
);
2399 if (attr
->omp_declare_target_link
)
2400 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET_LINK
, attr_bits
);
2402 MIO_NAME (ab_attribute
) (AB_PDT_KIND
, attr_bits
);
2404 MIO_NAME (ab_attribute
) (AB_PDT_LEN
, attr_bits
);
2406 MIO_NAME (ab_attribute
) (AB_PDT_TYPE
, attr_bits
);
2407 if (attr
->pdt_template
)
2408 MIO_NAME (ab_attribute
) (AB_PDT_TEMPLATE
, attr_bits
);
2409 if (attr
->pdt_array
)
2410 MIO_NAME (ab_attribute
) (AB_PDT_ARRAY
, attr_bits
);
2411 if (attr
->pdt_string
)
2412 MIO_NAME (ab_attribute
) (AB_PDT_STRING
, attr_bits
);
2413 switch (attr
->oacc_routine_lop
)
2415 case OACC_ROUTINE_LOP_NONE
:
2416 /* This is the default anyway, and for maintaining compatibility with
2417 the current MOD_VERSION, we're not emitting anything in that
2420 case OACC_ROUTINE_LOP_GANG
:
2421 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_GANG
, attr_bits
);
2423 case OACC_ROUTINE_LOP_WORKER
:
2424 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_WORKER
, attr_bits
);
2426 case OACC_ROUTINE_LOP_VECTOR
:
2427 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_VECTOR
, attr_bits
);
2429 case OACC_ROUTINE_LOP_SEQ
:
2430 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_LOP_SEQ
, attr_bits
);
2432 case OACC_ROUTINE_LOP_ERROR
:
2433 /* ... intentionally omitted here; it's only used internally. */
2437 if (attr
->oacc_routine_nohost
)
2438 MIO_NAME (ab_attribute
) (AB_OACC_ROUTINE_NOHOST
, attr_bits
);
2440 if (attr
->flavor
== FL_MODULE
&& gfc_current_ns
->omp_requires
)
2442 if (gfc_current_ns
->omp_requires
& OMP_REQ_REVERSE_OFFLOAD
)
2443 MIO_NAME (ab_attribute
) (AB_OMP_REQ_REVERSE_OFFLOAD
, attr_bits
);
2444 if (gfc_current_ns
->omp_requires
& OMP_REQ_UNIFIED_ADDRESS
)
2445 MIO_NAME (ab_attribute
) (AB_OMP_REQ_UNIFIED_ADDRESS
, attr_bits
);
2446 if (gfc_current_ns
->omp_requires
& OMP_REQ_UNIFIED_SHARED_MEMORY
)
2447 MIO_NAME (ab_attribute
) (AB_OMP_REQ_UNIFIED_SHARED_MEMORY
, attr_bits
);
2448 if (gfc_current_ns
->omp_requires
& OMP_REQ_SELF_MAPS
)
2449 MIO_NAME (ab_attribute
) (AB_OMP_REQ_SELF_MAPS
, attr_bits
);
2450 if (gfc_current_ns
->omp_requires
& OMP_REQ_DYNAMIC_ALLOCATORS
)
2451 MIO_NAME (ab_attribute
) (AB_OMP_REQ_DYNAMIC_ALLOCATORS
, attr_bits
);
2452 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2453 == OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
)
2454 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_SEQ_CST
, attr_bits
);
2455 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2456 == OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
)
2457 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_ACQ_REL
, attr_bits
);
2458 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2459 == OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE
)
2460 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_ACQUIRE
, attr_bits
);
2461 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2462 == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
)
2463 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_RELAXED
, attr_bits
);
2464 if ((gfc_current_ns
->omp_requires
& OMP_REQ_ATOMIC_MEM_ORDER_MASK
)
2465 == OMP_REQ_ATOMIC_MEM_ORDER_RELEASE
)
2466 MIO_NAME (ab_attribute
) (AB_OMP_REQ_MEM_ORDER_RELEASE
, attr_bits
);
2468 switch (attr
->omp_device_type
)
2470 case OMP_DEVICE_TYPE_UNSET
:
2472 case OMP_DEVICE_TYPE_HOST
:
2473 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_HOST
, attr_bits
);
2475 case OMP_DEVICE_TYPE_NOHOST
:
2476 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_NOHOST
, attr_bits
);
2478 case OMP_DEVICE_TYPE_ANY
:
2479 MIO_NAME (ab_attribute
) (AB_OMP_DEVICE_TYPE_ANY
, attr_bits
);
2491 if (t
== ATOM_RPAREN
)
2494 bad_module ("Expected attribute bit name");
2496 switch ((ab_attribute
) find_enum (attr_bits
))
2498 case AB_ALLOCATABLE
:
2499 attr
->allocatable
= 1;
2502 attr
->artificial
= 1;
2504 case AB_ASYNCHRONOUS
:
2505 attr
->asynchronous
= 1;
2508 attr
->dimension
= 1;
2510 case AB_CODIMENSION
:
2511 attr
->codimension
= 1;
2514 attr
->contiguous
= 1;
2520 attr
->intrinsic
= 1;
2528 case AB_CLASS_POINTER
:
2529 attr
->class_pointer
= 1;
2532 attr
->is_protected
= 1;
2538 attr
->volatile_
= 1;
2543 case AB_THREADPRIVATE
:
2544 attr
->threadprivate
= 1;
2555 case AB_IN_NAMELIST
:
2556 attr
->in_namelist
= 1;
2559 attr
->in_common
= 1;
2565 attr
->subroutine
= 1;
2577 attr
->elemental
= 1;
2582 case AB_IMPLICIT_PURE
:
2583 attr
->implicit_pure
= 1;
2585 case AB_UNLIMITED_POLY
:
2586 attr
->unlimited_polymorphic
= 1;
2589 attr
->recursive
= 1;
2591 case AB_ALWAYS_EXPLICIT
:
2592 attr
->always_explicit
= 1;
2594 case AB_CRAY_POINTER
:
2595 attr
->cray_pointer
= 1;
2597 case AB_CRAY_POINTEE
:
2598 attr
->cray_pointee
= 1;
2601 attr
->is_bind_c
= 1;
2603 case AB_IS_C_INTEROP
:
2604 attr
->is_c_interop
= 1;
2610 attr
->alloc_comp
= 1;
2612 case AB_COARRAY_COMP
:
2613 attr
->coarray_comp
= 1;
2616 attr
->lock_comp
= 1;
2619 attr
->event_comp
= 1;
2621 case AB_POINTER_COMP
:
2622 attr
->pointer_comp
= 1;
2624 case AB_PROC_POINTER_COMP
:
2625 attr
->proc_pointer_comp
= 1;
2627 case AB_PRIVATE_COMP
:
2628 attr
->private_comp
= 1;
2631 attr
->zero_comp
= 1;
2637 attr
->procedure
= 1;
2639 case AB_PROC_POINTER
:
2640 attr
->proc_pointer
= 1;
2648 case AB_OMP_DECLARE_TARGET
:
2649 attr
->omp_declare_target
= 1;
2651 case AB_OMP_DECLARE_TARGET_LINK
:
2652 attr
->omp_declare_target_link
= 1;
2654 case AB_ARRAY_OUTER_DEPENDENCY
:
2655 attr
->array_outer_dependency
=1;
2657 case AB_MODULE_PROCEDURE
:
2658 attr
->module_procedure
=1;
2660 case AB_OACC_DECLARE_CREATE
:
2661 attr
->oacc_declare_create
= 1;
2663 case AB_OACC_DECLARE_COPYIN
:
2664 attr
->oacc_declare_copyin
= 1;
2666 case AB_OACC_DECLARE_DEVICEPTR
:
2667 attr
->oacc_declare_deviceptr
= 1;
2669 case AB_OACC_DECLARE_DEVICE_RESIDENT
:
2670 attr
->oacc_declare_device_resident
= 1;
2672 case AB_OACC_DECLARE_LINK
:
2673 attr
->oacc_declare_link
= 1;
2684 case AB_PDT_TEMPLATE
:
2685 attr
->pdt_template
= 1;
2688 attr
->pdt_array
= 1;
2691 attr
->pdt_string
= 1;
2693 case AB_OACC_ROUTINE_LOP_GANG
:
2694 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2695 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_GANG
;
2697 case AB_OACC_ROUTINE_LOP_WORKER
:
2698 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2699 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_WORKER
;
2701 case AB_OACC_ROUTINE_LOP_VECTOR
:
2702 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2703 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_VECTOR
;
2705 case AB_OACC_ROUTINE_LOP_SEQ
:
2706 verify_OACC_ROUTINE_LOP_NONE (attr
->oacc_routine_lop
);
2707 attr
->oacc_routine_lop
= OACC_ROUTINE_LOP_SEQ
;
2709 case AB_OACC_ROUTINE_NOHOST
:
2710 attr
->oacc_routine_nohost
= 1;
2712 case AB_OMP_REQ_REVERSE_OFFLOAD
:
2713 gfc_omp_requires_add_clause (OMP_REQ_REVERSE_OFFLOAD
,
2718 case AB_OMP_REQ_UNIFIED_ADDRESS
:
2719 gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_ADDRESS
,
2724 case AB_OMP_REQ_UNIFIED_SHARED_MEMORY
:
2725 gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_SHARED_MEMORY
,
2726 "unified_shared_memory",
2730 case AB_OMP_REQ_SELF_MAPS
:
2731 gfc_omp_requires_add_clause (OMP_REQ_SELF_MAPS
,
2736 case AB_OMP_REQ_DYNAMIC_ALLOCATORS
:
2737 gfc_omp_requires_add_clause (OMP_REQ_DYNAMIC_ALLOCATORS
,
2738 "dynamic_allocators",
2742 case AB_OMP_REQ_MEM_ORDER_SEQ_CST
:
2743 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST
,
2744 "seq_cst", &gfc_current_locus
,
2747 case AB_OMP_REQ_MEM_ORDER_ACQ_REL
:
2748 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL
,
2749 "acq_rel", &gfc_current_locus
,
2752 case AB_OMP_REQ_MEM_ORDER_ACQUIRE
:
2753 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE
,
2754 "acquires", &gfc_current_locus
,
2757 case AB_OMP_REQ_MEM_ORDER_RELAXED
:
2758 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELAXED
,
2759 "relaxed", &gfc_current_locus
,
2762 case AB_OMP_REQ_MEM_ORDER_RELEASE
:
2763 gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELEASE
,
2764 "release", &gfc_current_locus
,
2767 case AB_OMP_DEVICE_TYPE_HOST
:
2768 attr
->omp_device_type
= OMP_DEVICE_TYPE_HOST
;
2770 case AB_OMP_DEVICE_TYPE_NOHOST
:
2771 attr
->omp_device_type
= OMP_DEVICE_TYPE_NOHOST
;
2773 case AB_OMP_DEVICE_TYPE_ANY
:
2774 attr
->omp_device_type
= OMP_DEVICE_TYPE_ANY
;
2782 static const mstring bt_types
[] = {
2783 minit ("INTEGER", BT_INTEGER
),
2784 minit ("REAL", BT_REAL
),
2785 minit ("COMPLEX", BT_COMPLEX
),
2786 minit ("LOGICAL", BT_LOGICAL
),
2787 minit ("CHARACTER", BT_CHARACTER
),
2788 minit ("UNION", BT_UNION
),
2789 minit ("DERIVED", BT_DERIVED
),
2790 minit ("CLASS", BT_CLASS
),
2791 minit ("PROCEDURE", BT_PROCEDURE
),
2792 minit ("UNKNOWN", BT_UNKNOWN
),
2793 minit ("VOID", BT_VOID
),
2794 minit ("ASSUMED", BT_ASSUMED
),
2795 minit ("UNSIGNED", BT_UNSIGNED
),
2801 mio_charlen (gfc_charlen
**clp
)
2807 if (iomode
== IO_OUTPUT
)
2811 mio_expr (&cl
->length
);
2815 if (peek_atom () != ATOM_RPAREN
)
2817 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2818 mio_expr (&cl
->length
);
2827 /* See if a name is a generated name. */
2830 check_unique_name (const char *name
)
2832 return *name
== '@';
2837 mio_typespec (gfc_typespec
*ts
)
2841 ts
->type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2843 if (!gfc_bt_struct (ts
->type
) && ts
->type
!= BT_CLASS
)
2844 mio_integer (&ts
->kind
);
2846 mio_symbol_ref (&ts
->u
.derived
);
2848 mio_symbol_ref (&ts
->interface
);
2850 /* Add info for C interop and is_iso_c. */
2851 mio_integer (&ts
->is_c_interop
);
2852 mio_integer (&ts
->is_iso_c
);
2854 /* If the typespec is for an identifier either from iso_c_binding, or
2855 a constant that was initialized to an identifier from it, use the
2856 f90_type. Otherwise, use the ts->type, since it shouldn't matter. */
2858 ts
->f90_type
= MIO_NAME (bt
) (ts
->f90_type
, bt_types
);
2860 ts
->f90_type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2862 if (ts
->type
!= BT_CHARACTER
)
2864 /* ts->u.cl is only valid for BT_CHARACTER. */
2869 mio_charlen (&ts
->u
.cl
);
2871 /* So as not to disturb the existing API, use an ATOM_NAME to
2872 transmit deferred characteristic for characters (F2003). */
2873 if (iomode
== IO_OUTPUT
)
2875 if (ts
->type
== BT_CHARACTER
&& ts
->deferred
)
2876 write_atom (ATOM_NAME
, "DEFERRED_CL");
2878 else if (peek_atom () != ATOM_RPAREN
)
2880 if (parse_atom () != ATOM_NAME
)
2881 bad_module ("Expected string");
2889 static const mstring array_spec_types
[] = {
2890 minit ("EXPLICIT", AS_EXPLICIT
),
2891 minit ("ASSUMED_RANK", AS_ASSUMED_RANK
),
2892 minit ("ASSUMED_SHAPE", AS_ASSUMED_SHAPE
),
2893 minit ("DEFERRED", AS_DEFERRED
),
2894 minit ("ASSUMED_SIZE", AS_ASSUMED_SIZE
),
2900 mio_array_spec (gfc_array_spec
**asp
)
2907 if (iomode
== IO_OUTPUT
)
2915 /* mio_integer expects nonnegative values. */
2916 rank
= as
->rank
> 0 ? as
->rank
: 0;
2917 mio_integer (&rank
);
2921 if (peek_atom () == ATOM_RPAREN
)
2927 *asp
= as
= gfc_get_array_spec ();
2928 mio_integer (&as
->rank
);
2931 mio_integer (&as
->corank
);
2932 as
->type
= MIO_NAME (array_type
) (as
->type
, array_spec_types
);
2934 if (iomode
== IO_INPUT
&& as
->type
== AS_ASSUMED_RANK
)
2936 if (iomode
== IO_INPUT
&& as
->corank
)
2937 as
->cotype
= (as
->type
== AS_DEFERRED
) ? AS_DEFERRED
: AS_EXPLICIT
;
2939 if (as
->rank
+ as
->corank
> 0)
2940 for (i
= 0; i
< as
->rank
+ as
->corank
; i
++)
2942 mio_expr (&as
->lower
[i
]);
2943 mio_expr (&as
->upper
[i
]);
2951 /* Given a pointer to an array reference structure (which lives in a
2952 gfc_ref structure), find the corresponding array specification
2953 structure. Storing the pointer in the ref structure doesn't quite
2954 work when loading from a module. Generating code for an array
2955 reference also needs more information than just the array spec. */
2957 static const mstring array_ref_types
[] = {
2958 minit ("FULL", AR_FULL
),
2959 minit ("ELEMENT", AR_ELEMENT
),
2960 minit ("SECTION", AR_SECTION
),
2966 mio_array_ref (gfc_array_ref
*ar
)
2971 ar
->type
= MIO_NAME (ar_type
) (ar
->type
, array_ref_types
);
2972 mio_integer (&ar
->dimen
);
2980 for (i
= 0; i
< ar
->dimen
; i
++)
2981 mio_expr (&ar
->start
[i
]);
2986 for (i
= 0; i
< ar
->dimen
; i
++)
2988 mio_expr (&ar
->start
[i
]);
2989 mio_expr (&ar
->end
[i
]);
2990 mio_expr (&ar
->stride
[i
]);
2996 gfc_internal_error ("mio_array_ref(): Unknown array ref");
2999 /* Unfortunately, ar->dimen_type is an anonymous enumerated type so
3000 we can't call mio_integer directly. Instead loop over each element
3001 and cast it to/from an integer. */
3002 if (iomode
== IO_OUTPUT
)
3004 for (i
= 0; i
< ar
->dimen
; i
++)
3006 HOST_WIDE_INT tmp
= (HOST_WIDE_INT
)ar
->dimen_type
[i
];
3007 write_atom (ATOM_INTEGER
, &tmp
);
3012 for (i
= 0; i
< ar
->dimen
; i
++)
3014 require_atom (ATOM_INTEGER
);
3015 ar
->dimen_type
[i
] = (enum gfc_array_ref_dimen_type
) atom_int
;
3019 if (iomode
== IO_INPUT
)
3021 ar
->where
= gfc_current_locus
;
3023 for (i
= 0; i
< ar
->dimen
; i
++)
3024 ar
->c_where
[i
] = gfc_current_locus
;
3031 /* Saves or restores a pointer. The pointer is converted back and
3032 forth from an integer. We return the pointer_info pointer so that
3033 the caller can take additional action based on the pointer type. */
3035 static pointer_info
*
3036 mio_pointer_ref (void *gp
)
3040 if (iomode
== IO_OUTPUT
)
3042 p
= get_pointer (*((char **) gp
));
3043 HOST_WIDE_INT hwi
= p
->integer
;
3044 write_atom (ATOM_INTEGER
, &hwi
);
3048 require_atom (ATOM_INTEGER
);
3049 p
= add_fixup (atom_int
, gp
);
3056 /* Save and load references to components that occur within
3057 expressions. We have to describe these references by a number and
3058 by name. The number is necessary for forward references during
3059 reading, and the name is necessary if the symbol already exists in
3060 the namespace and is not loaded again. */
3063 mio_component_ref (gfc_component
**cp
)
3067 p
= mio_pointer_ref (cp
);
3068 if (p
->type
== P_UNKNOWN
)
3069 p
->type
= P_COMPONENT
;
3073 static void mio_namespace_ref (gfc_namespace
**nsp
);
3074 static void mio_formal_arglist (gfc_formal_arglist
**formal
);
3075 static void mio_typebound_proc (gfc_typebound_proc
** proc
);
3076 static void mio_actual_arglist (gfc_actual_arglist
**ap
, bool pdt
);
3079 mio_component (gfc_component
*c
, int vtype
)
3085 if (iomode
== IO_OUTPUT
)
3087 p
= get_pointer (c
);
3088 mio_hwi (&p
->integer
);
3094 p
= get_integer (n
);
3095 associate_integer_pointer (p
, c
);
3098 if (p
->type
== P_UNKNOWN
)
3099 p
->type
= P_COMPONENT
;
3101 mio_pool_string (&c
->name
);
3102 mio_typespec (&c
->ts
);
3103 mio_array_spec (&c
->as
);
3105 /* PDT templates store the expression for the kind of a component here. */
3106 mio_expr (&c
->kind_expr
);
3108 /* PDT types store the component specification list here. */
3109 mio_actual_arglist (&c
->param_list
, true);
3111 mio_symbol_attribute (&c
->attr
);
3112 if (c
->ts
.type
== BT_CLASS
)
3113 c
->attr
.class_ok
= 1;
3114 c
->attr
.access
= MIO_NAME (gfc_access
) (c
->attr
.access
, access_types
);
3116 if (!vtype
|| strcmp (c
->name
, "_final") == 0
3117 || strcmp (c
->name
, "_hash") == 0)
3118 mio_expr (&c
->initializer
);
3120 if (c
->attr
.proc_pointer
)
3121 mio_typebound_proc (&c
->tb
);
3123 c
->loc
= gfc_current_locus
;
3130 mio_component_list (gfc_component
**cp
, int vtype
)
3132 gfc_component
*c
, *tail
;
3136 if (iomode
== IO_OUTPUT
)
3138 for (c
= *cp
; c
; c
= c
->next
)
3139 mio_component (c
, vtype
);
3148 if (peek_atom () == ATOM_RPAREN
)
3151 c
= gfc_get_component ();
3152 mio_component (c
, vtype
);
3168 mio_actual_arg (gfc_actual_arglist
*a
, bool pdt
)
3171 mio_pool_string (&a
->name
);
3172 mio_expr (&a
->expr
);
3174 mio_integer ((int *)&a
->spec_type
);
3180 mio_actual_arglist (gfc_actual_arglist
**ap
, bool pdt
)
3182 gfc_actual_arglist
*a
, *tail
;
3186 if (iomode
== IO_OUTPUT
)
3188 for (a
= *ap
; a
; a
= a
->next
)
3189 mio_actual_arg (a
, pdt
);
3198 if (peek_atom () != ATOM_LPAREN
)
3201 a
= gfc_get_actual_arglist ();
3209 mio_actual_arg (a
, pdt
);
3217 /* Read and write formal argument lists. */
3220 mio_formal_arglist (gfc_formal_arglist
**formal
)
3222 gfc_formal_arglist
*f
, *tail
;
3226 if (iomode
== IO_OUTPUT
)
3228 for (f
= *formal
; f
; f
= f
->next
)
3229 mio_symbol_ref (&f
->sym
);
3233 *formal
= tail
= NULL
;
3235 while (peek_atom () != ATOM_RPAREN
)
3237 f
= gfc_get_formal_arglist ();
3238 mio_symbol_ref (&f
->sym
);
3240 if (*formal
== NULL
)
3253 /* Save or restore a reference to a symbol node. */
3256 mio_symbol_ref (gfc_symbol
**symp
)
3260 p
= mio_pointer_ref (symp
);
3261 if (p
->type
== P_UNKNOWN
)
3264 if (iomode
== IO_OUTPUT
)
3266 if (p
->u
.wsym
.state
== UNREFERENCED
)
3267 p
->u
.wsym
.state
= NEEDS_WRITE
;
3271 if (p
->u
.rsym
.state
== UNUSED
)
3272 p
->u
.rsym
.state
= NEEDED
;
3278 /* Save or restore a reference to a symtree node. */
3281 mio_symtree_ref (gfc_symtree
**stp
)
3286 if (iomode
== IO_OUTPUT
)
3287 mio_symbol_ref (&(*stp
)->n
.sym
);
3290 require_atom (ATOM_INTEGER
);
3291 p
= get_integer (atom_int
);
3293 /* An unused equivalence member; make a symbol and a symtree
3295 if (in_load_equiv
&& p
->u
.rsym
.symtree
== NULL
)
3297 /* Since this is not used, it must have a unique name. */
3298 p
->u
.rsym
.symtree
= gfc_get_unique_symtree (gfc_current_ns
);
3300 /* Make the symbol. */
3301 if (p
->u
.rsym
.sym
== NULL
)
3303 p
->u
.rsym
.sym
= gfc_new_symbol (p
->u
.rsym
.true_name
,
3305 p
->u
.rsym
.sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
3308 p
->u
.rsym
.symtree
->n
.sym
= p
->u
.rsym
.sym
;
3309 p
->u
.rsym
.symtree
->n
.sym
->refs
++;
3310 p
->u
.rsym
.referenced
= 1;
3312 /* If the symbol is PRIVATE and in COMMON, load_commons will
3313 generate a fixup symbol, which must be associated. */
3315 resolve_fixups (p
->fixup
, p
->u
.rsym
.sym
);
3319 if (p
->type
== P_UNKNOWN
)
3322 if (p
->u
.rsym
.state
== UNUSED
)
3323 p
->u
.rsym
.state
= NEEDED
;
3325 if (p
->u
.rsym
.symtree
!= NULL
)
3327 *stp
= p
->u
.rsym
.symtree
;
3331 f
= XCNEW (fixup_t
);
3333 f
->next
= p
->u
.rsym
.stfixup
;
3334 p
->u
.rsym
.stfixup
= f
;
3336 f
->pointer
= (void **) stp
;
3343 mio_iterator (gfc_iterator
**ip
)
3349 if (iomode
== IO_OUTPUT
)
3356 if (peek_atom () == ATOM_RPAREN
)
3362 *ip
= gfc_get_iterator ();
3367 mio_expr (&iter
->var
);
3368 mio_expr (&iter
->start
);
3369 mio_expr (&iter
->end
);
3370 mio_expr (&iter
->step
);
3378 mio_constructor (gfc_constructor_base
*cp
)
3384 if (iomode
== IO_OUTPUT
)
3386 for (c
= gfc_constructor_first (*cp
); c
; c
= gfc_constructor_next (c
))
3389 mio_expr (&c
->expr
);
3390 mio_iterator (&c
->iterator
);
3396 while (peek_atom () != ATOM_RPAREN
)
3398 c
= gfc_constructor_append_expr (cp
, NULL
, NULL
);
3401 mio_expr (&c
->expr
);
3402 mio_iterator (&c
->iterator
);
3411 static const mstring ref_types
[] = {
3412 minit ("ARRAY", REF_ARRAY
),
3413 minit ("COMPONENT", REF_COMPONENT
),
3414 minit ("SUBSTRING", REF_SUBSTRING
),
3415 minit ("INQUIRY", REF_INQUIRY
),
3419 static const mstring inquiry_types
[] = {
3420 minit ("RE", INQUIRY_RE
),
3421 minit ("IM", INQUIRY_IM
),
3422 minit ("KIND", INQUIRY_KIND
),
3423 minit ("LEN", INQUIRY_LEN
),
3429 mio_ref (gfc_ref
**rp
)
3436 r
->type
= MIO_NAME (ref_type
) (r
->type
, ref_types
);
3441 mio_array_ref (&r
->u
.ar
);
3445 mio_symbol_ref (&r
->u
.c
.sym
);
3446 mio_component_ref (&r
->u
.c
.component
);
3450 mio_expr (&r
->u
.ss
.start
);
3451 mio_expr (&r
->u
.ss
.end
);
3452 mio_charlen (&r
->u
.ss
.length
);
3456 r
->u
.i
= MIO_NAME (inquiry_type
) (r
->u
.i
, inquiry_types
);
3465 mio_ref_list (gfc_ref
**rp
)
3467 gfc_ref
*ref
, *head
, *tail
;
3471 if (iomode
== IO_OUTPUT
)
3473 for (ref
= *rp
; ref
; ref
= ref
->next
)
3480 while (peek_atom () != ATOM_RPAREN
)
3483 head
= tail
= gfc_get_ref ();
3486 tail
->next
= gfc_get_ref ();
3500 /* Read and write an integer value. */
3503 mio_gmp_integer (mpz_t
*integer
)
3507 if (iomode
== IO_INPUT
)
3509 if (parse_atom () != ATOM_STRING
)
3510 bad_module ("Expected integer string");
3512 mpz_init (*integer
);
3513 if (mpz_set_str (*integer
, atom_string
, 10))
3514 bad_module ("Error converting integer");
3520 p
= mpz_get_str (NULL
, 10, *integer
);
3521 write_atom (ATOM_STRING
, p
);
3528 mio_gmp_real (mpfr_t
*real
)
3530 mpfr_exp_t exponent
;
3533 if (iomode
== IO_INPUT
)
3535 if (parse_atom () != ATOM_STRING
)
3536 bad_module ("Expected real string");
3539 mpfr_set_str (*real
, atom_string
, 16, GFC_RND_MODE
);
3544 p
= mpfr_get_str (NULL
, &exponent
, 16, 0, *real
, GFC_RND_MODE
);
3546 if (mpfr_nan_p (*real
) || mpfr_inf_p (*real
))
3548 write_atom (ATOM_STRING
, p
);
3553 atom_string
= XCNEWVEC (char, strlen (p
) + 20);
3555 sprintf (atom_string
, "0.%s@%ld", p
, exponent
);
3557 /* Fix negative numbers. */
3558 if (atom_string
[2] == '-')
3560 atom_string
[0] = '-';
3561 atom_string
[1] = '0';
3562 atom_string
[2] = '.';
3565 write_atom (ATOM_STRING
, atom_string
);
3573 /* Save and restore the shape of an array constructor. */
3576 mio_shape (mpz_t
**pshape
, int rank
)
3582 /* A NULL shape is represented by (). */
3585 if (iomode
== IO_OUTPUT
)
3597 if (t
== ATOM_RPAREN
)
3604 shape
= gfc_get_shape (rank
);
3608 for (n
= 0; n
< rank
; n
++)
3609 mio_gmp_integer (&shape
[n
]);
3615 static const mstring expr_types
[] = {
3616 minit ("OP", EXPR_OP
),
3617 minit ("FUNCTION", EXPR_FUNCTION
),
3618 minit ("CONSTANT", EXPR_CONSTANT
),
3619 minit ("VARIABLE", EXPR_VARIABLE
),
3620 minit ("SUBSTRING", EXPR_SUBSTRING
),
3621 minit ("STRUCTURE", EXPR_STRUCTURE
),
3622 minit ("ARRAY", EXPR_ARRAY
),
3623 minit ("NULL", EXPR_NULL
),
3624 minit ("COMPCALL", EXPR_COMPCALL
),
3628 /* INTRINSIC_ASSIGN is missing because it is used as an index for
3629 generic operators, not in expressions. INTRINSIC_USER is also
3630 replaced by the correct function name by the time we see it. */
3632 static const mstring intrinsics
[] =
3634 minit ("UPLUS", INTRINSIC_UPLUS
),
3635 minit ("UMINUS", INTRINSIC_UMINUS
),
3636 minit ("PLUS", INTRINSIC_PLUS
),
3637 minit ("MINUS", INTRINSIC_MINUS
),
3638 minit ("TIMES", INTRINSIC_TIMES
),
3639 minit ("DIVIDE", INTRINSIC_DIVIDE
),
3640 minit ("POWER", INTRINSIC_POWER
),
3641 minit ("CONCAT", INTRINSIC_CONCAT
),
3642 minit ("AND", INTRINSIC_AND
),
3643 minit ("OR", INTRINSIC_OR
),
3644 minit ("EQV", INTRINSIC_EQV
),
3645 minit ("NEQV", INTRINSIC_NEQV
),
3646 minit ("EQ_SIGN", INTRINSIC_EQ
),
3647 minit ("EQ", INTRINSIC_EQ_OS
),
3648 minit ("NE_SIGN", INTRINSIC_NE
),
3649 minit ("NE", INTRINSIC_NE_OS
),
3650 minit ("GT_SIGN", INTRINSIC_GT
),
3651 minit ("GT", INTRINSIC_GT_OS
),
3652 minit ("GE_SIGN", INTRINSIC_GE
),
3653 minit ("GE", INTRINSIC_GE_OS
),
3654 minit ("LT_SIGN", INTRINSIC_LT
),
3655 minit ("LT", INTRINSIC_LT_OS
),
3656 minit ("LE_SIGN", INTRINSIC_LE
),
3657 minit ("LE", INTRINSIC_LE_OS
),
3658 minit ("NOT", INTRINSIC_NOT
),
3659 minit ("PARENTHESES", INTRINSIC_PARENTHESES
),
3660 minit ("USER", INTRINSIC_USER
),
3665 /* Remedy a couple of situations where the gfc_expr's can be defective. */
3668 fix_mio_expr (gfc_expr
*e
)
3670 gfc_symtree
*ns_st
= NULL
;
3673 if (iomode
!= IO_OUTPUT
)
3678 /* If this is a symtree for a symbol that came from a contained module
3679 namespace, it has a unique name and we should look in the current
3680 namespace to see if the required, non-contained symbol is available
3681 yet. If so, the latter should be written. */
3682 if (e
->symtree
->n
.sym
&& check_unique_name (e
->symtree
->name
))
3684 const char *name
= e
->symtree
->n
.sym
->name
;
3685 if (gfc_fl_struct (e
->symtree
->n
.sym
->attr
.flavor
))
3686 name
= gfc_dt_upper_string (name
);
3687 ns_st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
3690 /* On the other hand, if the existing symbol is the module name or the
3691 new symbol is a dummy argument, do not do the promotion. */
3692 if (ns_st
&& ns_st
->n
.sym
3693 && ns_st
->n
.sym
->attr
.flavor
!= FL_MODULE
3694 && !e
->symtree
->n
.sym
->attr
.dummy
)
3697 else if (e
->expr_type
== EXPR_FUNCTION
3698 && (e
->value
.function
.name
|| e
->value
.function
.isym
))
3702 /* In some circumstances, a function used in an initialization
3703 expression, in one use associated module, can fail to be
3704 coupled to its symtree when used in a specification
3705 expression in another module. */
3706 fname
= e
->value
.function
.esym
? e
->value
.function
.esym
->name
3707 : e
->value
.function
.isym
->name
;
3708 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3713 /* This is probably a reference to a private procedure from another
3714 module. To prevent a segfault, make a generic with no specific
3715 instances. If this module is used, without the required
3716 specific coming from somewhere, the appropriate error message
3718 gfc_get_symbol (fname
, gfc_current_ns
, &sym
);
3719 sym
->attr
.flavor
= FL_PROCEDURE
;
3720 sym
->attr
.generic
= 1;
3721 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3722 gfc_commit_symbol (sym
);
3727 /* Read and write expressions. The form "()" is allowed to indicate a
3731 mio_expr (gfc_expr
**ep
)
3740 if (iomode
== IO_OUTPUT
)
3749 MIO_NAME (expr_t
) (e
->expr_type
, expr_types
);
3754 if (t
== ATOM_RPAREN
)
3761 bad_module ("Expected expression type");
3763 e
= *ep
= gfc_get_expr ();
3764 e
->where
= gfc_current_locus
;
3765 e
->expr_type
= (expr_t
) find_enum (expr_types
);
3768 mio_typespec (&e
->ts
);
3769 mio_integer (&e
->rank
);
3773 switch (e
->expr_type
)
3777 = MIO_NAME (gfc_intrinsic_op
) (e
->value
.op
.op
, intrinsics
);
3779 switch (e
->value
.op
.op
)
3781 case INTRINSIC_UPLUS
:
3782 case INTRINSIC_UMINUS
:
3784 case INTRINSIC_PARENTHESES
:
3785 mio_expr (&e
->value
.op
.op1
);
3788 case INTRINSIC_PLUS
:
3789 case INTRINSIC_MINUS
:
3790 case INTRINSIC_TIMES
:
3791 case INTRINSIC_DIVIDE
:
3792 case INTRINSIC_POWER
:
3793 case INTRINSIC_CONCAT
:
3797 case INTRINSIC_NEQV
:
3799 case INTRINSIC_EQ_OS
:
3801 case INTRINSIC_NE_OS
:
3803 case INTRINSIC_GT_OS
:
3805 case INTRINSIC_GE_OS
:
3807 case INTRINSIC_LT_OS
:
3809 case INTRINSIC_LE_OS
:
3810 mio_expr (&e
->value
.op
.op1
);
3811 mio_expr (&e
->value
.op
.op2
);
3814 case INTRINSIC_USER
:
3815 /* INTRINSIC_USER should not appear in resolved expressions,
3816 though for UDRs we need to stream unresolved ones. */
3817 if (iomode
== IO_OUTPUT
)
3818 write_atom (ATOM_STRING
, e
->value
.op
.uop
->name
);
3821 char *name
= read_string ();
3822 const char *uop_name
= find_use_name (name
, true);
3823 if (uop_name
== NULL
)
3825 size_t len
= strlen (name
);
3826 char *name2
= XCNEWVEC (char, len
+ 2);
3827 memcpy (name2
, name
, len
);
3829 name2
[len
+ 1] = '\0';
3831 uop_name
= name
= name2
;
3833 e
->value
.op
.uop
= gfc_get_uop (uop_name
);
3836 mio_expr (&e
->value
.op
.op1
);
3837 mio_expr (&e
->value
.op
.op2
);
3841 bad_module ("Bad operator");
3847 mio_symtree_ref (&e
->symtree
);
3848 mio_actual_arglist (&e
->value
.function
.actual
, false);
3850 if (iomode
== IO_OUTPUT
)
3852 e
->value
.function
.name
3853 = mio_allocated_string (e
->value
.function
.name
);
3854 if (e
->value
.function
.esym
)
3858 else if (e
->value
.function
.isym
== NULL
)
3862 mio_integer (&flag
);
3866 mio_symbol_ref (&e
->value
.function
.esym
);
3869 mio_ref_list (&e
->ref
);
3874 write_atom (ATOM_STRING
, e
->value
.function
.isym
->name
);
3879 require_atom (ATOM_STRING
);
3880 if (atom_string
[0] == '\0')
3881 e
->value
.function
.name
= NULL
;
3883 e
->value
.function
.name
= gfc_get_string ("%s", atom_string
);
3886 mio_integer (&flag
);
3890 mio_symbol_ref (&e
->value
.function
.esym
);
3893 mio_ref_list (&e
->ref
);
3898 require_atom (ATOM_STRING
);
3899 e
->value
.function
.isym
= gfc_find_function (atom_string
);
3907 mio_symtree_ref (&e
->symtree
);
3908 mio_ref_list (&e
->ref
);
3911 case EXPR_SUBSTRING
:
3912 e
->value
.character
.string
3913 = CONST_CAST (gfc_char_t
*,
3914 mio_allocated_wide_string (e
->value
.character
.string
,
3915 e
->value
.character
.length
));
3916 mio_ref_list (&e
->ref
);
3919 case EXPR_STRUCTURE
:
3921 mio_constructor (&e
->value
.constructor
);
3922 mio_shape (&e
->shape
, e
->rank
);
3930 mio_gmp_integer (&e
->value
.integer
);
3934 gfc_set_model_kind (e
->ts
.kind
);
3935 mio_gmp_real (&e
->value
.real
);
3939 gfc_set_model_kind (e
->ts
.kind
);
3940 mio_gmp_real (&mpc_realref (e
->value
.complex));
3941 mio_gmp_real (&mpc_imagref (e
->value
.complex));
3945 mio_integer (&e
->value
.logical
);
3949 hwi
= e
->value
.character
.length
;
3951 e
->value
.character
.length
= hwi
;
3952 e
->value
.character
.string
3953 = CONST_CAST (gfc_char_t
*,
3954 mio_allocated_wide_string (e
->value
.character
.string
,
3955 e
->value
.character
.length
));
3959 bad_module ("Bad type in constant expression");
3974 /* PDT types store the expression specification list here. */
3975 mio_actual_arglist (&e
->param_list
, true);
3981 /* Read and write namelists. */
3984 mio_namelist (gfc_symbol
*sym
)
3986 gfc_namelist
*n
, *m
;
3990 if (iomode
== IO_OUTPUT
)
3992 for (n
= sym
->namelist
; n
; n
= n
->next
)
3993 mio_symbol_ref (&n
->sym
);
3998 while (peek_atom () != ATOM_RPAREN
)
4000 n
= gfc_get_namelist ();
4001 mio_symbol_ref (&n
->sym
);
4003 if (sym
->namelist
== NULL
)
4010 sym
->namelist_tail
= m
;
4017 /* Save/restore lists of gfc_interface structures. When loading an
4018 interface, we are really appending to the existing list of
4019 interfaces. Checking for duplicate and ambiguous interfaces has to
4020 be done later when all symbols have been loaded. */
4023 mio_interface_rest (gfc_interface
**ip
)
4025 gfc_interface
*tail
, *p
;
4026 pointer_info
*pi
= NULL
;
4028 if (iomode
== IO_OUTPUT
)
4031 for (p
= *ip
; p
; p
= p
->next
)
4032 mio_symbol_ref (&p
->sym
);
4047 if (peek_atom () == ATOM_RPAREN
)
4050 p
= gfc_get_interface ();
4051 p
->where
= gfc_current_locus
;
4052 pi
= mio_symbol_ref (&p
->sym
);
4068 /* Save/restore a nameless operator interface. */
4071 mio_interface (gfc_interface
**ip
)
4074 mio_interface_rest (ip
);
4078 /* Save/restore a named operator interface. */
4081 mio_symbol_interface (const char **name
, const char **module
,
4085 mio_pool_string (name
);
4086 mio_pool_string (module
);
4087 mio_interface_rest (ip
);
4092 mio_namespace_ref (gfc_namespace
**nsp
)
4097 p
= mio_pointer_ref (nsp
);
4099 if (p
->type
== P_UNKNOWN
)
4100 p
->type
= P_NAMESPACE
;
4102 if (iomode
== IO_INPUT
&& p
->integer
!= 0)
4104 ns
= (gfc_namespace
*) p
->u
.pointer
;
4107 ns
= gfc_get_namespace (NULL
, 0);
4108 associate_integer_pointer (p
, ns
);
4116 /* Save/restore the f2k_derived namespace of a derived-type symbol. */
4118 static gfc_namespace
* current_f2k_derived
;
4121 mio_typebound_proc (gfc_typebound_proc
** proc
)
4124 int overriding_flag
;
4126 if (iomode
== IO_INPUT
)
4128 *proc
= gfc_get_typebound_proc (NULL
);
4129 (*proc
)->where
= gfc_current_locus
;
4135 (*proc
)->access
= MIO_NAME (gfc_access
) ((*proc
)->access
, access_types
);
4137 /* IO the NON_OVERRIDABLE/DEFERRED combination. */
4138 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
4139 overriding_flag
= ((*proc
)->deferred
<< 1) | (*proc
)->non_overridable
;
4140 overriding_flag
= mio_name (overriding_flag
, binding_overriding
);
4141 (*proc
)->deferred
= ((overriding_flag
& 2) != 0);
4142 (*proc
)->non_overridable
= ((overriding_flag
& 1) != 0);
4143 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
4145 (*proc
)->nopass
= mio_name ((*proc
)->nopass
, binding_passing
);
4146 (*proc
)->is_generic
= mio_name ((*proc
)->is_generic
, binding_generic
);
4147 (*proc
)->ppc
= mio_name((*proc
)->ppc
, binding_ppc
);
4149 mio_pool_string (&((*proc
)->pass_arg
));
4151 flag
= (int) (*proc
)->pass_arg_num
;
4152 mio_integer (&flag
);
4153 (*proc
)->pass_arg_num
= (unsigned) flag
;
4155 if ((*proc
)->is_generic
)
4162 if (iomode
== IO_OUTPUT
)
4163 for (g
= (*proc
)->u
.generic
; g
; g
= g
->next
)
4165 iop
= (int) g
->is_operator
;
4167 mio_allocated_string (g
->specific_st
->name
);
4171 (*proc
)->u
.generic
= NULL
;
4172 while (peek_atom () != ATOM_RPAREN
)
4174 gfc_symtree
** sym_root
;
4176 g
= gfc_get_tbp_generic ();
4180 g
->is_operator
= (bool) iop
;
4182 require_atom (ATOM_STRING
);
4183 sym_root
= ¤t_f2k_derived
->tb_sym_root
;
4184 g
->specific_st
= gfc_get_tbp_symtree (sym_root
, atom_string
);
4187 g
->next
= (*proc
)->u
.generic
;
4188 (*proc
)->u
.generic
= g
;
4194 else if (!(*proc
)->ppc
)
4195 mio_symtree_ref (&(*proc
)->u
.specific
);
4200 /* Walker-callback function for this purpose. */
4202 mio_typebound_symtree (gfc_symtree
* st
)
4204 if (iomode
== IO_OUTPUT
&& !st
->n
.tb
)
4207 if (iomode
== IO_OUTPUT
)
4210 mio_allocated_string (st
->name
);
4212 /* For IO_INPUT, the above is done in mio_f2k_derived. */
4214 mio_typebound_proc (&st
->n
.tb
);
4218 /* IO a full symtree (in all depth). */
4220 mio_full_typebound_tree (gfc_symtree
** root
)
4224 if (iomode
== IO_OUTPUT
)
4225 gfc_traverse_symtree (*root
, &mio_typebound_symtree
);
4228 while (peek_atom () == ATOM_LPAREN
)
4234 require_atom (ATOM_STRING
);
4235 st
= gfc_get_tbp_symtree (root
, atom_string
);
4238 mio_typebound_symtree (st
);
4246 mio_finalizer (gfc_finalizer
**f
)
4248 if (iomode
== IO_OUTPUT
)
4251 gcc_assert ((*f
)->proc_tree
); /* Should already be resolved. */
4252 mio_symtree_ref (&(*f
)->proc_tree
);
4256 *f
= gfc_get_finalizer ();
4257 (*f
)->where
= gfc_current_locus
; /* Value should not matter. */
4260 mio_symtree_ref (&(*f
)->proc_tree
);
4261 (*f
)->proc_sym
= NULL
;
4266 mio_f2k_derived (gfc_namespace
*f2k
)
4268 current_f2k_derived
= f2k
;
4270 /* Handle the list of finalizer procedures. */
4272 if (iomode
== IO_OUTPUT
)
4275 for (f
= f2k
->finalizers
; f
; f
= f
->next
)
4280 f2k
->finalizers
= NULL
;
4281 while (peek_atom () != ATOM_RPAREN
)
4283 gfc_finalizer
*cur
= NULL
;
4284 mio_finalizer (&cur
);
4285 cur
->next
= f2k
->finalizers
;
4286 f2k
->finalizers
= cur
;
4291 /* Handle type-bound procedures. */
4292 mio_full_typebound_tree (&f2k
->tb_sym_root
);
4294 /* Type-bound user operators. */
4295 mio_full_typebound_tree (&f2k
->tb_uop_root
);
4297 /* Type-bound intrinsic operators. */
4299 if (iomode
== IO_OUTPUT
)
4302 for (op
= GFC_INTRINSIC_BEGIN
; op
!= GFC_INTRINSIC_END
; ++op
)
4304 gfc_intrinsic_op realop
;
4306 if (op
== INTRINSIC_USER
|| !f2k
->tb_op
[op
])
4310 realop
= (gfc_intrinsic_op
) op
;
4311 mio_intrinsic_op (&realop
);
4312 mio_typebound_proc (&f2k
->tb_op
[op
]);
4317 while (peek_atom () != ATOM_RPAREN
)
4319 gfc_intrinsic_op op
= GFC_INTRINSIC_BEGIN
; /* Silence GCC. */
4322 mio_intrinsic_op (&op
);
4323 mio_typebound_proc (&f2k
->tb_op
[op
]);
4330 mio_full_f2k_derived (gfc_symbol
*sym
)
4334 if (iomode
== IO_OUTPUT
)
4336 if (sym
->f2k_derived
)
4337 mio_f2k_derived (sym
->f2k_derived
);
4341 if (peek_atom () != ATOM_RPAREN
)
4345 sym
->f2k_derived
= gfc_get_namespace (NULL
, 0);
4347 /* PDT templates make use of the mechanisms for formal args
4348 and so the parameter symbols are stored in the formal
4349 namespace. Transfer the sym_root to f2k_derived and then
4350 free the formal namespace since it is uneeded. */
4351 if (sym
->attr
.pdt_template
&& sym
->formal
&& sym
->formal
->sym
)
4353 ns
= sym
->formal
->sym
->ns
;
4354 sym
->f2k_derived
->sym_root
= ns
->sym_root
;
4355 ns
->sym_root
= NULL
;
4357 gfc_free_namespace (ns
);
4361 mio_f2k_derived (sym
->f2k_derived
);
4364 gcc_assert (!sym
->f2k_derived
);
4370 static const mstring omp_declare_simd_clauses
[] =
4372 minit ("INBRANCH", 0),
4373 minit ("NOTINBRANCH", 1),
4374 minit ("SIMDLEN", 2),
4375 minit ("UNIFORM", 3),
4376 minit ("LINEAR", 4),
4377 minit ("ALIGNED", 5),
4378 minit ("LINEAR_REF", 33),
4379 minit ("LINEAR_VAL", 34),
4380 minit ("LINEAR_UVAL", 35),
4384 /* Handle !$omp declare simd. */
4387 mio_omp_declare_simd (gfc_namespace
*ns
, gfc_omp_declare_simd
**odsp
)
4389 if (iomode
== IO_OUTPUT
)
4394 else if (peek_atom () != ATOM_LPAREN
)
4397 gfc_omp_declare_simd
*ods
= *odsp
;
4400 if (iomode
== IO_OUTPUT
)
4402 write_atom (ATOM_NAME
, "OMP_DECLARE_SIMD");
4405 gfc_omp_namelist
*n
;
4407 if (ods
->clauses
->inbranch
)
4408 mio_name (0, omp_declare_simd_clauses
);
4409 if (ods
->clauses
->notinbranch
)
4410 mio_name (1, omp_declare_simd_clauses
);
4411 if (ods
->clauses
->simdlen_expr
)
4413 mio_name (2, omp_declare_simd_clauses
);
4414 mio_expr (&ods
->clauses
->simdlen_expr
);
4416 for (n
= ods
->clauses
->lists
[OMP_LIST_UNIFORM
]; n
; n
= n
->next
)
4418 mio_name (3, omp_declare_simd_clauses
);
4419 mio_symbol_ref (&n
->sym
);
4421 for (n
= ods
->clauses
->lists
[OMP_LIST_LINEAR
]; n
; n
= n
->next
)
4423 if (n
->u
.linear
.op
== OMP_LINEAR_DEFAULT
)
4424 mio_name (4, omp_declare_simd_clauses
);
4426 mio_name (32 + n
->u
.linear
.op
, omp_declare_simd_clauses
);
4427 mio_symbol_ref (&n
->sym
);
4428 mio_expr (&n
->expr
);
4430 for (n
= ods
->clauses
->lists
[OMP_LIST_ALIGNED
]; n
; n
= n
->next
)
4432 mio_name (5, omp_declare_simd_clauses
);
4433 mio_symbol_ref (&n
->sym
);
4434 mio_expr (&n
->expr
);
4440 gfc_omp_namelist
**ptrs
[3] = { NULL
, NULL
, NULL
};
4442 require_atom (ATOM_NAME
);
4443 *odsp
= ods
= gfc_get_omp_declare_simd ();
4444 ods
->where
= gfc_current_locus
;
4445 ods
->proc_name
= ns
->proc_name
;
4446 if (peek_atom () == ATOM_NAME
)
4448 ods
->clauses
= gfc_get_omp_clauses ();
4449 ptrs
[0] = &ods
->clauses
->lists
[OMP_LIST_UNIFORM
];
4450 ptrs
[1] = &ods
->clauses
->lists
[OMP_LIST_LINEAR
];
4451 ptrs
[2] = &ods
->clauses
->lists
[OMP_LIST_ALIGNED
];
4453 while (peek_atom () == ATOM_NAME
)
4455 gfc_omp_namelist
*n
;
4456 int t
= mio_name (0, omp_declare_simd_clauses
);
4460 case 0: ods
->clauses
->inbranch
= true; break;
4461 case 1: ods
->clauses
->notinbranch
= true; break;
4462 case 2: mio_expr (&ods
->clauses
->simdlen_expr
); break;
4466 *ptrs
[t
- 3] = n
= gfc_get_omp_namelist ();
4468 n
->where
= gfc_current_locus
;
4469 ptrs
[t
- 3] = &n
->next
;
4470 mio_symbol_ref (&n
->sym
);
4472 mio_expr (&n
->expr
);
4477 *ptrs
[1] = n
= gfc_get_omp_namelist ();
4478 n
->u
.linear
.op
= (enum gfc_omp_linear_op
) (t
- 32);
4480 goto finish_namelist
;
4485 mio_omp_declare_simd (ns
, &ods
->next
);
4491 static const mstring omp_declare_reduction_stmt
[] =
4493 minit ("ASSIGN", 0),
4500 mio_omp_udr_expr (gfc_omp_udr
*udr
, gfc_symbol
**sym1
, gfc_symbol
**sym2
,
4501 gfc_namespace
*ns
, bool is_initializer
)
4503 if (iomode
== IO_OUTPUT
)
4505 if ((*sym1
)->module
== NULL
)
4507 (*sym1
)->module
= module_name
;
4508 (*sym2
)->module
= module_name
;
4510 mio_symbol_ref (sym1
);
4511 mio_symbol_ref (sym2
);
4512 if (ns
->code
->op
== EXEC_ASSIGN
)
4514 mio_name (0, omp_declare_reduction_stmt
);
4515 mio_expr (&ns
->code
->expr1
);
4516 mio_expr (&ns
->code
->expr2
);
4521 mio_name (1, omp_declare_reduction_stmt
);
4522 mio_symtree_ref (&ns
->code
->symtree
);
4523 mio_actual_arglist (&ns
->code
->ext
.actual
, false);
4525 flag
= ns
->code
->resolved_isym
!= NULL
;
4526 mio_integer (&flag
);
4528 write_atom (ATOM_STRING
, ns
->code
->resolved_isym
->name
);
4530 mio_symbol_ref (&ns
->code
->resolved_sym
);
4535 pointer_info
*p1
= mio_symbol_ref (sym1
);
4536 pointer_info
*p2
= mio_symbol_ref (sym2
);
4538 gcc_assert (p1
->u
.rsym
.ns
== p2
->u
.rsym
.ns
);
4539 gcc_assert (p1
->u
.rsym
.sym
== NULL
);
4540 /* Add hidden symbols to the symtree. */
4541 pointer_info
*q
= get_integer (p1
->u
.rsym
.ns
);
4542 q
->u
.pointer
= (void *) ns
;
4543 sym
= gfc_new_symbol (is_initializer
? "omp_priv" : "omp_out", ns
);
4545 sym
->module
= gfc_get_string ("%s", p1
->u
.rsym
.module
);
4546 associate_integer_pointer (p1
, sym
);
4547 sym
->attr
.omp_udr_artificial_var
= 1;
4548 gcc_assert (p2
->u
.rsym
.sym
== NULL
);
4549 sym
= gfc_new_symbol (is_initializer
? "omp_orig" : "omp_in", ns
);
4551 sym
->module
= gfc_get_string ("%s", p2
->u
.rsym
.module
);
4552 associate_integer_pointer (p2
, sym
);
4553 sym
->attr
.omp_udr_artificial_var
= 1;
4554 if (mio_name (0, omp_declare_reduction_stmt
) == 0)
4556 ns
->code
= gfc_get_code (EXEC_ASSIGN
);
4557 mio_expr (&ns
->code
->expr1
);
4558 mio_expr (&ns
->code
->expr2
);
4563 ns
->code
= gfc_get_code (EXEC_CALL
);
4564 mio_symtree_ref (&ns
->code
->symtree
);
4565 mio_actual_arglist (&ns
->code
->ext
.actual
, false);
4567 mio_integer (&flag
);
4570 require_atom (ATOM_STRING
);
4571 ns
->code
->resolved_isym
= gfc_find_subroutine (atom_string
);
4575 mio_symbol_ref (&ns
->code
->resolved_sym
);
4577 ns
->code
->loc
= gfc_current_locus
;
4583 /* Unlike most other routines, the address of the symbol node is already
4584 fixed on input and the name/module has already been filled in.
4585 If you update the symbol format here, don't forget to update read_module
4586 as well (look for "seek to the symbol's component list"). */
4589 mio_symbol (gfc_symbol
*sym
)
4591 int intmod
= INTMOD_NONE
;
4595 mio_symbol_attribute (&sym
->attr
);
4597 if (sym
->attr
.pdt_type
)
4598 sym
->name
= gfc_dt_upper_string (sym
->name
);
4600 /* Note that components are always saved, even if they are supposed
4601 to be private. Component access is checked during searching. */
4602 mio_component_list (&sym
->components
, sym
->attr
.vtype
);
4603 if (sym
->components
!= NULL
)
4604 sym
->component_access
4605 = MIO_NAME (gfc_access
) (sym
->component_access
, access_types
);
4607 mio_typespec (&sym
->ts
);
4608 if (sym
->ts
.type
== BT_CLASS
)
4609 sym
->attr
.class_ok
= 1;
4611 if (iomode
== IO_OUTPUT
)
4612 mio_namespace_ref (&sym
->formal_ns
);
4615 mio_namespace_ref (&sym
->formal_ns
);
4617 sym
->formal_ns
->proc_name
= sym
;
4620 /* Save/restore common block links. */
4621 mio_symbol_ref (&sym
->common_next
);
4623 mio_formal_arglist (&sym
->formal
);
4625 if (sym
->attr
.flavor
== FL_PARAMETER
)
4626 mio_expr (&sym
->value
);
4628 mio_array_spec (&sym
->as
);
4630 mio_symbol_ref (&sym
->result
);
4632 if (sym
->attr
.cray_pointee
)
4633 mio_symbol_ref (&sym
->cp_pointer
);
4635 /* Load/save the f2k_derived namespace of a derived-type symbol. */
4636 mio_full_f2k_derived (sym
);
4638 /* PDT types store the symbol specification list here. */
4639 mio_actual_arglist (&sym
->param_list
, true);
4643 /* Add the fields that say whether this is from an intrinsic module,
4644 and if so, what symbol it is within the module. */
4645 /* mio_integer (&(sym->from_intmod)); */
4646 if (iomode
== IO_OUTPUT
)
4648 intmod
= sym
->from_intmod
;
4649 mio_integer (&intmod
);
4653 mio_integer (&intmod
);
4655 sym
->from_intmod
= current_intmod
;
4657 sym
->from_intmod
= (intmod_id
) intmod
;
4660 mio_integer (&(sym
->intmod_sym_id
));
4662 if (gfc_fl_struct (sym
->attr
.flavor
))
4663 mio_integer (&(sym
->hash_value
));
4666 && sym
->formal_ns
->proc_name
== sym
4667 && sym
->formal_ns
->entries
== NULL
)
4668 mio_omp_declare_simd (sym
->formal_ns
, &sym
->formal_ns
->omp_declare_simd
);
4674 /************************* Top level subroutines *************************/
4676 /* A recursive function to look for a specific symbol by name and by
4677 module. Whilst several symtrees might point to one symbol, its
4678 is sufficient for the purposes here than one exist. Note that
4679 generic interfaces are distinguished as are symbols that have been
4680 renamed in another module. */
4681 static gfc_symtree
*
4682 find_symbol (gfc_symtree
*st
, const char *name
,
4683 const char *module
, int generic
)
4686 gfc_symtree
*retval
, *s
;
4688 if (st
== NULL
|| st
->n
.sym
== NULL
)
4691 c
= strcmp (name
, st
->n
.sym
->name
);
4692 if (c
== 0 && st
->n
.sym
->module
4693 && strcmp (module
, st
->n
.sym
->module
) == 0
4694 && !check_unique_name (st
->name
))
4696 s
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
4698 /* Detect symbols that are renamed by use association in another
4699 module by the absence of a symtree and null attr.use_rename,
4700 since the latter is not transmitted in the module file. */
4701 if (((!generic
&& !st
->n
.sym
->attr
.generic
)
4702 || (generic
&& st
->n
.sym
->attr
.generic
))
4703 && !(s
== NULL
&& !st
->n
.sym
->attr
.use_rename
))
4707 retval
= find_symbol (st
->left
, name
, module
, generic
);
4710 retval
= find_symbol (st
->right
, name
, module
, generic
);
4716 /* Skip a list between balanced left and right parens.
4717 By setting NEST_LEVEL one assumes that a number of NEST_LEVEL opening parens
4718 have been already parsed by hand, and the remaining of the content is to be
4719 skipped here. The default value is 0 (balanced parens). */
4722 skip_list (int nest_level
= 0)
4729 switch (parse_atom ())
4752 /* Load operator interfaces from the module. Interfaces are unusual
4753 in that they attach themselves to existing symbols. */
4756 load_operator_interfaces (void)
4759 /* "module" must be large enough for the case of submodules in which the name
4760 has the form module.submodule */
4761 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
4763 pointer_info
*pi
= NULL
;
4768 while (peek_atom () != ATOM_RPAREN
)
4772 mio_internal_string (name
);
4773 mio_internal_string (module
);
4775 n
= number_use_names (name
, true);
4778 for (i
= 1; i
<= n
; i
++)
4780 /* Decide if we need to load this one or not. */
4781 p
= find_use_name_n (name
, &i
, true);
4785 while (parse_atom () != ATOM_RPAREN
);
4791 uop
= gfc_get_uop (p
);
4792 pi
= mio_interface_rest (&uop
->op
);
4796 if (gfc_find_uop (p
, NULL
))
4798 uop
= gfc_get_uop (p
);
4799 uop
->op
= gfc_get_interface ();
4800 uop
->op
->where
= gfc_current_locus
;
4801 add_fixup (pi
->integer
, &uop
->op
->sym
);
4810 /* Load interfaces from the module. Interfaces are unusual in that
4811 they attach themselves to existing symbols. */
4814 load_generic_interfaces (void)
4817 /* "module" must be large enough for the case of submodules in which the name
4818 has the form module.submodule */
4819 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[2 * GFC_MAX_SYMBOL_LEN
+ 2];
4821 gfc_interface
*generic
= NULL
, *gen
= NULL
;
4823 bool ambiguous_set
= false;
4827 while (peek_atom () != ATOM_RPAREN
)
4831 mio_internal_string (name
);
4832 mio_internal_string (module
);
4834 n
= number_use_names (name
, false);
4835 renamed
= n
? 1 : 0;
4838 for (i
= 1; i
<= n
; i
++)
4841 /* Decide if we need to load this one or not. */
4842 p
= find_use_name_n (name
, &i
, false);
4844 if (!p
|| gfc_find_symbol (p
, NULL
, 0, &sym
))
4846 /* Skip the specific names for these cases. */
4847 while (i
== 1 && parse_atom () != ATOM_RPAREN
);
4852 st
= find_symbol (gfc_current_ns
->sym_root
,
4853 name
, module_name
, 1);
4855 /* If the symbol exists already and is being USEd without being
4856 in an ONLY clause, do not load a new symtree(11.3.2). */
4857 if (!only_flag
&& st
)
4865 if (strcmp (st
->name
, p
) != 0)
4867 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
4873 /* Since we haven't found a valid generic interface, we had
4877 gfc_get_symbol (p
, NULL
, &sym
);
4878 sym
->name
= gfc_get_string ("%s", name
);
4879 sym
->module
= module_name
;
4880 sym
->attr
.flavor
= FL_PROCEDURE
;
4881 sym
->attr
.generic
= 1;
4882 sym
->attr
.use_assoc
= 1;
4887 /* Unless sym is a generic interface, this reference
4890 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
4894 if (st
&& !sym
->attr
.generic
4897 && strcmp (module
, sym
->module
))
4899 ambiguous_set
= true;
4904 sym
->attr
.use_only
= only_flag
;
4905 sym
->attr
.use_rename
= renamed
;
4909 mio_interface_rest (&sym
->generic
);
4910 generic
= sym
->generic
;
4912 else if (!sym
->generic
)
4914 sym
->generic
= generic
;
4915 sym
->attr
.generic_copy
= 1;
4918 /* If a procedure that is not generic has generic interfaces
4919 that include itself, it is generic! We need to take care
4920 to retain symbols ambiguous that were already so. */
4921 if (sym
->attr
.use_assoc
4922 && !sym
->attr
.generic
4923 && sym
->attr
.flavor
== FL_PROCEDURE
)
4925 for (gen
= generic
; gen
; gen
= gen
->next
)
4927 if (gen
->sym
== sym
)
4929 sym
->attr
.generic
= 1;
4944 /* Load common blocks. */
4949 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4954 while (peek_atom () != ATOM_RPAREN
)
4959 mio_internal_string (name
);
4961 p
= gfc_get_common (name
, 1);
4963 mio_symbol_ref (&p
->head
);
4964 mio_integer (&flags
);
4968 p
->threadprivate
= 1;
4969 p
->omp_device_type
= (gfc_omp_device_type
) ((flags
>> 2) & 3);
4972 /* Get whether this was a bind(c) common or not. */
4973 mio_integer (&p
->is_bind_c
);
4974 /* Get the binding label. */
4975 label
= read_string ();
4977 p
->binding_label
= IDENTIFIER_POINTER (get_identifier (label
));
4987 /* Load equivalences. The flag in_load_equiv informs mio_expr_ref of this
4988 so that unused variables are not loaded and so that the expression can
4994 gfc_equiv
*head
, *tail
, *end
, *eq
, *equiv
;
4998 in_load_equiv
= true;
5000 end
= gfc_current_ns
->equiv
;
5001 while (end
!= NULL
&& end
->next
!= NULL
)
5004 while (peek_atom () != ATOM_RPAREN
) {
5008 while(peek_atom () != ATOM_RPAREN
)
5011 head
= tail
= gfc_get_equiv ();
5014 tail
->eq
= gfc_get_equiv ();
5018 mio_pool_string (&tail
->module
);
5019 mio_expr (&tail
->expr
);
5022 /* Check for duplicate equivalences being loaded from different modules */
5024 for (equiv
= gfc_current_ns
->equiv
; equiv
; equiv
= equiv
->next
)
5026 if (equiv
->module
&& head
->module
5027 && strcmp (equiv
->module
, head
->module
) == 0)
5036 for (eq
= head
; eq
; eq
= head
)
5039 gfc_free_expr (eq
->expr
);
5045 gfc_current_ns
->equiv
= head
;
5056 in_load_equiv
= false;
5060 /* This function loads OpenMP user defined reductions. */
5062 load_omp_udrs (void)
5065 while (peek_atom () != ATOM_RPAREN
)
5067 const char *name
= NULL
, *newname
;
5071 gfc_omp_reduction_op rop
= OMP_REDUCTION_USER
;
5074 mio_pool_string (&name
);
5077 if (startswith (name
, "operator "))
5079 const char *p
= name
+ sizeof ("operator ") - 1;
5080 if (strcmp (p
, "+") == 0)
5081 rop
= OMP_REDUCTION_PLUS
;
5082 else if (strcmp (p
, "*") == 0)
5083 rop
= OMP_REDUCTION_TIMES
;
5084 else if (strcmp (p
, "-") == 0)
5085 rop
= OMP_REDUCTION_MINUS
;
5086 else if (strcmp (p
, ".and.") == 0)
5087 rop
= OMP_REDUCTION_AND
;
5088 else if (strcmp (p
, ".or.") == 0)
5089 rop
= OMP_REDUCTION_OR
;
5090 else if (strcmp (p
, ".eqv.") == 0)
5091 rop
= OMP_REDUCTION_EQV
;
5092 else if (strcmp (p
, ".neqv.") == 0)
5093 rop
= OMP_REDUCTION_NEQV
;
5096 if (rop
== OMP_REDUCTION_USER
&& name
[0] == '.')
5098 size_t len
= strlen (name
+ 1);
5099 altname
= XALLOCAVEC (char, len
);
5100 gcc_assert (name
[len
] == '.');
5101 memcpy (altname
, name
+ 1, len
- 1);
5102 altname
[len
- 1] = '\0';
5105 if (rop
== OMP_REDUCTION_USER
)
5106 newname
= find_use_name (altname
? altname
: name
, !!altname
);
5107 else if (only_flag
&& find_use_operator ((gfc_intrinsic_op
) rop
) == NULL
)
5109 if (newname
== NULL
)
5114 if (altname
&& newname
!= altname
)
5116 size_t len
= strlen (newname
);
5117 altname
= XALLOCAVEC (char, len
+ 3);
5119 memcpy (altname
+ 1, newname
, len
);
5120 altname
[len
+ 1] = '.';
5121 altname
[len
+ 2] = '\0';
5122 name
= gfc_get_string ("%s", altname
);
5124 st
= gfc_find_symtree (gfc_current_ns
->omp_udr_root
, name
);
5125 gfc_omp_udr
*udr
= gfc_omp_udr_find (st
, &ts
);
5128 require_atom (ATOM_INTEGER
);
5129 pointer_info
*p
= get_integer (atom_int
);
5130 if (strcmp (p
->u
.rsym
.module
, udr
->omp_out
->module
))
5132 gfc_error ("Ambiguous !$OMP DECLARE REDUCTION from "
5134 p
->u
.rsym
.module
, &gfc_current_locus
);
5135 gfc_error ("Previous !$OMP DECLARE REDUCTION from module "
5137 udr
->omp_out
->module
, &udr
->where
);
5142 udr
= gfc_get_omp_udr ();
5146 udr
->where
= gfc_current_locus
;
5147 udr
->combiner_ns
= gfc_get_namespace (gfc_current_ns
, 1);
5148 udr
->combiner_ns
->proc_name
= gfc_current_ns
->proc_name
;
5149 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
,
5151 if (peek_atom () != ATOM_RPAREN
)
5153 udr
->initializer_ns
= gfc_get_namespace (gfc_current_ns
, 1);
5154 udr
->initializer_ns
->proc_name
= gfc_current_ns
->proc_name
;
5155 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
5156 udr
->initializer_ns
, true);
5160 udr
->next
= st
->n
.omp_udr
;
5161 st
->n
.omp_udr
= udr
;
5165 st
= gfc_new_symtree (&gfc_current_ns
->omp_udr_root
, name
);
5166 st
->n
.omp_udr
= udr
;
5174 /* Recursive function to traverse the pointer_info tree and load a
5175 needed symbol. We return nonzero if we load a symbol and stop the
5176 traversal, because the act of loading can alter the tree. */
5179 load_needed (pointer_info
*p
)
5190 rv
|= load_needed (p
->left
);
5191 rv
|= load_needed (p
->right
);
5193 if (p
->type
!= P_SYMBOL
|| p
->u
.rsym
.state
!= NEEDED
)
5196 p
->u
.rsym
.state
= USED
;
5198 set_module_locus (&p
->u
.rsym
.where
);
5200 sym
= p
->u
.rsym
.sym
;
5203 q
= get_integer (p
->u
.rsym
.ns
);
5205 ns
= (gfc_namespace
*) q
->u
.pointer
;
5208 /* Create an interface namespace if necessary. These are
5209 the namespaces that hold the formal parameters of module
5212 ns
= gfc_get_namespace (NULL
, 0);
5213 associate_integer_pointer (q
, ns
);
5216 /* Use the module sym as 'proc_name' so that gfc_get_symbol_decl
5217 doesn't go pear-shaped if the symbol is used. */
5219 gfc_find_symbol (p
->u
.rsym
.module
, gfc_current_ns
,
5222 sym
= gfc_new_symbol (p
->u
.rsym
.true_name
, ns
);
5223 sym
->name
= gfc_dt_lower_string (p
->u
.rsym
.true_name
);
5224 sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
5225 if (p
->u
.rsym
.binding_label
)
5226 sym
->binding_label
= IDENTIFIER_POINTER (get_identifier
5227 (p
->u
.rsym
.binding_label
));
5229 associate_integer_pointer (p
, sym
);
5233 sym
->attr
.use_assoc
= 1;
5235 /* Unliked derived types, a STRUCTURE may share names with other symbols.
5236 We greedily converted the symbol name to lowercase before we knew its
5237 type, so now we must fix it. */
5238 if (sym
->attr
.flavor
== FL_STRUCT
)
5239 sym
->name
= gfc_dt_upper_string (sym
->name
);
5241 /* Mark as only or rename for later diagnosis for explicitly imported
5242 but not used warnings; don't mark internal symbols such as __vtab,
5243 __def_init etc. Only mark them if they have been explicitly loaded. */
5245 if (only_flag
&& sym
->name
[0] != '_' && sym
->name
[1] != '_')
5249 /* Search the use/rename list for the variable; if the variable is
5251 for (u
= gfc_rename_list
; u
; u
= u
->next
)
5253 if (strcmp (u
->use_name
, sym
->name
) == 0)
5255 sym
->attr
.use_only
= 1;
5261 if (p
->u
.rsym
.renamed
)
5262 sym
->attr
.use_rename
= 1;
5268 /* Recursive function for cleaning up things after a module has been read. */
5271 read_cleanup (pointer_info
*p
)
5279 read_cleanup (p
->left
);
5280 read_cleanup (p
->right
);
5282 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== USED
&& !p
->u
.rsym
.referenced
)
5285 /* Add hidden symbols to the symtree. */
5286 q
= get_integer (p
->u
.rsym
.ns
);
5287 ns
= (gfc_namespace
*) q
->u
.pointer
;
5289 if (!p
->u
.rsym
.sym
->attr
.vtype
5290 && !p
->u
.rsym
.sym
->attr
.vtab
)
5291 st
= gfc_get_unique_symtree (ns
);
5294 /* There is no reason to use 'unique_symtrees' for vtabs or
5295 vtypes - their name is fine for a symtree and reduces the
5296 namespace pollution. */
5297 st
= gfc_find_symtree (ns
->sym_root
, p
->u
.rsym
.sym
->name
);
5299 st
= gfc_new_symtree (&ns
->sym_root
, p
->u
.rsym
.sym
->name
);
5302 st
->n
.sym
= p
->u
.rsym
.sym
;
5305 /* Fixup any symtree references. */
5306 p
->u
.rsym
.symtree
= st
;
5307 resolve_fixups (p
->u
.rsym
.stfixup
, st
);
5308 p
->u
.rsym
.stfixup
= NULL
;
5311 /* Free unused symbols. */
5312 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== UNUSED
)
5313 gfc_free_symbol (p
->u
.rsym
.sym
);
5317 /* It is not quite enough to check for ambiguity in the symbols by
5318 the loaded symbol and the new symbol not being identical. */
5320 check_for_ambiguous (gfc_symtree
*st
, pointer_info
*info
)
5324 symbol_attribute attr
;
5327 if (gfc_current_ns
->proc_name
&& st
->name
== gfc_current_ns
->proc_name
->name
)
5329 gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
5330 "current program unit", st
->name
, module_name
);
5335 rsym
= info
->u
.rsym
.sym
;
5339 if (st_sym
->attr
.vtab
|| st_sym
->attr
.vtype
)
5342 /* If the existing symbol is generic from a different module and
5343 the new symbol is generic there can be no ambiguity. */
5344 if (st_sym
->attr
.generic
5346 && st_sym
->module
!= module_name
)
5348 /* The new symbol's attributes have not yet been read. Since
5349 we need attr.generic, read it directly. */
5350 get_module_locus (&locus
);
5351 set_module_locus (&info
->u
.rsym
.where
);
5354 mio_symbol_attribute (&attr
);
5355 set_module_locus (&locus
);
5364 /* Read a module file. */
5369 module_locus operator_interfaces
, user_operators
, omp_udrs
;
5371 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5373 /* Workaround -Wmaybe-uninitialized false positive during
5374 profiledbootstrap by initializing them. */
5375 int ambiguous
= 0, j
, nuse
, symbol
= 0;
5376 pointer_info
*info
, *q
;
5377 gfc_use_rename
*u
= NULL
;
5381 get_module_locus (&operator_interfaces
); /* Skip these for now. */
5384 get_module_locus (&user_operators
);
5388 /* Skip commons and equivalences for now. */
5392 /* Skip OpenMP UDRs. */
5393 get_module_locus (&omp_udrs
);
5398 /* Create the fixup nodes for all the symbols. */
5400 while (peek_atom () != ATOM_RPAREN
)
5403 require_atom (ATOM_INTEGER
);
5404 info
= get_integer (atom_int
);
5406 info
->type
= P_SYMBOL
;
5407 info
->u
.rsym
.state
= UNUSED
;
5409 info
->u
.rsym
.true_name
= read_string ();
5410 info
->u
.rsym
.module
= read_string ();
5411 bind_label
= read_string ();
5412 if (strlen (bind_label
))
5413 info
->u
.rsym
.binding_label
= bind_label
;
5415 XDELETEVEC (bind_label
);
5417 require_atom (ATOM_INTEGER
);
5418 info
->u
.rsym
.ns
= atom_int
;
5420 get_module_locus (&info
->u
.rsym
.where
);
5422 /* See if the symbol has already been loaded by a previous module.
5423 If so, we reference the existing symbol and prevent it from
5424 being loaded again. This should not happen if the symbol being
5425 read is an index for an assumed shape dummy array (ns != 1). */
5427 sym
= find_true_name (info
->u
.rsym
.true_name
, info
->u
.rsym
.module
);
5430 || (sym
->attr
.flavor
== FL_VARIABLE
&& info
->u
.rsym
.ns
!=1))
5436 info
->u
.rsym
.state
= USED
;
5437 info
->u
.rsym
.sym
= sym
;
5438 /* The current symbol has already been loaded, so we can avoid loading
5439 it again. However, if it is a derived type, some of its components
5440 can be used in expressions in the module. To avoid the module loading
5441 failing, we need to associate the module's component pointer indexes
5442 with the existing symbol's component pointers. */
5443 if (gfc_fl_struct (sym
->attr
.flavor
))
5447 /* First seek to the symbol's component list. */
5448 mio_lparen (); /* symbol opening. */
5449 skip_list (); /* skip symbol attribute. */
5451 mio_lparen (); /* component list opening. */
5452 for (c
= sym
->components
; c
; c
= c
->next
)
5455 const char *comp_name
= NULL
;
5458 mio_lparen (); /* component opening. */
5460 p
= get_integer (n
);
5461 if (p
->u
.pointer
== NULL
)
5462 associate_integer_pointer (p
, c
);
5463 mio_pool_string (&comp_name
);
5464 if (comp_name
!= c
->name
)
5466 gfc_fatal_error ("Mismatch in components of derived type "
5467 "%qs from %qs at %C: expecting %qs, "
5468 "but got %qs", sym
->name
, sym
->module
,
5469 c
->name
, comp_name
);
5471 skip_list (1); /* component end. */
5473 mio_rparen (); /* component list closing. */
5475 skip_list (1); /* symbol end. */
5480 /* Some symbols do not have a namespace (eg. formal arguments),
5481 so the automatic "unique symtree" mechanism must be suppressed
5482 by marking them as referenced. */
5483 q
= get_integer (info
->u
.rsym
.ns
);
5484 if (q
->u
.pointer
== NULL
)
5486 info
->u
.rsym
.referenced
= 1;
5493 /* Parse the symtree lists. This lets us mark which symbols need to
5494 be loaded. Renaming is also done at this point by replacing the
5499 while (peek_atom () != ATOM_RPAREN
)
5501 mio_internal_string (name
);
5502 mio_integer (&ambiguous
);
5503 mio_integer (&symbol
);
5505 info
= get_integer (symbol
);
5507 /* See how many use names there are. If none, go through the start
5508 of the loop at least once. */
5509 nuse
= number_use_names (name
, false);
5510 info
->u
.rsym
.renamed
= nuse
? 1 : 0;
5515 for (j
= 1; j
<= nuse
; j
++)
5517 /* Get the jth local name for this symbol. */
5518 p
= find_use_name_n (name
, &j
, false);
5520 if (p
== NULL
&& strcmp (name
, module_name
) == 0)
5523 /* Exception: Always import vtabs & vtypes. */
5524 if (p
== NULL
&& name
[0] == '_'
5525 && (startswith (name
, "__vtab_")
5526 || startswith (name
, "__vtype_")))
5529 /* Skip symtree nodes not in an ONLY clause, unless there
5530 is an existing symtree loaded from another USE statement. */
5533 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
5535 && strcmp (st
->n
.sym
->name
, info
->u
.rsym
.true_name
) == 0
5536 && st
->n
.sym
->module
!= NULL
5537 && strcmp (st
->n
.sym
->module
, info
->u
.rsym
.module
) == 0)
5539 info
->u
.rsym
.symtree
= st
;
5540 info
->u
.rsym
.sym
= st
->n
.sym
;
5545 /* If a symbol of the same name and module exists already,
5546 this symbol, which is not in an ONLY clause, must not be
5547 added to the namespace(11.3.2). Note that find_symbol
5548 only returns the first occurrence that it finds. */
5549 if (!only_flag
&& !info
->u
.rsym
.renamed
5550 && strcmp (name
, module_name
) != 0
5551 && find_symbol (gfc_current_ns
->sym_root
, name
,
5555 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
5558 && !(st
->n
.sym
&& st
->n
.sym
->attr
.used_in_submodule
))
5560 /* Check for ambiguous symbols. */
5561 if (check_for_ambiguous (st
, info
))
5564 info
->u
.rsym
.symtree
= st
;
5570 /* This symbol is host associated from a module in a
5571 submodule. Hide it with a unique symtree. */
5572 gfc_symtree
*s
= gfc_get_unique_symtree (gfc_current_ns
);
5573 s
->n
.sym
= st
->n
.sym
;
5578 /* Create a symtree node in the current namespace for this
5580 st
= check_unique_name (p
)
5581 ? gfc_get_unique_symtree (gfc_current_ns
)
5582 : gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
5583 st
->ambiguous
= ambiguous
;
5586 sym
= info
->u
.rsym
.sym
;
5588 /* Create a symbol node if it doesn't already exist. */
5591 info
->u
.rsym
.sym
= gfc_new_symbol (info
->u
.rsym
.true_name
,
5593 info
->u
.rsym
.sym
->name
= gfc_dt_lower_string (info
->u
.rsym
.true_name
);
5594 sym
= info
->u
.rsym
.sym
;
5595 sym
->module
= gfc_get_string ("%s", info
->u
.rsym
.module
);
5597 if (info
->u
.rsym
.binding_label
)
5599 tree id
= get_identifier (info
->u
.rsym
.binding_label
);
5600 sym
->binding_label
= IDENTIFIER_POINTER (id
);
5607 if (strcmp (name
, p
) != 0)
5608 sym
->attr
.use_rename
= 1;
5611 || (!startswith (name
, "__vtab_")
5612 && !startswith (name
, "__vtype_")))
5613 sym
->attr
.use_only
= only_flag
;
5615 /* Store the symtree pointing to this symbol. */
5616 info
->u
.rsym
.symtree
= st
;
5618 if (info
->u
.rsym
.state
== UNUSED
)
5619 info
->u
.rsym
.state
= NEEDED
;
5620 info
->u
.rsym
.referenced
= 1;
5627 /* Load intrinsic operator interfaces. */
5628 set_module_locus (&operator_interfaces
);
5631 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
5633 gfc_use_rename
*u
= NULL
, *v
= NULL
;
5636 if (i
== INTRINSIC_USER
)
5641 u
= find_use_operator ((gfc_intrinsic_op
) i
);
5643 /* F2018:10.1.5.5.1 requires same interpretation of old and new-style
5644 relational operators. Special handling for USE, ONLY. */
5648 j
= INTRINSIC_EQ_OS
;
5650 case INTRINSIC_EQ_OS
:
5654 j
= INTRINSIC_NE_OS
;
5656 case INTRINSIC_NE_OS
:
5660 j
= INTRINSIC_GT_OS
;
5662 case INTRINSIC_GT_OS
:
5666 j
= INTRINSIC_GE_OS
;
5668 case INTRINSIC_GE_OS
:
5672 j
= INTRINSIC_LT_OS
;
5674 case INTRINSIC_LT_OS
:
5678 j
= INTRINSIC_LE_OS
;
5680 case INTRINSIC_LE_OS
:
5688 v
= find_use_operator ((gfc_intrinsic_op
) j
);
5690 if (u
== NULL
&& v
== NULL
)
5702 mio_interface (&gfc_current_ns
->op
[i
]);
5703 if (!gfc_current_ns
->op
[i
] && !gfc_current_ns
->op
[j
])
5714 /* Load generic and user operator interfaces. These must follow the
5715 loading of symtree because otherwise symbols can be marked as
5718 set_module_locus (&user_operators
);
5720 load_operator_interfaces ();
5721 load_generic_interfaces ();
5726 /* Load OpenMP user defined reductions. */
5727 set_module_locus (&omp_udrs
);
5730 /* At this point, we read those symbols that are needed but haven't
5731 been loaded yet. If one symbol requires another, the other gets
5732 marked as NEEDED if its previous state was UNUSED. */
5734 while (load_needed (pi_root
));
5736 /* Make sure all elements of the rename-list were found in the module. */
5738 for (u
= gfc_rename_list
; u
; u
= u
->next
)
5743 if (u
->op
== INTRINSIC_NONE
)
5745 gfc_error ("Symbol %qs referenced at %L not found in module %qs",
5746 u
->use_name
, &u
->where
, module_name
);
5750 if (u
->op
== INTRINSIC_USER
)
5752 gfc_error ("User operator %qs referenced at %L not found "
5753 "in module %qs", u
->use_name
, &u
->where
, module_name
);
5757 gfc_error ("Intrinsic operator %qs referenced at %L not found "
5758 "in module %qs", gfc_op2string (u
->op
), &u
->where
,
5762 /* Clean up symbol nodes that were never loaded, create references
5763 to hidden symbols. */
5765 read_cleanup (pi_root
);
5769 /* Given an access type that is specific to an entity and the default
5770 access, return nonzero if the entity is publicly accessible. If the
5771 element is declared as PUBLIC, then it is public; if declared
5772 PRIVATE, then private, and otherwise it is public unless the default
5773 access in this context has been declared PRIVATE. */
5775 static bool dump_smod
= false;
5778 check_access (gfc_access specific_access
, gfc_access default_access
)
5783 if (specific_access
== ACCESS_PUBLIC
)
5785 if (specific_access
== ACCESS_PRIVATE
)
5788 if (flag_module_private
)
5789 return default_access
== ACCESS_PUBLIC
;
5791 return default_access
!= ACCESS_PRIVATE
;
5796 gfc_check_symbol_access (gfc_symbol
*sym
)
5798 if (sym
->attr
.vtab
|| sym
->attr
.vtype
)
5801 return check_access (sym
->attr
.access
, sym
->ns
->default_access
);
5805 /* A structure to remember which commons we've already written. */
5807 struct written_common
5809 BBT_HEADER(written_common
);
5810 const char *name
, *label
;
5813 static struct written_common
*written_commons
= NULL
;
5815 /* Comparison function used for balancing the binary tree. */
5818 compare_written_commons (void *a1
, void *b1
)
5820 const char *aname
= ((struct written_common
*) a1
)->name
;
5821 const char *alabel
= ((struct written_common
*) a1
)->label
;
5822 const char *bname
= ((struct written_common
*) b1
)->name
;
5823 const char *blabel
= ((struct written_common
*) b1
)->label
;
5824 int c
= strcmp (aname
, bname
);
5826 return (c
!= 0 ? c
: strcmp (alabel
, blabel
));
5829 /* Free a list of written commons. */
5832 free_written_common (struct written_common
*w
)
5838 free_written_common (w
->left
);
5840 free_written_common (w
->right
);
5845 /* Write a common block to the module -- recursive helper function. */
5848 write_common_0 (gfc_symtree
*st
, bool this_module
)
5854 struct written_common
*w
;
5855 bool write_me
= true;
5860 write_common_0 (st
->left
, this_module
);
5862 /* We will write out the binding label, or "" if no label given. */
5863 name
= st
->n
.common
->name
;
5865 label
= (p
->is_bind_c
&& p
->binding_label
) ? p
->binding_label
: "";
5867 /* Check if we've already output this common. */
5868 w
= written_commons
;
5871 int c
= strcmp (name
, w
->name
);
5872 c
= (c
!= 0 ? c
: strcmp (label
, w
->label
));
5876 w
= (c
< 0) ? w
->left
: w
->right
;
5879 if (this_module
&& p
->use_assoc
)
5884 /* Write the common to the module. */
5886 mio_pool_string (&name
);
5888 mio_symbol_ref (&p
->head
);
5889 flags
= p
->saved
? 1 : 0;
5890 if (p
->threadprivate
)
5892 flags
|= p
->omp_device_type
<< 2;
5893 mio_integer (&flags
);
5895 /* Write out whether the common block is bind(c) or not. */
5896 mio_integer (&(p
->is_bind_c
));
5898 mio_pool_string (&label
);
5901 /* Record that we have written this common. */
5902 w
= XCNEW (struct written_common
);
5905 gfc_insert_bbt (&written_commons
, w
, compare_written_commons
);
5908 write_common_0 (st
->right
, this_module
);
5912 /* Write a common, by initializing the list of written commons, calling
5913 the recursive function write_common_0() and cleaning up afterwards. */
5916 write_common (gfc_symtree
*st
)
5918 written_commons
= NULL
;
5919 write_common_0 (st
, true);
5920 write_common_0 (st
, false);
5921 free_written_common (written_commons
);
5922 written_commons
= NULL
;
5926 /* Write the blank common block to the module. */
5929 write_blank_common (void)
5931 const char * name
= BLANK_COMMON_NAME
;
5933 /* TODO: Blank commons are not bind(c). The F2003 standard probably says
5934 this, but it hasn't been checked. Just making it so for now. */
5937 if (gfc_current_ns
->blank_common
.head
== NULL
)
5942 mio_pool_string (&name
);
5944 mio_symbol_ref (&gfc_current_ns
->blank_common
.head
);
5945 saved
= gfc_current_ns
->blank_common
.saved
;
5946 mio_integer (&saved
);
5948 /* Write out whether the common block is bind(c) or not. */
5949 mio_integer (&is_bind_c
);
5951 /* Write out an empty binding label. */
5952 write_atom (ATOM_STRING
, "");
5958 /* Write equivalences to the module. */
5967 for (eq
= gfc_current_ns
->equiv
; eq
; eq
= eq
->next
)
5971 for (e
= eq
; e
; e
= e
->eq
)
5973 if (e
->module
== NULL
)
5974 e
->module
= gfc_get_string ("%s.eq.%d", module_name
, num
);
5975 mio_allocated_string (e
->module
);
5976 mio_expr (&e
->expr
);
5985 /* Write a symbol to the module. */
5988 write_symbol (int n
, gfc_symbol
*sym
)
5992 if (sym
->attr
.flavor
== FL_UNKNOWN
|| sym
->attr
.flavor
== FL_LABEL
)
5993 gfc_internal_error ("write_symbol(): bad module symbol %qs", sym
->name
);
5997 if (gfc_fl_struct (sym
->attr
.flavor
))
6000 name
= gfc_dt_upper_string (sym
->name
);
6001 mio_pool_string (&name
);
6004 mio_pool_string (&sym
->name
);
6006 mio_pool_string (&sym
->module
);
6007 if ((sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
) && sym
->binding_label
)
6009 label
= sym
->binding_label
;
6010 mio_pool_string (&label
);
6013 write_atom (ATOM_STRING
, "");
6015 mio_pointer_ref (&sym
->ns
);
6022 /* Recursive traversal function to write the initial set of symbols to
6023 the module. We check to see if the symbol should be written
6024 according to the access specification. */
6027 write_symbol0 (gfc_symtree
*st
)
6031 bool dont_write
= false;
6036 write_symbol0 (st
->left
);
6039 if (sym
->module
== NULL
)
6040 sym
->module
= module_name
;
6042 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
6043 && !sym
->attr
.subroutine
&& !sym
->attr
.function
)
6046 if (!gfc_check_symbol_access (sym
))
6051 p
= get_pointer (sym
);
6052 if (p
->type
== P_UNKNOWN
)
6055 if (p
->u
.wsym
.state
!= WRITTEN
)
6057 write_symbol (p
->integer
, sym
);
6058 p
->u
.wsym
.state
= WRITTEN
;
6062 write_symbol0 (st
->right
);
6067 write_omp_udr (gfc_omp_udr
*udr
)
6071 case OMP_REDUCTION_USER
:
6072 /* Non-operators can't be used outside of the module. */
6073 if (udr
->name
[0] != '.')
6078 size_t len
= strlen (udr
->name
+ 1);
6079 char *name
= XALLOCAVEC (char, len
);
6080 memcpy (name
, udr
->name
, len
- 1);
6081 name
[len
- 1] = '\0';
6082 st
= gfc_find_symtree (gfc_current_ns
->uop_root
, name
);
6083 /* If corresponding user operator is private, don't write
6087 gfc_user_op
*uop
= st
->n
.uop
;
6088 if (!check_access (uop
->access
, uop
->ns
->default_access
))
6093 case OMP_REDUCTION_PLUS
:
6094 case OMP_REDUCTION_MINUS
:
6095 case OMP_REDUCTION_TIMES
:
6096 case OMP_REDUCTION_AND
:
6097 case OMP_REDUCTION_OR
:
6098 case OMP_REDUCTION_EQV
:
6099 case OMP_REDUCTION_NEQV
:
6100 /* If corresponding operator is private, don't write the UDR. */
6101 if (!check_access (gfc_current_ns
->operator_access
[udr
->rop
],
6102 gfc_current_ns
->default_access
))
6108 if (udr
->ts
.type
== BT_DERIVED
|| udr
->ts
.type
== BT_CLASS
)
6110 /* If derived type is private, don't write the UDR. */
6111 if (!gfc_check_symbol_access (udr
->ts
.u
.derived
))
6116 mio_pool_string (&udr
->name
);
6117 mio_typespec (&udr
->ts
);
6118 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
, false);
6119 if (udr
->initializer_ns
)
6120 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
6121 udr
->initializer_ns
, true);
6127 write_omp_udrs (gfc_symtree
*st
)
6132 write_omp_udrs (st
->left
);
6134 for (udr
= st
->n
.omp_udr
; udr
; udr
= udr
->next
)
6135 write_omp_udr (udr
);
6136 write_omp_udrs (st
->right
);
6140 /* Type for the temporary tree used when writing secondary symbols. */
6142 struct sorted_pointer_info
6144 BBT_HEADER (sorted_pointer_info
);
6149 #define gfc_get_sorted_pointer_info() XCNEW (sorted_pointer_info)
6151 /* Recursively traverse the temporary tree, free its contents. */
6154 free_sorted_pointer_info_tree (sorted_pointer_info
*p
)
6159 free_sorted_pointer_info_tree (p
->left
);
6160 free_sorted_pointer_info_tree (p
->right
);
6165 /* Comparison function for the temporary tree. */
6168 compare_sorted_pointer_info (void *_spi1
, void *_spi2
)
6170 sorted_pointer_info
*spi1
, *spi2
;
6171 spi1
= (sorted_pointer_info
*)_spi1
;
6172 spi2
= (sorted_pointer_info
*)_spi2
;
6174 if (spi1
->p
->integer
< spi2
->p
->integer
)
6176 if (spi1
->p
->integer
> spi2
->p
->integer
)
6182 /* Finds the symbols that need to be written and collects them in the
6183 sorted_pi tree so that they can be traversed in an order
6184 independent of memory addresses. */
6187 find_symbols_to_write(sorted_pointer_info
**tree
, pointer_info
*p
)
6192 if (p
->type
== P_SYMBOL
&& p
->u
.wsym
.state
== NEEDS_WRITE
)
6194 sorted_pointer_info
*sp
= gfc_get_sorted_pointer_info();
6197 gfc_insert_bbt (tree
, sp
, compare_sorted_pointer_info
);
6200 find_symbols_to_write (tree
, p
->left
);
6201 find_symbols_to_write (tree
, p
->right
);
6205 /* Recursive function that traverses the tree of symbols that need to be
6206 written and writes them in order. */
6209 write_symbol1_recursion (sorted_pointer_info
*sp
)
6214 write_symbol1_recursion (sp
->left
);
6216 pointer_info
*p1
= sp
->p
;
6217 gcc_assert (p1
->type
== P_SYMBOL
&& p1
->u
.wsym
.state
== NEEDS_WRITE
);
6219 p1
->u
.wsym
.state
= WRITTEN
;
6220 write_symbol (p1
->integer
, p1
->u
.wsym
.sym
);
6221 p1
->u
.wsym
.sym
->attr
.public_used
= 1;
6223 write_symbol1_recursion (sp
->right
);
6227 /* Write the secondary set of symbols to the module file. These are
6228 symbols that were not public yet are needed by the public symbols
6229 or another dependent symbol. The act of writing a symbol can add
6230 symbols to the pointer_info tree, so we return nonzero if a symbol
6231 was written and pass that information upwards. The caller will
6232 then call this function again until nothing was written. It uses
6233 the utility functions and a temporary tree to ensure a reproducible
6234 ordering of the symbol output and thus the module file. */
6237 write_symbol1 (pointer_info
*p
)
6242 /* Put symbols that need to be written into a tree sorted on the
6245 sorted_pointer_info
*spi_root
= NULL
;
6246 find_symbols_to_write (&spi_root
, p
);
6248 /* No symbols to write, return. */
6252 /* Otherwise, write and free the tree again. */
6253 write_symbol1_recursion (spi_root
);
6254 free_sorted_pointer_info_tree (spi_root
);
6260 /* Write operator interfaces associated with a symbol. */
6263 write_operator (gfc_user_op
*uop
)
6265 static char nullstring
[] = "";
6266 const char *p
= nullstring
;
6268 if (uop
->op
== NULL
|| !check_access (uop
->access
, uop
->ns
->default_access
))
6271 mio_symbol_interface (&uop
->name
, &p
, &uop
->op
);
6275 /* Write generic interfaces from the namespace sym_root. */
6278 write_generic (gfc_symtree
*st
)
6285 write_generic (st
->left
);
6288 if (sym
&& !check_unique_name (st
->name
)
6289 && sym
->generic
&& gfc_check_symbol_access (sym
))
6292 sym
->module
= module_name
;
6294 mio_symbol_interface (&st
->name
, &sym
->module
, &sym
->generic
);
6297 write_generic (st
->right
);
6302 write_symtree (gfc_symtree
*st
)
6309 /* A symbol in an interface body must not be visible in the
6311 if (sym
->ns
!= gfc_current_ns
6312 && sym
->ns
->proc_name
6313 && sym
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
6316 if (!gfc_check_symbol_access (sym
)
6317 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
6318 && !sym
->attr
.subroutine
&& !sym
->attr
.function
))
6321 if (check_unique_name (st
->name
))
6324 /* From F2003 onwards, intrinsic procedures are no longer subject to
6325 the restriction, "that an elemental intrinsic function here be of
6326 type integer or character and each argument must be an initialization
6327 expr of type integer or character" is lifted so that intrinsic
6328 procedures can be over-ridden. This requires that the intrinsic
6329 symbol not appear in the module file, thereby preventing ambiguity
6331 if (strcmp (sym
->module
, "(intrinsic)") == 0
6332 && (gfc_option
.allow_std
& GFC_STD_F2003
))
6335 p
= find_pointer (sym
);
6337 gfc_internal_error ("write_symtree(): Symbol not written");
6339 mio_pool_string (&st
->name
);
6340 mio_integer (&st
->ambiguous
);
6341 mio_hwi (&p
->integer
);
6350 /* Initialize the column counter. */
6353 /* Write the operator interfaces. */
6356 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
6358 if (i
== INTRINSIC_USER
)
6361 mio_interface (check_access (gfc_current_ns
->operator_access
[i
],
6362 gfc_current_ns
->default_access
)
6363 ? &gfc_current_ns
->op
[i
] : NULL
);
6371 gfc_traverse_user_op (gfc_current_ns
, write_operator
);
6377 write_generic (gfc_current_ns
->sym_root
);
6383 write_blank_common ();
6384 write_common (gfc_current_ns
->common_root
);
6396 write_omp_udrs (gfc_current_ns
->omp_udr_root
);
6401 /* Write symbol information. First we traverse all symbols in the
6402 primary namespace, writing those that need to be written.
6403 Sometimes writing one symbol will cause another to need to be
6404 written. A list of these symbols ends up on the write stack, and
6405 we end by popping the bottom of the stack and writing the symbol
6406 until the stack is empty. */
6410 write_symbol0 (gfc_current_ns
->sym_root
);
6411 while (write_symbol1 (pi_root
))
6420 gfc_traverse_symtree (gfc_current_ns
->sym_root
, write_symtree
);
6425 /* Read a CRC32 sum from the gzip trailer of a module file. Returns
6426 true on success, false on failure. */
6429 read_crc32_from_module_file (const char* filename
, uLong
* crc
)
6435 /* Open the file in binary mode. */
6436 if ((file
= fopen (filename
, "rb")) == NULL
)
6439 /* The gzip crc32 value is found in the [END-8, END-4] bytes of the
6440 file. See RFC 1952. */
6441 if (fseek (file
, -8, SEEK_END
) != 0)
6447 /* Read the CRC32. */
6448 if (fread (buf
, 1, 4, file
) != 4)
6454 /* Close the file. */
6457 val
= (buf
[0] & 0xFF) + ((buf
[1] & 0xFF) << 8) + ((buf
[2] & 0xFF) << 16)
6458 + ((buf
[3] & 0xFF) << 24);
6461 /* For debugging, the CRC value printed in hexadecimal should match
6462 the CRC printed by "zcat -l -v filename".
6463 printf("CRC of file %s is %x\n", filename, val); */
6469 /* Given module, dump it to disk. If there was an error while
6470 processing the module, dump_flag will be set to zero and we delete
6471 the module file, even if it was already there. */
6474 dump_module (const char *name
, int dump_flag
)
6477 char *filename
, *filename_tmp
;
6480 module_name
= gfc_get_string ("%s", name
);
6484 name
= submodule_name
;
6485 n
= strlen (name
) + strlen (SUBMODULE_EXTENSION
) + 1;
6488 n
= strlen (name
) + strlen (MODULE_EXTENSION
) + 1;
6490 if (gfc_option
.module_dir
!= NULL
)
6492 n
+= strlen (gfc_option
.module_dir
);
6493 filename
= (char *) alloca (n
);
6494 strcpy (filename
, gfc_option
.module_dir
);
6495 strcat (filename
, name
);
6499 filename
= (char *) alloca (n
);
6500 strcpy (filename
, name
);
6504 strcat (filename
, SUBMODULE_EXTENSION
);
6506 strcat (filename
, MODULE_EXTENSION
);
6508 /* Name of the temporary file used to write the module. */
6509 filename_tmp
= (char *) alloca (n
+ 1);
6510 strcpy (filename_tmp
, filename
);
6511 strcat (filename_tmp
, "0");
6513 /* There was an error while processing the module. We delete the
6514 module file, even if it was already there. */
6521 if (gfc_cpp_makedep ())
6522 gfc_cpp_add_target (filename
);
6524 /* Write the module to the temporary file. */
6525 module_fp
= gzopen (filename_tmp
, "w");
6526 if (module_fp
== NULL
)
6527 gfc_fatal_error ("Cannot open module file %qs for writing at %C: %s",
6528 filename_tmp
, xstrerror (errno
));
6530 /* Use lbasename to ensure module files are reproducible regardless
6531 of the build path (see the reproducible builds project). */
6532 gzprintf (module_fp
, "GFORTRAN module version '%s' created from %s\n",
6533 MOD_VERSION
, lbasename (gfc_source_file
));
6535 /* Write the module itself. */
6542 free_pi_tree (pi_root
);
6547 if (gzclose (module_fp
))
6548 gfc_fatal_error ("Error writing module file %qs for writing: %s",
6549 filename_tmp
, xstrerror (errno
));
6551 /* Read the CRC32 from the gzip trailers of the module files and
6553 if (!read_crc32_from_module_file (filename_tmp
, &crc
)
6554 || !read_crc32_from_module_file (filename
, &crc_old
)
6557 /* Module file have changed, replace the old one. */
6558 if (remove (filename
) && errno
!= ENOENT
)
6559 gfc_fatal_error ("Cannot delete module file %qs: %s", filename
,
6561 if (rename (filename_tmp
, filename
))
6562 gfc_fatal_error ("Cannot rename module file %qs to %qs: %s",
6563 filename_tmp
, filename
, xstrerror (errno
));
6567 if (remove (filename_tmp
))
6568 gfc_fatal_error ("Cannot delete temporary module file %qs: %s",
6569 filename_tmp
, xstrerror (errno
));
6574 /* Suppress the output of a .smod file by module, if no module
6575 procedures have been seen. */
6576 static bool no_module_procedures
;
6579 check_for_module_procedures (gfc_symbol
*sym
)
6581 if (sym
&& sym
->attr
.module_procedure
)
6582 no_module_procedures
= false;
6587 gfc_dump_module (const char *name
, int dump_flag
)
6589 if (gfc_state_stack
->state
== COMP_SUBMODULE
)
6594 no_module_procedures
= true;
6595 gfc_traverse_ns (gfc_current_ns
, check_for_module_procedures
);
6597 dump_module (name
, dump_flag
);
6599 if (no_module_procedures
|| dump_smod
)
6602 /* Write a submodule file from a module. The 'dump_smod' flag switches
6603 off the check for PRIVATE entities. */
6605 submodule_name
= module_name
;
6606 dump_module (name
, dump_flag
);
6611 create_intrinsic_function (const char *name
, int id
,
6612 const char *modname
, intmod_id module
,
6613 bool subroutine
, gfc_symbol
*result_type
)
6615 gfc_intrinsic_sym
*isym
;
6616 gfc_symtree
*tmp_symtree
;
6619 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6622 if (tmp_symtree
->n
.sym
&& tmp_symtree
->n
.sym
->module
6623 && strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6625 gfc_error ("Symbol %qs at %C already declared", name
);
6629 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6630 sym
= tmp_symtree
->n
.sym
;
6634 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6635 isym
= gfc_intrinsic_subroutine_by_id (isym_id
);
6636 sym
->attr
.subroutine
= 1;
6640 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6641 isym
= gfc_intrinsic_function_by_id (isym_id
);
6643 sym
->attr
.function
= 1;
6646 sym
->ts
.type
= BT_DERIVED
;
6647 sym
->ts
.u
.derived
= result_type
;
6648 sym
->ts
.is_c_interop
= 1;
6649 isym
->ts
.f90_type
= BT_VOID
;
6650 isym
->ts
.type
= BT_DERIVED
;
6651 isym
->ts
.f90_type
= BT_VOID
;
6652 isym
->ts
.u
.derived
= result_type
;
6653 isym
->ts
.is_c_interop
= 1;
6658 sym
->attr
.flavor
= FL_PROCEDURE
;
6659 sym
->attr
.intrinsic
= 1;
6661 sym
->module
= gfc_get_string ("%s", modname
);
6662 sym
->attr
.use_assoc
= 1;
6663 sym
->from_intmod
= module
;
6664 sym
->intmod_sym_id
= id
;
6668 /* Import the intrinsic ISO_C_BINDING module, generating symbols in
6669 the current namespace for all named constants, pointer types, and
6670 procedures in the module unless the only clause was used or a rename
6671 list was provided. */
6674 import_iso_c_binding_module (void)
6676 gfc_symbol
*mod_sym
= NULL
, *return_type
;
6677 gfc_symtree
*mod_symtree
= NULL
, *tmp_symtree
;
6678 gfc_symtree
*c_ptr
= NULL
, *c_funptr
= NULL
;
6679 const char *iso_c_module_name
= "__iso_c_binding";
6682 bool want_c_ptr
= false, want_c_funptr
= false;
6684 /* Look only in the current namespace. */
6685 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, iso_c_module_name
);
6687 if (mod_symtree
== NULL
)
6689 /* symtree doesn't already exist in current namespace. */
6690 gfc_get_sym_tree (iso_c_module_name
, gfc_current_ns
, &mod_symtree
,
6693 if (mod_symtree
!= NULL
)
6694 mod_sym
= mod_symtree
->n
.sym
;
6696 gfc_internal_error ("import_iso_c_binding_module(): Unable to "
6697 "create symbol for %s", iso_c_module_name
);
6699 mod_sym
->attr
.flavor
= FL_MODULE
;
6700 mod_sym
->attr
.intrinsic
= 1;
6701 mod_sym
->module
= gfc_get_string ("%s", iso_c_module_name
);
6702 mod_sym
->from_intmod
= INTMOD_ISO_C_BINDING
;
6705 /* Check whether C_PTR or C_FUNPTR are in the include list, if so, load it;
6706 check also whether C_NULL_(FUN)PTR or C_(FUN)LOC are requested, which
6708 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6710 if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_PTR
].name
,
6713 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_LOC
].name
,
6716 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_FUNPTR
].name
,
6718 want_c_funptr
= true;
6719 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNLOC
].name
,
6721 want_c_funptr
= true;
6722 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_PTR
].name
,
6725 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6726 (iso_c_binding_symbol
)
6728 u
->local_name
[0] ? u
->local_name
6732 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNPTR
].name
,
6736 = generate_isocbinding_symbol (iso_c_module_name
,
6737 (iso_c_binding_symbol
)
6739 u
->local_name
[0] ? u
->local_name
6745 if ((want_c_ptr
|| !only_flag
) && !c_ptr
)
6746 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6747 (iso_c_binding_symbol
)
6749 NULL
, NULL
, only_flag
);
6750 if ((want_c_funptr
|| !only_flag
) && !c_funptr
)
6751 c_funptr
= generate_isocbinding_symbol (iso_c_module_name
,
6752 (iso_c_binding_symbol
)
6754 NULL
, NULL
, only_flag
);
6756 /* Generate the symbols for the named constants representing
6757 the kinds for intrinsic data types. */
6758 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
6761 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6762 if (strcmp (c_interop_kinds_table
[i
].name
, u
->use_name
) == 0)
6771 #define NAMED_FUNCTION(a,b,c,d) \
6773 not_in_std = (gfc_option.allow_std & d) == 0; \
6776 #define NAMED_SUBROUTINE(a,b,c,d) \
6778 not_in_std = (gfc_option.allow_std & d) == 0; \
6781 #define NAMED_INTCST(a,b,c,d) \
6783 not_in_std = (gfc_option.allow_std & d) == 0; \
6786 #define NAMED_UINTCST(a,b,c,d) \
6788 not_in_std = (gfc_option.allow_std & d) == 0; \
6791 #define NAMED_REALCST(a,b,c,d) \
6793 not_in_std = (gfc_option.allow_std & d) == 0; \
6796 #define NAMED_CMPXCST(a,b,c,d) \
6798 not_in_std = (gfc_option.allow_std & d) == 0; \
6801 #include "iso-c-binding.def"
6809 gfc_error ("The symbol %qs, referenced at %L, is not "
6810 "in the selected standard", name
, &u
->where
);
6816 #define NAMED_FUNCTION(a,b,c,d) \
6818 if (a == ISOCBINDING_LOC) \
6819 return_type = c_ptr->n.sym; \
6820 else if (a == ISOCBINDING_FUNLOC) \
6821 return_type = c_funptr->n.sym; \
6823 return_type = NULL; \
6824 create_intrinsic_function (u->local_name[0] \
6825 ? u->local_name : u->use_name, \
6826 a, iso_c_module_name, \
6827 INTMOD_ISO_C_BINDING, false, \
6830 #define NAMED_SUBROUTINE(a,b,c,d) \
6832 create_intrinsic_function (u->local_name[0] ? u->local_name \
6834 a, iso_c_module_name, \
6835 INTMOD_ISO_C_BINDING, true, NULL); \
6837 #include "iso-c-binding.def"
6839 case ISOCBINDING_PTR
:
6840 case ISOCBINDING_FUNPTR
:
6841 /* Already handled above. */
6844 if (i
== ISOCBINDING_NULL_PTR
)
6845 tmp_symtree
= c_ptr
;
6846 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6847 tmp_symtree
= c_funptr
;
6850 generate_isocbinding_symbol (iso_c_module_name
,
6851 (iso_c_binding_symbol
) i
,
6853 ? u
->local_name
: u
->use_name
,
6854 tmp_symtree
, false);
6858 if (!found
&& !only_flag
)
6860 /* Skip, if the symbol is not in the enabled standard. */
6863 #define NAMED_FUNCTION(a,b,c,d) \
6865 if ((gfc_option.allow_std & d) == 0) \
6868 #define NAMED_SUBROUTINE(a,b,c,d) \
6870 if ((gfc_option.allow_std & d) == 0) \
6873 #define NAMED_INTCST(a,b,c,d) \
6875 if ((gfc_option.allow_std & d) == 0) \
6878 #define NAMED_UINTCST(a,b,c,d) \
6880 if ((gfc_option.allow_std & d) == 0) \
6883 #define NAMED_REALCST(a,b,c,d) \
6885 if ((gfc_option.allow_std & d) == 0) \
6888 #define NAMED_CMPXCST(a,b,c,d) \
6890 if ((gfc_option.allow_std & d) == 0) \
6893 #include "iso-c-binding.def"
6895 ; /* Not GFC_STD_* versioned. */
6900 #define NAMED_FUNCTION(a,b,c,d) \
6902 if (a == ISOCBINDING_LOC) \
6903 return_type = c_ptr->n.sym; \
6904 else if (a == ISOCBINDING_FUNLOC) \
6905 return_type = c_funptr->n.sym; \
6907 return_type = NULL; \
6908 create_intrinsic_function (b, a, iso_c_module_name, \
6909 INTMOD_ISO_C_BINDING, false, \
6912 #define NAMED_SUBROUTINE(a,b,c,d) \
6914 create_intrinsic_function (b, a, iso_c_module_name, \
6915 INTMOD_ISO_C_BINDING, true, NULL); \
6917 #include "iso-c-binding.def"
6919 case ISOCBINDING_PTR
:
6920 case ISOCBINDING_FUNPTR
:
6921 /* Already handled above. */
6924 if (i
== ISOCBINDING_NULL_PTR
)
6925 tmp_symtree
= c_ptr
;
6926 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6927 tmp_symtree
= c_funptr
;
6930 generate_isocbinding_symbol (iso_c_module_name
,
6931 (iso_c_binding_symbol
) i
, NULL
,
6932 tmp_symtree
, false);
6937 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6942 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
6943 "module ISO_C_BINDING", u
->use_name
, &u
->where
);
6948 /* Add an integer named constant from a given module. */
6951 create_int_parameter (const char *name
, int value
, const char *modname
,
6952 intmod_id module
, int id
)
6954 gfc_symtree
*tmp_symtree
;
6957 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6958 if (tmp_symtree
!= NULL
)
6960 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6963 gfc_error ("Symbol %qs already declared", name
);
6966 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6967 sym
= tmp_symtree
->n
.sym
;
6969 sym
->module
= gfc_get_string ("%s", modname
);
6970 sym
->attr
.flavor
= FL_PARAMETER
;
6971 sym
->ts
.type
= BT_INTEGER
;
6972 sym
->ts
.kind
= gfc_default_integer_kind
;
6973 sym
->value
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, value
);
6974 sym
->attr
.use_assoc
= 1;
6975 sym
->from_intmod
= module
;
6976 sym
->intmod_sym_id
= id
;
6980 /* Value is already contained by the array constructor, but not
6984 create_int_parameter_array (const char *name
, int size
, gfc_expr
*value
,
6985 const char *modname
, intmod_id module
, int id
)
6987 gfc_symtree
*tmp_symtree
;
6990 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6991 if (tmp_symtree
!= NULL
)
6993 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6996 gfc_error ("Symbol %qs already declared", name
);
6999 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
7000 sym
= tmp_symtree
->n
.sym
;
7002 sym
->module
= gfc_get_string ("%s", modname
);
7003 sym
->attr
.flavor
= FL_PARAMETER
;
7004 sym
->ts
.type
= BT_INTEGER
;
7005 sym
->ts
.kind
= gfc_default_integer_kind
;
7006 sym
->attr
.use_assoc
= 1;
7007 sym
->from_intmod
= module
;
7008 sym
->intmod_sym_id
= id
;
7009 sym
->attr
.dimension
= 1;
7010 sym
->as
= gfc_get_array_spec ();
7012 sym
->as
->type
= AS_EXPLICIT
;
7013 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
7014 sym
->as
->upper
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, size
);
7017 sym
->value
->shape
= gfc_get_shape (1);
7018 mpz_init_set_ui (sym
->value
->shape
[0], size
);
7022 /* Add an derived type for a given module. */
7025 create_derived_type (const char *name
, const char *modname
,
7026 intmod_id module
, int id
)
7028 gfc_symtree
*tmp_symtree
;
7029 gfc_symbol
*sym
, *dt_sym
;
7030 gfc_interface
*intr
, *head
;
7032 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
7033 if (tmp_symtree
!= NULL
)
7035 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
7038 gfc_error ("Symbol %qs already declared", name
);
7041 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
7042 sym
= tmp_symtree
->n
.sym
;
7043 sym
->module
= gfc_get_string ("%s", modname
);
7044 sym
->from_intmod
= module
;
7045 sym
->intmod_sym_id
= id
;
7046 sym
->attr
.flavor
= FL_PROCEDURE
;
7047 sym
->attr
.function
= 1;
7048 sym
->attr
.generic
= 1;
7050 gfc_get_sym_tree (gfc_dt_upper_string (sym
->name
),
7051 gfc_current_ns
, &tmp_symtree
, false);
7052 dt_sym
= tmp_symtree
->n
.sym
;
7053 dt_sym
->name
= gfc_get_string ("%s", sym
->name
);
7054 dt_sym
->attr
.flavor
= FL_DERIVED
;
7055 dt_sym
->attr
.private_comp
= 1;
7056 dt_sym
->attr
.zero_comp
= 1;
7057 dt_sym
->attr
.use_assoc
= 1;
7058 dt_sym
->module
= gfc_get_string ("%s", modname
);
7059 dt_sym
->from_intmod
= module
;
7060 dt_sym
->intmod_sym_id
= id
;
7062 head
= sym
->generic
;
7063 intr
= gfc_get_interface ();
7065 intr
->where
= gfc_current_locus
;
7067 sym
->generic
= intr
;
7068 sym
->attr
.if_source
= IFSRC_DECL
;
7072 /* Read the contents of the module file into a temporary buffer. */
7075 read_module_to_tmpbuf ()
7077 /* We don't know the uncompressed size, so enlarge the buffer as
7083 module_content
= XNEWVEC (char, cursz
);
7087 int nread
= gzread (module_fp
, module_content
+ len
, rsize
);
7092 module_content
= XRESIZEVEC (char, module_content
, cursz
);
7093 rsize
= cursz
- len
;
7096 module_content
= XRESIZEVEC (char, module_content
, len
+ 1);
7097 module_content
[len
] = '\0';
7103 /* USE the ISO_FORTRAN_ENV intrinsic module. */
7106 use_iso_fortran_env_module (void)
7108 static char mod
[] = "iso_fortran_env";
7110 gfc_symbol
*mod_sym
;
7111 gfc_symtree
*mod_symtree
;
7115 intmod_sym symbol
[] = {
7116 #define NAMED_INTCST(a,b,c,d) { a, b, 0, d },
7117 #define NAMED_UINTCST(a,b,c,d) { a, b, 0, d },
7118 #define NAMED_KINDARRAY(a,b,c,d) { a, b, 0, d },
7119 #define NAMED_DERIVED_TYPE(a,b,c,d) { a, b, 0, d },
7120 #define NAMED_FUNCTION(a,b,c,d) { a, b, c, d },
7121 #define NAMED_SUBROUTINE(a,b,c,d) { a, b, c, d },
7122 #include "iso-fortran-env.def"
7123 { ISOFORTRANENV_INVALID
, NULL
, -1234, 0 } };
7125 /* We could have used c in the NAMED_{,U}INTCST macros
7126 instead of 0, but then current g++ expands the initialization
7127 as clearing the whole object followed by explicit stores of
7128 all the non-zero elements (over 150), while by using 0s for
7129 the non-constant initializers and initializing them afterwards
7130 g++ will often copy everything from .rodata and then only override
7131 over 30 non-constant ones. */
7133 #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c;
7134 #define NAMED_UINTCST(a,b,c,d) symbol[i++].value = c;
7135 #define NAMED_KINDARRAY(a,b,c,d) i++;
7136 #define NAMED_DERIVED_TYPE(a,b,c,d) i++;
7137 #define NAMED_FUNCTION(a,b,c,d) i++;
7138 #define NAMED_SUBROUTINE(a,b,c,d) i++;
7139 #include "iso-fortran-env.def"
7140 gcc_checking_assert (i
== (int) ARRAY_SIZE (symbol
) - 1);
7142 /* Generate the symbol for the module itself. */
7143 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, mod
);
7144 if (mod_symtree
== NULL
)
7146 gfc_get_sym_tree (mod
, gfc_current_ns
, &mod_symtree
, false);
7147 gcc_assert (mod_symtree
);
7148 mod_sym
= mod_symtree
->n
.sym
;
7150 mod_sym
->attr
.flavor
= FL_MODULE
;
7151 mod_sym
->attr
.intrinsic
= 1;
7152 mod_sym
->module
= gfc_get_string ("%s", mod
);
7153 mod_sym
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
7156 if (!mod_symtree
->n
.sym
->attr
.intrinsic
)
7157 gfc_error ("Use of intrinsic module %qs at %C conflicts with "
7158 "non-intrinsic module name used previously", mod
);
7160 /* Generate the symbols for the module integer named constants. */
7162 for (i
= 0; symbol
[i
].name
; i
++)
7165 for (u
= gfc_rename_list
; u
; u
= u
->next
)
7167 if (strcmp (symbol
[i
].name
, u
->use_name
) == 0)
7172 if (!gfc_notify_std (symbol
[i
].standard
, "The symbol %qs, "
7173 "referenced at %L, is not in the selected "
7174 "standard", symbol
[i
].name
, &u
->where
))
7177 if ((flag_default_integer
|| flag_default_real_8
)
7178 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
7179 gfc_warning_now (0, "Use of the NUMERIC_STORAGE_SIZE named "
7180 "constant from intrinsic module "
7181 "ISO_FORTRAN_ENV at %L is incompatible with "
7182 "option %qs", &u
->where
,
7183 flag_default_integer
7184 ? "-fdefault-integer-8"
7185 : "-fdefault-real-8");
7186 switch (symbol
[i
].id
)
7188 #define NAMED_INTCST(a,b,c,d) \
7190 #include "iso-fortran-env.def"
7191 create_int_parameter (u
->local_name
[0] ? u
->local_name
7193 symbol
[i
].value
, mod
,
7194 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7197 #define NAMED_UINTCST(a,b,c,d) \
7199 #include "iso-fortran-env.def"
7200 create_int_parameter (u
->local_name
[0] ? u
->local_name
7202 symbol
[i
].value
, mod
,
7203 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7206 #define NAMED_KINDARRAY(a,b,KINDS,d) \
7208 expr = gfc_get_array_expr (BT_INTEGER, \
7209 gfc_default_integer_kind,\
7211 for (j = 0; KINDS[j].kind != 0; j++) \
7212 gfc_constructor_append_expr (&expr->value.constructor, \
7213 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7214 KINDS[j].kind), NULL); \
7215 create_int_parameter_array (u->local_name[0] ? u->local_name \
7218 INTMOD_ISO_FORTRAN_ENV, \
7221 #include "iso-fortran-env.def"
7223 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7225 #include "iso-fortran-env.def"
7226 create_derived_type (u
->local_name
[0] ? u
->local_name
7228 mod
, INTMOD_ISO_FORTRAN_ENV
,
7232 #define NAMED_FUNCTION(a,b,c,d) \
7234 #include "iso-fortran-env.def"
7235 create_intrinsic_function (u
->local_name
[0] ? u
->local_name
7238 INTMOD_ISO_FORTRAN_ENV
, false,
7248 if (!found
&& !only_flag
)
7250 if ((gfc_option
.allow_std
& symbol
[i
].standard
) == 0)
7253 if ((flag_default_integer
|| flag_default_real_8
)
7254 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
7256 "Use of the NUMERIC_STORAGE_SIZE named constant "
7257 "from intrinsic module ISO_FORTRAN_ENV at %C is "
7258 "incompatible with option %s",
7259 flag_default_integer
7260 ? "-fdefault-integer-8" : "-fdefault-real-8");
7262 switch (symbol
[i
].id
)
7264 #define NAMED_INTCST(a,b,c,d) \
7266 #include "iso-fortran-env.def"
7267 create_int_parameter (symbol
[i
].name
, symbol
[i
].value
, mod
,
7268 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7271 #define NAMED_UINTCST(a,b,c,d) \
7273 #include "iso-fortran-env.def"
7274 create_int_parameter (symbol
[i
].name
, symbol
[i
].value
, mod
,
7275 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
7278 #define NAMED_KINDARRAY(a,b,KINDS,d) \
7280 expr = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind, \
7282 for (j = 0; KINDS[j].kind != 0; j++) \
7283 gfc_constructor_append_expr (&expr->value.constructor, \
7284 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7285 KINDS[j].kind), NULL); \
7286 create_int_parameter_array (symbol[i].name, j, expr, mod, \
7287 INTMOD_ISO_FORTRAN_ENV, symbol[i].id);\
7289 #include "iso-fortran-env.def"
7291 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7293 #include "iso-fortran-env.def"
7294 create_derived_type (symbol
[i
].name
, mod
, INTMOD_ISO_FORTRAN_ENV
,
7298 #define NAMED_FUNCTION(a,b,c,d) \
7300 #include "iso-fortran-env.def"
7301 create_intrinsic_function (symbol
[i
].name
, symbol
[i
].id
, mod
,
7302 INTMOD_ISO_FORTRAN_ENV
, false, NULL
);
7311 for (u
= gfc_rename_list
; u
; u
= u
->next
)
7316 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
7317 "module ISO_FORTRAN_ENV", u
->use_name
, &u
->where
);
7322 /* Process a USE directive. */
7325 gfc_use_module (gfc_use_list
*module
)
7330 gfc_symtree
*mod_symtree
;
7331 gfc_use_list
*use_stmt
;
7332 locus old_locus
= gfc_current_locus
;
7334 gfc_current_locus
= module
->where
;
7335 module_name
= module
->module_name
;
7336 gfc_rename_list
= module
->rename
;
7337 only_flag
= module
->only_flag
;
7338 current_intmod
= INTMOD_NONE
;
7341 gfc_warning_now (OPT_Wuse_without_only
,
7342 "USE statement at %C has no ONLY qualifier");
7344 if (gfc_state_stack
->state
== COMP_MODULE
7345 || module
->submodule_name
== NULL
)
7347 filename
= XALLOCAVEC (char, strlen (module_name
)
7348 + strlen (MODULE_EXTENSION
) + 1);
7349 strcpy (filename
, module_name
);
7350 strcat (filename
, MODULE_EXTENSION
);
7354 filename
= XALLOCAVEC (char, strlen (module
->submodule_name
)
7355 + strlen (SUBMODULE_EXTENSION
) + 1);
7356 strcpy (filename
, module
->submodule_name
);
7357 strcat (filename
, SUBMODULE_EXTENSION
);
7360 /* First, try to find an non-intrinsic module, unless the USE statement
7361 specified that the module is intrinsic. */
7363 if (!module
->intrinsic
)
7364 module_fp
= gzopen_included_file (filename
, true, true);
7366 /* Then, see if it's an intrinsic one, unless the USE statement
7367 specified that the module is non-intrinsic. */
7368 if (module_fp
== NULL
&& !module
->non_intrinsic
)
7370 if (strcmp (module_name
, "iso_fortran_env") == 0
7371 && gfc_notify_std (GFC_STD_F2003
, "ISO_FORTRAN_ENV "
7372 "intrinsic module at %C"))
7374 use_iso_fortran_env_module ();
7375 free_rename (module
->rename
);
7376 module
->rename
= NULL
;
7377 gfc_current_locus
= old_locus
;
7378 module
->intrinsic
= true;
7382 if (strcmp (module_name
, "iso_c_binding") == 0
7383 && gfc_notify_std (GFC_STD_F2003
, "ISO_C_BINDING module at %C"))
7385 import_iso_c_binding_module();
7386 free_rename (module
->rename
);
7387 module
->rename
= NULL
;
7388 gfc_current_locus
= old_locus
;
7389 module
->intrinsic
= true;
7393 module_fp
= gzopen_intrinsic_module (filename
);
7395 if (module_fp
== NULL
&& module
->intrinsic
)
7396 gfc_fatal_error ("Cannot find an intrinsic module named %qs at %C",
7399 /* Check for the IEEE modules, so we can mark their symbols
7400 accordingly when we read them. */
7401 if (strcmp (module_name
, "ieee_features") == 0
7402 && gfc_notify_std (GFC_STD_F2003
, "IEEE_FEATURES module at %C"))
7404 current_intmod
= INTMOD_IEEE_FEATURES
;
7406 else if (strcmp (module_name
, "ieee_exceptions") == 0
7407 && gfc_notify_std (GFC_STD_F2003
,
7408 "IEEE_EXCEPTIONS module at %C"))
7410 current_intmod
= INTMOD_IEEE_EXCEPTIONS
;
7412 else if (strcmp (module_name
, "ieee_arithmetic") == 0
7413 && gfc_notify_std (GFC_STD_F2003
,
7414 "IEEE_ARITHMETIC module at %C"))
7416 current_intmod
= INTMOD_IEEE_ARITHMETIC
;
7420 if (module_fp
== NULL
)
7422 if (gfc_state_stack
->state
!= COMP_SUBMODULE
7423 && module
->submodule_name
== NULL
)
7424 gfc_fatal_error ("Cannot open module file %qs for reading at %C: %s",
7425 filename
, xstrerror (errno
));
7427 gfc_fatal_error ("Module file %qs has not been generated, either "
7428 "because the module does not contain a MODULE "
7429 "PROCEDURE or there is an error in the module.",
7433 /* Check that we haven't already USEd an intrinsic module with the
7436 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, module_name
);
7437 if (mod_symtree
&& mod_symtree
->n
.sym
->attr
.intrinsic
)
7438 gfc_error ("Use of non-intrinsic module %qs at %C conflicts with "
7439 "intrinsic module name used previously", module_name
);
7446 read_module_to_tmpbuf ();
7447 gzclose (module_fp
);
7449 /* Skip the first line of the module, after checking that this is
7450 a gfortran module file. */
7456 bad_module ("Unexpected end of module");
7459 if ((start
== 1 && strcmp (atom_name
, "GFORTRAN") != 0)
7460 || (start
== 2 && strcmp (atom_name
, " module") != 0))
7461 gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran"
7462 " module file", module_fullpath
);
7466 if (strcmp (atom_name
, " version") != 0
7467 || module_char () != ' '
7468 || parse_atom () != ATOM_STRING
)
7470 else if (strcmp (atom_string
, MOD_VERSION
))
7472 static const char *compat_mod_versions
[] = COMPAT_MOD_VERSIONS
;
7474 for (unsigned i
= 0; i
< ARRAY_SIZE (compat_mod_versions
); ++i
)
7475 if (!strcmp (atom_string
, compat_mod_versions
[i
]))
7482 gfc_fatal_error ("Cannot read module file %qs opened at %C,"
7483 " because it was created by a different"
7484 " version of GNU Fortran", module_fullpath
);
7493 /* Make sure we're not reading the same module that we may be building. */
7494 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
7495 if ((p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
)
7496 && strcmp (p
->sym
->name
, module_name
) == 0)
7498 if (p
->state
== COMP_SUBMODULE
)
7499 gfc_fatal_error ("Cannot USE a submodule that is currently built");
7501 gfc_fatal_error ("Cannot USE a module that is currently built");
7505 init_true_name_tree ();
7509 free_true_name (true_name_root
);
7510 true_name_root
= NULL
;
7512 free_pi_tree (pi_root
);
7515 XDELETEVEC (module_content
);
7516 module_content
= NULL
;
7518 use_stmt
= gfc_get_use_list ();
7519 *use_stmt
= *module
;
7520 use_stmt
->next
= gfc_current_ns
->use_stmts
;
7521 gfc_current_ns
->use_stmts
= use_stmt
;
7523 gfc_current_locus
= old_locus
;
7527 /* Remove duplicated intrinsic operators from the rename list. */
7530 rename_list_remove_duplicate (gfc_use_rename
*list
)
7532 gfc_use_rename
*seek
, *last
;
7534 for (; list
; list
= list
->next
)
7535 if (list
->op
!= INTRINSIC_USER
&& list
->op
!= INTRINSIC_NONE
)
7538 for (seek
= list
->next
; seek
; seek
= last
->next
)
7540 if (list
->op
== seek
->op
)
7542 last
->next
= seek
->next
;
7552 /* Process all USE directives. */
7555 gfc_use_modules (void)
7557 gfc_use_list
*next
, *seek
, *last
;
7559 for (next
= module_list
; next
; next
= next
->next
)
7561 bool non_intrinsic
= next
->non_intrinsic
;
7562 bool intrinsic
= next
->intrinsic
;
7563 bool neither
= !non_intrinsic
&& !intrinsic
;
7565 for (seek
= next
->next
; seek
; seek
= seek
->next
)
7567 if (next
->module_name
!= seek
->module_name
)
7570 if (seek
->non_intrinsic
)
7571 non_intrinsic
= true;
7572 else if (seek
->intrinsic
)
7578 if (intrinsic
&& neither
&& !non_intrinsic
)
7583 filename
= XALLOCAVEC (char,
7584 strlen (next
->module_name
)
7585 + strlen (MODULE_EXTENSION
) + 1);
7586 strcpy (filename
, next
->module_name
);
7587 strcat (filename
, MODULE_EXTENSION
);
7588 fp
= gfc_open_included_file (filename
, true, true);
7591 non_intrinsic
= true;
7597 for (seek
= next
->next
; seek
; seek
= last
->next
)
7599 if (next
->module_name
!= seek
->module_name
)
7605 if ((!next
->intrinsic
&& !seek
->intrinsic
)
7606 || (next
->intrinsic
&& seek
->intrinsic
)
7609 if (!seek
->only_flag
)
7610 next
->only_flag
= false;
7613 gfc_use_rename
*r
= seek
->rename
;
7616 r
->next
= next
->rename
;
7617 next
->rename
= seek
->rename
;
7619 last
->next
= seek
->next
;
7627 for (; module_list
; module_list
= next
)
7629 next
= module_list
->next
;
7630 rename_list_remove_duplicate (module_list
->rename
);
7631 gfc_use_module (module_list
);
7635 old_module_list_tail
= &module_list
;
7636 gfc_rename_list
= NULL
;
7641 gfc_free_use_stmts (gfc_use_list
*use_stmts
)
7644 for (; use_stmts
; use_stmts
= next
)
7646 gfc_use_rename
*next_rename
;
7648 for (; use_stmts
->rename
; use_stmts
->rename
= next_rename
)
7650 next_rename
= use_stmts
->rename
->next
;
7651 free (use_stmts
->rename
);
7653 next
= use_stmts
->next
;
7659 /* Remember the end of the MODULE_LIST list, so that the list can be restored
7660 to its previous state if the current statement is erroneous. */
7663 gfc_save_module_list ()
7665 gfc_use_list
**tail
= &module_list
;
7666 while (*tail
!= NULL
)
7667 tail
= &(*tail
)->next
;
7668 old_module_list_tail
= tail
;
7672 /* Restore the MODULE_LIST list to its previous value and free the use
7673 statements that are no longer part of the list. */
7676 gfc_restore_old_module_list ()
7678 gfc_free_use_stmts (*old_module_list_tail
);
7679 *old_module_list_tail
= NULL
;
7684 gfc_module_init_2 (void)
7686 last_atom
= ATOM_LPAREN
;
7687 gfc_rename_list
= NULL
;
7693 gfc_module_done_2 (void)
7695 free_rename (gfc_rename_list
);
7696 gfc_rename_list
= NULL
;