1 /* Handle modules, which amounts to loading and saving symbols and
2 their attendant structures.
3 Copyright (C) 2000-2017 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 "14"
90 /* Structure that describes a position within a module file. */
99 /* Structure for list of symbols of intrinsic modules. */
112 P_UNKNOWN
= 0, P_OTHER
, P_NAMESPACE
, P_COMPONENT
, P_SYMBOL
116 /* The fixup structure lists pointers to pointers that have to
117 be updated when a pointer value becomes known. */
119 typedef struct fixup_t
122 struct fixup_t
*next
;
127 /* Structure for holding extra info needed for pointers being read. */
143 typedef struct pointer_info
145 BBT_HEADER (pointer_info
);
149 /* The first component of each member of the union is the pointer
156 void *pointer
; /* Member for doing pointer searches. */
161 char *true_name
, *module
, *binding_label
;
163 gfc_symtree
*symtree
;
164 enum gfc_rsym_state state
;
165 int ns
, referenced
, renamed
;
173 enum gfc_wsym_state state
;
182 #define gfc_get_pointer_info() XCNEW (pointer_info)
185 /* Local variables */
187 /* The gzFile for the module we're reading or writing. */
188 static gzFile module_fp
;
191 /* The name of the module we're reading (USE'ing) or writing. */
192 static const char *module_name
;
193 /* The name of the .smod file that the submodule will write to. */
194 static const char *submodule_name
;
196 static gfc_use_list
*module_list
;
198 /* If we're reading an intrinsic module, this is its ID. */
199 static intmod_id current_intmod
;
201 /* Content of module. */
202 static char* module_content
;
204 static long module_pos
;
205 static int module_line
, module_column
, only_flag
;
206 static int prev_module_line
, prev_module_column
;
209 { IO_INPUT
, IO_OUTPUT
}
212 static gfc_use_rename
*gfc_rename_list
;
213 static pointer_info
*pi_root
;
214 static int symbol_number
; /* Counter for assigning symbol numbers */
216 /* Tells mio_expr_ref to make symbols for unused equivalence members. */
217 static bool in_load_equiv
;
221 /*****************************************************************/
223 /* Pointer/integer conversion. Pointers between structures are stored
224 as integers in the module file. The next couple of subroutines
225 handle this translation for reading and writing. */
227 /* Recursively free the tree of pointer structures. */
230 free_pi_tree (pointer_info
*p
)
235 if (p
->fixup
!= NULL
)
236 gfc_internal_error ("free_pi_tree(): Unresolved fixup");
238 free_pi_tree (p
->left
);
239 free_pi_tree (p
->right
);
241 if (iomode
== IO_INPUT
)
243 XDELETEVEC (p
->u
.rsym
.true_name
);
244 XDELETEVEC (p
->u
.rsym
.module
);
245 XDELETEVEC (p
->u
.rsym
.binding_label
);
252 /* Compare pointers when searching by pointer. Used when writing a
256 compare_pointers (void *_sn1
, void *_sn2
)
258 pointer_info
*sn1
, *sn2
;
260 sn1
= (pointer_info
*) _sn1
;
261 sn2
= (pointer_info
*) _sn2
;
263 if (sn1
->u
.pointer
< sn2
->u
.pointer
)
265 if (sn1
->u
.pointer
> sn2
->u
.pointer
)
272 /* Compare integers when searching by integer. Used when reading a
276 compare_integers (void *_sn1
, void *_sn2
)
278 pointer_info
*sn1
, *sn2
;
280 sn1
= (pointer_info
*) _sn1
;
281 sn2
= (pointer_info
*) _sn2
;
283 if (sn1
->integer
< sn2
->integer
)
285 if (sn1
->integer
> sn2
->integer
)
292 /* Initialize the pointer_info tree. */
301 compare
= (iomode
== IO_INPUT
) ? compare_integers
: compare_pointers
;
303 /* Pointer 0 is the NULL pointer. */
304 p
= gfc_get_pointer_info ();
309 gfc_insert_bbt (&pi_root
, p
, compare
);
311 /* Pointer 1 is the current namespace. */
312 p
= gfc_get_pointer_info ();
313 p
->u
.pointer
= gfc_current_ns
;
315 p
->type
= P_NAMESPACE
;
317 gfc_insert_bbt (&pi_root
, p
, compare
);
323 /* During module writing, call here with a pointer to something,
324 returning the pointer_info node. */
326 static pointer_info
*
327 find_pointer (void *gp
)
334 if (p
->u
.pointer
== gp
)
336 p
= (gp
< p
->u
.pointer
) ? p
->left
: p
->right
;
343 /* Given a pointer while writing, returns the pointer_info tree node,
344 creating it if it doesn't exist. */
346 static pointer_info
*
347 get_pointer (void *gp
)
351 p
= find_pointer (gp
);
355 /* Pointer doesn't have an integer. Give it one. */
356 p
= gfc_get_pointer_info ();
359 p
->integer
= symbol_number
++;
361 gfc_insert_bbt (&pi_root
, p
, compare_pointers
);
367 /* Given an integer during reading, find it in the pointer_info tree,
368 creating the node if not found. */
370 static pointer_info
*
371 get_integer (int integer
)
381 c
= compare_integers (&t
, p
);
385 p
= (c
< 0) ? p
->left
: p
->right
;
391 p
= gfc_get_pointer_info ();
392 p
->integer
= integer
;
395 gfc_insert_bbt (&pi_root
, p
, compare_integers
);
401 /* Resolve any fixups using a known pointer. */
404 resolve_fixups (fixup_t
*f
, void *gp
)
417 /* Convert a string such that it starts with a lower-case character. Used
418 to convert the symtree name of a derived-type to the symbol name or to
419 the name of the associated generic function. */
422 gfc_dt_lower_string (const char *name
)
424 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
425 return gfc_get_string ("%c%s", (char) TOLOWER ((unsigned char) name
[0]),
427 return gfc_get_string ("%s", name
);
431 /* Convert a string such that it starts with an upper-case character. Used to
432 return the symtree-name for a derived type; the symbol name itself and the
433 symtree/symbol name of the associated generic function start with a lower-
437 gfc_dt_upper_string (const char *name
)
439 if (name
[0] != (char) TOUPPER ((unsigned char) name
[0]))
440 return gfc_get_string ("%c%s", (char) TOUPPER ((unsigned char) name
[0]),
442 return gfc_get_string ("%s", name
);
445 /* Call here during module reading when we know what pointer to
446 associate with an integer. Any fixups that exist are resolved at
450 associate_integer_pointer (pointer_info
*p
, void *gp
)
452 if (p
->u
.pointer
!= NULL
)
453 gfc_internal_error ("associate_integer_pointer(): Already associated");
457 resolve_fixups (p
->fixup
, gp
);
463 /* During module reading, given an integer and a pointer to a pointer,
464 either store the pointer from an already-known value or create a
465 fixup structure in order to store things later. Returns zero if
466 the reference has been actually stored, or nonzero if the reference
467 must be fixed later (i.e., associate_integer_pointer must be called
468 sometime later. Returns the pointer_info structure. */
470 static pointer_info
*
471 add_fixup (int integer
, void *gp
)
477 p
= get_integer (integer
);
479 if (p
->integer
== 0 || p
->u
.pointer
!= NULL
)
482 *cp
= (char *) p
->u
.pointer
;
491 f
->pointer
= (void **) gp
;
498 /*****************************************************************/
500 /* Parser related subroutines */
502 /* Free the rename list left behind by a USE statement. */
505 free_rename (gfc_use_rename
*list
)
507 gfc_use_rename
*next
;
509 for (; list
; list
= next
)
517 /* Match a USE statement. */
522 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module_nature
[GFC_MAX_SYMBOL_LEN
+ 1];
523 gfc_use_rename
*tail
= NULL
, *new_use
;
524 interface_type type
, type2
;
527 gfc_use_list
*use_list
;
529 use_list
= gfc_get_use_list ();
531 if (gfc_match (" , ") == MATCH_YES
)
533 if ((m
= gfc_match (" %n ::", module_nature
)) == MATCH_YES
)
535 if (!gfc_notify_std (GFC_STD_F2003
, "module "
536 "nature in USE statement at %C"))
539 if (strcmp (module_nature
, "intrinsic") == 0)
540 use_list
->intrinsic
= true;
543 if (strcmp (module_nature
, "non_intrinsic") == 0)
544 use_list
->non_intrinsic
= true;
547 gfc_error ("Module nature in USE statement at %C shall "
548 "be either INTRINSIC or NON_INTRINSIC");
555 /* Help output a better error message than "Unclassifiable
557 gfc_match (" %n", module_nature
);
558 if (strcmp (module_nature
, "intrinsic") == 0
559 || strcmp (module_nature
, "non_intrinsic") == 0)
560 gfc_error ("\"::\" was expected after module nature at %C "
561 "but was not found");
568 m
= gfc_match (" ::");
569 if (m
== MATCH_YES
&&
570 !gfc_notify_std(GFC_STD_F2003
, "\"USE :: module\" at %C"))
575 m
= gfc_match ("% ");
584 use_list
->where
= gfc_current_locus
;
586 m
= gfc_match_name (name
);
593 use_list
->module_name
= gfc_get_string ("%s", name
);
595 if (gfc_match_eos () == MATCH_YES
)
598 if (gfc_match_char (',') != MATCH_YES
)
601 if (gfc_match (" only :") == MATCH_YES
)
602 use_list
->only_flag
= true;
604 if (gfc_match_eos () == MATCH_YES
)
609 /* Get a new rename struct and add it to the rename list. */
610 new_use
= gfc_get_use_rename ();
611 new_use
->where
= gfc_current_locus
;
614 if (use_list
->rename
== NULL
)
615 use_list
->rename
= new_use
;
617 tail
->next
= new_use
;
620 /* See what kind of interface we're dealing with. Assume it is
622 new_use
->op
= INTRINSIC_NONE
;
623 if (gfc_match_generic_spec (&type
, name
, &op
) == MATCH_ERROR
)
628 case INTERFACE_NAMELESS
:
629 gfc_error ("Missing generic specification in USE statement at %C");
632 case INTERFACE_USER_OP
:
633 case INTERFACE_GENERIC
:
635 m
= gfc_match (" =>");
637 if (type
== INTERFACE_USER_OP
&& m
== MATCH_YES
638 && (!gfc_notify_std(GFC_STD_F2003
, "Renaming "
639 "operators in USE statements at %C")))
642 if (type
== INTERFACE_USER_OP
)
643 new_use
->op
= INTRINSIC_USER
;
645 if (use_list
->only_flag
)
648 strcpy (new_use
->use_name
, name
);
651 strcpy (new_use
->local_name
, name
);
652 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
657 if (m
== MATCH_ERROR
)
665 strcpy (new_use
->local_name
, name
);
667 m
= gfc_match_generic_spec (&type2
, new_use
->use_name
, &op
);
672 if (m
== MATCH_ERROR
)
676 if (strcmp (new_use
->use_name
, use_list
->module_name
) == 0
677 || strcmp (new_use
->local_name
, use_list
->module_name
) == 0)
679 gfc_error ("The name %qs at %C has already been used as "
680 "an external module name", use_list
->module_name
);
685 case INTERFACE_INTRINSIC_OP
:
693 if (gfc_match_eos () == MATCH_YES
)
695 if (gfc_match_char (',') != MATCH_YES
)
702 gfc_use_list
*last
= module_list
;
705 last
->next
= use_list
;
708 module_list
= use_list
;
713 gfc_syntax_error (ST_USE
);
716 free_rename (use_list
->rename
);
722 /* Match a SUBMODULE statement.
724 According to F2008:11.2.3.2, "The submodule identifier is the
725 ordered pair whose first element is the ancestor module name and
726 whose second element is the submodule name. 'Submodule_name' is
727 used for the submodule filename and uses '@' as a separator, whilst
728 the name of the symbol for the module uses '.' as a a separator.
729 The reasons for these choices are:
730 (i) To follow another leading brand in the submodule filenames;
731 (ii) Since '.' is not particularly visible in the filenames; and
732 (iii) The linker does not permit '@' in mnemonics. */
735 gfc_match_submodule (void)
738 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
739 gfc_use_list
*use_list
;
740 bool seen_colon
= false;
742 if (!gfc_notify_std (GFC_STD_F2008
, "SUBMODULE declaration at %C"))
745 if (gfc_current_state () != COMP_NONE
)
747 gfc_error ("SUBMODULE declaration at %C cannot appear within "
748 "another scoping unit");
752 gfc_new_block
= NULL
;
753 gcc_assert (module_list
== NULL
);
755 if (gfc_match_char ('(') != MATCH_YES
)
760 m
= gfc_match (" %n", name
);
764 use_list
= gfc_get_use_list ();
765 use_list
->where
= gfc_current_locus
;
769 gfc_use_list
*last
= module_list
;
772 last
->next
= use_list
;
773 use_list
->module_name
774 = gfc_get_string ("%s.%s", module_list
->module_name
, name
);
775 use_list
->submodule_name
776 = gfc_get_string ("%s@%s", module_list
->module_name
, name
);
780 module_list
= use_list
;
781 use_list
->module_name
= gfc_get_string ("%s", name
);
782 use_list
->submodule_name
= use_list
->module_name
;
785 if (gfc_match_char (')') == MATCH_YES
)
788 if (gfc_match_char (':') != MATCH_YES
795 m
= gfc_match (" %s%t", &gfc_new_block
);
799 submodule_name
= gfc_get_string ("%s@%s", module_list
->module_name
,
800 gfc_new_block
->name
);
802 gfc_new_block
->name
= gfc_get_string ("%s.%s",
803 module_list
->module_name
,
804 gfc_new_block
->name
);
806 if (!gfc_add_flavor (&gfc_new_block
->attr
, FL_MODULE
,
807 gfc_new_block
->name
, NULL
))
810 /* Just retain the ultimate .(s)mod file for reading, since it
811 contains all the information in its ancestors. */
812 use_list
= module_list
;
813 for (; module_list
->next
; use_list
= module_list
)
815 module_list
= use_list
->next
;
822 gfc_error ("Syntax error in SUBMODULE statement at %C");
827 /* Given a name and a number, inst, return the inst name
828 under which to load this symbol. Returns NULL if this
829 symbol shouldn't be loaded. If inst is zero, returns
830 the number of instances of this name. If interface is
831 true, a user-defined operator is sought, otherwise only
832 non-operators are sought. */
835 find_use_name_n (const char *name
, int *inst
, bool interface
)
838 const char *low_name
= NULL
;
841 /* For derived types. */
842 if (name
[0] != (char) TOLOWER ((unsigned char) name
[0]))
843 low_name
= gfc_dt_lower_string (name
);
846 for (u
= gfc_rename_list
; u
; u
= u
->next
)
848 if ((!low_name
&& strcmp (u
->use_name
, name
) != 0)
849 || (low_name
&& strcmp (u
->use_name
, low_name
) != 0)
850 || (u
->op
== INTRINSIC_USER
&& !interface
)
851 || (u
->op
!= INTRINSIC_USER
&& interface
))
864 return only_flag
? NULL
: name
;
870 if (u
->local_name
[0] == '\0')
872 return gfc_dt_upper_string (u
->local_name
);
875 return (u
->local_name
[0] != '\0') ? u
->local_name
: name
;
879 /* Given a name, return the name under which to load this symbol.
880 Returns NULL if this symbol shouldn't be loaded. */
883 find_use_name (const char *name
, bool interface
)
886 return find_use_name_n (name
, &i
, interface
);
890 /* Given a real name, return the number of use names associated with it. */
893 number_use_names (const char *name
, bool interface
)
896 find_use_name_n (name
, &i
, interface
);
901 /* Try to find the operator in the current list. */
903 static gfc_use_rename
*
904 find_use_operator (gfc_intrinsic_op op
)
908 for (u
= gfc_rename_list
; u
; u
= u
->next
)
916 /*****************************************************************/
918 /* The next couple of subroutines maintain a tree used to avoid a
919 brute-force search for a combination of true name and module name.
920 While symtree names, the name that a particular symbol is known by
921 can changed with USE statements, we still have to keep track of the
922 true names to generate the correct reference, and also avoid
923 loading the same real symbol twice in a program unit.
925 When we start reading, the true name tree is built and maintained
926 as symbols are read. The tree is searched as we load new symbols
927 to see if it already exists someplace in the namespace. */
929 typedef struct true_name
931 BBT_HEADER (true_name
);
937 static true_name
*true_name_root
;
940 /* Compare two true_name structures. */
943 compare_true_names (void *_t1
, void *_t2
)
948 t1
= (true_name
*) _t1
;
949 t2
= (true_name
*) _t2
;
951 c
= ((t1
->sym
->module
> t2
->sym
->module
)
952 - (t1
->sym
->module
< t2
->sym
->module
));
956 return strcmp (t1
->name
, t2
->name
);
960 /* Given a true name, search the true name tree to see if it exists
961 within the main namespace. */
964 find_true_name (const char *name
, const char *module
)
970 t
.name
= gfc_get_string ("%s", name
);
972 sym
.module
= gfc_get_string ("%s", module
);
980 c
= compare_true_names ((void *) (&t
), (void *) p
);
984 p
= (c
< 0) ? p
->left
: p
->right
;
991 /* Given a gfc_symbol pointer that is not in the true name tree, add it. */
994 add_true_name (gfc_symbol
*sym
)
998 t
= XCNEW (true_name
);
1000 if (gfc_fl_struct (sym
->attr
.flavor
))
1001 t
->name
= gfc_dt_upper_string (sym
->name
);
1003 t
->name
= sym
->name
;
1005 gfc_insert_bbt (&true_name_root
, t
, compare_true_names
);
1009 /* Recursive function to build the initial true name tree by
1010 recursively traversing the current namespace. */
1013 build_tnt (gfc_symtree
*st
)
1019 build_tnt (st
->left
);
1020 build_tnt (st
->right
);
1022 if (gfc_fl_struct (st
->n
.sym
->attr
.flavor
))
1023 name
= gfc_dt_upper_string (st
->n
.sym
->name
);
1025 name
= st
->n
.sym
->name
;
1027 if (find_true_name (name
, st
->n
.sym
->module
) != NULL
)
1030 add_true_name (st
->n
.sym
);
1034 /* Initialize the true name tree with the current namespace. */
1037 init_true_name_tree (void)
1039 true_name_root
= NULL
;
1040 build_tnt (gfc_current_ns
->sym_root
);
1044 /* Recursively free a true name tree node. */
1047 free_true_name (true_name
*t
)
1051 free_true_name (t
->left
);
1052 free_true_name (t
->right
);
1058 /*****************************************************************/
1060 /* Module reading and writing. */
1062 /* The following are versions similar to the ones in scanner.c, but
1063 for dealing with compressed module files. */
1066 gzopen_included_file_1 (const char *name
, gfc_directorylist
*list
,
1067 bool module
, bool system
)
1070 gfc_directorylist
*p
;
1073 for (p
= list
; p
; p
= p
->next
)
1075 if (module
&& !p
->use_for_modules
)
1078 fullname
= (char *) alloca(strlen (p
->path
) + strlen (name
) + 1);
1079 strcpy (fullname
, p
->path
);
1080 strcat (fullname
, name
);
1082 f
= gzopen (fullname
, "r");
1085 if (gfc_cpp_makedep ())
1086 gfc_cpp_add_dep (fullname
, system
);
1096 gzopen_included_file (const char *name
, bool include_cwd
, bool module
)
1100 if (IS_ABSOLUTE_PATH (name
) || include_cwd
)
1102 f
= gzopen (name
, "r");
1103 if (f
&& gfc_cpp_makedep ())
1104 gfc_cpp_add_dep (name
, false);
1108 f
= gzopen_included_file_1 (name
, include_dirs
, module
, false);
1114 gzopen_intrinsic_module (const char* name
)
1118 if (IS_ABSOLUTE_PATH (name
))
1120 f
= gzopen (name
, "r");
1121 if (f
&& gfc_cpp_makedep ())
1122 gfc_cpp_add_dep (name
, true);
1126 f
= gzopen_included_file_1 (name
, intrinsic_modules_dirs
, true, true);
1134 ATOM_NAME
, ATOM_LPAREN
, ATOM_RPAREN
, ATOM_INTEGER
, ATOM_STRING
1137 static atom_type last_atom
;
1140 /* The name buffer must be at least as long as a symbol name. Right
1141 now it's not clear how we're going to store numeric constants--
1142 probably as a hexadecimal string, since this will allow the exact
1143 number to be preserved (this can't be done by a decimal
1144 representation). Worry about that later. TODO! */
1146 #define MAX_ATOM_SIZE 100
1148 static int atom_int
;
1149 static char *atom_string
, atom_name
[MAX_ATOM_SIZE
];
1152 /* Report problems with a module. Error reporting is not very
1153 elaborate, since this sorts of errors shouldn't really happen.
1154 This subroutine never returns. */
1156 static void bad_module (const char *) ATTRIBUTE_NORETURN
;
1159 bad_module (const char *msgid
)
1161 XDELETEVEC (module_content
);
1162 module_content
= NULL
;
1167 gfc_fatal_error ("Reading module %qs at line %d column %d: %s",
1168 module_name
, module_line
, module_column
, msgid
);
1171 gfc_fatal_error ("Writing module %qs at line %d column %d: %s",
1172 module_name
, module_line
, module_column
, msgid
);
1175 gfc_fatal_error ("Module %qs at line %d column %d: %s",
1176 module_name
, module_line
, module_column
, msgid
);
1182 /* Set the module's input pointer. */
1185 set_module_locus (module_locus
*m
)
1187 module_column
= m
->column
;
1188 module_line
= m
->line
;
1189 module_pos
= m
->pos
;
1193 /* Get the module's input pointer so that we can restore it later. */
1196 get_module_locus (module_locus
*m
)
1198 m
->column
= module_column
;
1199 m
->line
= module_line
;
1200 m
->pos
= module_pos
;
1204 /* Get the next character in the module, updating our reckoning of
1210 const char c
= module_content
[module_pos
++];
1212 bad_module ("Unexpected EOF");
1214 prev_module_line
= module_line
;
1215 prev_module_column
= module_column
;
1227 /* Unget a character while remembering the line and column. Works for
1228 a single character only. */
1231 module_unget_char (void)
1233 module_line
= prev_module_line
;
1234 module_column
= prev_module_column
;
1238 /* Parse a string constant. The delimiter is guaranteed to be a
1248 atom_string
= XNEWVEC (char, cursz
);
1256 int c2
= module_char ();
1259 module_unget_char ();
1267 atom_string
= XRESIZEVEC (char, atom_string
, cursz
);
1269 atom_string
[len
] = c
;
1273 atom_string
= XRESIZEVEC (char, atom_string
, len
+ 1);
1274 atom_string
[len
] = '\0'; /* C-style string for debug purposes. */
1278 /* Parse a small integer. */
1281 parse_integer (int c
)
1290 module_unget_char ();
1294 atom_int
= 10 * atom_int
+ c
- '0';
1295 if (atom_int
> 99999999)
1296 bad_module ("Integer overflow");
1318 if (!ISALNUM (c
) && c
!= '_' && c
!= '-')
1320 module_unget_char ();
1325 if (++len
> GFC_MAX_SYMBOL_LEN
)
1326 bad_module ("Name too long");
1334 /* Read the next atom in the module's input stream. */
1345 while (c
== ' ' || c
== '\r' || c
== '\n');
1370 return ATOM_INTEGER
;
1428 bad_module ("Bad name");
1435 /* Peek at the next atom on the input. */
1446 while (c
== ' ' || c
== '\r' || c
== '\n');
1451 module_unget_char ();
1455 module_unget_char ();
1459 module_unget_char ();
1472 module_unget_char ();
1473 return ATOM_INTEGER
;
1527 module_unget_char ();
1531 bad_module ("Bad name");
1536 /* Read the next atom from the input, requiring that it be a
1540 require_atom (atom_type type
)
1546 column
= module_column
;
1555 p
= _("Expected name");
1558 p
= _("Expected left parenthesis");
1561 p
= _("Expected right parenthesis");
1564 p
= _("Expected integer");
1567 p
= _("Expected string");
1570 gfc_internal_error ("require_atom(): bad atom type required");
1573 module_column
= column
;
1580 /* Given a pointer to an mstring array, require that the current input
1581 be one of the strings in the array. We return the enum value. */
1584 find_enum (const mstring
*m
)
1588 i
= gfc_string2code (m
, atom_name
);
1592 bad_module ("find_enum(): Enum not found");
1598 /* Read a string. The caller is responsible for freeing. */
1604 require_atom (ATOM_STRING
);
1611 /**************** Module output subroutines ***************************/
1613 /* Output a character to a module file. */
1616 write_char (char out
)
1618 if (gzputc (module_fp
, out
) == EOF
)
1619 gfc_fatal_error ("Error writing modules file: %s", xstrerror (errno
));
1631 /* Write an atom to a module. The line wrapping isn't perfect, but it
1632 should work most of the time. This isn't that big of a deal, since
1633 the file really isn't meant to be read by people anyway. */
1636 write_atom (atom_type atom
, const void *v
)
1640 /* Workaround -Wmaybe-uninitialized false positive during
1641 profiledbootstrap by initializing them. */
1649 p
= (const char *) v
;
1661 i
= *((const int *) v
);
1663 gfc_internal_error ("write_atom(): Writing negative integer");
1665 sprintf (buffer
, "%d", i
);
1670 gfc_internal_error ("write_atom(): Trying to write dab atom");
1674 if(p
== NULL
|| *p
== '\0')
1679 if (atom
!= ATOM_RPAREN
)
1681 if (module_column
+ len
> 72)
1686 if (last_atom
!= ATOM_LPAREN
&& module_column
!= 1)
1691 if (atom
== ATOM_STRING
)
1694 while (p
!= NULL
&& *p
)
1696 if (atom
== ATOM_STRING
&& *p
== '\'')
1701 if (atom
== ATOM_STRING
)
1709 /***************** Mid-level I/O subroutines *****************/
1711 /* These subroutines let their caller read or write atoms without
1712 caring about which of the two is actually happening. This lets a
1713 subroutine concentrate on the actual format of the data being
1716 static void mio_expr (gfc_expr
**);
1717 pointer_info
*mio_symbol_ref (gfc_symbol
**);
1718 pointer_info
*mio_interface_rest (gfc_interface
**);
1719 static void mio_symtree_ref (gfc_symtree
**);
1721 /* Read or write an enumerated value. On writing, we return the input
1722 value for the convenience of callers. We avoid using an integer
1723 pointer because enums are sometimes inside bitfields. */
1726 mio_name (int t
, const mstring
*m
)
1728 if (iomode
== IO_OUTPUT
)
1729 write_atom (ATOM_NAME
, gfc_code2string (m
, t
));
1732 require_atom (ATOM_NAME
);
1739 /* Specialization of mio_name. */
1741 #define DECL_MIO_NAME(TYPE) \
1742 static inline TYPE \
1743 MIO_NAME(TYPE) (TYPE t, const mstring *m) \
1745 return (TYPE) mio_name ((int) t, m); \
1747 #define MIO_NAME(TYPE) mio_name_##TYPE
1752 if (iomode
== IO_OUTPUT
)
1753 write_atom (ATOM_LPAREN
, NULL
);
1755 require_atom (ATOM_LPAREN
);
1762 if (iomode
== IO_OUTPUT
)
1763 write_atom (ATOM_RPAREN
, NULL
);
1765 require_atom (ATOM_RPAREN
);
1770 mio_integer (int *ip
)
1772 if (iomode
== IO_OUTPUT
)
1773 write_atom (ATOM_INTEGER
, ip
);
1776 require_atom (ATOM_INTEGER
);
1782 /* Read or write a gfc_intrinsic_op value. */
1785 mio_intrinsic_op (gfc_intrinsic_op
* op
)
1787 /* FIXME: Would be nicer to do this via the operators symbolic name. */
1788 if (iomode
== IO_OUTPUT
)
1790 int converted
= (int) *op
;
1791 write_atom (ATOM_INTEGER
, &converted
);
1795 require_atom (ATOM_INTEGER
);
1796 *op
= (gfc_intrinsic_op
) atom_int
;
1801 /* Read or write a character pointer that points to a string on the heap. */
1804 mio_allocated_string (const char *s
)
1806 if (iomode
== IO_OUTPUT
)
1808 write_atom (ATOM_STRING
, s
);
1813 require_atom (ATOM_STRING
);
1819 /* Functions for quoting and unquoting strings. */
1822 quote_string (const gfc_char_t
*s
, const size_t slength
)
1824 const gfc_char_t
*p
;
1828 /* Calculate the length we'll need: a backslash takes two ("\\"),
1829 non-printable characters take 10 ("\Uxxxxxxxx") and others take 1. */
1830 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1834 else if (!gfc_wide_is_printable (*p
))
1840 q
= res
= XCNEWVEC (char, len
+ 1);
1841 for (p
= s
, i
= 0; i
< slength
; p
++, i
++)
1844 *q
++ = '\\', *q
++ = '\\';
1845 else if (!gfc_wide_is_printable (*p
))
1847 sprintf (q
, "\\U%08" HOST_WIDE_INT_PRINT
"x",
1848 (unsigned HOST_WIDE_INT
) *p
);
1852 *q
++ = (unsigned char) *p
;
1860 unquote_string (const char *s
)
1866 for (p
= s
, len
= 0; *p
; p
++, len
++)
1873 else if (p
[1] == 'U')
1874 p
+= 9; /* That is a "\U????????". */
1876 gfc_internal_error ("unquote_string(): got bad string");
1879 res
= gfc_get_wide_string (len
+ 1);
1880 for (i
= 0, p
= s
; i
< len
; i
++, p
++)
1885 res
[i
] = (unsigned char) *p
;
1886 else if (p
[1] == '\\')
1888 res
[i
] = (unsigned char) '\\';
1893 /* We read the 8-digits hexadecimal constant that follows. */
1898 gcc_assert (p
[1] == 'U');
1899 for (j
= 0; j
< 8; j
++)
1902 gcc_assert (sscanf (&p
[j
+2], "%01x", &n
) == 1);
1916 /* Read or write a character pointer that points to a wide string on the
1917 heap, performing quoting/unquoting of nonprintable characters using the
1918 form \U???????? (where each ? is a hexadecimal digit).
1919 Length is the length of the string, only known and used in output mode. */
1921 static const gfc_char_t
*
1922 mio_allocated_wide_string (const gfc_char_t
*s
, const size_t length
)
1924 if (iomode
== IO_OUTPUT
)
1926 char *quoted
= quote_string (s
, length
);
1927 write_atom (ATOM_STRING
, quoted
);
1933 gfc_char_t
*unquoted
;
1935 require_atom (ATOM_STRING
);
1936 unquoted
= unquote_string (atom_string
);
1943 /* Read or write a string that is in static memory. */
1946 mio_pool_string (const char **stringp
)
1948 /* TODO: one could write the string only once, and refer to it via a
1951 /* As a special case we have to deal with a NULL string. This
1952 happens for the 'module' member of 'gfc_symbol's that are not in a
1953 module. We read / write these as the empty string. */
1954 if (iomode
== IO_OUTPUT
)
1956 const char *p
= *stringp
== NULL
? "" : *stringp
;
1957 write_atom (ATOM_STRING
, p
);
1961 require_atom (ATOM_STRING
);
1962 *stringp
= (atom_string
[0] == '\0'
1963 ? NULL
: gfc_get_string ("%s", atom_string
));
1969 /* Read or write a string that is inside of some already-allocated
1973 mio_internal_string (char *string
)
1975 if (iomode
== IO_OUTPUT
)
1976 write_atom (ATOM_STRING
, string
);
1979 require_atom (ATOM_STRING
);
1980 strcpy (string
, atom_string
);
1987 { AB_ALLOCATABLE
, AB_DIMENSION
, AB_EXTERNAL
, AB_INTRINSIC
, AB_OPTIONAL
,
1988 AB_POINTER
, AB_TARGET
, AB_DUMMY
, AB_RESULT
, AB_DATA
,
1989 AB_IN_NAMELIST
, AB_IN_COMMON
, AB_FUNCTION
, AB_SUBROUTINE
, AB_SEQUENCE
,
1990 AB_ELEMENTAL
, AB_PURE
, AB_RECURSIVE
, AB_GENERIC
, AB_ALWAYS_EXPLICIT
,
1991 AB_CRAY_POINTER
, AB_CRAY_POINTEE
, AB_THREADPRIVATE
,
1992 AB_ALLOC_COMP
, AB_POINTER_COMP
, AB_PROC_POINTER_COMP
, AB_PRIVATE_COMP
,
1993 AB_VALUE
, AB_VOLATILE
, AB_PROTECTED
, AB_LOCK_COMP
, AB_EVENT_COMP
,
1994 AB_IS_BIND_C
, AB_IS_C_INTEROP
, AB_IS_ISO_C
, AB_ABSTRACT
, AB_ZERO_COMP
,
1995 AB_IS_CLASS
, AB_PROCEDURE
, AB_PROC_POINTER
, AB_ASYNCHRONOUS
, AB_CODIMENSION
,
1996 AB_COARRAY_COMP
, AB_VTYPE
, AB_VTAB
, AB_CONTIGUOUS
, AB_CLASS_POINTER
,
1997 AB_IMPLICIT_PURE
, AB_ARTIFICIAL
, AB_UNLIMITED_POLY
, AB_OMP_DECLARE_TARGET
,
1998 AB_ARRAY_OUTER_DEPENDENCY
, AB_MODULE_PROCEDURE
, AB_OACC_DECLARE_CREATE
,
1999 AB_OACC_DECLARE_COPYIN
, AB_OACC_DECLARE_DEVICEPTR
,
2000 AB_OACC_DECLARE_DEVICE_RESIDENT
, AB_OACC_DECLARE_LINK
,
2001 AB_OMP_DECLARE_TARGET_LINK
, AB_PDT_KIND
, AB_PDT_LEN
, AB_PDT_TYPE
,
2002 AB_PDT_TEMPLATE
, AB_PDT_ARRAY
, AB_PDT_STRING
2005 static const mstring attr_bits
[] =
2007 minit ("ALLOCATABLE", AB_ALLOCATABLE
),
2008 minit ("ARTIFICIAL", AB_ARTIFICIAL
),
2009 minit ("ASYNCHRONOUS", AB_ASYNCHRONOUS
),
2010 minit ("DIMENSION", AB_DIMENSION
),
2011 minit ("CODIMENSION", AB_CODIMENSION
),
2012 minit ("CONTIGUOUS", AB_CONTIGUOUS
),
2013 minit ("EXTERNAL", AB_EXTERNAL
),
2014 minit ("INTRINSIC", AB_INTRINSIC
),
2015 minit ("OPTIONAL", AB_OPTIONAL
),
2016 minit ("POINTER", AB_POINTER
),
2017 minit ("VOLATILE", AB_VOLATILE
),
2018 minit ("TARGET", AB_TARGET
),
2019 minit ("THREADPRIVATE", AB_THREADPRIVATE
),
2020 minit ("DUMMY", AB_DUMMY
),
2021 minit ("RESULT", AB_RESULT
),
2022 minit ("DATA", AB_DATA
),
2023 minit ("IN_NAMELIST", AB_IN_NAMELIST
),
2024 minit ("IN_COMMON", AB_IN_COMMON
),
2025 minit ("FUNCTION", AB_FUNCTION
),
2026 minit ("SUBROUTINE", AB_SUBROUTINE
),
2027 minit ("SEQUENCE", AB_SEQUENCE
),
2028 minit ("ELEMENTAL", AB_ELEMENTAL
),
2029 minit ("PURE", AB_PURE
),
2030 minit ("RECURSIVE", AB_RECURSIVE
),
2031 minit ("GENERIC", AB_GENERIC
),
2032 minit ("ALWAYS_EXPLICIT", AB_ALWAYS_EXPLICIT
),
2033 minit ("CRAY_POINTER", AB_CRAY_POINTER
),
2034 minit ("CRAY_POINTEE", AB_CRAY_POINTEE
),
2035 minit ("IS_BIND_C", AB_IS_BIND_C
),
2036 minit ("IS_C_INTEROP", AB_IS_C_INTEROP
),
2037 minit ("IS_ISO_C", AB_IS_ISO_C
),
2038 minit ("VALUE", AB_VALUE
),
2039 minit ("ALLOC_COMP", AB_ALLOC_COMP
),
2040 minit ("COARRAY_COMP", AB_COARRAY_COMP
),
2041 minit ("LOCK_COMP", AB_LOCK_COMP
),
2042 minit ("EVENT_COMP", AB_EVENT_COMP
),
2043 minit ("POINTER_COMP", AB_POINTER_COMP
),
2044 minit ("PROC_POINTER_COMP", AB_PROC_POINTER_COMP
),
2045 minit ("PRIVATE_COMP", AB_PRIVATE_COMP
),
2046 minit ("ZERO_COMP", AB_ZERO_COMP
),
2047 minit ("PROTECTED", AB_PROTECTED
),
2048 minit ("ABSTRACT", AB_ABSTRACT
),
2049 minit ("IS_CLASS", AB_IS_CLASS
),
2050 minit ("PROCEDURE", AB_PROCEDURE
),
2051 minit ("PROC_POINTER", AB_PROC_POINTER
),
2052 minit ("VTYPE", AB_VTYPE
),
2053 minit ("VTAB", AB_VTAB
),
2054 minit ("CLASS_POINTER", AB_CLASS_POINTER
),
2055 minit ("IMPLICIT_PURE", AB_IMPLICIT_PURE
),
2056 minit ("UNLIMITED_POLY", AB_UNLIMITED_POLY
),
2057 minit ("OMP_DECLARE_TARGET", AB_OMP_DECLARE_TARGET
),
2058 minit ("ARRAY_OUTER_DEPENDENCY", AB_ARRAY_OUTER_DEPENDENCY
),
2059 minit ("MODULE_PROCEDURE", AB_MODULE_PROCEDURE
),
2060 minit ("OACC_DECLARE_CREATE", AB_OACC_DECLARE_CREATE
),
2061 minit ("OACC_DECLARE_COPYIN", AB_OACC_DECLARE_COPYIN
),
2062 minit ("OACC_DECLARE_DEVICEPTR", AB_OACC_DECLARE_DEVICEPTR
),
2063 minit ("OACC_DECLARE_DEVICE_RESIDENT", AB_OACC_DECLARE_DEVICE_RESIDENT
),
2064 minit ("OACC_DECLARE_LINK", AB_OACC_DECLARE_LINK
),
2065 minit ("OMP_DECLARE_TARGET_LINK", AB_OMP_DECLARE_TARGET_LINK
),
2066 minit ("PDT_KIND", AB_PDT_KIND
),
2067 minit ("PDT_LEN", AB_PDT_LEN
),
2068 minit ("PDT_TYPE", AB_PDT_TYPE
),
2069 minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE
),
2070 minit ("PDT_ARRAY", AB_PDT_ARRAY
),
2071 minit ("PDT_STRING", AB_PDT_STRING
),
2075 /* For binding attributes. */
2076 static const mstring binding_passing
[] =
2079 minit ("NOPASS", 1),
2082 static const mstring binding_overriding
[] =
2084 minit ("OVERRIDABLE", 0),
2085 minit ("NON_OVERRIDABLE", 1),
2086 minit ("DEFERRED", 2),
2089 static const mstring binding_generic
[] =
2091 minit ("SPECIFIC", 0),
2092 minit ("GENERIC", 1),
2095 static const mstring binding_ppc
[] =
2097 minit ("NO_PPC", 0),
2102 /* Specialization of mio_name. */
2103 DECL_MIO_NAME (ab_attribute
)
2104 DECL_MIO_NAME (ar_type
)
2105 DECL_MIO_NAME (array_type
)
2107 DECL_MIO_NAME (expr_t
)
2108 DECL_MIO_NAME (gfc_access
)
2109 DECL_MIO_NAME (gfc_intrinsic_op
)
2110 DECL_MIO_NAME (ifsrc
)
2111 DECL_MIO_NAME (save_state
)
2112 DECL_MIO_NAME (procedure_type
)
2113 DECL_MIO_NAME (ref_type
)
2114 DECL_MIO_NAME (sym_flavor
)
2115 DECL_MIO_NAME (sym_intent
)
2116 #undef DECL_MIO_NAME
2118 /* Symbol attributes are stored in list with the first three elements
2119 being the enumerated fields, while the remaining elements (if any)
2120 indicate the individual attribute bits. The access field is not
2121 saved-- it controls what symbols are exported when a module is
2125 mio_symbol_attribute (symbol_attribute
*attr
)
2128 unsigned ext_attr
,extension_level
;
2132 attr
->flavor
= MIO_NAME (sym_flavor
) (attr
->flavor
, flavors
);
2133 attr
->intent
= MIO_NAME (sym_intent
) (attr
->intent
, intents
);
2134 attr
->proc
= MIO_NAME (procedure_type
) (attr
->proc
, procedures
);
2135 attr
->if_source
= MIO_NAME (ifsrc
) (attr
->if_source
, ifsrc_types
);
2136 attr
->save
= MIO_NAME (save_state
) (attr
->save
, save_status
);
2138 ext_attr
= attr
->ext_attr
;
2139 mio_integer ((int *) &ext_attr
);
2140 attr
->ext_attr
= ext_attr
;
2142 extension_level
= attr
->extension
;
2143 mio_integer ((int *) &extension_level
);
2144 attr
->extension
= extension_level
;
2146 if (iomode
== IO_OUTPUT
)
2148 if (attr
->allocatable
)
2149 MIO_NAME (ab_attribute
) (AB_ALLOCATABLE
, attr_bits
);
2150 if (attr
->artificial
)
2151 MIO_NAME (ab_attribute
) (AB_ARTIFICIAL
, attr_bits
);
2152 if (attr
->asynchronous
)
2153 MIO_NAME (ab_attribute
) (AB_ASYNCHRONOUS
, attr_bits
);
2154 if (attr
->dimension
)
2155 MIO_NAME (ab_attribute
) (AB_DIMENSION
, attr_bits
);
2156 if (attr
->codimension
)
2157 MIO_NAME (ab_attribute
) (AB_CODIMENSION
, attr_bits
);
2158 if (attr
->contiguous
)
2159 MIO_NAME (ab_attribute
) (AB_CONTIGUOUS
, attr_bits
);
2161 MIO_NAME (ab_attribute
) (AB_EXTERNAL
, attr_bits
);
2162 if (attr
->intrinsic
)
2163 MIO_NAME (ab_attribute
) (AB_INTRINSIC
, attr_bits
);
2165 MIO_NAME (ab_attribute
) (AB_OPTIONAL
, attr_bits
);
2167 MIO_NAME (ab_attribute
) (AB_POINTER
, attr_bits
);
2168 if (attr
->class_pointer
)
2169 MIO_NAME (ab_attribute
) (AB_CLASS_POINTER
, attr_bits
);
2170 if (attr
->is_protected
)
2171 MIO_NAME (ab_attribute
) (AB_PROTECTED
, attr_bits
);
2173 MIO_NAME (ab_attribute
) (AB_VALUE
, attr_bits
);
2174 if (attr
->volatile_
)
2175 MIO_NAME (ab_attribute
) (AB_VOLATILE
, attr_bits
);
2177 MIO_NAME (ab_attribute
) (AB_TARGET
, attr_bits
);
2178 if (attr
->threadprivate
)
2179 MIO_NAME (ab_attribute
) (AB_THREADPRIVATE
, attr_bits
);
2181 MIO_NAME (ab_attribute
) (AB_DUMMY
, attr_bits
);
2183 MIO_NAME (ab_attribute
) (AB_RESULT
, attr_bits
);
2184 /* We deliberately don't preserve the "entry" flag. */
2187 MIO_NAME (ab_attribute
) (AB_DATA
, attr_bits
);
2188 if (attr
->in_namelist
)
2189 MIO_NAME (ab_attribute
) (AB_IN_NAMELIST
, attr_bits
);
2190 if (attr
->in_common
)
2191 MIO_NAME (ab_attribute
) (AB_IN_COMMON
, attr_bits
);
2194 MIO_NAME (ab_attribute
) (AB_FUNCTION
, attr_bits
);
2195 if (attr
->subroutine
)
2196 MIO_NAME (ab_attribute
) (AB_SUBROUTINE
, attr_bits
);
2198 MIO_NAME (ab_attribute
) (AB_GENERIC
, attr_bits
);
2200 MIO_NAME (ab_attribute
) (AB_ABSTRACT
, attr_bits
);
2203 MIO_NAME (ab_attribute
) (AB_SEQUENCE
, attr_bits
);
2204 if (attr
->elemental
)
2205 MIO_NAME (ab_attribute
) (AB_ELEMENTAL
, attr_bits
);
2207 MIO_NAME (ab_attribute
) (AB_PURE
, attr_bits
);
2208 if (attr
->implicit_pure
)
2209 MIO_NAME (ab_attribute
) (AB_IMPLICIT_PURE
, attr_bits
);
2210 if (attr
->unlimited_polymorphic
)
2211 MIO_NAME (ab_attribute
) (AB_UNLIMITED_POLY
, attr_bits
);
2212 if (attr
->recursive
)
2213 MIO_NAME (ab_attribute
) (AB_RECURSIVE
, attr_bits
);
2214 if (attr
->always_explicit
)
2215 MIO_NAME (ab_attribute
) (AB_ALWAYS_EXPLICIT
, attr_bits
);
2216 if (attr
->cray_pointer
)
2217 MIO_NAME (ab_attribute
) (AB_CRAY_POINTER
, attr_bits
);
2218 if (attr
->cray_pointee
)
2219 MIO_NAME (ab_attribute
) (AB_CRAY_POINTEE
, attr_bits
);
2220 if (attr
->is_bind_c
)
2221 MIO_NAME(ab_attribute
) (AB_IS_BIND_C
, attr_bits
);
2222 if (attr
->is_c_interop
)
2223 MIO_NAME(ab_attribute
) (AB_IS_C_INTEROP
, attr_bits
);
2225 MIO_NAME(ab_attribute
) (AB_IS_ISO_C
, attr_bits
);
2226 if (attr
->alloc_comp
)
2227 MIO_NAME (ab_attribute
) (AB_ALLOC_COMP
, attr_bits
);
2228 if (attr
->pointer_comp
)
2229 MIO_NAME (ab_attribute
) (AB_POINTER_COMP
, attr_bits
);
2230 if (attr
->proc_pointer_comp
)
2231 MIO_NAME (ab_attribute
) (AB_PROC_POINTER_COMP
, attr_bits
);
2232 if (attr
->private_comp
)
2233 MIO_NAME (ab_attribute
) (AB_PRIVATE_COMP
, attr_bits
);
2234 if (attr
->coarray_comp
)
2235 MIO_NAME (ab_attribute
) (AB_COARRAY_COMP
, attr_bits
);
2236 if (attr
->lock_comp
)
2237 MIO_NAME (ab_attribute
) (AB_LOCK_COMP
, attr_bits
);
2238 if (attr
->event_comp
)
2239 MIO_NAME (ab_attribute
) (AB_EVENT_COMP
, attr_bits
);
2240 if (attr
->zero_comp
)
2241 MIO_NAME (ab_attribute
) (AB_ZERO_COMP
, attr_bits
);
2243 MIO_NAME (ab_attribute
) (AB_IS_CLASS
, attr_bits
);
2244 if (attr
->procedure
)
2245 MIO_NAME (ab_attribute
) (AB_PROCEDURE
, attr_bits
);
2246 if (attr
->proc_pointer
)
2247 MIO_NAME (ab_attribute
) (AB_PROC_POINTER
, attr_bits
);
2249 MIO_NAME (ab_attribute
) (AB_VTYPE
, attr_bits
);
2251 MIO_NAME (ab_attribute
) (AB_VTAB
, attr_bits
);
2252 if (attr
->omp_declare_target
)
2253 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET
, attr_bits
);
2254 if (attr
->array_outer_dependency
)
2255 MIO_NAME (ab_attribute
) (AB_ARRAY_OUTER_DEPENDENCY
, attr_bits
);
2256 if (attr
->module_procedure
)
2257 MIO_NAME (ab_attribute
) (AB_MODULE_PROCEDURE
, attr_bits
);
2258 if (attr
->oacc_declare_create
)
2259 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_CREATE
, attr_bits
);
2260 if (attr
->oacc_declare_copyin
)
2261 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_COPYIN
, attr_bits
);
2262 if (attr
->oacc_declare_deviceptr
)
2263 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICEPTR
, attr_bits
);
2264 if (attr
->oacc_declare_device_resident
)
2265 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_DEVICE_RESIDENT
, attr_bits
);
2266 if (attr
->oacc_declare_link
)
2267 MIO_NAME (ab_attribute
) (AB_OACC_DECLARE_LINK
, attr_bits
);
2268 if (attr
->omp_declare_target_link
)
2269 MIO_NAME (ab_attribute
) (AB_OMP_DECLARE_TARGET_LINK
, attr_bits
);
2271 MIO_NAME (ab_attribute
) (AB_PDT_KIND
, attr_bits
);
2273 MIO_NAME (ab_attribute
) (AB_PDT_LEN
, attr_bits
);
2275 MIO_NAME (ab_attribute
) (AB_PDT_TYPE
, attr_bits
);
2276 if (attr
->pdt_template
)
2277 MIO_NAME (ab_attribute
) (AB_PDT_TEMPLATE
, attr_bits
);
2278 if (attr
->pdt_array
)
2279 MIO_NAME (ab_attribute
) (AB_PDT_ARRAY
, attr_bits
);
2280 if (attr
->pdt_string
)
2281 MIO_NAME (ab_attribute
) (AB_PDT_STRING
, attr_bits
);
2291 if (t
== ATOM_RPAREN
)
2294 bad_module ("Expected attribute bit name");
2296 switch ((ab_attribute
) find_enum (attr_bits
))
2298 case AB_ALLOCATABLE
:
2299 attr
->allocatable
= 1;
2302 attr
->artificial
= 1;
2304 case AB_ASYNCHRONOUS
:
2305 attr
->asynchronous
= 1;
2308 attr
->dimension
= 1;
2310 case AB_CODIMENSION
:
2311 attr
->codimension
= 1;
2314 attr
->contiguous
= 1;
2320 attr
->intrinsic
= 1;
2328 case AB_CLASS_POINTER
:
2329 attr
->class_pointer
= 1;
2332 attr
->is_protected
= 1;
2338 attr
->volatile_
= 1;
2343 case AB_THREADPRIVATE
:
2344 attr
->threadprivate
= 1;
2355 case AB_IN_NAMELIST
:
2356 attr
->in_namelist
= 1;
2359 attr
->in_common
= 1;
2365 attr
->subroutine
= 1;
2377 attr
->elemental
= 1;
2382 case AB_IMPLICIT_PURE
:
2383 attr
->implicit_pure
= 1;
2385 case AB_UNLIMITED_POLY
:
2386 attr
->unlimited_polymorphic
= 1;
2389 attr
->recursive
= 1;
2391 case AB_ALWAYS_EXPLICIT
:
2392 attr
->always_explicit
= 1;
2394 case AB_CRAY_POINTER
:
2395 attr
->cray_pointer
= 1;
2397 case AB_CRAY_POINTEE
:
2398 attr
->cray_pointee
= 1;
2401 attr
->is_bind_c
= 1;
2403 case AB_IS_C_INTEROP
:
2404 attr
->is_c_interop
= 1;
2410 attr
->alloc_comp
= 1;
2412 case AB_COARRAY_COMP
:
2413 attr
->coarray_comp
= 1;
2416 attr
->lock_comp
= 1;
2419 attr
->event_comp
= 1;
2421 case AB_POINTER_COMP
:
2422 attr
->pointer_comp
= 1;
2424 case AB_PROC_POINTER_COMP
:
2425 attr
->proc_pointer_comp
= 1;
2427 case AB_PRIVATE_COMP
:
2428 attr
->private_comp
= 1;
2431 attr
->zero_comp
= 1;
2437 attr
->procedure
= 1;
2439 case AB_PROC_POINTER
:
2440 attr
->proc_pointer
= 1;
2448 case AB_OMP_DECLARE_TARGET
:
2449 attr
->omp_declare_target
= 1;
2451 case AB_OMP_DECLARE_TARGET_LINK
:
2452 attr
->omp_declare_target_link
= 1;
2454 case AB_ARRAY_OUTER_DEPENDENCY
:
2455 attr
->array_outer_dependency
=1;
2457 case AB_MODULE_PROCEDURE
:
2458 attr
->module_procedure
=1;
2460 case AB_OACC_DECLARE_CREATE
:
2461 attr
->oacc_declare_create
= 1;
2463 case AB_OACC_DECLARE_COPYIN
:
2464 attr
->oacc_declare_copyin
= 1;
2466 case AB_OACC_DECLARE_DEVICEPTR
:
2467 attr
->oacc_declare_deviceptr
= 1;
2469 case AB_OACC_DECLARE_DEVICE_RESIDENT
:
2470 attr
->oacc_declare_device_resident
= 1;
2472 case AB_OACC_DECLARE_LINK
:
2473 attr
->oacc_declare_link
= 1;
2484 case AB_PDT_TEMPLATE
:
2485 attr
->pdt_template
= 1;
2488 attr
->pdt_array
= 1;
2491 attr
->pdt_string
= 1;
2499 static const mstring bt_types
[] = {
2500 minit ("INTEGER", BT_INTEGER
),
2501 minit ("REAL", BT_REAL
),
2502 minit ("COMPLEX", BT_COMPLEX
),
2503 minit ("LOGICAL", BT_LOGICAL
),
2504 minit ("CHARACTER", BT_CHARACTER
),
2505 minit ("UNION", BT_UNION
),
2506 minit ("DERIVED", BT_DERIVED
),
2507 minit ("CLASS", BT_CLASS
),
2508 minit ("PROCEDURE", BT_PROCEDURE
),
2509 minit ("UNKNOWN", BT_UNKNOWN
),
2510 minit ("VOID", BT_VOID
),
2511 minit ("ASSUMED", BT_ASSUMED
),
2517 mio_charlen (gfc_charlen
**clp
)
2523 if (iomode
== IO_OUTPUT
)
2527 mio_expr (&cl
->length
);
2531 if (peek_atom () != ATOM_RPAREN
)
2533 cl
= gfc_new_charlen (gfc_current_ns
, NULL
);
2534 mio_expr (&cl
->length
);
2543 /* See if a name is a generated name. */
2546 check_unique_name (const char *name
)
2548 return *name
== '@';
2553 mio_typespec (gfc_typespec
*ts
)
2557 ts
->type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2559 if (!gfc_bt_struct (ts
->type
) && ts
->type
!= BT_CLASS
)
2560 mio_integer (&ts
->kind
);
2562 mio_symbol_ref (&ts
->u
.derived
);
2564 mio_symbol_ref (&ts
->interface
);
2566 /* Add info for C interop and is_iso_c. */
2567 mio_integer (&ts
->is_c_interop
);
2568 mio_integer (&ts
->is_iso_c
);
2570 /* If the typespec is for an identifier either from iso_c_binding, or
2571 a constant that was initialized to an identifier from it, use the
2572 f90_type. Otherwise, use the ts->type, since it shouldn't matter. */
2574 ts
->f90_type
= MIO_NAME (bt
) (ts
->f90_type
, bt_types
);
2576 ts
->f90_type
= MIO_NAME (bt
) (ts
->type
, bt_types
);
2578 if (ts
->type
!= BT_CHARACTER
)
2580 /* ts->u.cl is only valid for BT_CHARACTER. */
2585 mio_charlen (&ts
->u
.cl
);
2587 /* So as not to disturb the existing API, use an ATOM_NAME to
2588 transmit deferred characteristic for characters (F2003). */
2589 if (iomode
== IO_OUTPUT
)
2591 if (ts
->type
== BT_CHARACTER
&& ts
->deferred
)
2592 write_atom (ATOM_NAME
, "DEFERRED_CL");
2594 else if (peek_atom () != ATOM_RPAREN
)
2596 if (parse_atom () != ATOM_NAME
)
2597 bad_module ("Expected string");
2605 static const mstring array_spec_types
[] = {
2606 minit ("EXPLICIT", AS_EXPLICIT
),
2607 minit ("ASSUMED_RANK", AS_ASSUMED_RANK
),
2608 minit ("ASSUMED_SHAPE", AS_ASSUMED_SHAPE
),
2609 minit ("DEFERRED", AS_DEFERRED
),
2610 minit ("ASSUMED_SIZE", AS_ASSUMED_SIZE
),
2616 mio_array_spec (gfc_array_spec
**asp
)
2623 if (iomode
== IO_OUTPUT
)
2631 /* mio_integer expects nonnegative values. */
2632 rank
= as
->rank
> 0 ? as
->rank
: 0;
2633 mio_integer (&rank
);
2637 if (peek_atom () == ATOM_RPAREN
)
2643 *asp
= as
= gfc_get_array_spec ();
2644 mio_integer (&as
->rank
);
2647 mio_integer (&as
->corank
);
2648 as
->type
= MIO_NAME (array_type
) (as
->type
, array_spec_types
);
2650 if (iomode
== IO_INPUT
&& as
->type
== AS_ASSUMED_RANK
)
2652 if (iomode
== IO_INPUT
&& as
->corank
)
2653 as
->cotype
= (as
->type
== AS_DEFERRED
) ? AS_DEFERRED
: AS_EXPLICIT
;
2655 if (as
->rank
+ as
->corank
> 0)
2656 for (i
= 0; i
< as
->rank
+ as
->corank
; i
++)
2658 mio_expr (&as
->lower
[i
]);
2659 mio_expr (&as
->upper
[i
]);
2667 /* Given a pointer to an array reference structure (which lives in a
2668 gfc_ref structure), find the corresponding array specification
2669 structure. Storing the pointer in the ref structure doesn't quite
2670 work when loading from a module. Generating code for an array
2671 reference also needs more information than just the array spec. */
2673 static const mstring array_ref_types
[] = {
2674 minit ("FULL", AR_FULL
),
2675 minit ("ELEMENT", AR_ELEMENT
),
2676 minit ("SECTION", AR_SECTION
),
2682 mio_array_ref (gfc_array_ref
*ar
)
2687 ar
->type
= MIO_NAME (ar_type
) (ar
->type
, array_ref_types
);
2688 mio_integer (&ar
->dimen
);
2696 for (i
= 0; i
< ar
->dimen
; i
++)
2697 mio_expr (&ar
->start
[i
]);
2702 for (i
= 0; i
< ar
->dimen
; i
++)
2704 mio_expr (&ar
->start
[i
]);
2705 mio_expr (&ar
->end
[i
]);
2706 mio_expr (&ar
->stride
[i
]);
2712 gfc_internal_error ("mio_array_ref(): Unknown array ref");
2715 /* Unfortunately, ar->dimen_type is an anonymous enumerated type so
2716 we can't call mio_integer directly. Instead loop over each element
2717 and cast it to/from an integer. */
2718 if (iomode
== IO_OUTPUT
)
2720 for (i
= 0; i
< ar
->dimen
; i
++)
2722 int tmp
= (int)ar
->dimen_type
[i
];
2723 write_atom (ATOM_INTEGER
, &tmp
);
2728 for (i
= 0; i
< ar
->dimen
; i
++)
2730 require_atom (ATOM_INTEGER
);
2731 ar
->dimen_type
[i
] = (enum gfc_array_ref_dimen_type
) atom_int
;
2735 if (iomode
== IO_INPUT
)
2737 ar
->where
= gfc_current_locus
;
2739 for (i
= 0; i
< ar
->dimen
; i
++)
2740 ar
->c_where
[i
] = gfc_current_locus
;
2747 /* Saves or restores a pointer. The pointer is converted back and
2748 forth from an integer. We return the pointer_info pointer so that
2749 the caller can take additional action based on the pointer type. */
2751 static pointer_info
*
2752 mio_pointer_ref (void *gp
)
2756 if (iomode
== IO_OUTPUT
)
2758 p
= get_pointer (*((char **) gp
));
2759 write_atom (ATOM_INTEGER
, &p
->integer
);
2763 require_atom (ATOM_INTEGER
);
2764 p
= add_fixup (atom_int
, gp
);
2771 /* Save and load references to components that occur within
2772 expressions. We have to describe these references by a number and
2773 by name. The number is necessary for forward references during
2774 reading, and the name is necessary if the symbol already exists in
2775 the namespace and is not loaded again. */
2778 mio_component_ref (gfc_component
**cp
)
2782 p
= mio_pointer_ref (cp
);
2783 if (p
->type
== P_UNKNOWN
)
2784 p
->type
= P_COMPONENT
;
2788 static void mio_namespace_ref (gfc_namespace
**nsp
);
2789 static void mio_formal_arglist (gfc_formal_arglist
**formal
);
2790 static void mio_typebound_proc (gfc_typebound_proc
** proc
);
2793 mio_component (gfc_component
*c
, int vtype
)
2800 if (iomode
== IO_OUTPUT
)
2802 p
= get_pointer (c
);
2803 mio_integer (&p
->integer
);
2808 p
= get_integer (n
);
2809 associate_integer_pointer (p
, c
);
2812 if (p
->type
== P_UNKNOWN
)
2813 p
->type
= P_COMPONENT
;
2815 mio_pool_string (&c
->name
);
2816 mio_typespec (&c
->ts
);
2817 mio_array_spec (&c
->as
);
2819 /* PDT templates store the expression for the kind of a component here. */
2820 mio_expr (&c
->kind_expr
);
2822 mio_symbol_attribute (&c
->attr
);
2823 if (c
->ts
.type
== BT_CLASS
)
2824 c
->attr
.class_ok
= 1;
2825 c
->attr
.access
= MIO_NAME (gfc_access
) (c
->attr
.access
, access_types
);
2827 if (!vtype
|| strcmp (c
->name
, "_final") == 0
2828 || strcmp (c
->name
, "_hash") == 0)
2829 mio_expr (&c
->initializer
);
2831 if (c
->attr
.proc_pointer
)
2832 mio_typebound_proc (&c
->tb
);
2839 mio_component_list (gfc_component
**cp
, int vtype
)
2841 gfc_component
*c
, *tail
;
2845 if (iomode
== IO_OUTPUT
)
2847 for (c
= *cp
; c
; c
= c
->next
)
2848 mio_component (c
, vtype
);
2857 if (peek_atom () == ATOM_RPAREN
)
2860 c
= gfc_get_component ();
2861 mio_component (c
, vtype
);
2877 mio_actual_arg (gfc_actual_arglist
*a
)
2880 mio_pool_string (&a
->name
);
2881 mio_expr (&a
->expr
);
2887 mio_actual_arglist (gfc_actual_arglist
**ap
)
2889 gfc_actual_arglist
*a
, *tail
;
2893 if (iomode
== IO_OUTPUT
)
2895 for (a
= *ap
; a
; a
= a
->next
)
2905 if (peek_atom () != ATOM_LPAREN
)
2908 a
= gfc_get_actual_arglist ();
2924 /* Read and write formal argument lists. */
2927 mio_formal_arglist (gfc_formal_arglist
**formal
)
2929 gfc_formal_arglist
*f
, *tail
;
2933 if (iomode
== IO_OUTPUT
)
2935 for (f
= *formal
; f
; f
= f
->next
)
2936 mio_symbol_ref (&f
->sym
);
2940 *formal
= tail
= NULL
;
2942 while (peek_atom () != ATOM_RPAREN
)
2944 f
= gfc_get_formal_arglist ();
2945 mio_symbol_ref (&f
->sym
);
2947 if (*formal
== NULL
)
2960 /* Save or restore a reference to a symbol node. */
2963 mio_symbol_ref (gfc_symbol
**symp
)
2967 p
= mio_pointer_ref (symp
);
2968 if (p
->type
== P_UNKNOWN
)
2971 if (iomode
== IO_OUTPUT
)
2973 if (p
->u
.wsym
.state
== UNREFERENCED
)
2974 p
->u
.wsym
.state
= NEEDS_WRITE
;
2978 if (p
->u
.rsym
.state
== UNUSED
)
2979 p
->u
.rsym
.state
= NEEDED
;
2985 /* Save or restore a reference to a symtree node. */
2988 mio_symtree_ref (gfc_symtree
**stp
)
2993 if (iomode
== IO_OUTPUT
)
2994 mio_symbol_ref (&(*stp
)->n
.sym
);
2997 require_atom (ATOM_INTEGER
);
2998 p
= get_integer (atom_int
);
3000 /* An unused equivalence member; make a symbol and a symtree
3002 if (in_load_equiv
&& p
->u
.rsym
.symtree
== NULL
)
3004 /* Since this is not used, it must have a unique name. */
3005 p
->u
.rsym
.symtree
= gfc_get_unique_symtree (gfc_current_ns
);
3007 /* Make the symbol. */
3008 if (p
->u
.rsym
.sym
== NULL
)
3010 p
->u
.rsym
.sym
= gfc_new_symbol (p
->u
.rsym
.true_name
,
3012 p
->u
.rsym
.sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
3015 p
->u
.rsym
.symtree
->n
.sym
= p
->u
.rsym
.sym
;
3016 p
->u
.rsym
.symtree
->n
.sym
->refs
++;
3017 p
->u
.rsym
.referenced
= 1;
3019 /* If the symbol is PRIVATE and in COMMON, load_commons will
3020 generate a fixup symbol, which must be associated. */
3022 resolve_fixups (p
->fixup
, p
->u
.rsym
.sym
);
3026 if (p
->type
== P_UNKNOWN
)
3029 if (p
->u
.rsym
.state
== UNUSED
)
3030 p
->u
.rsym
.state
= NEEDED
;
3032 if (p
->u
.rsym
.symtree
!= NULL
)
3034 *stp
= p
->u
.rsym
.symtree
;
3038 f
= XCNEW (fixup_t
);
3040 f
->next
= p
->u
.rsym
.stfixup
;
3041 p
->u
.rsym
.stfixup
= f
;
3043 f
->pointer
= (void **) stp
;
3050 mio_iterator (gfc_iterator
**ip
)
3056 if (iomode
== IO_OUTPUT
)
3063 if (peek_atom () == ATOM_RPAREN
)
3069 *ip
= gfc_get_iterator ();
3074 mio_expr (&iter
->var
);
3075 mio_expr (&iter
->start
);
3076 mio_expr (&iter
->end
);
3077 mio_expr (&iter
->step
);
3085 mio_constructor (gfc_constructor_base
*cp
)
3091 if (iomode
== IO_OUTPUT
)
3093 for (c
= gfc_constructor_first (*cp
); c
; c
= gfc_constructor_next (c
))
3096 mio_expr (&c
->expr
);
3097 mio_iterator (&c
->iterator
);
3103 while (peek_atom () != ATOM_RPAREN
)
3105 c
= gfc_constructor_append_expr (cp
, NULL
, NULL
);
3108 mio_expr (&c
->expr
);
3109 mio_iterator (&c
->iterator
);
3118 static const mstring ref_types
[] = {
3119 minit ("ARRAY", REF_ARRAY
),
3120 minit ("COMPONENT", REF_COMPONENT
),
3121 minit ("SUBSTRING", REF_SUBSTRING
),
3127 mio_ref (gfc_ref
**rp
)
3134 r
->type
= MIO_NAME (ref_type
) (r
->type
, ref_types
);
3139 mio_array_ref (&r
->u
.ar
);
3143 mio_symbol_ref (&r
->u
.c
.sym
);
3144 mio_component_ref (&r
->u
.c
.component
);
3148 mio_expr (&r
->u
.ss
.start
);
3149 mio_expr (&r
->u
.ss
.end
);
3150 mio_charlen (&r
->u
.ss
.length
);
3159 mio_ref_list (gfc_ref
**rp
)
3161 gfc_ref
*ref
, *head
, *tail
;
3165 if (iomode
== IO_OUTPUT
)
3167 for (ref
= *rp
; ref
; ref
= ref
->next
)
3174 while (peek_atom () != ATOM_RPAREN
)
3177 head
= tail
= gfc_get_ref ();
3180 tail
->next
= gfc_get_ref ();
3194 /* Read and write an integer value. */
3197 mio_gmp_integer (mpz_t
*integer
)
3201 if (iomode
== IO_INPUT
)
3203 if (parse_atom () != ATOM_STRING
)
3204 bad_module ("Expected integer string");
3206 mpz_init (*integer
);
3207 if (mpz_set_str (*integer
, atom_string
, 10))
3208 bad_module ("Error converting integer");
3214 p
= mpz_get_str (NULL
, 10, *integer
);
3215 write_atom (ATOM_STRING
, p
);
3222 mio_gmp_real (mpfr_t
*real
)
3227 if (iomode
== IO_INPUT
)
3229 if (parse_atom () != ATOM_STRING
)
3230 bad_module ("Expected real string");
3233 mpfr_set_str (*real
, atom_string
, 16, GFC_RND_MODE
);
3238 p
= mpfr_get_str (NULL
, &exponent
, 16, 0, *real
, GFC_RND_MODE
);
3240 if (mpfr_nan_p (*real
) || mpfr_inf_p (*real
))
3242 write_atom (ATOM_STRING
, p
);
3247 atom_string
= XCNEWVEC (char, strlen (p
) + 20);
3249 sprintf (atom_string
, "0.%s@%ld", p
, exponent
);
3251 /* Fix negative numbers. */
3252 if (atom_string
[2] == '-')
3254 atom_string
[0] = '-';
3255 atom_string
[1] = '0';
3256 atom_string
[2] = '.';
3259 write_atom (ATOM_STRING
, atom_string
);
3267 /* Save and restore the shape of an array constructor. */
3270 mio_shape (mpz_t
**pshape
, int rank
)
3276 /* A NULL shape is represented by (). */
3279 if (iomode
== IO_OUTPUT
)
3291 if (t
== ATOM_RPAREN
)
3298 shape
= gfc_get_shape (rank
);
3302 for (n
= 0; n
< rank
; n
++)
3303 mio_gmp_integer (&shape
[n
]);
3309 static const mstring expr_types
[] = {
3310 minit ("OP", EXPR_OP
),
3311 minit ("FUNCTION", EXPR_FUNCTION
),
3312 minit ("CONSTANT", EXPR_CONSTANT
),
3313 minit ("VARIABLE", EXPR_VARIABLE
),
3314 minit ("SUBSTRING", EXPR_SUBSTRING
),
3315 minit ("STRUCTURE", EXPR_STRUCTURE
),
3316 minit ("ARRAY", EXPR_ARRAY
),
3317 minit ("NULL", EXPR_NULL
),
3318 minit ("COMPCALL", EXPR_COMPCALL
),
3322 /* INTRINSIC_ASSIGN is missing because it is used as an index for
3323 generic operators, not in expressions. INTRINSIC_USER is also
3324 replaced by the correct function name by the time we see it. */
3326 static const mstring intrinsics
[] =
3328 minit ("UPLUS", INTRINSIC_UPLUS
),
3329 minit ("UMINUS", INTRINSIC_UMINUS
),
3330 minit ("PLUS", INTRINSIC_PLUS
),
3331 minit ("MINUS", INTRINSIC_MINUS
),
3332 minit ("TIMES", INTRINSIC_TIMES
),
3333 minit ("DIVIDE", INTRINSIC_DIVIDE
),
3334 minit ("POWER", INTRINSIC_POWER
),
3335 minit ("CONCAT", INTRINSIC_CONCAT
),
3336 minit ("AND", INTRINSIC_AND
),
3337 minit ("OR", INTRINSIC_OR
),
3338 minit ("EQV", INTRINSIC_EQV
),
3339 minit ("NEQV", INTRINSIC_NEQV
),
3340 minit ("EQ_SIGN", INTRINSIC_EQ
),
3341 minit ("EQ", INTRINSIC_EQ_OS
),
3342 minit ("NE_SIGN", INTRINSIC_NE
),
3343 minit ("NE", INTRINSIC_NE_OS
),
3344 minit ("GT_SIGN", INTRINSIC_GT
),
3345 minit ("GT", INTRINSIC_GT_OS
),
3346 minit ("GE_SIGN", INTRINSIC_GE
),
3347 minit ("GE", INTRINSIC_GE_OS
),
3348 minit ("LT_SIGN", INTRINSIC_LT
),
3349 minit ("LT", INTRINSIC_LT_OS
),
3350 minit ("LE_SIGN", INTRINSIC_LE
),
3351 minit ("LE", INTRINSIC_LE_OS
),
3352 minit ("NOT", INTRINSIC_NOT
),
3353 minit ("PARENTHESES", INTRINSIC_PARENTHESES
),
3354 minit ("USER", INTRINSIC_USER
),
3359 /* Remedy a couple of situations where the gfc_expr's can be defective. */
3362 fix_mio_expr (gfc_expr
*e
)
3364 gfc_symtree
*ns_st
= NULL
;
3367 if (iomode
!= IO_OUTPUT
)
3372 /* If this is a symtree for a symbol that came from a contained module
3373 namespace, it has a unique name and we should look in the current
3374 namespace to see if the required, non-contained symbol is available
3375 yet. If so, the latter should be written. */
3376 if (e
->symtree
->n
.sym
&& check_unique_name (e
->symtree
->name
))
3378 const char *name
= e
->symtree
->n
.sym
->name
;
3379 if (gfc_fl_struct (e
->symtree
->n
.sym
->attr
.flavor
))
3380 name
= gfc_dt_upper_string (name
);
3381 ns_st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
3384 /* On the other hand, if the existing symbol is the module name or the
3385 new symbol is a dummy argument, do not do the promotion. */
3386 if (ns_st
&& ns_st
->n
.sym
3387 && ns_st
->n
.sym
->attr
.flavor
!= FL_MODULE
3388 && !e
->symtree
->n
.sym
->attr
.dummy
)
3391 else if (e
->expr_type
== EXPR_FUNCTION
3392 && (e
->value
.function
.name
|| e
->value
.function
.isym
))
3396 /* In some circumstances, a function used in an initialization
3397 expression, in one use associated module, can fail to be
3398 coupled to its symtree when used in a specification
3399 expression in another module. */
3400 fname
= e
->value
.function
.esym
? e
->value
.function
.esym
->name
3401 : e
->value
.function
.isym
->name
;
3402 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3407 /* This is probably a reference to a private procedure from another
3408 module. To prevent a segfault, make a generic with no specific
3409 instances. If this module is used, without the required
3410 specific coming from somewhere, the appropriate error message
3412 gfc_get_symbol (fname
, gfc_current_ns
, &sym
);
3413 sym
->attr
.flavor
= FL_PROCEDURE
;
3414 sym
->attr
.generic
= 1;
3415 e
->symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, fname
);
3416 gfc_commit_symbol (sym
);
3421 /* Read and write expressions. The form "()" is allowed to indicate a
3425 mio_expr (gfc_expr
**ep
)
3433 if (iomode
== IO_OUTPUT
)
3442 MIO_NAME (expr_t
) (e
->expr_type
, expr_types
);
3447 if (t
== ATOM_RPAREN
)
3454 bad_module ("Expected expression type");
3456 e
= *ep
= gfc_get_expr ();
3457 e
->where
= gfc_current_locus
;
3458 e
->expr_type
= (expr_t
) find_enum (expr_types
);
3461 mio_typespec (&e
->ts
);
3462 mio_integer (&e
->rank
);
3466 switch (e
->expr_type
)
3470 = MIO_NAME (gfc_intrinsic_op
) (e
->value
.op
.op
, intrinsics
);
3472 switch (e
->value
.op
.op
)
3474 case INTRINSIC_UPLUS
:
3475 case INTRINSIC_UMINUS
:
3477 case INTRINSIC_PARENTHESES
:
3478 mio_expr (&e
->value
.op
.op1
);
3481 case INTRINSIC_PLUS
:
3482 case INTRINSIC_MINUS
:
3483 case INTRINSIC_TIMES
:
3484 case INTRINSIC_DIVIDE
:
3485 case INTRINSIC_POWER
:
3486 case INTRINSIC_CONCAT
:
3490 case INTRINSIC_NEQV
:
3492 case INTRINSIC_EQ_OS
:
3494 case INTRINSIC_NE_OS
:
3496 case INTRINSIC_GT_OS
:
3498 case INTRINSIC_GE_OS
:
3500 case INTRINSIC_LT_OS
:
3502 case INTRINSIC_LE_OS
:
3503 mio_expr (&e
->value
.op
.op1
);
3504 mio_expr (&e
->value
.op
.op2
);
3507 case INTRINSIC_USER
:
3508 /* INTRINSIC_USER should not appear in resolved expressions,
3509 though for UDRs we need to stream unresolved ones. */
3510 if (iomode
== IO_OUTPUT
)
3511 write_atom (ATOM_STRING
, e
->value
.op
.uop
->name
);
3514 char *name
= read_string ();
3515 const char *uop_name
= find_use_name (name
, true);
3516 if (uop_name
== NULL
)
3518 size_t len
= strlen (name
);
3519 char *name2
= XCNEWVEC (char, len
+ 2);
3520 memcpy (name2
, name
, len
);
3522 name2
[len
+ 1] = '\0';
3524 uop_name
= name
= name2
;
3526 e
->value
.op
.uop
= gfc_get_uop (uop_name
);
3529 mio_expr (&e
->value
.op
.op1
);
3530 mio_expr (&e
->value
.op
.op2
);
3534 bad_module ("Bad operator");
3540 mio_symtree_ref (&e
->symtree
);
3541 mio_actual_arglist (&e
->value
.function
.actual
);
3543 if (iomode
== IO_OUTPUT
)
3545 e
->value
.function
.name
3546 = mio_allocated_string (e
->value
.function
.name
);
3547 if (e
->value
.function
.esym
)
3551 else if (e
->value
.function
.isym
== NULL
)
3555 mio_integer (&flag
);
3559 mio_symbol_ref (&e
->value
.function
.esym
);
3562 mio_ref_list (&e
->ref
);
3567 write_atom (ATOM_STRING
, e
->value
.function
.isym
->name
);
3572 require_atom (ATOM_STRING
);
3573 if (atom_string
[0] == '\0')
3574 e
->value
.function
.name
= NULL
;
3576 e
->value
.function
.name
= gfc_get_string ("%s", atom_string
);
3579 mio_integer (&flag
);
3583 mio_symbol_ref (&e
->value
.function
.esym
);
3586 mio_ref_list (&e
->ref
);
3591 require_atom (ATOM_STRING
);
3592 e
->value
.function
.isym
= gfc_find_function (atom_string
);
3600 mio_symtree_ref (&e
->symtree
);
3601 mio_ref_list (&e
->ref
);
3604 case EXPR_SUBSTRING
:
3605 e
->value
.character
.string
3606 = CONST_CAST (gfc_char_t
*,
3607 mio_allocated_wide_string (e
->value
.character
.string
,
3608 e
->value
.character
.length
));
3609 mio_ref_list (&e
->ref
);
3612 case EXPR_STRUCTURE
:
3614 mio_constructor (&e
->value
.constructor
);
3615 mio_shape (&e
->shape
, e
->rank
);
3622 mio_gmp_integer (&e
->value
.integer
);
3626 gfc_set_model_kind (e
->ts
.kind
);
3627 mio_gmp_real (&e
->value
.real
);
3631 gfc_set_model_kind (e
->ts
.kind
);
3632 mio_gmp_real (&mpc_realref (e
->value
.complex));
3633 mio_gmp_real (&mpc_imagref (e
->value
.complex));
3637 mio_integer (&e
->value
.logical
);
3641 mio_integer (&e
->value
.character
.length
);
3642 e
->value
.character
.string
3643 = CONST_CAST (gfc_char_t
*,
3644 mio_allocated_wide_string (e
->value
.character
.string
,
3645 e
->value
.character
.length
));
3649 bad_module ("Bad type in constant expression");
3667 /* Read and write namelists. */
3670 mio_namelist (gfc_symbol
*sym
)
3672 gfc_namelist
*n
, *m
;
3673 const char *check_name
;
3677 if (iomode
== IO_OUTPUT
)
3679 for (n
= sym
->namelist
; n
; n
= n
->next
)
3680 mio_symbol_ref (&n
->sym
);
3684 /* This departure from the standard is flagged as an error.
3685 It does, in fact, work correctly. TODO: Allow it
3687 if (sym
->attr
.flavor
== FL_NAMELIST
)
3689 check_name
= find_use_name (sym
->name
, false);
3690 if (check_name
&& strcmp (check_name
, sym
->name
) != 0)
3691 gfc_error ("Namelist %s cannot be renamed by USE "
3692 "association to %s", sym
->name
, check_name
);
3696 while (peek_atom () != ATOM_RPAREN
)
3698 n
= gfc_get_namelist ();
3699 mio_symbol_ref (&n
->sym
);
3701 if (sym
->namelist
== NULL
)
3708 sym
->namelist_tail
= m
;
3715 /* Save/restore lists of gfc_interface structures. When loading an
3716 interface, we are really appending to the existing list of
3717 interfaces. Checking for duplicate and ambiguous interfaces has to
3718 be done later when all symbols have been loaded. */
3721 mio_interface_rest (gfc_interface
**ip
)
3723 gfc_interface
*tail
, *p
;
3724 pointer_info
*pi
= NULL
;
3726 if (iomode
== IO_OUTPUT
)
3729 for (p
= *ip
; p
; p
= p
->next
)
3730 mio_symbol_ref (&p
->sym
);
3745 if (peek_atom () == ATOM_RPAREN
)
3748 p
= gfc_get_interface ();
3749 p
->where
= gfc_current_locus
;
3750 pi
= mio_symbol_ref (&p
->sym
);
3766 /* Save/restore a nameless operator interface. */
3769 mio_interface (gfc_interface
**ip
)
3772 mio_interface_rest (ip
);
3776 /* Save/restore a named operator interface. */
3779 mio_symbol_interface (const char **name
, const char **module
,
3783 mio_pool_string (name
);
3784 mio_pool_string (module
);
3785 mio_interface_rest (ip
);
3790 mio_namespace_ref (gfc_namespace
**nsp
)
3795 p
= mio_pointer_ref (nsp
);
3797 if (p
->type
== P_UNKNOWN
)
3798 p
->type
= P_NAMESPACE
;
3800 if (iomode
== IO_INPUT
&& p
->integer
!= 0)
3802 ns
= (gfc_namespace
*) p
->u
.pointer
;
3805 ns
= gfc_get_namespace (NULL
, 0);
3806 associate_integer_pointer (p
, ns
);
3814 /* Save/restore the f2k_derived namespace of a derived-type symbol. */
3816 static gfc_namespace
* current_f2k_derived
;
3819 mio_typebound_proc (gfc_typebound_proc
** proc
)
3822 int overriding_flag
;
3824 if (iomode
== IO_INPUT
)
3826 *proc
= gfc_get_typebound_proc (NULL
);
3827 (*proc
)->where
= gfc_current_locus
;
3833 (*proc
)->access
= MIO_NAME (gfc_access
) ((*proc
)->access
, access_types
);
3835 /* IO the NON_OVERRIDABLE/DEFERRED combination. */
3836 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
3837 overriding_flag
= ((*proc
)->deferred
<< 1) | (*proc
)->non_overridable
;
3838 overriding_flag
= mio_name (overriding_flag
, binding_overriding
);
3839 (*proc
)->deferred
= ((overriding_flag
& 2) != 0);
3840 (*proc
)->non_overridable
= ((overriding_flag
& 1) != 0);
3841 gcc_assert (!((*proc
)->deferred
&& (*proc
)->non_overridable
));
3843 (*proc
)->nopass
= mio_name ((*proc
)->nopass
, binding_passing
);
3844 (*proc
)->is_generic
= mio_name ((*proc
)->is_generic
, binding_generic
);
3845 (*proc
)->ppc
= mio_name((*proc
)->ppc
, binding_ppc
);
3847 mio_pool_string (&((*proc
)->pass_arg
));
3849 flag
= (int) (*proc
)->pass_arg_num
;
3850 mio_integer (&flag
);
3851 (*proc
)->pass_arg_num
= (unsigned) flag
;
3853 if ((*proc
)->is_generic
)
3860 if (iomode
== IO_OUTPUT
)
3861 for (g
= (*proc
)->u
.generic
; g
; g
= g
->next
)
3863 iop
= (int) g
->is_operator
;
3865 mio_allocated_string (g
->specific_st
->name
);
3869 (*proc
)->u
.generic
= NULL
;
3870 while (peek_atom () != ATOM_RPAREN
)
3872 gfc_symtree
** sym_root
;
3874 g
= gfc_get_tbp_generic ();
3878 g
->is_operator
= (bool) iop
;
3880 require_atom (ATOM_STRING
);
3881 sym_root
= ¤t_f2k_derived
->tb_sym_root
;
3882 g
->specific_st
= gfc_get_tbp_symtree (sym_root
, atom_string
);
3885 g
->next
= (*proc
)->u
.generic
;
3886 (*proc
)->u
.generic
= g
;
3892 else if (!(*proc
)->ppc
)
3893 mio_symtree_ref (&(*proc
)->u
.specific
);
3898 /* Walker-callback function for this purpose. */
3900 mio_typebound_symtree (gfc_symtree
* st
)
3902 if (iomode
== IO_OUTPUT
&& !st
->n
.tb
)
3905 if (iomode
== IO_OUTPUT
)
3908 mio_allocated_string (st
->name
);
3910 /* For IO_INPUT, the above is done in mio_f2k_derived. */
3912 mio_typebound_proc (&st
->n
.tb
);
3916 /* IO a full symtree (in all depth). */
3918 mio_full_typebound_tree (gfc_symtree
** root
)
3922 if (iomode
== IO_OUTPUT
)
3923 gfc_traverse_symtree (*root
, &mio_typebound_symtree
);
3926 while (peek_atom () == ATOM_LPAREN
)
3932 require_atom (ATOM_STRING
);
3933 st
= gfc_get_tbp_symtree (root
, atom_string
);
3936 mio_typebound_symtree (st
);
3944 mio_finalizer (gfc_finalizer
**f
)
3946 if (iomode
== IO_OUTPUT
)
3949 gcc_assert ((*f
)->proc_tree
); /* Should already be resolved. */
3950 mio_symtree_ref (&(*f
)->proc_tree
);
3954 *f
= gfc_get_finalizer ();
3955 (*f
)->where
= gfc_current_locus
; /* Value should not matter. */
3958 mio_symtree_ref (&(*f
)->proc_tree
);
3959 (*f
)->proc_sym
= NULL
;
3964 mio_f2k_derived (gfc_namespace
*f2k
)
3966 current_f2k_derived
= f2k
;
3968 /* Handle the list of finalizer procedures. */
3970 if (iomode
== IO_OUTPUT
)
3973 for (f
= f2k
->finalizers
; f
; f
= f
->next
)
3978 f2k
->finalizers
= NULL
;
3979 while (peek_atom () != ATOM_RPAREN
)
3981 gfc_finalizer
*cur
= NULL
;
3982 mio_finalizer (&cur
);
3983 cur
->next
= f2k
->finalizers
;
3984 f2k
->finalizers
= cur
;
3989 /* Handle type-bound procedures. */
3990 mio_full_typebound_tree (&f2k
->tb_sym_root
);
3992 /* Type-bound user operators. */
3993 mio_full_typebound_tree (&f2k
->tb_uop_root
);
3995 /* Type-bound intrinsic operators. */
3997 if (iomode
== IO_OUTPUT
)
4000 for (op
= GFC_INTRINSIC_BEGIN
; op
!= GFC_INTRINSIC_END
; ++op
)
4002 gfc_intrinsic_op realop
;
4004 if (op
== INTRINSIC_USER
|| !f2k
->tb_op
[op
])
4008 realop
= (gfc_intrinsic_op
) op
;
4009 mio_intrinsic_op (&realop
);
4010 mio_typebound_proc (&f2k
->tb_op
[op
]);
4015 while (peek_atom () != ATOM_RPAREN
)
4017 gfc_intrinsic_op op
= GFC_INTRINSIC_BEGIN
; /* Silence GCC. */
4020 mio_intrinsic_op (&op
);
4021 mio_typebound_proc (&f2k
->tb_op
[op
]);
4028 mio_full_f2k_derived (gfc_symbol
*sym
)
4032 if (iomode
== IO_OUTPUT
)
4034 if (sym
->f2k_derived
)
4035 mio_f2k_derived (sym
->f2k_derived
);
4039 if (peek_atom () != ATOM_RPAREN
)
4043 sym
->f2k_derived
= gfc_get_namespace (NULL
, 0);
4045 /* PDT templates make use of the mechanisms for formal args
4046 and so the parameter symbols are stored in the formal
4047 namespace. Transfer the sym_root to f2k_derived and then
4048 free the formal namespace since it is uneeded. */
4049 if (sym
->attr
.pdt_template
&& sym
->formal
&& sym
->formal
->sym
)
4051 ns
= sym
->formal
->sym
->ns
;
4052 sym
->f2k_derived
->sym_root
= ns
->sym_root
;
4053 ns
->sym_root
= NULL
;
4055 gfc_free_namespace (ns
);
4059 mio_f2k_derived (sym
->f2k_derived
);
4062 gcc_assert (!sym
->f2k_derived
);
4068 static const mstring omp_declare_simd_clauses
[] =
4070 minit ("INBRANCH", 0),
4071 minit ("NOTINBRANCH", 1),
4072 minit ("SIMDLEN", 2),
4073 minit ("UNIFORM", 3),
4074 minit ("LINEAR", 4),
4075 minit ("ALIGNED", 5),
4079 /* Handle !$omp declare simd. */
4082 mio_omp_declare_simd (gfc_namespace
*ns
, gfc_omp_declare_simd
**odsp
)
4084 if (iomode
== IO_OUTPUT
)
4089 else if (peek_atom () != ATOM_LPAREN
)
4092 gfc_omp_declare_simd
*ods
= *odsp
;
4095 if (iomode
== IO_OUTPUT
)
4097 write_atom (ATOM_NAME
, "OMP_DECLARE_SIMD");
4100 gfc_omp_namelist
*n
;
4102 if (ods
->clauses
->inbranch
)
4103 mio_name (0, omp_declare_simd_clauses
);
4104 if (ods
->clauses
->notinbranch
)
4105 mio_name (1, omp_declare_simd_clauses
);
4106 if (ods
->clauses
->simdlen_expr
)
4108 mio_name (2, omp_declare_simd_clauses
);
4109 mio_expr (&ods
->clauses
->simdlen_expr
);
4111 for (n
= ods
->clauses
->lists
[OMP_LIST_UNIFORM
]; n
; n
= n
->next
)
4113 mio_name (3, omp_declare_simd_clauses
);
4114 mio_symbol_ref (&n
->sym
);
4116 for (n
= ods
->clauses
->lists
[OMP_LIST_LINEAR
]; n
; n
= n
->next
)
4118 mio_name (4, omp_declare_simd_clauses
);
4119 mio_symbol_ref (&n
->sym
);
4120 mio_expr (&n
->expr
);
4122 for (n
= ods
->clauses
->lists
[OMP_LIST_ALIGNED
]; n
; n
= n
->next
)
4124 mio_name (5, omp_declare_simd_clauses
);
4125 mio_symbol_ref (&n
->sym
);
4126 mio_expr (&n
->expr
);
4132 gfc_omp_namelist
**ptrs
[3] = { NULL
, NULL
, NULL
};
4134 require_atom (ATOM_NAME
);
4135 *odsp
= ods
= gfc_get_omp_declare_simd ();
4136 ods
->where
= gfc_current_locus
;
4137 ods
->proc_name
= ns
->proc_name
;
4138 if (peek_atom () == ATOM_NAME
)
4140 ods
->clauses
= gfc_get_omp_clauses ();
4141 ptrs
[0] = &ods
->clauses
->lists
[OMP_LIST_UNIFORM
];
4142 ptrs
[1] = &ods
->clauses
->lists
[OMP_LIST_LINEAR
];
4143 ptrs
[2] = &ods
->clauses
->lists
[OMP_LIST_ALIGNED
];
4145 while (peek_atom () == ATOM_NAME
)
4147 gfc_omp_namelist
*n
;
4148 int t
= mio_name (0, omp_declare_simd_clauses
);
4152 case 0: ods
->clauses
->inbranch
= true; break;
4153 case 1: ods
->clauses
->notinbranch
= true; break;
4154 case 2: mio_expr (&ods
->clauses
->simdlen_expr
); break;
4158 *ptrs
[t
- 3] = n
= gfc_get_omp_namelist ();
4159 ptrs
[t
- 3] = &n
->next
;
4160 mio_symbol_ref (&n
->sym
);
4162 mio_expr (&n
->expr
);
4168 mio_omp_declare_simd (ns
, &ods
->next
);
4174 static const mstring omp_declare_reduction_stmt
[] =
4176 minit ("ASSIGN", 0),
4183 mio_omp_udr_expr (gfc_omp_udr
*udr
, gfc_symbol
**sym1
, gfc_symbol
**sym2
,
4184 gfc_namespace
*ns
, bool is_initializer
)
4186 if (iomode
== IO_OUTPUT
)
4188 if ((*sym1
)->module
== NULL
)
4190 (*sym1
)->module
= module_name
;
4191 (*sym2
)->module
= module_name
;
4193 mio_symbol_ref (sym1
);
4194 mio_symbol_ref (sym2
);
4195 if (ns
->code
->op
== EXEC_ASSIGN
)
4197 mio_name (0, omp_declare_reduction_stmt
);
4198 mio_expr (&ns
->code
->expr1
);
4199 mio_expr (&ns
->code
->expr2
);
4204 mio_name (1, omp_declare_reduction_stmt
);
4205 mio_symtree_ref (&ns
->code
->symtree
);
4206 mio_actual_arglist (&ns
->code
->ext
.actual
);
4208 flag
= ns
->code
->resolved_isym
!= NULL
;
4209 mio_integer (&flag
);
4211 write_atom (ATOM_STRING
, ns
->code
->resolved_isym
->name
);
4213 mio_symbol_ref (&ns
->code
->resolved_sym
);
4218 pointer_info
*p1
= mio_symbol_ref (sym1
);
4219 pointer_info
*p2
= mio_symbol_ref (sym2
);
4221 gcc_assert (p1
->u
.rsym
.ns
== p2
->u
.rsym
.ns
);
4222 gcc_assert (p1
->u
.rsym
.sym
== NULL
);
4223 /* Add hidden symbols to the symtree. */
4224 pointer_info
*q
= get_integer (p1
->u
.rsym
.ns
);
4225 q
->u
.pointer
= (void *) ns
;
4226 sym
= gfc_new_symbol (is_initializer
? "omp_priv" : "omp_out", ns
);
4228 sym
->module
= gfc_get_string ("%s", p1
->u
.rsym
.module
);
4229 associate_integer_pointer (p1
, sym
);
4230 sym
->attr
.omp_udr_artificial_var
= 1;
4231 gcc_assert (p2
->u
.rsym
.sym
== NULL
);
4232 sym
= gfc_new_symbol (is_initializer
? "omp_orig" : "omp_in", ns
);
4234 sym
->module
= gfc_get_string ("%s", p2
->u
.rsym
.module
);
4235 associate_integer_pointer (p2
, sym
);
4236 sym
->attr
.omp_udr_artificial_var
= 1;
4237 if (mio_name (0, omp_declare_reduction_stmt
) == 0)
4239 ns
->code
= gfc_get_code (EXEC_ASSIGN
);
4240 mio_expr (&ns
->code
->expr1
);
4241 mio_expr (&ns
->code
->expr2
);
4246 ns
->code
= gfc_get_code (EXEC_CALL
);
4247 mio_symtree_ref (&ns
->code
->symtree
);
4248 mio_actual_arglist (&ns
->code
->ext
.actual
);
4250 mio_integer (&flag
);
4253 require_atom (ATOM_STRING
);
4254 ns
->code
->resolved_isym
= gfc_find_subroutine (atom_string
);
4258 mio_symbol_ref (&ns
->code
->resolved_sym
);
4260 ns
->code
->loc
= gfc_current_locus
;
4266 /* Unlike most other routines, the address of the symbol node is already
4267 fixed on input and the name/module has already been filled in.
4268 If you update the symbol format here, don't forget to update read_module
4269 as well (look for "seek to the symbol's component list"). */
4272 mio_symbol (gfc_symbol
*sym
)
4274 int intmod
= INTMOD_NONE
;
4278 mio_symbol_attribute (&sym
->attr
);
4280 /* Note that components are always saved, even if they are supposed
4281 to be private. Component access is checked during searching. */
4282 mio_component_list (&sym
->components
, sym
->attr
.vtype
);
4283 if (sym
->components
!= NULL
)
4284 sym
->component_access
4285 = MIO_NAME (gfc_access
) (sym
->component_access
, access_types
);
4287 mio_typespec (&sym
->ts
);
4288 if (sym
->ts
.type
== BT_CLASS
)
4289 sym
->attr
.class_ok
= 1;
4291 if (iomode
== IO_OUTPUT
)
4292 mio_namespace_ref (&sym
->formal_ns
);
4295 mio_namespace_ref (&sym
->formal_ns
);
4297 sym
->formal_ns
->proc_name
= sym
;
4300 /* Save/restore common block links. */
4301 mio_symbol_ref (&sym
->common_next
);
4303 mio_formal_arglist (&sym
->formal
);
4305 if (sym
->attr
.flavor
== FL_PARAMETER
)
4306 mio_expr (&sym
->value
);
4308 mio_array_spec (&sym
->as
);
4310 mio_symbol_ref (&sym
->result
);
4312 if (sym
->attr
.cray_pointee
)
4313 mio_symbol_ref (&sym
->cp_pointer
);
4315 /* Load/save the f2k_derived namespace of a derived-type symbol. */
4316 mio_full_f2k_derived (sym
);
4320 /* Add the fields that say whether this is from an intrinsic module,
4321 and if so, what symbol it is within the module. */
4322 /* mio_integer (&(sym->from_intmod)); */
4323 if (iomode
== IO_OUTPUT
)
4325 intmod
= sym
->from_intmod
;
4326 mio_integer (&intmod
);
4330 mio_integer (&intmod
);
4332 sym
->from_intmod
= current_intmod
;
4334 sym
->from_intmod
= (intmod_id
) intmod
;
4337 mio_integer (&(sym
->intmod_sym_id
));
4339 if (gfc_fl_struct (sym
->attr
.flavor
))
4340 mio_integer (&(sym
->hash_value
));
4343 && sym
->formal_ns
->proc_name
== sym
4344 && sym
->formal_ns
->entries
== NULL
)
4345 mio_omp_declare_simd (sym
->formal_ns
, &sym
->formal_ns
->omp_declare_simd
);
4351 /************************* Top level subroutines *************************/
4353 /* A recursive function to look for a specific symbol by name and by
4354 module. Whilst several symtrees might point to one symbol, its
4355 is sufficient for the purposes here than one exist. Note that
4356 generic interfaces are distinguished as are symbols that have been
4357 renamed in another module. */
4358 static gfc_symtree
*
4359 find_symbol (gfc_symtree
*st
, const char *name
,
4360 const char *module
, int generic
)
4363 gfc_symtree
*retval
, *s
;
4365 if (st
== NULL
|| st
->n
.sym
== NULL
)
4368 c
= strcmp (name
, st
->n
.sym
->name
);
4369 if (c
== 0 && st
->n
.sym
->module
4370 && strcmp (module
, st
->n
.sym
->module
) == 0
4371 && !check_unique_name (st
->name
))
4373 s
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
4375 /* Detect symbols that are renamed by use association in another
4376 module by the absence of a symtree and null attr.use_rename,
4377 since the latter is not transmitted in the module file. */
4378 if (((!generic
&& !st
->n
.sym
->attr
.generic
)
4379 || (generic
&& st
->n
.sym
->attr
.generic
))
4380 && !(s
== NULL
&& !st
->n
.sym
->attr
.use_rename
))
4384 retval
= find_symbol (st
->left
, name
, module
, generic
);
4387 retval
= find_symbol (st
->right
, name
, module
, generic
);
4393 /* Skip a list between balanced left and right parens.
4394 By setting NEST_LEVEL one assumes that a number of NEST_LEVEL opening parens
4395 have been already parsed by hand, and the remaining of the content is to be
4396 skipped here. The default value is 0 (balanced parens). */
4399 skip_list (int nest_level
= 0)
4406 switch (parse_atom ())
4429 /* Load operator interfaces from the module. Interfaces are unusual
4430 in that they attach themselves to existing symbols. */
4433 load_operator_interfaces (void)
4436 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[GFC_MAX_SYMBOL_LEN
+ 1];
4438 pointer_info
*pi
= NULL
;
4443 while (peek_atom () != ATOM_RPAREN
)
4447 mio_internal_string (name
);
4448 mio_internal_string (module
);
4450 n
= number_use_names (name
, true);
4453 for (i
= 1; i
<= n
; i
++)
4455 /* Decide if we need to load this one or not. */
4456 p
= find_use_name_n (name
, &i
, true);
4460 while (parse_atom () != ATOM_RPAREN
);
4466 uop
= gfc_get_uop (p
);
4467 pi
= mio_interface_rest (&uop
->op
);
4471 if (gfc_find_uop (p
, NULL
))
4473 uop
= gfc_get_uop (p
);
4474 uop
->op
= gfc_get_interface ();
4475 uop
->op
->where
= gfc_current_locus
;
4476 add_fixup (pi
->integer
, &uop
->op
->sym
);
4485 /* Load interfaces from the module. Interfaces are unusual in that
4486 they attach themselves to existing symbols. */
4489 load_generic_interfaces (void)
4492 char name
[GFC_MAX_SYMBOL_LEN
+ 1], module
[GFC_MAX_SYMBOL_LEN
+ 1];
4494 gfc_interface
*generic
= NULL
, *gen
= NULL
;
4496 bool ambiguous_set
= false;
4500 while (peek_atom () != ATOM_RPAREN
)
4504 mio_internal_string (name
);
4505 mio_internal_string (module
);
4507 n
= number_use_names (name
, false);
4508 renamed
= n
? 1 : 0;
4511 for (i
= 1; i
<= n
; i
++)
4514 /* Decide if we need to load this one or not. */
4515 p
= find_use_name_n (name
, &i
, false);
4517 st
= find_symbol (gfc_current_ns
->sym_root
,
4518 name
, module_name
, 1);
4520 if (!p
|| gfc_find_symbol (p
, NULL
, 0, &sym
))
4522 /* Skip the specific names for these cases. */
4523 while (i
== 1 && parse_atom () != ATOM_RPAREN
);
4528 /* If the symbol exists already and is being USEd without being
4529 in an ONLY clause, do not load a new symtree(11.3.2). */
4530 if (!only_flag
&& st
)
4538 if (strcmp (st
->name
, p
) != 0)
4540 st
= gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
4546 /* Since we haven't found a valid generic interface, we had
4550 gfc_get_symbol (p
, NULL
, &sym
);
4551 sym
->name
= gfc_get_string ("%s", name
);
4552 sym
->module
= module_name
;
4553 sym
->attr
.flavor
= FL_PROCEDURE
;
4554 sym
->attr
.generic
= 1;
4555 sym
->attr
.use_assoc
= 1;
4560 /* Unless sym is a generic interface, this reference
4563 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
4567 if (st
&& !sym
->attr
.generic
4570 && strcmp (module
, sym
->module
))
4572 ambiguous_set
= true;
4577 sym
->attr
.use_only
= only_flag
;
4578 sym
->attr
.use_rename
= renamed
;
4582 mio_interface_rest (&sym
->generic
);
4583 generic
= sym
->generic
;
4585 else if (!sym
->generic
)
4587 sym
->generic
= generic
;
4588 sym
->attr
.generic_copy
= 1;
4591 /* If a procedure that is not generic has generic interfaces
4592 that include itself, it is generic! We need to take care
4593 to retain symbols ambiguous that were already so. */
4594 if (sym
->attr
.use_assoc
4595 && !sym
->attr
.generic
4596 && sym
->attr
.flavor
== FL_PROCEDURE
)
4598 for (gen
= generic
; gen
; gen
= gen
->next
)
4600 if (gen
->sym
== sym
)
4602 sym
->attr
.generic
= 1;
4617 /* Load common blocks. */
4622 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4627 while (peek_atom () != ATOM_RPAREN
)
4632 mio_internal_string (name
);
4634 p
= gfc_get_common (name
, 1);
4636 mio_symbol_ref (&p
->head
);
4637 mio_integer (&flags
);
4641 p
->threadprivate
= 1;
4644 /* Get whether this was a bind(c) common or not. */
4645 mio_integer (&p
->is_bind_c
);
4646 /* Get the binding label. */
4647 label
= read_string ();
4649 p
->binding_label
= IDENTIFIER_POINTER (get_identifier (label
));
4659 /* Load equivalences. The flag in_load_equiv informs mio_expr_ref of this
4660 so that unused variables are not loaded and so that the expression can
4666 gfc_equiv
*head
, *tail
, *end
, *eq
, *equiv
;
4670 in_load_equiv
= true;
4672 end
= gfc_current_ns
->equiv
;
4673 while (end
!= NULL
&& end
->next
!= NULL
)
4676 while (peek_atom () != ATOM_RPAREN
) {
4680 while(peek_atom () != ATOM_RPAREN
)
4683 head
= tail
= gfc_get_equiv ();
4686 tail
->eq
= gfc_get_equiv ();
4690 mio_pool_string (&tail
->module
);
4691 mio_expr (&tail
->expr
);
4694 /* Check for duplicate equivalences being loaded from different modules */
4696 for (equiv
= gfc_current_ns
->equiv
; equiv
; equiv
= equiv
->next
)
4698 if (equiv
->module
&& head
->module
4699 && strcmp (equiv
->module
, head
->module
) == 0)
4708 for (eq
= head
; eq
; eq
= head
)
4711 gfc_free_expr (eq
->expr
);
4717 gfc_current_ns
->equiv
= head
;
4728 in_load_equiv
= false;
4732 /* This function loads OpenMP user defined reductions. */
4734 load_omp_udrs (void)
4737 while (peek_atom () != ATOM_RPAREN
)
4739 const char *name
= NULL
, *newname
;
4743 gfc_omp_reduction_op rop
= OMP_REDUCTION_USER
;
4746 mio_pool_string (&name
);
4749 if (strncmp (name
, "operator ", sizeof ("operator ") - 1) == 0)
4751 const char *p
= name
+ sizeof ("operator ") - 1;
4752 if (strcmp (p
, "+") == 0)
4753 rop
= OMP_REDUCTION_PLUS
;
4754 else if (strcmp (p
, "*") == 0)
4755 rop
= OMP_REDUCTION_TIMES
;
4756 else if (strcmp (p
, "-") == 0)
4757 rop
= OMP_REDUCTION_MINUS
;
4758 else if (strcmp (p
, ".and.") == 0)
4759 rop
= OMP_REDUCTION_AND
;
4760 else if (strcmp (p
, ".or.") == 0)
4761 rop
= OMP_REDUCTION_OR
;
4762 else if (strcmp (p
, ".eqv.") == 0)
4763 rop
= OMP_REDUCTION_EQV
;
4764 else if (strcmp (p
, ".neqv.") == 0)
4765 rop
= OMP_REDUCTION_NEQV
;
4768 if (rop
== OMP_REDUCTION_USER
&& name
[0] == '.')
4770 size_t len
= strlen (name
+ 1);
4771 altname
= XALLOCAVEC (char, len
);
4772 gcc_assert (name
[len
] == '.');
4773 memcpy (altname
, name
+ 1, len
- 1);
4774 altname
[len
- 1] = '\0';
4777 if (rop
== OMP_REDUCTION_USER
)
4778 newname
= find_use_name (altname
? altname
: name
, !!altname
);
4779 else if (only_flag
&& find_use_operator ((gfc_intrinsic_op
) rop
) == NULL
)
4781 if (newname
== NULL
)
4786 if (altname
&& newname
!= altname
)
4788 size_t len
= strlen (newname
);
4789 altname
= XALLOCAVEC (char, len
+ 3);
4791 memcpy (altname
+ 1, newname
, len
);
4792 altname
[len
+ 1] = '.';
4793 altname
[len
+ 2] = '\0';
4794 name
= gfc_get_string ("%s", altname
);
4796 st
= gfc_find_symtree (gfc_current_ns
->omp_udr_root
, name
);
4797 gfc_omp_udr
*udr
= gfc_omp_udr_find (st
, &ts
);
4800 require_atom (ATOM_INTEGER
);
4801 pointer_info
*p
= get_integer (atom_int
);
4802 if (strcmp (p
->u
.rsym
.module
, udr
->omp_out
->module
))
4804 gfc_error ("Ambiguous !$OMP DECLARE REDUCTION from "
4806 p
->u
.rsym
.module
, &gfc_current_locus
);
4807 gfc_error ("Previous !$OMP DECLARE REDUCTION from module "
4809 udr
->omp_out
->module
, &udr
->where
);
4814 udr
= gfc_get_omp_udr ();
4818 udr
->where
= gfc_current_locus
;
4819 udr
->combiner_ns
= gfc_get_namespace (gfc_current_ns
, 1);
4820 udr
->combiner_ns
->proc_name
= gfc_current_ns
->proc_name
;
4821 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
,
4823 if (peek_atom () != ATOM_RPAREN
)
4825 udr
->initializer_ns
= gfc_get_namespace (gfc_current_ns
, 1);
4826 udr
->initializer_ns
->proc_name
= gfc_current_ns
->proc_name
;
4827 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
4828 udr
->initializer_ns
, true);
4832 udr
->next
= st
->n
.omp_udr
;
4833 st
->n
.omp_udr
= udr
;
4837 st
= gfc_new_symtree (&gfc_current_ns
->omp_udr_root
, name
);
4838 st
->n
.omp_udr
= udr
;
4846 /* Recursive function to traverse the pointer_info tree and load a
4847 needed symbol. We return nonzero if we load a symbol and stop the
4848 traversal, because the act of loading can alter the tree. */
4851 load_needed (pointer_info
*p
)
4862 rv
|= load_needed (p
->left
);
4863 rv
|= load_needed (p
->right
);
4865 if (p
->type
!= P_SYMBOL
|| p
->u
.rsym
.state
!= NEEDED
)
4868 p
->u
.rsym
.state
= USED
;
4870 set_module_locus (&p
->u
.rsym
.where
);
4872 sym
= p
->u
.rsym
.sym
;
4875 q
= get_integer (p
->u
.rsym
.ns
);
4877 ns
= (gfc_namespace
*) q
->u
.pointer
;
4880 /* Create an interface namespace if necessary. These are
4881 the namespaces that hold the formal parameters of module
4884 ns
= gfc_get_namespace (NULL
, 0);
4885 associate_integer_pointer (q
, ns
);
4888 /* Use the module sym as 'proc_name' so that gfc_get_symbol_decl
4889 doesn't go pear-shaped if the symbol is used. */
4891 gfc_find_symbol (p
->u
.rsym
.module
, gfc_current_ns
,
4894 sym
= gfc_new_symbol (p
->u
.rsym
.true_name
, ns
);
4895 sym
->name
= gfc_dt_lower_string (p
->u
.rsym
.true_name
);
4896 sym
->module
= gfc_get_string ("%s", p
->u
.rsym
.module
);
4897 if (p
->u
.rsym
.binding_label
)
4898 sym
->binding_label
= IDENTIFIER_POINTER (get_identifier
4899 (p
->u
.rsym
.binding_label
));
4901 associate_integer_pointer (p
, sym
);
4905 sym
->attr
.use_assoc
= 1;
4907 /* Unliked derived types, a STRUCTURE may share names with other symbols.
4908 We greedily converted the the symbol name to lowercase before we knew its
4909 type, so now we must fix it. */
4910 if (sym
->attr
.flavor
== FL_STRUCT
)
4911 sym
->name
= gfc_dt_upper_string (sym
->name
);
4913 /* Mark as only or rename for later diagnosis for explicitly imported
4914 but not used warnings; don't mark internal symbols such as __vtab,
4915 __def_init etc. Only mark them if they have been explicitly loaded. */
4917 if (only_flag
&& sym
->name
[0] != '_' && sym
->name
[1] != '_')
4921 /* Search the use/rename list for the variable; if the variable is
4923 for (u
= gfc_rename_list
; u
; u
= u
->next
)
4925 if (strcmp (u
->use_name
, sym
->name
) == 0)
4927 sym
->attr
.use_only
= 1;
4933 if (p
->u
.rsym
.renamed
)
4934 sym
->attr
.use_rename
= 1;
4940 /* Recursive function for cleaning up things after a module has been read. */
4943 read_cleanup (pointer_info
*p
)
4951 read_cleanup (p
->left
);
4952 read_cleanup (p
->right
);
4954 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== USED
&& !p
->u
.rsym
.referenced
)
4957 /* Add hidden symbols to the symtree. */
4958 q
= get_integer (p
->u
.rsym
.ns
);
4959 ns
= (gfc_namespace
*) q
->u
.pointer
;
4961 if (!p
->u
.rsym
.sym
->attr
.vtype
4962 && !p
->u
.rsym
.sym
->attr
.vtab
)
4963 st
= gfc_get_unique_symtree (ns
);
4966 /* There is no reason to use 'unique_symtrees' for vtabs or
4967 vtypes - their name is fine for a symtree and reduces the
4968 namespace pollution. */
4969 st
= gfc_find_symtree (ns
->sym_root
, p
->u
.rsym
.sym
->name
);
4971 st
= gfc_new_symtree (&ns
->sym_root
, p
->u
.rsym
.sym
->name
);
4974 st
->n
.sym
= p
->u
.rsym
.sym
;
4977 /* Fixup any symtree references. */
4978 p
->u
.rsym
.symtree
= st
;
4979 resolve_fixups (p
->u
.rsym
.stfixup
, st
);
4980 p
->u
.rsym
.stfixup
= NULL
;
4983 /* Free unused symbols. */
4984 if (p
->type
== P_SYMBOL
&& p
->u
.rsym
.state
== UNUSED
)
4985 gfc_free_symbol (p
->u
.rsym
.sym
);
4989 /* It is not quite enough to check for ambiguity in the symbols by
4990 the loaded symbol and the new symbol not being identical. */
4992 check_for_ambiguous (gfc_symtree
*st
, pointer_info
*info
)
4996 symbol_attribute attr
;
4999 if (gfc_current_ns
->proc_name
&& st
->name
== gfc_current_ns
->proc_name
->name
)
5001 gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
5002 "current program unit", st
->name
, module_name
);
5007 rsym
= info
->u
.rsym
.sym
;
5011 if (st_sym
->attr
.vtab
|| st_sym
->attr
.vtype
)
5014 /* If the existing symbol is generic from a different module and
5015 the new symbol is generic there can be no ambiguity. */
5016 if (st_sym
->attr
.generic
5018 && st_sym
->module
!= module_name
)
5020 /* The new symbol's attributes have not yet been read. Since
5021 we need attr.generic, read it directly. */
5022 get_module_locus (&locus
);
5023 set_module_locus (&info
->u
.rsym
.where
);
5026 mio_symbol_attribute (&attr
);
5027 set_module_locus (&locus
);
5036 /* Read a module file. */
5041 module_locus operator_interfaces
, user_operators
, omp_udrs
;
5043 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
5045 /* Workaround -Wmaybe-uninitialized false positive during
5046 profiledbootstrap by initializing them. */
5047 int ambiguous
= 0, j
, nuse
, symbol
= 0;
5048 pointer_info
*info
, *q
;
5049 gfc_use_rename
*u
= NULL
;
5053 get_module_locus (&operator_interfaces
); /* Skip these for now. */
5056 get_module_locus (&user_operators
);
5060 /* Skip commons and equivalences for now. */
5064 /* Skip OpenMP UDRs. */
5065 get_module_locus (&omp_udrs
);
5070 /* Create the fixup nodes for all the symbols. */
5072 while (peek_atom () != ATOM_RPAREN
)
5075 require_atom (ATOM_INTEGER
);
5076 info
= get_integer (atom_int
);
5078 info
->type
= P_SYMBOL
;
5079 info
->u
.rsym
.state
= UNUSED
;
5081 info
->u
.rsym
.true_name
= read_string ();
5082 info
->u
.rsym
.module
= read_string ();
5083 bind_label
= read_string ();
5084 if (strlen (bind_label
))
5085 info
->u
.rsym
.binding_label
= bind_label
;
5087 XDELETEVEC (bind_label
);
5089 require_atom (ATOM_INTEGER
);
5090 info
->u
.rsym
.ns
= atom_int
;
5092 get_module_locus (&info
->u
.rsym
.where
);
5094 /* See if the symbol has already been loaded by a previous module.
5095 If so, we reference the existing symbol and prevent it from
5096 being loaded again. This should not happen if the symbol being
5097 read is an index for an assumed shape dummy array (ns != 1). */
5099 sym
= find_true_name (info
->u
.rsym
.true_name
, info
->u
.rsym
.module
);
5102 || (sym
->attr
.flavor
== FL_VARIABLE
&& info
->u
.rsym
.ns
!=1))
5108 info
->u
.rsym
.state
= USED
;
5109 info
->u
.rsym
.sym
= sym
;
5110 /* The current symbol has already been loaded, so we can avoid loading
5111 it again. However, if it is a derived type, some of its components
5112 can be used in expressions in the module. To avoid the module loading
5113 failing, we need to associate the module's component pointer indexes
5114 with the existing symbol's component pointers. */
5115 if (gfc_fl_struct (sym
->attr
.flavor
))
5119 /* First seek to the symbol's component list. */
5120 mio_lparen (); /* symbol opening. */
5121 skip_list (); /* skip symbol attribute. */
5123 mio_lparen (); /* component list opening. */
5124 for (c
= sym
->components
; c
; c
= c
->next
)
5127 const char *comp_name
;
5130 mio_lparen (); /* component opening. */
5132 p
= get_integer (n
);
5133 if (p
->u
.pointer
== NULL
)
5134 associate_integer_pointer (p
, c
);
5135 mio_pool_string (&comp_name
);
5136 gcc_assert (comp_name
== c
->name
);
5137 skip_list (1); /* component end. */
5139 mio_rparen (); /* component list closing. */
5141 skip_list (1); /* symbol end. */
5146 /* Some symbols do not have a namespace (eg. formal arguments),
5147 so the automatic "unique symtree" mechanism must be suppressed
5148 by marking them as referenced. */
5149 q
= get_integer (info
->u
.rsym
.ns
);
5150 if (q
->u
.pointer
== NULL
)
5152 info
->u
.rsym
.referenced
= 1;
5159 /* Parse the symtree lists. This lets us mark which symbols need to
5160 be loaded. Renaming is also done at this point by replacing the
5165 while (peek_atom () != ATOM_RPAREN
)
5167 mio_internal_string (name
);
5168 mio_integer (&ambiguous
);
5169 mio_integer (&symbol
);
5171 info
= get_integer (symbol
);
5173 /* See how many use names there are. If none, go through the start
5174 of the loop at least once. */
5175 nuse
= number_use_names (name
, false);
5176 info
->u
.rsym
.renamed
= nuse
? 1 : 0;
5181 for (j
= 1; j
<= nuse
; j
++)
5183 /* Get the jth local name for this symbol. */
5184 p
= find_use_name_n (name
, &j
, false);
5186 if (p
== NULL
&& strcmp (name
, module_name
) == 0)
5189 /* Exception: Always import vtabs & vtypes. */
5190 if (p
== NULL
&& name
[0] == '_'
5191 && (strncmp (name
, "__vtab_", 5) == 0
5192 || strncmp (name
, "__vtype_", 6) == 0))
5195 /* Skip symtree nodes not in an ONLY clause, unless there
5196 is an existing symtree loaded from another USE statement. */
5199 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
5201 && strcmp (st
->n
.sym
->name
, info
->u
.rsym
.true_name
) == 0
5202 && st
->n
.sym
->module
!= NULL
5203 && strcmp (st
->n
.sym
->module
, info
->u
.rsym
.module
) == 0)
5205 info
->u
.rsym
.symtree
= st
;
5206 info
->u
.rsym
.sym
= st
->n
.sym
;
5211 /* If a symbol of the same name and module exists already,
5212 this symbol, which is not in an ONLY clause, must not be
5213 added to the namespace(11.3.2). Note that find_symbol
5214 only returns the first occurrence that it finds. */
5215 if (!only_flag
&& !info
->u
.rsym
.renamed
5216 && strcmp (name
, module_name
) != 0
5217 && find_symbol (gfc_current_ns
->sym_root
, name
,
5221 st
= gfc_find_symtree (gfc_current_ns
->sym_root
, p
);
5224 && !(st
->n
.sym
&& st
->n
.sym
->attr
.used_in_submodule
))
5226 /* Check for ambiguous symbols. */
5227 if (check_for_ambiguous (st
, info
))
5230 info
->u
.rsym
.symtree
= st
;
5236 /* This symbol is host associated from a module in a
5237 submodule. Hide it with a unique symtree. */
5238 gfc_symtree
*s
= gfc_get_unique_symtree (gfc_current_ns
);
5239 s
->n
.sym
= st
->n
.sym
;
5244 /* Create a symtree node in the current namespace for this
5246 st
= check_unique_name (p
)
5247 ? gfc_get_unique_symtree (gfc_current_ns
)
5248 : gfc_new_symtree (&gfc_current_ns
->sym_root
, p
);
5249 st
->ambiguous
= ambiguous
;
5252 sym
= info
->u
.rsym
.sym
;
5254 /* Create a symbol node if it doesn't already exist. */
5257 info
->u
.rsym
.sym
= gfc_new_symbol (info
->u
.rsym
.true_name
,
5259 info
->u
.rsym
.sym
->name
= gfc_dt_lower_string (info
->u
.rsym
.true_name
);
5260 sym
= info
->u
.rsym
.sym
;
5261 sym
->module
= gfc_get_string ("%s", info
->u
.rsym
.module
);
5263 if (info
->u
.rsym
.binding_label
)
5265 tree id
= get_identifier (info
->u
.rsym
.binding_label
);
5266 sym
->binding_label
= IDENTIFIER_POINTER (id
);
5273 if (strcmp (name
, p
) != 0)
5274 sym
->attr
.use_rename
= 1;
5277 || (strncmp (name
, "__vtab_", 5) != 0
5278 && strncmp (name
, "__vtype_", 6) != 0))
5279 sym
->attr
.use_only
= only_flag
;
5281 /* Store the symtree pointing to this symbol. */
5282 info
->u
.rsym
.symtree
= st
;
5284 if (info
->u
.rsym
.state
== UNUSED
)
5285 info
->u
.rsym
.state
= NEEDED
;
5286 info
->u
.rsym
.referenced
= 1;
5293 /* Load intrinsic operator interfaces. */
5294 set_module_locus (&operator_interfaces
);
5297 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
5299 if (i
== INTRINSIC_USER
)
5304 u
= find_use_operator ((gfc_intrinsic_op
) i
);
5315 mio_interface (&gfc_current_ns
->op
[i
]);
5316 if (u
&& !gfc_current_ns
->op
[i
])
5322 /* Load generic and user operator interfaces. These must follow the
5323 loading of symtree because otherwise symbols can be marked as
5326 set_module_locus (&user_operators
);
5328 load_operator_interfaces ();
5329 load_generic_interfaces ();
5334 /* Load OpenMP user defined reductions. */
5335 set_module_locus (&omp_udrs
);
5338 /* At this point, we read those symbols that are needed but haven't
5339 been loaded yet. If one symbol requires another, the other gets
5340 marked as NEEDED if its previous state was UNUSED. */
5342 while (load_needed (pi_root
));
5344 /* Make sure all elements of the rename-list were found in the module. */
5346 for (u
= gfc_rename_list
; u
; u
= u
->next
)
5351 if (u
->op
== INTRINSIC_NONE
)
5353 gfc_error ("Symbol %qs referenced at %L not found in module %qs",
5354 u
->use_name
, &u
->where
, module_name
);
5358 if (u
->op
== INTRINSIC_USER
)
5360 gfc_error ("User operator %qs referenced at %L not found "
5361 "in module %qs", u
->use_name
, &u
->where
, module_name
);
5365 gfc_error ("Intrinsic operator %qs referenced at %L not found "
5366 "in module %qs", gfc_op2string (u
->op
), &u
->where
,
5370 /* Clean up symbol nodes that were never loaded, create references
5371 to hidden symbols. */
5373 read_cleanup (pi_root
);
5377 /* Given an access type that is specific to an entity and the default
5378 access, return nonzero if the entity is publicly accessible. If the
5379 element is declared as PUBLIC, then it is public; if declared
5380 PRIVATE, then private, and otherwise it is public unless the default
5381 access in this context has been declared PRIVATE. */
5383 static bool dump_smod
= false;
5386 check_access (gfc_access specific_access
, gfc_access default_access
)
5391 if (specific_access
== ACCESS_PUBLIC
)
5393 if (specific_access
== ACCESS_PRIVATE
)
5396 if (flag_module_private
)
5397 return default_access
== ACCESS_PUBLIC
;
5399 return default_access
!= ACCESS_PRIVATE
;
5404 gfc_check_symbol_access (gfc_symbol
*sym
)
5406 if (sym
->attr
.vtab
|| sym
->attr
.vtype
)
5409 return check_access (sym
->attr
.access
, sym
->ns
->default_access
);
5413 /* A structure to remember which commons we've already written. */
5415 struct written_common
5417 BBT_HEADER(written_common
);
5418 const char *name
, *label
;
5421 static struct written_common
*written_commons
= NULL
;
5423 /* Comparison function used for balancing the binary tree. */
5426 compare_written_commons (void *a1
, void *b1
)
5428 const char *aname
= ((struct written_common
*) a1
)->name
;
5429 const char *alabel
= ((struct written_common
*) a1
)->label
;
5430 const char *bname
= ((struct written_common
*) b1
)->name
;
5431 const char *blabel
= ((struct written_common
*) b1
)->label
;
5432 int c
= strcmp (aname
, bname
);
5434 return (c
!= 0 ? c
: strcmp (alabel
, blabel
));
5437 /* Free a list of written commons. */
5440 free_written_common (struct written_common
*w
)
5446 free_written_common (w
->left
);
5448 free_written_common (w
->right
);
5453 /* Write a common block to the module -- recursive helper function. */
5456 write_common_0 (gfc_symtree
*st
, bool this_module
)
5462 struct written_common
*w
;
5463 bool write_me
= true;
5468 write_common_0 (st
->left
, this_module
);
5470 /* We will write out the binding label, or "" if no label given. */
5471 name
= st
->n
.common
->name
;
5473 label
= (p
->is_bind_c
&& p
->binding_label
) ? p
->binding_label
: "";
5475 /* Check if we've already output this common. */
5476 w
= written_commons
;
5479 int c
= strcmp (name
, w
->name
);
5480 c
= (c
!= 0 ? c
: strcmp (label
, w
->label
));
5484 w
= (c
< 0) ? w
->left
: w
->right
;
5487 if (this_module
&& p
->use_assoc
)
5492 /* Write the common to the module. */
5494 mio_pool_string (&name
);
5496 mio_symbol_ref (&p
->head
);
5497 flags
= p
->saved
? 1 : 0;
5498 if (p
->threadprivate
)
5500 mio_integer (&flags
);
5502 /* Write out whether the common block is bind(c) or not. */
5503 mio_integer (&(p
->is_bind_c
));
5505 mio_pool_string (&label
);
5508 /* Record that we have written this common. */
5509 w
= XCNEW (struct written_common
);
5512 gfc_insert_bbt (&written_commons
, w
, compare_written_commons
);
5515 write_common_0 (st
->right
, this_module
);
5519 /* Write a common, by initializing the list of written commons, calling
5520 the recursive function write_common_0() and cleaning up afterwards. */
5523 write_common (gfc_symtree
*st
)
5525 written_commons
= NULL
;
5526 write_common_0 (st
, true);
5527 write_common_0 (st
, false);
5528 free_written_common (written_commons
);
5529 written_commons
= NULL
;
5533 /* Write the blank common block to the module. */
5536 write_blank_common (void)
5538 const char * name
= BLANK_COMMON_NAME
;
5540 /* TODO: Blank commons are not bind(c). The F2003 standard probably says
5541 this, but it hasn't been checked. Just making it so for now. */
5544 if (gfc_current_ns
->blank_common
.head
== NULL
)
5549 mio_pool_string (&name
);
5551 mio_symbol_ref (&gfc_current_ns
->blank_common
.head
);
5552 saved
= gfc_current_ns
->blank_common
.saved
;
5553 mio_integer (&saved
);
5555 /* Write out whether the common block is bind(c) or not. */
5556 mio_integer (&is_bind_c
);
5558 /* Write out an empty binding label. */
5559 write_atom (ATOM_STRING
, "");
5565 /* Write equivalences to the module. */
5574 for (eq
= gfc_current_ns
->equiv
; eq
; eq
= eq
->next
)
5578 for (e
= eq
; e
; e
= e
->eq
)
5580 if (e
->module
== NULL
)
5581 e
->module
= gfc_get_string ("%s.eq.%d", module_name
, num
);
5582 mio_allocated_string (e
->module
);
5583 mio_expr (&e
->expr
);
5592 /* Write a symbol to the module. */
5595 write_symbol (int n
, gfc_symbol
*sym
)
5599 if (sym
->attr
.flavor
== FL_UNKNOWN
|| sym
->attr
.flavor
== FL_LABEL
)
5600 gfc_internal_error ("write_symbol(): bad module symbol %qs", sym
->name
);
5604 if (gfc_fl_struct (sym
->attr
.flavor
))
5607 name
= gfc_dt_upper_string (sym
->name
);
5608 mio_pool_string (&name
);
5611 mio_pool_string (&sym
->name
);
5613 mio_pool_string (&sym
->module
);
5614 if ((sym
->attr
.is_bind_c
|| sym
->attr
.is_iso_c
) && sym
->binding_label
)
5616 label
= sym
->binding_label
;
5617 mio_pool_string (&label
);
5620 write_atom (ATOM_STRING
, "");
5622 mio_pointer_ref (&sym
->ns
);
5629 /* Recursive traversal function to write the initial set of symbols to
5630 the module. We check to see if the symbol should be written
5631 according to the access specification. */
5634 write_symbol0 (gfc_symtree
*st
)
5638 bool dont_write
= false;
5643 write_symbol0 (st
->left
);
5646 if (sym
->module
== NULL
)
5647 sym
->module
= module_name
;
5649 if (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
5650 && !sym
->attr
.subroutine
&& !sym
->attr
.function
)
5653 if (!gfc_check_symbol_access (sym
))
5658 p
= get_pointer (sym
);
5659 if (p
->type
== P_UNKNOWN
)
5662 if (p
->u
.wsym
.state
!= WRITTEN
)
5664 write_symbol (p
->integer
, sym
);
5665 p
->u
.wsym
.state
= WRITTEN
;
5669 write_symbol0 (st
->right
);
5674 write_omp_udr (gfc_omp_udr
*udr
)
5678 case OMP_REDUCTION_USER
:
5679 /* Non-operators can't be used outside of the module. */
5680 if (udr
->name
[0] != '.')
5685 size_t len
= strlen (udr
->name
+ 1);
5686 char *name
= XALLOCAVEC (char, len
);
5687 memcpy (name
, udr
->name
, len
- 1);
5688 name
[len
- 1] = '\0';
5689 st
= gfc_find_symtree (gfc_current_ns
->uop_root
, name
);
5690 /* If corresponding user operator is private, don't write
5694 gfc_user_op
*uop
= st
->n
.uop
;
5695 if (!check_access (uop
->access
, uop
->ns
->default_access
))
5700 case OMP_REDUCTION_PLUS
:
5701 case OMP_REDUCTION_MINUS
:
5702 case OMP_REDUCTION_TIMES
:
5703 case OMP_REDUCTION_AND
:
5704 case OMP_REDUCTION_OR
:
5705 case OMP_REDUCTION_EQV
:
5706 case OMP_REDUCTION_NEQV
:
5707 /* If corresponding operator is private, don't write the UDR. */
5708 if (!check_access (gfc_current_ns
->operator_access
[udr
->rop
],
5709 gfc_current_ns
->default_access
))
5715 if (udr
->ts
.type
== BT_DERIVED
|| udr
->ts
.type
== BT_CLASS
)
5717 /* If derived type is private, don't write the UDR. */
5718 if (!gfc_check_symbol_access (udr
->ts
.u
.derived
))
5723 mio_pool_string (&udr
->name
);
5724 mio_typespec (&udr
->ts
);
5725 mio_omp_udr_expr (udr
, &udr
->omp_out
, &udr
->omp_in
, udr
->combiner_ns
, false);
5726 if (udr
->initializer_ns
)
5727 mio_omp_udr_expr (udr
, &udr
->omp_priv
, &udr
->omp_orig
,
5728 udr
->initializer_ns
, true);
5734 write_omp_udrs (gfc_symtree
*st
)
5739 write_omp_udrs (st
->left
);
5741 for (udr
= st
->n
.omp_udr
; udr
; udr
= udr
->next
)
5742 write_omp_udr (udr
);
5743 write_omp_udrs (st
->right
);
5747 /* Type for the temporary tree used when writing secondary symbols. */
5749 struct sorted_pointer_info
5751 BBT_HEADER (sorted_pointer_info
);
5756 #define gfc_get_sorted_pointer_info() XCNEW (sorted_pointer_info)
5758 /* Recursively traverse the temporary tree, free its contents. */
5761 free_sorted_pointer_info_tree (sorted_pointer_info
*p
)
5766 free_sorted_pointer_info_tree (p
->left
);
5767 free_sorted_pointer_info_tree (p
->right
);
5772 /* Comparison function for the temporary tree. */
5775 compare_sorted_pointer_info (void *_spi1
, void *_spi2
)
5777 sorted_pointer_info
*spi1
, *spi2
;
5778 spi1
= (sorted_pointer_info
*)_spi1
;
5779 spi2
= (sorted_pointer_info
*)_spi2
;
5781 if (spi1
->p
->integer
< spi2
->p
->integer
)
5783 if (spi1
->p
->integer
> spi2
->p
->integer
)
5789 /* Finds the symbols that need to be written and collects them in the
5790 sorted_pi tree so that they can be traversed in an order
5791 independent of memory addresses. */
5794 find_symbols_to_write(sorted_pointer_info
**tree
, pointer_info
*p
)
5799 if (p
->type
== P_SYMBOL
&& p
->u
.wsym
.state
== NEEDS_WRITE
)
5801 sorted_pointer_info
*sp
= gfc_get_sorted_pointer_info();
5804 gfc_insert_bbt (tree
, sp
, compare_sorted_pointer_info
);
5807 find_symbols_to_write (tree
, p
->left
);
5808 find_symbols_to_write (tree
, p
->right
);
5812 /* Recursive function that traverses the tree of symbols that need to be
5813 written and writes them in order. */
5816 write_symbol1_recursion (sorted_pointer_info
*sp
)
5821 write_symbol1_recursion (sp
->left
);
5823 pointer_info
*p1
= sp
->p
;
5824 gcc_assert (p1
->type
== P_SYMBOL
&& p1
->u
.wsym
.state
== NEEDS_WRITE
);
5826 p1
->u
.wsym
.state
= WRITTEN
;
5827 write_symbol (p1
->integer
, p1
->u
.wsym
.sym
);
5828 p1
->u
.wsym
.sym
->attr
.public_used
= 1;
5830 write_symbol1_recursion (sp
->right
);
5834 /* Write the secondary set of symbols to the module file. These are
5835 symbols that were not public yet are needed by the public symbols
5836 or another dependent symbol. The act of writing a symbol can add
5837 symbols to the pointer_info tree, so we return nonzero if a symbol
5838 was written and pass that information upwards. The caller will
5839 then call this function again until nothing was written. It uses
5840 the utility functions and a temporary tree to ensure a reproducible
5841 ordering of the symbol output and thus the module file. */
5844 write_symbol1 (pointer_info
*p
)
5849 /* Put symbols that need to be written into a tree sorted on the
5852 sorted_pointer_info
*spi_root
= NULL
;
5853 find_symbols_to_write (&spi_root
, p
);
5855 /* No symbols to write, return. */
5859 /* Otherwise, write and free the tree again. */
5860 write_symbol1_recursion (spi_root
);
5861 free_sorted_pointer_info_tree (spi_root
);
5867 /* Write operator interfaces associated with a symbol. */
5870 write_operator (gfc_user_op
*uop
)
5872 static char nullstring
[] = "";
5873 const char *p
= nullstring
;
5875 if (uop
->op
== NULL
|| !check_access (uop
->access
, uop
->ns
->default_access
))
5878 mio_symbol_interface (&uop
->name
, &p
, &uop
->op
);
5882 /* Write generic interfaces from the namespace sym_root. */
5885 write_generic (gfc_symtree
*st
)
5892 write_generic (st
->left
);
5895 if (sym
&& !check_unique_name (st
->name
)
5896 && sym
->generic
&& gfc_check_symbol_access (sym
))
5899 sym
->module
= module_name
;
5901 mio_symbol_interface (&st
->name
, &sym
->module
, &sym
->generic
);
5904 write_generic (st
->right
);
5909 write_symtree (gfc_symtree
*st
)
5916 /* A symbol in an interface body must not be visible in the
5918 if (sym
->ns
!= gfc_current_ns
5919 && sym
->ns
->proc_name
5920 && sym
->ns
->proc_name
->attr
.if_source
== IFSRC_IFBODY
)
5923 if (!gfc_check_symbol_access (sym
)
5924 || (sym
->attr
.flavor
== FL_PROCEDURE
&& sym
->attr
.generic
5925 && !sym
->attr
.subroutine
&& !sym
->attr
.function
))
5928 if (check_unique_name (st
->name
))
5931 p
= find_pointer (sym
);
5933 gfc_internal_error ("write_symtree(): Symbol not written");
5935 mio_pool_string (&st
->name
);
5936 mio_integer (&st
->ambiguous
);
5937 mio_integer (&p
->integer
);
5946 /* Write the operator interfaces. */
5949 for (i
= GFC_INTRINSIC_BEGIN
; i
!= GFC_INTRINSIC_END
; i
++)
5951 if (i
== INTRINSIC_USER
)
5954 mio_interface (check_access (gfc_current_ns
->operator_access
[i
],
5955 gfc_current_ns
->default_access
)
5956 ? &gfc_current_ns
->op
[i
] : NULL
);
5964 gfc_traverse_user_op (gfc_current_ns
, write_operator
);
5970 write_generic (gfc_current_ns
->sym_root
);
5976 write_blank_common ();
5977 write_common (gfc_current_ns
->common_root
);
5989 write_omp_udrs (gfc_current_ns
->omp_udr_root
);
5994 /* Write symbol information. First we traverse all symbols in the
5995 primary namespace, writing those that need to be written.
5996 Sometimes writing one symbol will cause another to need to be
5997 written. A list of these symbols ends up on the write stack, and
5998 we end by popping the bottom of the stack and writing the symbol
5999 until the stack is empty. */
6003 write_symbol0 (gfc_current_ns
->sym_root
);
6004 while (write_symbol1 (pi_root
))
6013 gfc_traverse_symtree (gfc_current_ns
->sym_root
, write_symtree
);
6018 /* Read a CRC32 sum from the gzip trailer of a module file. Returns
6019 true on success, false on failure. */
6022 read_crc32_from_module_file (const char* filename
, uLong
* crc
)
6028 /* Open the file in binary mode. */
6029 if ((file
= fopen (filename
, "rb")) == NULL
)
6032 /* The gzip crc32 value is found in the [END-8, END-4] bytes of the
6033 file. See RFC 1952. */
6034 if (fseek (file
, -8, SEEK_END
) != 0)
6040 /* Read the CRC32. */
6041 if (fread (buf
, 1, 4, file
) != 4)
6047 /* Close the file. */
6050 val
= (buf
[0] & 0xFF) + ((buf
[1] & 0xFF) << 8) + ((buf
[2] & 0xFF) << 16)
6051 + ((buf
[3] & 0xFF) << 24);
6054 /* For debugging, the CRC value printed in hexadecimal should match
6055 the CRC printed by "zcat -l -v filename".
6056 printf("CRC of file %s is %x\n", filename, val); */
6062 /* Given module, dump it to disk. If there was an error while
6063 processing the module, dump_flag will be set to zero and we delete
6064 the module file, even if it was already there. */
6067 dump_module (const char *name
, int dump_flag
)
6070 char *filename
, *filename_tmp
;
6073 module_name
= gfc_get_string ("%s", name
);
6077 name
= submodule_name
;
6078 n
= strlen (name
) + strlen (SUBMODULE_EXTENSION
) + 1;
6081 n
= strlen (name
) + strlen (MODULE_EXTENSION
) + 1;
6083 if (gfc_option
.module_dir
!= NULL
)
6085 n
+= strlen (gfc_option
.module_dir
);
6086 filename
= (char *) alloca (n
);
6087 strcpy (filename
, gfc_option
.module_dir
);
6088 strcat (filename
, name
);
6092 filename
= (char *) alloca (n
);
6093 strcpy (filename
, name
);
6097 strcat (filename
, SUBMODULE_EXTENSION
);
6099 strcat (filename
, MODULE_EXTENSION
);
6101 /* Name of the temporary file used to write the module. */
6102 filename_tmp
= (char *) alloca (n
+ 1);
6103 strcpy (filename_tmp
, filename
);
6104 strcat (filename_tmp
, "0");
6106 /* There was an error while processing the module. We delete the
6107 module file, even if it was already there. */
6114 if (gfc_cpp_makedep ())
6115 gfc_cpp_add_target (filename
);
6117 /* Write the module to the temporary file. */
6118 module_fp
= gzopen (filename_tmp
, "w");
6119 if (module_fp
== NULL
)
6120 gfc_fatal_error ("Can't open module file %qs for writing at %C: %s",
6121 filename_tmp
, xstrerror (errno
));
6123 gzprintf (module_fp
, "GFORTRAN module version '%s' created from %s\n",
6124 MOD_VERSION
, gfc_source_file
);
6126 /* Write the module itself. */
6133 free_pi_tree (pi_root
);
6138 if (gzclose (module_fp
))
6139 gfc_fatal_error ("Error writing module file %qs for writing: %s",
6140 filename_tmp
, xstrerror (errno
));
6142 /* Read the CRC32 from the gzip trailers of the module files and
6144 if (!read_crc32_from_module_file (filename_tmp
, &crc
)
6145 || !read_crc32_from_module_file (filename
, &crc_old
)
6148 /* Module file have changed, replace the old one. */
6149 if (remove (filename
) && errno
!= ENOENT
)
6150 gfc_fatal_error ("Can't delete module file %qs: %s", filename
,
6152 if (rename (filename_tmp
, filename
))
6153 gfc_fatal_error ("Can't rename module file %qs to %qs: %s",
6154 filename_tmp
, filename
, xstrerror (errno
));
6158 if (remove (filename_tmp
))
6159 gfc_fatal_error ("Can't delete temporary module file %qs: %s",
6160 filename_tmp
, xstrerror (errno
));
6165 /* Suppress the output of a .smod file by module, if no module
6166 procedures have been seen. */
6167 static bool no_module_procedures
;
6170 check_for_module_procedures (gfc_symbol
*sym
)
6172 if (sym
&& sym
->attr
.module_procedure
)
6173 no_module_procedures
= false;
6178 gfc_dump_module (const char *name
, int dump_flag
)
6180 if (gfc_state_stack
->state
== COMP_SUBMODULE
)
6185 no_module_procedures
= true;
6186 gfc_traverse_ns (gfc_current_ns
, check_for_module_procedures
);
6188 dump_module (name
, dump_flag
);
6190 if (no_module_procedures
|| dump_smod
)
6193 /* Write a submodule file from a module. The 'dump_smod' flag switches
6194 off the check for PRIVATE entities. */
6196 submodule_name
= module_name
;
6197 dump_module (name
, dump_flag
);
6202 create_intrinsic_function (const char *name
, int id
,
6203 const char *modname
, intmod_id module
,
6204 bool subroutine
, gfc_symbol
*result_type
)
6206 gfc_intrinsic_sym
*isym
;
6207 gfc_symtree
*tmp_symtree
;
6210 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6213 if (tmp_symtree
->n
.sym
&& tmp_symtree
->n
.sym
->module
6214 && strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6216 gfc_error ("Symbol %qs at %C already declared", name
);
6220 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6221 sym
= tmp_symtree
->n
.sym
;
6225 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6226 isym
= gfc_intrinsic_subroutine_by_id (isym_id
);
6227 sym
->attr
.subroutine
= 1;
6231 gfc_isym_id isym_id
= gfc_isym_id_by_intmod (module
, id
);
6232 isym
= gfc_intrinsic_function_by_id (isym_id
);
6234 sym
->attr
.function
= 1;
6237 sym
->ts
.type
= BT_DERIVED
;
6238 sym
->ts
.u
.derived
= result_type
;
6239 sym
->ts
.is_c_interop
= 1;
6240 isym
->ts
.f90_type
= BT_VOID
;
6241 isym
->ts
.type
= BT_DERIVED
;
6242 isym
->ts
.f90_type
= BT_VOID
;
6243 isym
->ts
.u
.derived
= result_type
;
6244 isym
->ts
.is_c_interop
= 1;
6249 sym
->attr
.flavor
= FL_PROCEDURE
;
6250 sym
->attr
.intrinsic
= 1;
6252 sym
->module
= gfc_get_string ("%s", modname
);
6253 sym
->attr
.use_assoc
= 1;
6254 sym
->from_intmod
= module
;
6255 sym
->intmod_sym_id
= id
;
6259 /* Import the intrinsic ISO_C_BINDING module, generating symbols in
6260 the current namespace for all named constants, pointer types, and
6261 procedures in the module unless the only clause was used or a rename
6262 list was provided. */
6265 import_iso_c_binding_module (void)
6267 gfc_symbol
*mod_sym
= NULL
, *return_type
;
6268 gfc_symtree
*mod_symtree
= NULL
, *tmp_symtree
;
6269 gfc_symtree
*c_ptr
= NULL
, *c_funptr
= NULL
;
6270 const char *iso_c_module_name
= "__iso_c_binding";
6273 bool want_c_ptr
= false, want_c_funptr
= false;
6275 /* Look only in the current namespace. */
6276 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, iso_c_module_name
);
6278 if (mod_symtree
== NULL
)
6280 /* symtree doesn't already exist in current namespace. */
6281 gfc_get_sym_tree (iso_c_module_name
, gfc_current_ns
, &mod_symtree
,
6284 if (mod_symtree
!= NULL
)
6285 mod_sym
= mod_symtree
->n
.sym
;
6287 gfc_internal_error ("import_iso_c_binding_module(): Unable to "
6288 "create symbol for %s", iso_c_module_name
);
6290 mod_sym
->attr
.flavor
= FL_MODULE
;
6291 mod_sym
->attr
.intrinsic
= 1;
6292 mod_sym
->module
= gfc_get_string ("%s", iso_c_module_name
);
6293 mod_sym
->from_intmod
= INTMOD_ISO_C_BINDING
;
6296 /* Check whether C_PTR or C_FUNPTR are in the include list, if so, load it;
6297 check also whether C_NULL_(FUN)PTR or C_(FUN)LOC are requested, which
6299 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6301 if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_PTR
].name
,
6304 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_LOC
].name
,
6307 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_NULL_FUNPTR
].name
,
6309 want_c_funptr
= true;
6310 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNLOC
].name
,
6312 want_c_funptr
= true;
6313 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_PTR
].name
,
6316 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6317 (iso_c_binding_symbol
)
6319 u
->local_name
[0] ? u
->local_name
6323 else if (strcmp (c_interop_kinds_table
[ISOCBINDING_FUNPTR
].name
,
6327 = generate_isocbinding_symbol (iso_c_module_name
,
6328 (iso_c_binding_symbol
)
6330 u
->local_name
[0] ? u
->local_name
6336 if ((want_c_ptr
|| !only_flag
) && !c_ptr
)
6337 c_ptr
= generate_isocbinding_symbol (iso_c_module_name
,
6338 (iso_c_binding_symbol
)
6340 NULL
, NULL
, only_flag
);
6341 if ((want_c_funptr
|| !only_flag
) && !c_funptr
)
6342 c_funptr
= generate_isocbinding_symbol (iso_c_module_name
,
6343 (iso_c_binding_symbol
)
6345 NULL
, NULL
, only_flag
);
6347 /* Generate the symbols for the named constants representing
6348 the kinds for intrinsic data types. */
6349 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
6352 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6353 if (strcmp (c_interop_kinds_table
[i
].name
, u
->use_name
) == 0)
6362 #define NAMED_FUNCTION(a,b,c,d) \
6364 not_in_std = (gfc_option.allow_std & d) == 0; \
6367 #define NAMED_SUBROUTINE(a,b,c,d) \
6369 not_in_std = (gfc_option.allow_std & d) == 0; \
6372 #define NAMED_INTCST(a,b,c,d) \
6374 not_in_std = (gfc_option.allow_std & d) == 0; \
6377 #define NAMED_REALCST(a,b,c,d) \
6379 not_in_std = (gfc_option.allow_std & d) == 0; \
6382 #define NAMED_CMPXCST(a,b,c,d) \
6384 not_in_std = (gfc_option.allow_std & d) == 0; \
6387 #include "iso-c-binding.def"
6395 gfc_error ("The symbol %qs, referenced at %L, is not "
6396 "in the selected standard", name
, &u
->where
);
6402 #define NAMED_FUNCTION(a,b,c,d) \
6404 if (a == ISOCBINDING_LOC) \
6405 return_type = c_ptr->n.sym; \
6406 else if (a == ISOCBINDING_FUNLOC) \
6407 return_type = c_funptr->n.sym; \
6409 return_type = NULL; \
6410 create_intrinsic_function (u->local_name[0] \
6411 ? u->local_name : u->use_name, \
6412 a, iso_c_module_name, \
6413 INTMOD_ISO_C_BINDING, false, \
6416 #define NAMED_SUBROUTINE(a,b,c,d) \
6418 create_intrinsic_function (u->local_name[0] ? u->local_name \
6420 a, iso_c_module_name, \
6421 INTMOD_ISO_C_BINDING, true, NULL); \
6423 #include "iso-c-binding.def"
6425 case ISOCBINDING_PTR
:
6426 case ISOCBINDING_FUNPTR
:
6427 /* Already handled above. */
6430 if (i
== ISOCBINDING_NULL_PTR
)
6431 tmp_symtree
= c_ptr
;
6432 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6433 tmp_symtree
= c_funptr
;
6436 generate_isocbinding_symbol (iso_c_module_name
,
6437 (iso_c_binding_symbol
) i
,
6439 ? u
->local_name
: u
->use_name
,
6440 tmp_symtree
, false);
6444 if (!found
&& !only_flag
)
6446 /* Skip, if the symbol is not in the enabled standard. */
6449 #define NAMED_FUNCTION(a,b,c,d) \
6451 if ((gfc_option.allow_std & d) == 0) \
6454 #define NAMED_SUBROUTINE(a,b,c,d) \
6456 if ((gfc_option.allow_std & d) == 0) \
6459 #define NAMED_INTCST(a,b,c,d) \
6461 if ((gfc_option.allow_std & d) == 0) \
6464 #define NAMED_REALCST(a,b,c,d) \
6466 if ((gfc_option.allow_std & d) == 0) \
6469 #define NAMED_CMPXCST(a,b,c,d) \
6471 if ((gfc_option.allow_std & d) == 0) \
6474 #include "iso-c-binding.def"
6476 ; /* Not GFC_STD_* versioned. */
6481 #define NAMED_FUNCTION(a,b,c,d) \
6483 if (a == ISOCBINDING_LOC) \
6484 return_type = c_ptr->n.sym; \
6485 else if (a == ISOCBINDING_FUNLOC) \
6486 return_type = c_funptr->n.sym; \
6488 return_type = NULL; \
6489 create_intrinsic_function (b, a, iso_c_module_name, \
6490 INTMOD_ISO_C_BINDING, false, \
6493 #define NAMED_SUBROUTINE(a,b,c,d) \
6495 create_intrinsic_function (b, a, iso_c_module_name, \
6496 INTMOD_ISO_C_BINDING, true, NULL); \
6498 #include "iso-c-binding.def"
6500 case ISOCBINDING_PTR
:
6501 case ISOCBINDING_FUNPTR
:
6502 /* Already handled above. */
6505 if (i
== ISOCBINDING_NULL_PTR
)
6506 tmp_symtree
= c_ptr
;
6507 else if (i
== ISOCBINDING_NULL_FUNPTR
)
6508 tmp_symtree
= c_funptr
;
6511 generate_isocbinding_symbol (iso_c_module_name
,
6512 (iso_c_binding_symbol
) i
, NULL
,
6513 tmp_symtree
, false);
6518 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6523 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
6524 "module ISO_C_BINDING", u
->use_name
, &u
->where
);
6529 /* Add an integer named constant from a given module. */
6532 create_int_parameter (const char *name
, int value
, const char *modname
,
6533 intmod_id module
, int id
)
6535 gfc_symtree
*tmp_symtree
;
6538 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6539 if (tmp_symtree
!= NULL
)
6541 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6544 gfc_error ("Symbol %qs already declared", name
);
6547 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6548 sym
= tmp_symtree
->n
.sym
;
6550 sym
->module
= gfc_get_string ("%s", modname
);
6551 sym
->attr
.flavor
= FL_PARAMETER
;
6552 sym
->ts
.type
= BT_INTEGER
;
6553 sym
->ts
.kind
= gfc_default_integer_kind
;
6554 sym
->value
= gfc_get_int_expr (gfc_default_integer_kind
, NULL
, value
);
6555 sym
->attr
.use_assoc
= 1;
6556 sym
->from_intmod
= module
;
6557 sym
->intmod_sym_id
= id
;
6561 /* Value is already contained by the array constructor, but not
6565 create_int_parameter_array (const char *name
, int size
, gfc_expr
*value
,
6566 const char *modname
, intmod_id module
, int id
)
6568 gfc_symtree
*tmp_symtree
;
6571 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6572 if (tmp_symtree
!= NULL
)
6574 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6577 gfc_error ("Symbol %qs already declared", name
);
6580 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6581 sym
= tmp_symtree
->n
.sym
;
6583 sym
->module
= gfc_get_string ("%s", modname
);
6584 sym
->attr
.flavor
= FL_PARAMETER
;
6585 sym
->ts
.type
= BT_INTEGER
;
6586 sym
->ts
.kind
= gfc_default_integer_kind
;
6587 sym
->attr
.use_assoc
= 1;
6588 sym
->from_intmod
= module
;
6589 sym
->intmod_sym_id
= id
;
6590 sym
->attr
.dimension
= 1;
6591 sym
->as
= gfc_get_array_spec ();
6593 sym
->as
->type
= AS_EXPLICIT
;
6594 sym
->as
->lower
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, 1);
6595 sym
->as
->upper
[0] = gfc_get_int_expr (gfc_default_integer_kind
, NULL
, size
);
6598 sym
->value
->shape
= gfc_get_shape (1);
6599 mpz_init_set_ui (sym
->value
->shape
[0], size
);
6603 /* Add an derived type for a given module. */
6606 create_derived_type (const char *name
, const char *modname
,
6607 intmod_id module
, int id
)
6609 gfc_symtree
*tmp_symtree
;
6610 gfc_symbol
*sym
, *dt_sym
;
6611 gfc_interface
*intr
, *head
;
6613 tmp_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, name
);
6614 if (tmp_symtree
!= NULL
)
6616 if (strcmp (modname
, tmp_symtree
->n
.sym
->module
) == 0)
6619 gfc_error ("Symbol %qs already declared", name
);
6622 gfc_get_sym_tree (name
, gfc_current_ns
, &tmp_symtree
, false);
6623 sym
= tmp_symtree
->n
.sym
;
6624 sym
->module
= gfc_get_string ("%s", modname
);
6625 sym
->from_intmod
= module
;
6626 sym
->intmod_sym_id
= id
;
6627 sym
->attr
.flavor
= FL_PROCEDURE
;
6628 sym
->attr
.function
= 1;
6629 sym
->attr
.generic
= 1;
6631 gfc_get_sym_tree (gfc_dt_upper_string (sym
->name
),
6632 gfc_current_ns
, &tmp_symtree
, false);
6633 dt_sym
= tmp_symtree
->n
.sym
;
6634 dt_sym
->name
= gfc_get_string ("%s", sym
->name
);
6635 dt_sym
->attr
.flavor
= FL_DERIVED
;
6636 dt_sym
->attr
.private_comp
= 1;
6637 dt_sym
->attr
.zero_comp
= 1;
6638 dt_sym
->attr
.use_assoc
= 1;
6639 dt_sym
->module
= gfc_get_string ("%s", modname
);
6640 dt_sym
->from_intmod
= module
;
6641 dt_sym
->intmod_sym_id
= id
;
6643 head
= sym
->generic
;
6644 intr
= gfc_get_interface ();
6646 intr
->where
= gfc_current_locus
;
6648 sym
->generic
= intr
;
6649 sym
->attr
.if_source
= IFSRC_DECL
;
6653 /* Read the contents of the module file into a temporary buffer. */
6656 read_module_to_tmpbuf ()
6658 /* We don't know the uncompressed size, so enlarge the buffer as
6664 module_content
= XNEWVEC (char, cursz
);
6668 int nread
= gzread (module_fp
, module_content
+ len
, rsize
);
6673 module_content
= XRESIZEVEC (char, module_content
, cursz
);
6674 rsize
= cursz
- len
;
6677 module_content
= XRESIZEVEC (char, module_content
, len
+ 1);
6678 module_content
[len
] = '\0';
6684 /* USE the ISO_FORTRAN_ENV intrinsic module. */
6687 use_iso_fortran_env_module (void)
6689 static char mod
[] = "iso_fortran_env";
6691 gfc_symbol
*mod_sym
;
6692 gfc_symtree
*mod_symtree
;
6696 intmod_sym symbol
[] = {
6697 #define NAMED_INTCST(a,b,c,d) { a, b, 0, d },
6698 #define NAMED_KINDARRAY(a,b,c,d) { a, b, 0, d },
6699 #define NAMED_DERIVED_TYPE(a,b,c,d) { a, b, 0, d },
6700 #define NAMED_FUNCTION(a,b,c,d) { a, b, c, d },
6701 #define NAMED_SUBROUTINE(a,b,c,d) { a, b, c, d },
6702 #include "iso-fortran-env.def"
6703 { ISOFORTRANENV_INVALID
, NULL
, -1234, 0 } };
6706 #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c;
6707 #include "iso-fortran-env.def"
6709 /* Generate the symbol for the module itself. */
6710 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, mod
);
6711 if (mod_symtree
== NULL
)
6713 gfc_get_sym_tree (mod
, gfc_current_ns
, &mod_symtree
, false);
6714 gcc_assert (mod_symtree
);
6715 mod_sym
= mod_symtree
->n
.sym
;
6717 mod_sym
->attr
.flavor
= FL_MODULE
;
6718 mod_sym
->attr
.intrinsic
= 1;
6719 mod_sym
->module
= gfc_get_string ("%s", mod
);
6720 mod_sym
->from_intmod
= INTMOD_ISO_FORTRAN_ENV
;
6723 if (!mod_symtree
->n
.sym
->attr
.intrinsic
)
6724 gfc_error ("Use of intrinsic module %qs at %C conflicts with "
6725 "non-intrinsic module name used previously", mod
);
6727 /* Generate the symbols for the module integer named constants. */
6729 for (i
= 0; symbol
[i
].name
; i
++)
6732 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6734 if (strcmp (symbol
[i
].name
, u
->use_name
) == 0)
6739 if (!gfc_notify_std (symbol
[i
].standard
, "The symbol %qs, "
6740 "referenced at %L, is not in the selected "
6741 "standard", symbol
[i
].name
, &u
->where
))
6744 if ((flag_default_integer
|| flag_default_real_8
)
6745 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
6746 gfc_warning_now (0, "Use of the NUMERIC_STORAGE_SIZE named "
6747 "constant from intrinsic module "
6748 "ISO_FORTRAN_ENV at %L is incompatible with "
6749 "option %qs", &u
->where
,
6750 flag_default_integer
6751 ? "-fdefault-integer-8"
6752 : "-fdefault-real-8");
6753 switch (symbol
[i
].id
)
6755 #define NAMED_INTCST(a,b,c,d) \
6757 #include "iso-fortran-env.def"
6758 create_int_parameter (u
->local_name
[0] ? u
->local_name
6760 symbol
[i
].value
, mod
,
6761 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
6764 #define NAMED_KINDARRAY(a,b,KINDS,d) \
6766 expr = gfc_get_array_expr (BT_INTEGER, \
6767 gfc_default_integer_kind,\
6769 for (j = 0; KINDS[j].kind != 0; j++) \
6770 gfc_constructor_append_expr (&expr->value.constructor, \
6771 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
6772 KINDS[j].kind), NULL); \
6773 create_int_parameter_array (u->local_name[0] ? u->local_name \
6776 INTMOD_ISO_FORTRAN_ENV, \
6779 #include "iso-fortran-env.def"
6781 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
6783 #include "iso-fortran-env.def"
6784 create_derived_type (u
->local_name
[0] ? u
->local_name
6786 mod
, INTMOD_ISO_FORTRAN_ENV
,
6790 #define NAMED_FUNCTION(a,b,c,d) \
6792 #include "iso-fortran-env.def"
6793 create_intrinsic_function (u
->local_name
[0] ? u
->local_name
6796 INTMOD_ISO_FORTRAN_ENV
, false,
6806 if (!found
&& !only_flag
)
6808 if ((gfc_option
.allow_std
& symbol
[i
].standard
) == 0)
6811 if ((flag_default_integer
|| flag_default_real_8
)
6812 && symbol
[i
].id
== ISOFORTRANENV_NUMERIC_STORAGE_SIZE
)
6814 "Use of the NUMERIC_STORAGE_SIZE named constant "
6815 "from intrinsic module ISO_FORTRAN_ENV at %C is "
6816 "incompatible with option %s",
6817 flag_default_integer
6818 ? "-fdefault-integer-8" : "-fdefault-real-8");
6820 switch (symbol
[i
].id
)
6822 #define NAMED_INTCST(a,b,c,d) \
6824 #include "iso-fortran-env.def"
6825 create_int_parameter (symbol
[i
].name
, symbol
[i
].value
, mod
,
6826 INTMOD_ISO_FORTRAN_ENV
, symbol
[i
].id
);
6829 #define NAMED_KINDARRAY(a,b,KINDS,d) \
6831 expr = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind, \
6833 for (j = 0; KINDS[j].kind != 0; j++) \
6834 gfc_constructor_append_expr (&expr->value.constructor, \
6835 gfc_get_int_expr (gfc_default_integer_kind, NULL, \
6836 KINDS[j].kind), NULL); \
6837 create_int_parameter_array (symbol[i].name, j, expr, mod, \
6838 INTMOD_ISO_FORTRAN_ENV, symbol[i].id);\
6840 #include "iso-fortran-env.def"
6842 #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
6844 #include "iso-fortran-env.def"
6845 create_derived_type (symbol
[i
].name
, mod
, INTMOD_ISO_FORTRAN_ENV
,
6849 #define NAMED_FUNCTION(a,b,c,d) \
6851 #include "iso-fortran-env.def"
6852 create_intrinsic_function (symbol
[i
].name
, symbol
[i
].id
, mod
,
6853 INTMOD_ISO_FORTRAN_ENV
, false,
6863 for (u
= gfc_rename_list
; u
; u
= u
->next
)
6868 gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
6869 "module ISO_FORTRAN_ENV", u
->use_name
, &u
->where
);
6874 /* Process a USE directive. */
6877 gfc_use_module (gfc_use_list
*module
)
6882 gfc_symtree
*mod_symtree
;
6883 gfc_use_list
*use_stmt
;
6884 locus old_locus
= gfc_current_locus
;
6886 gfc_current_locus
= module
->where
;
6887 module_name
= module
->module_name
;
6888 gfc_rename_list
= module
->rename
;
6889 only_flag
= module
->only_flag
;
6890 current_intmod
= INTMOD_NONE
;
6893 gfc_warning_now (OPT_Wuse_without_only
,
6894 "USE statement at %C has no ONLY qualifier");
6896 if (gfc_state_stack
->state
== COMP_MODULE
6897 || module
->submodule_name
== NULL
)
6899 filename
= XALLOCAVEC (char, strlen (module_name
)
6900 + strlen (MODULE_EXTENSION
) + 1);
6901 strcpy (filename
, module_name
);
6902 strcat (filename
, MODULE_EXTENSION
);
6906 filename
= XALLOCAVEC (char, strlen (module
->submodule_name
)
6907 + strlen (SUBMODULE_EXTENSION
) + 1);
6908 strcpy (filename
, module
->submodule_name
);
6909 strcat (filename
, SUBMODULE_EXTENSION
);
6912 /* First, try to find an non-intrinsic module, unless the USE statement
6913 specified that the module is intrinsic. */
6915 if (!module
->intrinsic
)
6916 module_fp
= gzopen_included_file (filename
, true, true);
6918 /* Then, see if it's an intrinsic one, unless the USE statement
6919 specified that the module is non-intrinsic. */
6920 if (module_fp
== NULL
&& !module
->non_intrinsic
)
6922 if (strcmp (module_name
, "iso_fortran_env") == 0
6923 && gfc_notify_std (GFC_STD_F2003
, "ISO_FORTRAN_ENV "
6924 "intrinsic module at %C"))
6926 use_iso_fortran_env_module ();
6927 free_rename (module
->rename
);
6928 module
->rename
= NULL
;
6929 gfc_current_locus
= old_locus
;
6930 module
->intrinsic
= true;
6934 if (strcmp (module_name
, "iso_c_binding") == 0
6935 && gfc_notify_std (GFC_STD_F2003
, "ISO_C_BINDING module at %C"))
6937 import_iso_c_binding_module();
6938 free_rename (module
->rename
);
6939 module
->rename
= NULL
;
6940 gfc_current_locus
= old_locus
;
6941 module
->intrinsic
= true;
6945 module_fp
= gzopen_intrinsic_module (filename
);
6947 if (module_fp
== NULL
&& module
->intrinsic
)
6948 gfc_fatal_error ("Can't find an intrinsic module named %qs at %C",
6951 /* Check for the IEEE modules, so we can mark their symbols
6952 accordingly when we read them. */
6953 if (strcmp (module_name
, "ieee_features") == 0
6954 && gfc_notify_std (GFC_STD_F2003
, "IEEE_FEATURES module at %C"))
6956 current_intmod
= INTMOD_IEEE_FEATURES
;
6958 else if (strcmp (module_name
, "ieee_exceptions") == 0
6959 && gfc_notify_std (GFC_STD_F2003
,
6960 "IEEE_EXCEPTIONS module at %C"))
6962 current_intmod
= INTMOD_IEEE_EXCEPTIONS
;
6964 else if (strcmp (module_name
, "ieee_arithmetic") == 0
6965 && gfc_notify_std (GFC_STD_F2003
,
6966 "IEEE_ARITHMETIC module at %C"))
6968 current_intmod
= INTMOD_IEEE_ARITHMETIC
;
6972 if (module_fp
== NULL
)
6974 if (gfc_state_stack
->state
!= COMP_SUBMODULE
6975 && module
->submodule_name
== NULL
)
6976 gfc_fatal_error ("Can't open module file %qs for reading at %C: %s",
6977 filename
, xstrerror (errno
));
6979 gfc_fatal_error ("Module file %qs has not been generated, either "
6980 "because the module does not contain a MODULE "
6981 "PROCEDURE or there is an error in the module.",
6985 /* Check that we haven't already USEd an intrinsic module with the
6988 mod_symtree
= gfc_find_symtree (gfc_current_ns
->sym_root
, module_name
);
6989 if (mod_symtree
&& mod_symtree
->n
.sym
->attr
.intrinsic
)
6990 gfc_error ("Use of non-intrinsic module %qs at %C conflicts with "
6991 "intrinsic module name used previously", module_name
);
6998 read_module_to_tmpbuf ();
6999 gzclose (module_fp
);
7001 /* Skip the first line of the module, after checking that this is
7002 a gfortran module file. */
7008 bad_module ("Unexpected end of module");
7011 if ((start
== 1 && strcmp (atom_name
, "GFORTRAN") != 0)
7012 || (start
== 2 && strcmp (atom_name
, " module") != 0))
7013 gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran"
7014 " module file", filename
);
7017 if (strcmp (atom_name
, " version") != 0
7018 || module_char () != ' '
7019 || parse_atom () != ATOM_STRING
7020 || strcmp (atom_string
, MOD_VERSION
))
7021 gfc_fatal_error ("Cannot read module file %qs opened at %C,"
7022 " because it was created by a different"
7023 " version of GNU Fortran", filename
);
7032 /* Make sure we're not reading the same module that we may be building. */
7033 for (p
= gfc_state_stack
; p
; p
= p
->previous
)
7034 if ((p
->state
== COMP_MODULE
|| p
->state
== COMP_SUBMODULE
)
7035 && strcmp (p
->sym
->name
, module_name
) == 0)
7036 gfc_fatal_error ("Can't USE the same %smodule we're building",
7037 p
->state
== COMP_SUBMODULE
? "sub" : "");
7040 init_true_name_tree ();
7044 free_true_name (true_name_root
);
7045 true_name_root
= NULL
;
7047 free_pi_tree (pi_root
);
7050 XDELETEVEC (module_content
);
7051 module_content
= NULL
;
7053 use_stmt
= gfc_get_use_list ();
7054 *use_stmt
= *module
;
7055 use_stmt
->next
= gfc_current_ns
->use_stmts
;
7056 gfc_current_ns
->use_stmts
= use_stmt
;
7058 gfc_current_locus
= old_locus
;
7062 /* Remove duplicated intrinsic operators from the rename list. */
7065 rename_list_remove_duplicate (gfc_use_rename
*list
)
7067 gfc_use_rename
*seek
, *last
;
7069 for (; list
; list
= list
->next
)
7070 if (list
->op
!= INTRINSIC_USER
&& list
->op
!= INTRINSIC_NONE
)
7073 for (seek
= list
->next
; seek
; seek
= last
->next
)
7075 if (list
->op
== seek
->op
)
7077 last
->next
= seek
->next
;
7087 /* Process all USE directives. */
7090 gfc_use_modules (void)
7092 gfc_use_list
*next
, *seek
, *last
;
7094 for (next
= module_list
; next
; next
= next
->next
)
7096 bool non_intrinsic
= next
->non_intrinsic
;
7097 bool intrinsic
= next
->intrinsic
;
7098 bool neither
= !non_intrinsic
&& !intrinsic
;
7100 for (seek
= next
->next
; seek
; seek
= seek
->next
)
7102 if (next
->module_name
!= seek
->module_name
)
7105 if (seek
->non_intrinsic
)
7106 non_intrinsic
= true;
7107 else if (seek
->intrinsic
)
7113 if (intrinsic
&& neither
&& !non_intrinsic
)
7118 filename
= XALLOCAVEC (char,
7119 strlen (next
->module_name
)
7120 + strlen (MODULE_EXTENSION
) + 1);
7121 strcpy (filename
, next
->module_name
);
7122 strcat (filename
, MODULE_EXTENSION
);
7123 fp
= gfc_open_included_file (filename
, true, true);
7126 non_intrinsic
= true;
7132 for (seek
= next
->next
; seek
; seek
= last
->next
)
7134 if (next
->module_name
!= seek
->module_name
)
7140 if ((!next
->intrinsic
&& !seek
->intrinsic
)
7141 || (next
->intrinsic
&& seek
->intrinsic
)
7144 if (!seek
->only_flag
)
7145 next
->only_flag
= false;
7148 gfc_use_rename
*r
= seek
->rename
;
7151 r
->next
= next
->rename
;
7152 next
->rename
= seek
->rename
;
7154 last
->next
= seek
->next
;
7162 for (; module_list
; module_list
= next
)
7164 next
= module_list
->next
;
7165 rename_list_remove_duplicate (module_list
->rename
);
7166 gfc_use_module (module_list
);
7169 gfc_rename_list
= NULL
;
7174 gfc_free_use_stmts (gfc_use_list
*use_stmts
)
7177 for (; use_stmts
; use_stmts
= next
)
7179 gfc_use_rename
*next_rename
;
7181 for (; use_stmts
->rename
; use_stmts
->rename
= next_rename
)
7183 next_rename
= use_stmts
->rename
->next
;
7184 free (use_stmts
->rename
);
7186 next
= use_stmts
->next
;
7193 gfc_module_init_2 (void)
7195 last_atom
= ATOM_LPAREN
;
7196 gfc_rename_list
= NULL
;
7202 gfc_module_done_2 (void)
7204 free_rename (gfc_rename_list
);
7205 gfc_rename_list
= NULL
;