Line data Source code
1 : /* Handle modules, which amounts to loading and saving symbols and
2 : their attendant structures.
3 : Copyright (C) 2000-2026 Free Software Foundation, Inc.
4 : Contributed by Andy Vaught
5 :
6 : This file is part of GCC.
7 :
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
11 : version.
12 :
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
16 : for more details.
17 :
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/>. */
21 :
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.
29 :
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:
34 :
35 : ( ( <Interface info for UPLUS> )
36 : ( <Interface info for UMINUS> )
37 : ...
38 : )
39 : ( ( <name of operator interface> <module of op interface> <i/f1> ... )
40 : ...
41 : )
42 : ( ( <name of generic interface> <module of generic interface> <i/f1> ... )
43 : ...
44 : )
45 : ( ( <common name> <symbol> <saved flag>)
46 : ...
47 : )
48 :
49 : ( equivalence list )
50 :
51 : ( <Symbol Number (in no particular order)>
52 : <True name of symbol>
53 : <Module name of symbol>
54 : ( <symbol information> )
55 : ...
56 : )
57 : ( <Symtree name>
58 : <Ambiguous flag>
59 : <Symbol number>
60 : ...
61 : )
62 :
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
65 : particular order. */
66 :
67 : #include "config.h"
68 : #include "system.h"
69 : #include "coretypes.h"
70 : #include "options.h"
71 : #include "tree.h"
72 : #include "gfortran.h"
73 : #include "stringpool.h"
74 : #include "arith.h"
75 : #include "match.h"
76 : #include "parse.h" /* FIXME */
77 : #include "constructor.h"
78 : #include "cpp.h"
79 : #include "diagnostic-core.h"
80 : #include "scanner.h"
81 : #include <zlib.h>
82 :
83 : #define MODULE_EXTENSION ".mod"
84 : #define SUBMODULE_EXTENSION ".smod"
85 :
86 : /* Don't put any single quote (') in MOD_VERSION, if you want it to be
87 : recognized. */
88 : #define MOD_VERSION "16"
89 : #define MOD_VERSION_NUMERIC 16
90 : /* Older mod versions we can still parse. */
91 : #define COMPAT_MOD_VERSIONS { "15" }
92 :
93 :
94 : /* Structure that describes a position within a module file. */
95 :
96 : typedef struct
97 : {
98 : int column, line;
99 : long pos;
100 : }
101 : module_locus;
102 :
103 : /* Structure for list of symbols of intrinsic modules. */
104 : typedef struct
105 : {
106 : int id;
107 : const char *name;
108 : int value;
109 : int standard;
110 : }
111 : intmod_sym;
112 :
113 :
114 : typedef enum
115 : {
116 : P_UNKNOWN = 0, P_OTHER, P_NAMESPACE, P_COMPONENT, P_SYMBOL
117 : }
118 : pointer_t;
119 :
120 : /* The fixup structure lists pointers to pointers that have to
121 : be updated when a pointer value becomes known. */
122 :
123 : typedef struct fixup_t
124 : {
125 : void **pointer;
126 : struct fixup_t *next;
127 : }
128 : fixup_t;
129 :
130 :
131 : /* Structure for holding extra info needed for pointers being read. */
132 :
133 : enum gfc_rsym_state
134 : {
135 : UNUSED,
136 : NEEDED,
137 : USED
138 : };
139 :
140 : enum gfc_wsym_state
141 : {
142 : UNREFERENCED = 0,
143 : NEEDS_WRITE,
144 : WRITTEN
145 : };
146 :
147 : typedef struct pointer_info
148 : {
149 : BBT_HEADER (pointer_info);
150 : HOST_WIDE_INT integer;
151 : pointer_t type;
152 :
153 : /* The first component of each member of the union is the pointer
154 : being stored. */
155 :
156 : fixup_t *fixup;
157 :
158 : union
159 : {
160 : void *pointer; /* Member for doing pointer searches. */
161 :
162 : struct
163 : {
164 : gfc_symbol *sym;
165 : char *true_name, *module, *binding_label;
166 : fixup_t *stfixup;
167 : gfc_symtree *symtree;
168 : enum gfc_rsym_state state;
169 : int ns, referenced, renamed;
170 : module_locus where;
171 : }
172 : rsym;
173 :
174 : struct
175 : {
176 : gfc_symbol *sym;
177 : enum gfc_wsym_state state;
178 : }
179 : wsym;
180 : }
181 : u;
182 :
183 : }
184 : pointer_info;
185 :
186 : #define gfc_get_pointer_info() XCNEW (pointer_info)
187 :
188 :
189 : /* Local variables */
190 :
191 : /* The gzFile for the module we're reading or writing. */
192 : static gzFile module_fp;
193 :
194 : /* Fully qualified module path */
195 : static char *module_fullpath = NULL;
196 :
197 : /* The name of the module we're reading (USE'ing) or writing. */
198 : static const char *module_name;
199 : /* The name of the .smod file that the submodule will write to. */
200 : static const char *submodule_name;
201 :
202 : /* The list of use statements to apply to the current namespace
203 : before parsing the non-use statements. */
204 : static gfc_use_list *module_list;
205 : /* The end of the MODULE_LIST list above at the time the recognition
206 : of the current statement started. */
207 : static gfc_use_list **old_module_list_tail;
208 :
209 : /* If we're reading an intrinsic module, this is its ID. */
210 : static intmod_id current_intmod;
211 :
212 : /* Content of module. */
213 : static char* module_content;
214 :
215 : static long module_pos;
216 : static int module_line, module_column, only_flag;
217 : static int prev_module_line, prev_module_column;
218 :
219 : static enum
220 : { IO_INPUT, IO_OUTPUT }
221 : iomode;
222 :
223 : static gfc_use_rename *gfc_rename_list;
224 : static pointer_info *pi_root;
225 : static int symbol_number; /* Counter for assigning symbol numbers */
226 :
227 : /* Tells mio_expr_ref to make symbols for unused equivalence members. */
228 : static bool in_load_equiv;
229 :
230 :
231 :
232 : /*****************************************************************/
233 :
234 : /* Pointer/integer conversion. Pointers between structures are stored
235 : as integers in the module file. The next couple of subroutines
236 : handle this translation for reading and writing. */
237 :
238 : /* Recursively free the tree of pointer structures. */
239 :
240 : static void
241 4434216 : free_pi_tree (pointer_info *p)
242 : {
243 4434216 : if (p == NULL)
244 : return;
245 :
246 2204858 : if (p->fixup != NULL)
247 0 : gfc_internal_error ("free_pi_tree(): Unresolved fixup");
248 :
249 2204858 : free_pi_tree (p->left);
250 2204858 : free_pi_tree (p->right);
251 :
252 2204858 : if (iomode == IO_INPUT)
253 : {
254 1770921 : XDELETEVEC (p->u.rsym.true_name);
255 1770921 : XDELETEVEC (p->u.rsym.module);
256 1770921 : XDELETEVEC (p->u.rsym.binding_label);
257 : }
258 :
259 2204858 : free (p);
260 : }
261 :
262 :
263 : /* Compare pointers when searching by pointer. Used when writing a
264 : module. */
265 :
266 : static int
267 2519466 : compare_pointers (void *_sn1, void *_sn2)
268 : {
269 2519466 : pointer_info *sn1, *sn2;
270 :
271 2519466 : sn1 = (pointer_info *) _sn1;
272 2519466 : sn2 = (pointer_info *) _sn2;
273 :
274 2519466 : if (sn1->u.pointer < sn2->u.pointer)
275 : return -1;
276 1488519 : if (sn1->u.pointer > sn2->u.pointer)
277 1488519 : return 1;
278 :
279 : return 0;
280 : }
281 :
282 :
283 : /* Compare integers when searching by integer. Used when reading a
284 : module. */
285 :
286 : static int
287 83998442 : compare_integers (void *_sn1, void *_sn2)
288 : {
289 83998442 : pointer_info *sn1, *sn2;
290 :
291 83998442 : sn1 = (pointer_info *) _sn1;
292 83998442 : sn2 = (pointer_info *) _sn2;
293 :
294 13635845 : if (sn1->integer < sn2->integer)
295 : return -1;
296 37905971 : if (sn1->integer > sn2->integer)
297 9114135 : return 1;
298 :
299 : return 0;
300 : }
301 :
302 :
303 : /* Initialize the pointer_info tree. */
304 :
305 : static void
306 24500 : init_pi_tree (void)
307 : {
308 24500 : compare_fn compare;
309 24500 : pointer_info *p;
310 :
311 24500 : pi_root = NULL;
312 24500 : compare = (iomode == IO_INPUT) ? compare_integers : compare_pointers;
313 :
314 : /* Pointer 0 is the NULL pointer. */
315 24500 : p = gfc_get_pointer_info ();
316 24500 : p->u.pointer = NULL;
317 24500 : p->integer = 0;
318 24500 : p->type = P_OTHER;
319 :
320 24500 : gfc_insert_bbt (&pi_root, p, compare);
321 :
322 : /* Pointer 1 is the current namespace. */
323 24500 : p = gfc_get_pointer_info ();
324 24500 : p->u.pointer = gfc_current_ns;
325 24500 : p->integer = 1;
326 24500 : p->type = P_NAMESPACE;
327 :
328 24500 : gfc_insert_bbt (&pi_root, p, compare);
329 :
330 24500 : symbol_number = 2;
331 24500 : }
332 :
333 :
334 : /* During module writing, call here with a pointer to something,
335 : returning the pointer_info node. */
336 :
337 : static pointer_info *
338 2113705 : find_pointer (void *gp)
339 : {
340 2113705 : pointer_info *p;
341 :
342 2113705 : p = pi_root;
343 11181159 : while (p != NULL)
344 : {
345 10767938 : if (p->u.pointer == gp)
346 : break;
347 9067454 : p = (gp < p->u.pointer) ? p->left : p->right;
348 : }
349 :
350 2113705 : return p;
351 : }
352 :
353 :
354 : /* Given a pointer while writing, returns the pointer_info tree node,
355 : creating it if it doesn't exist. */
356 :
357 : static pointer_info *
358 1980676 : get_pointer (void *gp)
359 : {
360 1980676 : pointer_info *p;
361 :
362 1980676 : p = find_pointer (gp);
363 1980676 : if (p != NULL)
364 : return p;
365 :
366 : /* Pointer doesn't have an integer. Give it one. */
367 413221 : p = gfc_get_pointer_info ();
368 :
369 413221 : p->u.pointer = gp;
370 413221 : p->integer = symbol_number++;
371 :
372 413221 : gfc_insert_bbt (&pi_root, p, compare_pointers);
373 :
374 413221 : return p;
375 : }
376 :
377 :
378 : /* Given an integer during reading, find it in the pointer_info tree,
379 : creating the node if not found. */
380 :
381 : static pointer_info *
382 9141890 : get_integer (HOST_WIDE_INT integer)
383 : {
384 9141890 : pointer_info *p, t;
385 9141890 : int c;
386 :
387 9141890 : t.integer = integer;
388 :
389 9141890 : p = pi_root;
390 72105234 : while (p != NULL)
391 : {
392 70362597 : c = compare_integers (&t, p);
393 : if (c == 0)
394 : break;
395 :
396 62963344 : p = (c < 0) ? p->left : p->right;
397 : }
398 :
399 9141890 : if (p != NULL)
400 : return p;
401 :
402 1742637 : p = gfc_get_pointer_info ();
403 1742637 : p->integer = integer;
404 1742637 : p->u.pointer = NULL;
405 :
406 1742637 : gfc_insert_bbt (&pi_root, p, compare_integers);
407 :
408 1742637 : return p;
409 : }
410 :
411 :
412 : /* Resolve any fixups using a known pointer. */
413 :
414 : static void
415 1782313 : resolve_fixups (fixup_t *f, void *gp)
416 : {
417 1782313 : fixup_t *next;
418 :
419 2691238 : for (; f; f = next)
420 : {
421 908925 : next = f->next;
422 908925 : *(f->pointer) = gp;
423 908925 : free (f);
424 : }
425 1782313 : }
426 :
427 :
428 : /* Convert a string such that it starts with a lower-case character. Used
429 : to convert the symtree name of a derived-type to the symbol name or to
430 : the name of the associated generic function. */
431 :
432 : const char *
433 1125741 : gfc_dt_lower_string (const char *name)
434 : {
435 1125741 : if (name[0] != (char) TOLOWER ((unsigned char) name[0]))
436 67746 : return gfc_get_string ("%c%s", (char) TOLOWER ((unsigned char) name[0]),
437 67746 : &name[1]);
438 1057995 : return gfc_get_string ("%s", name);
439 : }
440 :
441 :
442 : /* Convert a string such that it starts with an upper-case character. Used to
443 : return the symtree-name for a derived type; the symbol name itself and the
444 : symtree/symbol name of the associated generic function start with a lower-
445 : case character. */
446 :
447 : const char *
448 1564303 : gfc_dt_upper_string (const char *name)
449 : {
450 1564303 : if (name[0] != (char) TOUPPER ((unsigned char) name[0]))
451 1536729 : return gfc_get_string ("%c%s", (char) TOUPPER ((unsigned char) name[0]),
452 1536729 : &name[1]);
453 27574 : return gfc_get_string ("%s", name);
454 : }
455 :
456 : /* Call here during module reading when we know what pointer to
457 : associate with an integer. Any fixups that exist are resolved at
458 : this time. */
459 :
460 : static void
461 1089167 : associate_integer_pointer (pointer_info *p, void *gp)
462 : {
463 1089167 : if (p->u.pointer != NULL)
464 0 : gfc_internal_error ("associate_integer_pointer(): Already associated");
465 :
466 1089167 : p->u.pointer = gp;
467 :
468 1089167 : resolve_fixups (p->fixup, gp);
469 :
470 1089167 : p->fixup = NULL;
471 1089167 : }
472 :
473 :
474 : /* During module reading, given an integer and a pointer to a pointer,
475 : either store the pointer from an already-known value or create a
476 : fixup structure in order to store things later. Returns zero if
477 : the reference has been actually stored, or nonzero if the reference
478 : must be fixed later (i.e., associate_integer_pointer must be called
479 : sometime later. Returns the pointer_info structure. */
480 :
481 : static pointer_info *
482 5717030 : add_fixup (HOST_WIDE_INT integer, void *gp)
483 : {
484 5717030 : pointer_info *p;
485 5717030 : fixup_t *f;
486 5717030 : char **cp;
487 :
488 5717030 : p = get_integer (integer);
489 :
490 5717030 : if (p->integer == 0 || p->u.pointer != NULL)
491 : {
492 4820530 : cp = (char **) gp;
493 4820530 : *cp = (char *) p->u.pointer;
494 : }
495 : else
496 : {
497 896500 : f = XCNEW (fixup_t);
498 :
499 896500 : f->next = p->fixup;
500 896500 : p->fixup = f;
501 :
502 896500 : f->pointer = (void **) gp;
503 : }
504 :
505 5717030 : return p;
506 : }
507 :
508 :
509 : /*****************************************************************/
510 :
511 : /* Parser related subroutines */
512 :
513 : /* Free the rename list left behind by a USE statement. */
514 :
515 : static void
516 95129 : free_rename (gfc_use_rename *list)
517 : {
518 95129 : gfc_use_rename *next;
519 :
520 106348 : for (; list; list = next)
521 : {
522 11219 : next = list->next;
523 11219 : free (list);
524 : }
525 0 : }
526 :
527 :
528 : /* Match a USE statement. */
529 :
530 : match
531 25067 : gfc_match_use (void)
532 : {
533 25067 : char name[GFC_MAX_SYMBOL_LEN + 1], module_nature[GFC_MAX_SYMBOL_LEN + 1];
534 25067 : gfc_use_rename *tail = NULL, *new_use;
535 25067 : interface_type type, type2;
536 25067 : gfc_intrinsic_op op;
537 25067 : match m;
538 25067 : gfc_use_list *use_list;
539 25067 : gfc_symtree *st;
540 25067 : locus loc;
541 :
542 25067 : use_list = gfc_get_use_list ();
543 :
544 25067 : if (gfc_match (" , ") == MATCH_YES)
545 : {
546 4053 : if ((m = gfc_match (" %n ::", module_nature)) == MATCH_YES)
547 : {
548 4051 : if (!gfc_notify_std (GFC_STD_F2003, "module "
549 : "nature in USE statement at %C"))
550 0 : goto cleanup;
551 :
552 4051 : if (strcmp (module_nature, "intrinsic") == 0)
553 4037 : use_list->intrinsic = true;
554 : else
555 : {
556 14 : if (strcmp (module_nature, "non_intrinsic") == 0)
557 13 : use_list->non_intrinsic = true;
558 : else
559 : {
560 1 : gfc_error ("Module nature in USE statement at %C shall "
561 : "be either INTRINSIC or NON_INTRINSIC");
562 1 : goto cleanup;
563 : }
564 : }
565 : }
566 : else
567 : {
568 : /* Help output a better error message than "Unclassifiable
569 : statement". */
570 2 : gfc_match (" %n", module_nature);
571 2 : if (strcmp (module_nature, "intrinsic") == 0
572 1 : || strcmp (module_nature, "non_intrinsic") == 0)
573 2 : gfc_error ("\"::\" was expected after module nature at %C "
574 : "but was not found");
575 2 : free (use_list);
576 2 : return m;
577 : }
578 : }
579 : else
580 : {
581 21014 : m = gfc_match (" ::");
582 21346 : if (m == MATCH_YES &&
583 332 : !gfc_notify_std(GFC_STD_F2003, "\"USE :: module\" at %C"))
584 0 : goto cleanup;
585 :
586 21014 : if (m != MATCH_YES)
587 : {
588 20682 : m = gfc_match ("% ");
589 20682 : if (m != MATCH_YES)
590 : {
591 17 : free (use_list);
592 17 : return m;
593 : }
594 : }
595 : }
596 :
597 25047 : use_list->where = gfc_current_locus;
598 :
599 25047 : m = gfc_match_name (name);
600 25047 : if (m != MATCH_YES)
601 : {
602 12 : free (use_list);
603 12 : return m;
604 : }
605 :
606 25035 : use_list->module_name = gfc_get_string ("%s", name);
607 :
608 25035 : if (gfc_match_eos () == MATCH_YES)
609 15388 : goto done;
610 :
611 9647 : if (gfc_match_char (',') != MATCH_YES)
612 0 : goto syntax;
613 :
614 9647 : if (gfc_match (" only :") == MATCH_YES)
615 9400 : use_list->only_flag = true;
616 :
617 9647 : if (gfc_match_eos () == MATCH_YES)
618 1 : goto done;
619 :
620 14331 : for (;;)
621 : {
622 : /* Get a new rename struct and add it to the rename list. */
623 14331 : new_use = gfc_get_use_rename ();
624 14331 : new_use->where = gfc_current_locus;
625 14331 : new_use->found = 0;
626 :
627 14331 : if (use_list->rename == NULL)
628 9646 : use_list->rename = new_use;
629 : else
630 4685 : tail->next = new_use;
631 14331 : tail = new_use;
632 :
633 : /* See what kind of interface we're dealing with. Assume it is
634 : not an operator. */
635 14331 : new_use->op = INTRINSIC_NONE;
636 14331 : if (gfc_match_generic_spec (&type, name, &op) == MATCH_ERROR)
637 0 : goto cleanup;
638 :
639 14331 : switch (type)
640 : {
641 1 : case INTERFACE_NAMELESS:
642 1 : gfc_error ("Missing generic specification in USE statement at %C");
643 1 : goto cleanup;
644 :
645 14213 : case INTERFACE_USER_OP:
646 14213 : case INTERFACE_GENERIC:
647 14213 : case INTERFACE_DTIO:
648 14213 : loc = gfc_current_locus;
649 :
650 14213 : m = gfc_match (" =>");
651 :
652 80 : if (type == INTERFACE_USER_OP && m == MATCH_YES
653 14259 : && (!gfc_notify_std(GFC_STD_F2003, "Renaming "
654 : "operators in USE statements at %C")))
655 2 : goto cleanup;
656 :
657 14211 : if (type == INTERFACE_USER_OP)
658 78 : new_use->op = INTRINSIC_USER;
659 :
660 14211 : if (use_list->only_flag)
661 : {
662 13861 : if (m != MATCH_YES)
663 13502 : strcpy (new_use->use_name, name);
664 : else
665 : {
666 359 : strcpy (new_use->local_name, name);
667 359 : m = gfc_match_generic_spec (&type2, new_use->use_name, &op);
668 359 : if (type != type2)
669 1 : goto syntax;
670 358 : if (m == MATCH_NO)
671 0 : goto syntax;
672 358 : if (m == MATCH_ERROR)
673 0 : goto cleanup;
674 : }
675 : }
676 : else
677 : {
678 350 : if (m != MATCH_YES)
679 0 : goto syntax;
680 350 : strcpy (new_use->local_name, name);
681 :
682 350 : m = gfc_match_generic_spec (&type2, new_use->use_name, &op);
683 350 : if (type != type2)
684 2 : goto syntax;
685 348 : if (m == MATCH_NO)
686 0 : goto syntax;
687 348 : if (m == MATCH_ERROR)
688 0 : goto cleanup;
689 : }
690 :
691 14208 : st = gfc_find_symtree (gfc_current_ns->sym_root, name);
692 14208 : if (st && type != INTERFACE_USER_OP
693 13 : && (st->n.sym->module != use_list->module_name
694 3 : || strcmp (st->n.sym->name, new_use->use_name) != 0))
695 : {
696 10 : if (m == MATCH_YES)
697 7 : gfc_error ("Symbol %qs at %L conflicts with the rename symbol "
698 : "at %L", name, &st->n.sym->declared_at, &loc);
699 : else
700 3 : gfc_error ("Symbol %qs at %L conflicts with the symbol "
701 : "at %L", name, &st->n.sym->declared_at, &loc);
702 10 : goto cleanup;
703 : }
704 :
705 14198 : if (strcmp (new_use->use_name, use_list->module_name) == 0
706 14196 : || strcmp (new_use->local_name, use_list->module_name) == 0)
707 : {
708 3 : gfc_error ("The name %qs at %C has already been used as "
709 : "an external module name", use_list->module_name);
710 3 : goto cleanup;
711 : }
712 : break;
713 :
714 117 : case INTERFACE_INTRINSIC_OP:
715 117 : new_use->op = op;
716 117 : break;
717 :
718 0 : default:
719 0 : gcc_unreachable ();
720 : }
721 :
722 14312 : if (gfc_match_eos () == MATCH_YES)
723 : break;
724 4687 : if (gfc_match_char (',') != MATCH_YES)
725 2 : goto syntax;
726 : }
727 :
728 9625 : done:
729 25014 : if (module_list)
730 : {
731 : gfc_use_list *last = module_list;
732 4232 : while (last->next)
733 : last = last->next;
734 3386 : last->next = use_list;
735 : }
736 : else
737 21628 : module_list = use_list;
738 :
739 : return MATCH_YES;
740 :
741 5 : syntax:
742 5 : gfc_syntax_error (ST_USE);
743 :
744 22 : cleanup:
745 22 : free_rename (use_list->rename);
746 22 : free (use_list);
747 22 : return MATCH_ERROR;
748 : }
749 :
750 :
751 : /* Match a SUBMODULE statement.
752 :
753 : According to F2008:11.2.3.2, "The submodule identifier is the
754 : ordered pair whose first element is the ancestor module name and
755 : whose second element is the submodule name. 'Submodule_name' is
756 : used for the submodule filename and uses '@' as a separator, whilst
757 : the name of the symbol for the module uses '.' as a separator.
758 : The reasons for these choices are:
759 : (i) To follow another leading brand in the submodule filenames;
760 : (ii) Since '.' is not particularly visible in the filenames; and
761 : (iii) The linker does not permit '@' in mnemonics. */
762 :
763 : match
764 276 : gfc_match_submodule (void)
765 : {
766 276 : match m;
767 276 : char name[GFC_MAX_SYMBOL_LEN + 1];
768 276 : gfc_use_list *use_list;
769 276 : bool seen_colon = false;
770 :
771 276 : if (!gfc_notify_std (GFC_STD_F2008, "SUBMODULE declaration at %C"))
772 : return MATCH_ERROR;
773 :
774 275 : if (gfc_current_state () != COMP_NONE)
775 : {
776 3 : gfc_error ("SUBMODULE declaration at %C cannot appear within "
777 : "another scoping unit");
778 3 : return MATCH_ERROR;
779 : }
780 :
781 272 : gfc_new_block = NULL;
782 272 : gcc_assert (module_list == NULL);
783 :
784 272 : if (gfc_match_char ('(') != MATCH_YES)
785 0 : goto syntax;
786 :
787 299 : while (1)
788 : {
789 299 : m = gfc_match (" %n", name);
790 299 : if (m != MATCH_YES)
791 0 : goto syntax;
792 :
793 299 : use_list = gfc_get_use_list ();
794 299 : use_list->where = gfc_current_locus;
795 :
796 299 : if (module_list)
797 : {
798 : gfc_use_list *last = module_list;
799 27 : while (last->next)
800 : last = last->next;
801 27 : last->next = use_list;
802 27 : use_list->module_name
803 27 : = gfc_get_string ("%s.%s", module_list->module_name, name);
804 27 : use_list->submodule_name
805 27 : = gfc_get_string ("%s@%s", module_list->module_name, name);
806 : }
807 : else
808 : {
809 272 : module_list = use_list;
810 272 : use_list->module_name = gfc_get_string ("%s", name);
811 272 : use_list->submodule_name = use_list->module_name;
812 : }
813 :
814 299 : if (gfc_match_char (')') == MATCH_YES)
815 : break;
816 :
817 56 : if (gfc_match_char (':') != MATCH_YES
818 28 : || seen_colon)
819 1 : goto syntax;
820 :
821 : seen_colon = true;
822 : }
823 :
824 271 : m = gfc_match (" %s%t", &gfc_new_block);
825 271 : if (m != MATCH_YES)
826 0 : goto syntax;
827 :
828 271 : submodule_name = gfc_get_string ("%s@%s", module_list->module_name,
829 : gfc_new_block->name);
830 :
831 271 : gfc_new_block->name = gfc_get_string ("%s.%s",
832 : module_list->module_name,
833 : gfc_new_block->name);
834 :
835 271 : if (!gfc_add_flavor (&gfc_new_block->attr, FL_MODULE,
836 : gfc_new_block->name, NULL))
837 : return MATCH_ERROR;
838 :
839 : /* Just retain the ultimate .(s)mod file for reading, since it
840 : contains all the information in its ancestors. */
841 271 : use_list = module_list;
842 297 : for (; module_list->next; use_list = module_list)
843 : {
844 26 : module_list = use_list->next;
845 26 : free (use_list);
846 : }
847 :
848 : return MATCH_YES;
849 :
850 1 : syntax:
851 1 : gfc_error ("Syntax error in SUBMODULE statement at %C");
852 1 : return MATCH_ERROR;
853 : }
854 :
855 :
856 : /* Given a name and a number, inst, return the inst name
857 : under which to load this symbol. Returns NULL if this
858 : symbol shouldn't be loaded. If inst is zero, returns
859 : the number of instances of this name. If interface is
860 : true, a user-defined operator is sought, otherwise only
861 : non-operators are sought. */
862 :
863 : static const char *
864 1212059 : find_use_name_n (const char *name, int *inst, bool interface)
865 : {
866 1212059 : gfc_use_rename *u;
867 1212059 : const char *low_name = NULL;
868 1212059 : int i;
869 :
870 : /* For derived types. */
871 1212059 : if (name[0] != (char) TOLOWER ((unsigned char) name[0]))
872 30876 : low_name = gfc_dt_lower_string (name);
873 :
874 1212059 : i = 0;
875 1360213 : for (u = gfc_rename_list; u; u = u->next)
876 : {
877 152697 : if ((!low_name && strcmp (u->use_name, name) != 0)
878 4352 : || (low_name && strcmp (u->use_name, low_name) != 0)
879 9127 : || (u->op == INTRINSIC_USER && !interface)
880 9125 : || (u->op != INTRINSIC_USER && interface))
881 143572 : continue;
882 9125 : if (++i == *inst)
883 : break;
884 : }
885 :
886 1212059 : if (!*inst)
887 : {
888 605958 : *inst = i;
889 605958 : return NULL;
890 : }
891 :
892 606101 : if (u == NULL)
893 601558 : return only_flag ? NULL : name;
894 :
895 4543 : u->found = 1;
896 :
897 4543 : if (low_name)
898 : {
899 756 : if (u->local_name[0] == '\0')
900 : return name;
901 108 : return gfc_dt_upper_string (u->local_name);
902 : }
903 :
904 3787 : return (u->local_name[0] != '\0') ? u->local_name : name;
905 : }
906 :
907 :
908 : /* Given a name, return the name under which to load this symbol.
909 : Returns NULL if this symbol shouldn't be loaded. */
910 :
911 : static const char *
912 86 : find_use_name (const char *name, bool interface)
913 : {
914 86 : int i = 1;
915 50 : return find_use_name_n (name, &i, interface);
916 : }
917 :
918 :
919 : /* Given a real name, return the number of use names associated with it. */
920 :
921 : static int
922 605958 : number_use_names (const char *name, bool interface)
923 : {
924 605958 : int i = 0;
925 0 : find_use_name_n (name, &i, interface);
926 605958 : return i;
927 : }
928 :
929 :
930 : /* Try to find the operator in the current list. */
931 :
932 : static gfc_use_rename *
933 72078 : find_use_operator (gfc_intrinsic_op op)
934 : {
935 72078 : gfc_use_rename *u;
936 :
937 180792 : for (u = gfc_rename_list; u; u = u->next)
938 108922 : if (u->op == op)
939 : return u;
940 :
941 : return NULL;
942 : }
943 :
944 :
945 : /*****************************************************************/
946 :
947 : /* The next couple of subroutines maintain a tree used to avoid a
948 : brute-force search for a combination of true name and module name.
949 : While symtree names, the name that a particular symbol is known by
950 : can changed with USE statements, we still have to keep track of the
951 : true names to generate the correct reference, and also avoid
952 : loading the same real symbol twice in a program unit.
953 :
954 : When we start reading, the true name tree is built and maintained
955 : as symbols are read. The tree is searched as we load new symbols
956 : to see if it already exists someplace in the namespace. */
957 :
958 : typedef struct true_name
959 : {
960 : BBT_HEADER (true_name);
961 : const char *name;
962 : gfc_symbol *sym;
963 : }
964 : true_name;
965 :
966 : static true_name *true_name_root;
967 :
968 :
969 : /* Compare two true_name structures. */
970 :
971 : static int
972 3374187 : compare_true_names (void *_t1, void *_t2)
973 : {
974 3374187 : true_name *t1, *t2;
975 3374187 : int c;
976 :
977 3374187 : t1 = (true_name *) _t1;
978 3374187 : t2 = (true_name *) _t2;
979 :
980 3374187 : c = ((t1->sym->module > t2->sym->module)
981 3374187 : - (t1->sym->module < t2->sym->module));
982 3374187 : if (c != 0)
983 : return c;
984 :
985 1043528 : return strcmp (t1->name, t2->name);
986 : }
987 :
988 :
989 : /* Given a true name, search the true name tree to see if it exists
990 : within the main namespace. */
991 :
992 : static gfc_symbol *
993 1403928 : find_true_name (const char *name, const char *module)
994 : {
995 1403928 : true_name t, *p;
996 1403928 : gfc_symbol sym;
997 1403928 : int c;
998 :
999 1403928 : t.name = gfc_get_string ("%s", name);
1000 1403928 : if (module != NULL)
1001 1382248 : sym.module = gfc_get_string ("%s", module);
1002 : else
1003 : sym.module = NULL;
1004 1403928 : t.sym = &sym;
1005 :
1006 1403928 : p = true_name_root;
1007 4300977 : while (p != NULL)
1008 : {
1009 2947808 : c = compare_true_names ((void *) (&t), (void *) p);
1010 2947808 : if (c == 0)
1011 50759 : return p->sym;
1012 :
1013 2897049 : p = (c < 0) ? p->left : p->right;
1014 : }
1015 :
1016 : return NULL;
1017 : }
1018 :
1019 :
1020 : /* Given a gfc_symbol pointer that is not in the true name tree, add it. */
1021 :
1022 : static void
1023 105069 : add_true_name (gfc_symbol *sym)
1024 : {
1025 105069 : true_name *t;
1026 :
1027 105069 : t = XCNEW (true_name);
1028 105069 : t->sym = sym;
1029 105069 : if (gfc_fl_struct (sym->attr.flavor))
1030 5796 : t->name = gfc_dt_upper_string (sym->name);
1031 : else
1032 99273 : t->name = sym->name;
1033 :
1034 105069 : gfc_insert_bbt (&true_name_root, t, compare_true_names);
1035 105069 : }
1036 :
1037 :
1038 : /* Recursive function to build the initial true name tree by
1039 : recursively traversing the current namespace. */
1040 :
1041 : static void
1042 225820 : build_tnt (gfc_symtree *st)
1043 : {
1044 225820 : const char *name;
1045 225820 : if (st == NULL)
1046 : return;
1047 :
1048 105839 : build_tnt (st->left);
1049 105839 : build_tnt (st->right);
1050 :
1051 105839 : if (gfc_fl_struct (st->n.sym->attr.flavor))
1052 6238 : name = gfc_dt_upper_string (st->n.sym->name);
1053 : else
1054 99601 : name = st->n.sym->name;
1055 :
1056 105839 : if (find_true_name (name, st->n.sym->module) != NULL)
1057 : return;
1058 :
1059 105069 : add_true_name (st->n.sym);
1060 : }
1061 :
1062 :
1063 : /* Initialize the true name tree with the current namespace. */
1064 :
1065 : static void
1066 14142 : init_true_name_tree (void)
1067 : {
1068 14142 : true_name_root = NULL;
1069 14142 : build_tnt (gfc_current_ns->sym_root);
1070 14142 : }
1071 :
1072 :
1073 : /* Recursively free a true name tree node. */
1074 :
1075 : static void
1076 224280 : free_true_name (true_name *t)
1077 : {
1078 224280 : if (t == NULL)
1079 : return;
1080 105069 : free_true_name (t->left);
1081 105069 : free_true_name (t->right);
1082 :
1083 105069 : free (t);
1084 : }
1085 :
1086 :
1087 : /*****************************************************************/
1088 :
1089 : /* Module reading and writing. */
1090 :
1091 : /* The following are versions similar to the ones in scanner.cc, but
1092 : for dealing with compressed module files. */
1093 :
1094 : static gzFile
1095 10437 : gzopen_included_file_1 (const char *name, gfc_directorylist *list,
1096 : bool module, bool system)
1097 : {
1098 10437 : char *fullname;
1099 10437 : gfc_directorylist *p;
1100 10437 : gzFile f;
1101 :
1102 36729 : for (p = list; p; p = p->next)
1103 : {
1104 28545 : if (module && !p->use_for_modules)
1105 4496 : continue;
1106 :
1107 24049 : fullname = (char *) alloca(strlen (p->path) + strlen (name) + 2);
1108 24049 : strcpy (fullname, p->path);
1109 24049 : strcat (fullname, "/");
1110 24049 : strcat (fullname, name);
1111 :
1112 24049 : f = gzopen (fullname, "r");
1113 24049 : if (f != NULL)
1114 : {
1115 2253 : if (gfc_cpp_makedep ())
1116 0 : gfc_cpp_add_dep (fullname, system);
1117 :
1118 2253 : free (module_fullpath);
1119 2253 : module_fullpath = xstrdup (fullname);
1120 2253 : return f;
1121 : }
1122 : }
1123 :
1124 : return NULL;
1125 : }
1126 :
1127 : static gzFile
1128 21088 : gzopen_included_file (const char *name, bool include_cwd, bool module)
1129 : {
1130 21088 : gzFile f = NULL;
1131 :
1132 21088 : if (IS_ABSOLUTE_PATH (name) || include_cwd)
1133 : {
1134 21088 : f = gzopen (name, "r");
1135 21088 : if (f)
1136 : {
1137 11889 : if (gfc_cpp_makedep ())
1138 0 : gfc_cpp_add_dep (name, false);
1139 :
1140 11889 : free (module_fullpath);
1141 11889 : module_fullpath = xstrdup (name);
1142 : }
1143 : }
1144 :
1145 11889 : if (!f)
1146 9199 : f = gzopen_included_file_1 (name, include_dirs, module, false);
1147 :
1148 21088 : return f;
1149 : }
1150 :
1151 : static gzFile
1152 1238 : gzopen_intrinsic_module (const char* name)
1153 : {
1154 1238 : gzFile f = NULL;
1155 :
1156 1238 : if (IS_ABSOLUTE_PATH (name))
1157 : {
1158 0 : f = gzopen (name, "r");
1159 0 : if (f)
1160 : {
1161 0 : if (gfc_cpp_makedep ())
1162 0 : gfc_cpp_add_dep (name, true);
1163 :
1164 0 : free (module_fullpath);
1165 0 : module_fullpath = xstrdup (name);
1166 : }
1167 : }
1168 :
1169 0 : if (!f)
1170 1238 : f = gzopen_included_file_1 (name, intrinsic_modules_dirs, true, true);
1171 :
1172 1238 : return f;
1173 : }
1174 :
1175 :
1176 : enum atom_type
1177 : {
1178 : ATOM_NAME, ATOM_LPAREN, ATOM_RPAREN, ATOM_INTEGER, ATOM_STRING
1179 : };
1180 :
1181 : static atom_type last_atom;
1182 :
1183 :
1184 : /* The name buffer must be at least as long as a symbol name. Right
1185 : now it's not clear how we're going to store numeric constants--
1186 : probably as a hexadecimal string, since this will allow the exact
1187 : number to be preserved (this can't be done by a decimal
1188 : representation). Worry about that later. TODO! */
1189 :
1190 : #define MAX_ATOM_SIZE 100
1191 :
1192 : static HOST_WIDE_INT atom_int;
1193 : static char *atom_string, atom_name[MAX_ATOM_SIZE];
1194 :
1195 :
1196 : /* Report problems with a module. Error reporting is not very
1197 : elaborate, since this sorts of errors shouldn't really happen.
1198 : This subroutine never returns. */
1199 :
1200 : static void bad_module (const char *) ATTRIBUTE_NORETURN;
1201 :
1202 : static void
1203 0 : bad_module (const char *msgid)
1204 : {
1205 0 : XDELETEVEC (module_content);
1206 0 : module_content = NULL;
1207 :
1208 0 : switch (iomode)
1209 : {
1210 0 : case IO_INPUT:
1211 0 : gfc_fatal_error ("Reading module %qs at line %d column %d: %s",
1212 : module_fullpath, module_line, module_column, msgid);
1213 0 : break;
1214 0 : case IO_OUTPUT:
1215 0 : gfc_fatal_error ("Writing module %qs at line %d column %d: %s",
1216 : module_name, module_line, module_column, msgid);
1217 0 : break;
1218 0 : default:
1219 0 : gfc_fatal_error ("Module %qs at line %d column %d: %s",
1220 : module_name, module_line, module_column, msgid);
1221 : break;
1222 : }
1223 : }
1224 :
1225 :
1226 : /* Set the module's input pointer. */
1227 :
1228 : static void
1229 1148240 : set_module_locus (module_locus *m)
1230 : {
1231 1148240 : module_column = m->column;
1232 1148240 : module_line = m->line;
1233 1148240 : module_pos = m->pos;
1234 0 : }
1235 :
1236 :
1237 : /* Get the module's input pointer so that we can restore it later. */
1238 :
1239 : static void
1240 1354677 : get_module_locus (module_locus *m)
1241 : {
1242 1354677 : m->column = module_column;
1243 1354677 : m->line = module_line;
1244 1354677 : m->pos = module_pos;
1245 0 : }
1246 :
1247 : /* Peek at the next character in the module. */
1248 :
1249 : static int
1250 616 : module_peek_char (void)
1251 : {
1252 616 : return module_content[module_pos];
1253 : }
1254 :
1255 : /* Get the next character in the module, updating our reckoning of
1256 : where we are. */
1257 :
1258 : static int
1259 580172920 : module_char (void)
1260 : {
1261 580172920 : const char c = module_content[module_pos++];
1262 580172920 : if (c == '\0')
1263 0 : bad_module ("Unexpected EOF");
1264 :
1265 580172920 : prev_module_line = module_line;
1266 580172920 : prev_module_column = module_column;
1267 :
1268 580172920 : if (c == '\n')
1269 : {
1270 12443792 : module_line++;
1271 12443792 : module_column = 0;
1272 : }
1273 :
1274 580172920 : module_column++;
1275 580172920 : return c;
1276 : }
1277 :
1278 : /* Unget a character while remembering the line and column. Works for
1279 : a single character only. */
1280 :
1281 : static void
1282 85610365 : module_unget_char (void)
1283 : {
1284 85610365 : module_line = prev_module_line;
1285 85610365 : module_column = prev_module_column;
1286 85610365 : module_pos--;
1287 0 : }
1288 :
1289 : /* Parse a string constant. The delimiter is guaranteed to be a
1290 : single quote. */
1291 :
1292 : static void
1293 5890874 : parse_string (void)
1294 : {
1295 5890874 : int c;
1296 5890874 : size_t cursz = 30;
1297 5890874 : size_t len = 0;
1298 :
1299 5890874 : atom_string = XNEWVEC (char, cursz);
1300 :
1301 89085080 : for ( ; ; )
1302 : {
1303 47487977 : c = module_char ();
1304 :
1305 47487977 : if (c == '\'')
1306 : {
1307 5890874 : int c2 = module_char ();
1308 5890874 : if (c2 != '\'')
1309 : {
1310 5890874 : module_unget_char ();
1311 5890874 : break;
1312 : }
1313 : }
1314 :
1315 41597103 : if (len >= cursz)
1316 : {
1317 71814 : cursz *= 2;
1318 71814 : atom_string = XRESIZEVEC (char, atom_string, cursz);
1319 : }
1320 41597103 : atom_string[len] = c;
1321 41597103 : len++;
1322 41597103 : }
1323 :
1324 5890874 : atom_string = XRESIZEVEC (char, atom_string, len + 1);
1325 5890874 : atom_string[len] = '\0'; /* C-style string for debug purposes. */
1326 5890874 : }
1327 :
1328 :
1329 : /* Parse an integer. Should fit in a HOST_WIDE_INT. */
1330 :
1331 : static void
1332 38271880 : parse_integer (int c)
1333 : {
1334 38271880 : int sign = 1;
1335 :
1336 38271880 : atom_int = 0;
1337 38271880 : switch (c)
1338 : {
1339 : case ('-'):
1340 38271880 : sign = -1;
1341 : case ('+'):
1342 : break;
1343 38271264 : default:
1344 38271264 : atom_int = c - '0';
1345 38271264 : break;
1346 : }
1347 :
1348 57067726 : for (;;)
1349 : {
1350 47669803 : c = module_char ();
1351 47669803 : if (!ISDIGIT (c))
1352 : {
1353 38271880 : module_unget_char ();
1354 38271880 : break;
1355 : }
1356 :
1357 9397923 : atom_int = 10 * atom_int + c - '0';
1358 : }
1359 :
1360 38271880 : atom_int *= sign;
1361 38271880 : }
1362 :
1363 :
1364 : /* Parse a name. */
1365 :
1366 : static void
1367 27855828 : parse_name (int c)
1368 : {
1369 27855828 : char *p;
1370 27855828 : int len;
1371 :
1372 27855828 : p = atom_name;
1373 :
1374 27855828 : *p++ = c;
1375 27855828 : len = 1;
1376 :
1377 237637259 : for (;;)
1378 : {
1379 237637259 : c = module_char ();
1380 237637259 : if (!ISALNUM (c) && c != '_' && c != '-')
1381 : {
1382 27855828 : module_unget_char ();
1383 27855828 : break;
1384 : }
1385 :
1386 209781431 : *p++ = c;
1387 209781431 : if (++len > GFC_MAX_SYMBOL_LEN)
1388 0 : bad_module ("Name too long");
1389 : }
1390 :
1391 27855828 : *p = '\0';
1392 :
1393 27855828 : }
1394 :
1395 :
1396 : /* Read the next atom in the module's input stream. */
1397 :
1398 : static atom_type
1399 134598772 : parse_atom (void)
1400 : {
1401 224925306 : int c;
1402 :
1403 224925306 : do
1404 : {
1405 224925306 : c = module_char ();
1406 : }
1407 224925306 : while (c == ' ' || c == '\r' || c == '\n');
1408 :
1409 134598772 : switch (c)
1410 : {
1411 : case '(':
1412 : return ATOM_LPAREN;
1413 :
1414 31304227 : case ')':
1415 31304227 : return ATOM_RPAREN;
1416 :
1417 5890874 : case '\'':
1418 5890874 : parse_string ();
1419 5890874 : return ATOM_STRING;
1420 :
1421 38271264 : case '0':
1422 38271264 : case '1':
1423 38271264 : case '2':
1424 38271264 : case '3':
1425 38271264 : case '4':
1426 38271264 : case '5':
1427 38271264 : case '6':
1428 38271264 : case '7':
1429 38271264 : case '8':
1430 38271264 : case '9':
1431 38271264 : parse_integer (c);
1432 38271264 : return ATOM_INTEGER;
1433 :
1434 616 : case '+':
1435 616 : case '-':
1436 616 : if (ISDIGIT (module_peek_char ()))
1437 : {
1438 616 : parse_integer (c);
1439 616 : return ATOM_INTEGER;
1440 : }
1441 : else
1442 0 : bad_module ("Bad name");
1443 :
1444 27813402 : case 'a':
1445 27813402 : case 'b':
1446 27813402 : case 'c':
1447 27813402 : case 'd':
1448 27813402 : case 'e':
1449 27813402 : case 'f':
1450 27813402 : case 'g':
1451 27813402 : case 'h':
1452 27813402 : case 'i':
1453 27813402 : case 'j':
1454 27813402 : case 'k':
1455 27813402 : case 'l':
1456 27813402 : case 'm':
1457 27813402 : case 'n':
1458 27813402 : case 'o':
1459 27813402 : case 'p':
1460 27813402 : case 'q':
1461 27813402 : case 'r':
1462 27813402 : case 's':
1463 27813402 : case 't':
1464 27813402 : case 'u':
1465 27813402 : case 'v':
1466 27813402 : case 'w':
1467 27813402 : case 'x':
1468 27813402 : case 'y':
1469 27813402 : case 'z':
1470 27813402 : case 'A':
1471 27813402 : case 'B':
1472 27813402 : case 'C':
1473 27813402 : case 'D':
1474 27813402 : case 'E':
1475 27813402 : case 'F':
1476 27813402 : case 'G':
1477 27813402 : case 'H':
1478 27813402 : case 'I':
1479 27813402 : case 'J':
1480 27813402 : case 'K':
1481 27813402 : case 'L':
1482 27813402 : case 'M':
1483 27813402 : case 'N':
1484 27813402 : case 'O':
1485 27813402 : case 'P':
1486 27813402 : case 'Q':
1487 27813402 : case 'R':
1488 27813402 : case 'S':
1489 27813402 : case 'T':
1490 27813402 : case 'U':
1491 27813402 : case 'V':
1492 27813402 : case 'W':
1493 27813402 : case 'X':
1494 27813402 : case 'Y':
1495 27813402 : case 'Z':
1496 27813402 : parse_name (c);
1497 27813402 : return ATOM_NAME;
1498 :
1499 0 : default:
1500 0 : bad_module ("Bad name");
1501 : }
1502 :
1503 : /* Not reached. */
1504 : }
1505 :
1506 :
1507 : /* Peek at the next atom on the input. */
1508 :
1509 : static atom_type
1510 13591783 : peek_atom (void)
1511 : {
1512 16039453 : int c;
1513 :
1514 16039453 : do
1515 : {
1516 16039453 : c = module_char ();
1517 : }
1518 16039453 : while (c == ' ' || c == '\r' || c == '\n');
1519 :
1520 13591783 : switch (c)
1521 : {
1522 322281 : case '(':
1523 322281 : module_unget_char ();
1524 322281 : return ATOM_LPAREN;
1525 :
1526 10731858 : case ')':
1527 10731858 : module_unget_char ();
1528 10731858 : return ATOM_RPAREN;
1529 :
1530 545203 : case '\'':
1531 545203 : module_unget_char ();
1532 545203 : return ATOM_STRING;
1533 :
1534 1987205 : case '0':
1535 1987205 : case '1':
1536 1987205 : case '2':
1537 1987205 : case '3':
1538 1987205 : case '4':
1539 1987205 : case '5':
1540 1987205 : case '6':
1541 1987205 : case '7':
1542 1987205 : case '8':
1543 1987205 : case '9':
1544 1987205 : module_unget_char ();
1545 1987205 : return ATOM_INTEGER;
1546 :
1547 0 : case '+':
1548 0 : case '-':
1549 0 : if (ISDIGIT (module_peek_char ()))
1550 : {
1551 0 : module_unget_char ();
1552 0 : return ATOM_INTEGER;
1553 : }
1554 : else
1555 0 : bad_module ("Bad name");
1556 :
1557 5236 : case 'a':
1558 5236 : case 'b':
1559 5236 : case 'c':
1560 5236 : case 'd':
1561 5236 : case 'e':
1562 5236 : case 'f':
1563 5236 : case 'g':
1564 5236 : case 'h':
1565 5236 : case 'i':
1566 5236 : case 'j':
1567 5236 : case 'k':
1568 5236 : case 'l':
1569 5236 : case 'm':
1570 5236 : case 'n':
1571 5236 : case 'o':
1572 5236 : case 'p':
1573 5236 : case 'q':
1574 5236 : case 'r':
1575 5236 : case 's':
1576 5236 : case 't':
1577 5236 : case 'u':
1578 5236 : case 'v':
1579 5236 : case 'w':
1580 5236 : case 'x':
1581 5236 : case 'y':
1582 5236 : case 'z':
1583 5236 : case 'A':
1584 5236 : case 'B':
1585 5236 : case 'C':
1586 5236 : case 'D':
1587 5236 : case 'E':
1588 5236 : case 'F':
1589 5236 : case 'G':
1590 5236 : case 'H':
1591 5236 : case 'I':
1592 5236 : case 'J':
1593 5236 : case 'K':
1594 5236 : case 'L':
1595 5236 : case 'M':
1596 5236 : case 'N':
1597 5236 : case 'O':
1598 5236 : case 'P':
1599 5236 : case 'Q':
1600 5236 : case 'R':
1601 5236 : case 'S':
1602 5236 : case 'T':
1603 5236 : case 'U':
1604 5236 : case 'V':
1605 5236 : case 'W':
1606 5236 : case 'X':
1607 5236 : case 'Y':
1608 5236 : case 'Z':
1609 5236 : module_unget_char ();
1610 5236 : return ATOM_NAME;
1611 :
1612 0 : default:
1613 0 : bad_module ("Bad name");
1614 : }
1615 : }
1616 :
1617 :
1618 : /* Read the next atom from the input, requiring that it be a
1619 : particular kind. */
1620 :
1621 : static void
1622 61661966 : require_atom (atom_type type)
1623 : {
1624 61661966 : atom_type t;
1625 61661966 : const char *p;
1626 61661966 : int column, line;
1627 :
1628 61661966 : column = module_column;
1629 61661966 : line = module_line;
1630 :
1631 61661966 : t = parse_atom ();
1632 61661966 : if (t != type)
1633 : {
1634 0 : switch (type)
1635 : {
1636 0 : case ATOM_NAME:
1637 0 : p = _("Expected name");
1638 0 : break;
1639 0 : case ATOM_LPAREN:
1640 0 : p = _("Expected left parenthesis");
1641 0 : break;
1642 0 : case ATOM_RPAREN:
1643 0 : p = _("Expected right parenthesis");
1644 0 : break;
1645 0 : case ATOM_INTEGER:
1646 0 : p = _("Expected integer");
1647 0 : break;
1648 0 : case ATOM_STRING:
1649 0 : p = _("Expected string");
1650 0 : break;
1651 0 : default:
1652 0 : gfc_internal_error ("require_atom(): bad atom type required");
1653 : }
1654 :
1655 0 : module_column = column;
1656 0 : module_line = line;
1657 0 : bad_module (p);
1658 : }
1659 61661966 : }
1660 :
1661 :
1662 : /* Given a pointer to an mstring array, require that the current input
1663 : be one of the strings in the array. We return the enum value. */
1664 :
1665 : static int
1666 12752750 : find_enum (const mstring *m)
1667 : {
1668 12752750 : int i;
1669 :
1670 12752750 : i = gfc_string2code (m, atom_name);
1671 12752750 : if (i >= 0)
1672 12752750 : return i;
1673 :
1674 0 : bad_module ("find_enum(): Enum not found");
1675 :
1676 : /* Not reached. */
1677 : }
1678 :
1679 :
1680 : /* Read a string. The caller is responsible for freeing. */
1681 :
1682 : static char*
1683 3894475 : read_string (void)
1684 : {
1685 3894475 : char* p;
1686 0 : require_atom (ATOM_STRING);
1687 3894475 : p = atom_string;
1688 3894475 : atom_string = NULL;
1689 3894475 : return p;
1690 : }
1691 :
1692 :
1693 : /**************** Module output subroutines ***************************/
1694 :
1695 : /* Output a character to a module file. */
1696 :
1697 : static void
1698 71294603 : write_char (char out)
1699 : {
1700 71294603 : if (gzputc (module_fp, out) == EOF)
1701 0 : gfc_fatal_error ("Error writing modules file: %s", xstrerror (errno));
1702 :
1703 71294603 : if (out != '\n')
1704 69998221 : module_column++;
1705 : else
1706 : {
1707 1296382 : module_column = 1;
1708 1296382 : module_line++;
1709 : }
1710 71294603 : }
1711 :
1712 :
1713 : /* Write an atom to a module. The line wrapping isn't perfect, but it
1714 : should work most of the time. This isn't that big of a deal, since
1715 : the file really isn't meant to be read by people anyway. */
1716 :
1717 : static void
1718 18981065 : write_atom (atom_type atom, const void *v)
1719 : {
1720 18981065 : char buffer[32];
1721 :
1722 : /* Workaround -Wmaybe-uninitialized false positive during
1723 : profiledbootstrap by initializing them. */
1724 18981065 : int len;
1725 18981065 : HOST_WIDE_INT i = 0;
1726 18981065 : const char *p;
1727 :
1728 18981065 : switch (atom)
1729 : {
1730 : case ATOM_STRING:
1731 : case ATOM_NAME:
1732 : p = (const char *) v;
1733 : break;
1734 :
1735 : case ATOM_LPAREN:
1736 : p = "(";
1737 : break;
1738 :
1739 : case ATOM_RPAREN:
1740 : p = ")";
1741 : break;
1742 :
1743 5156999 : case ATOM_INTEGER:
1744 5156999 : i = *((const HOST_WIDE_INT *) v);
1745 :
1746 5156999 : snprintf (buffer, sizeof (buffer), HOST_WIDE_INT_PRINT_DEC, i);
1747 5156999 : p = buffer;
1748 5156999 : break;
1749 :
1750 0 : default:
1751 0 : gfc_internal_error ("write_atom(): Trying to write dab atom");
1752 :
1753 : }
1754 :
1755 18981065 : if(p == NULL || *p == '\0')
1756 : len = 0;
1757 : else
1758 18585336 : len = strlen (p);
1759 :
1760 18981065 : if (atom != ATOM_RPAREN)
1761 : {
1762 14628212 : if (module_column + len > 72)
1763 885581 : write_char ('\n');
1764 : else
1765 : {
1766 :
1767 13742631 : if (last_atom != ATOM_LPAREN && module_column != 1)
1768 11938868 : write_char (' ');
1769 : }
1770 : }
1771 :
1772 14628212 : if (atom == ATOM_STRING)
1773 1178078 : write_char ('\'');
1774 :
1775 74684262 : while (p != NULL && *p)
1776 : {
1777 55703197 : if (atom == ATOM_STRING && *p == '\'')
1778 0 : write_char ('\'');
1779 55703197 : write_char (*p++);
1780 : }
1781 :
1782 18981065 : if (atom == ATOM_STRING)
1783 1178078 : write_char ('\'');
1784 :
1785 18981065 : last_atom = atom;
1786 18981065 : }
1787 :
1788 :
1789 :
1790 : /***************** Mid-level I/O subroutines *****************/
1791 :
1792 : /* These subroutines let their caller read or write atoms without
1793 : caring about which of the two is actually happening. This lets a
1794 : subroutine concentrate on the actual format of the data being
1795 : written. */
1796 :
1797 : static void mio_expr (gfc_expr **);
1798 : pointer_info *mio_symbol_ref (gfc_symbol **);
1799 : pointer_info *mio_interface_rest (gfc_interface **);
1800 : static void mio_symtree_ref (gfc_symtree **);
1801 :
1802 : /* Read or write an enumerated value. On writing, we return the input
1803 : value for the convenience of callers. We avoid using an integer
1804 : pointer because enums are sometimes inside bitfields. */
1805 :
1806 : static int
1807 14034434 : mio_name (int t, const mstring *m)
1808 : {
1809 14034434 : if (iomode == IO_OUTPUT)
1810 3938898 : write_atom (ATOM_NAME, gfc_code2string (m, t));
1811 : else
1812 : {
1813 10095536 : require_atom (ATOM_NAME);
1814 10095536 : t = find_enum (m);
1815 : }
1816 :
1817 14034434 : return t;
1818 : }
1819 :
1820 : /* Specialization of mio_name. */
1821 :
1822 : #define DECL_MIO_NAME(TYPE) \
1823 : static inline TYPE \
1824 : MIO_NAME(TYPE) (TYPE t, const mstring *m) \
1825 : { \
1826 : return (TYPE) mio_name ((int) t, m); \
1827 : }
1828 : #define MIO_NAME(TYPE) mio_name_##TYPE
1829 :
1830 : static void
1831 18735051 : mio_lparen (void)
1832 : {
1833 18735051 : if (iomode == IO_OUTPUT)
1834 4352853 : write_atom (ATOM_LPAREN, NULL);
1835 : else
1836 14382198 : require_atom (ATOM_LPAREN);
1837 18735051 : }
1838 :
1839 :
1840 : static void
1841 17184416 : mio_rparen (void)
1842 : {
1843 17184416 : if (iomode == IO_OUTPUT)
1844 4352853 : write_atom (ATOM_RPAREN, NULL);
1845 : else
1846 12831563 : require_atom (ATOM_RPAREN);
1847 17184416 : }
1848 :
1849 :
1850 : static void
1851 14212260 : mio_integer (int *ip)
1852 : {
1853 14212260 : if (iomode == IO_OUTPUT)
1854 : {
1855 3177674 : HOST_WIDE_INT hwi = *ip;
1856 3177674 : write_atom (ATOM_INTEGER, &hwi);
1857 : }
1858 : else
1859 : {
1860 11034586 : require_atom (ATOM_INTEGER);
1861 11034586 : *ip = atom_int;
1862 : }
1863 14212260 : }
1864 :
1865 : static void
1866 419842 : mio_hwi (HOST_WIDE_INT *hwi)
1867 : {
1868 419842 : if (iomode == IO_OUTPUT)
1869 250306 : write_atom (ATOM_INTEGER, hwi);
1870 : else
1871 : {
1872 169536 : require_atom (ATOM_INTEGER);
1873 169536 : *hwi = atom_int;
1874 : }
1875 419842 : }
1876 :
1877 :
1878 : /* Read or write a gfc_intrinsic_op value. */
1879 :
1880 : static void
1881 1344 : mio_intrinsic_op (gfc_intrinsic_op* op)
1882 : {
1883 : /* FIXME: Would be nicer to do this via the operators symbolic name. */
1884 1344 : if (iomode == IO_OUTPUT)
1885 : {
1886 714 : HOST_WIDE_INT converted = (HOST_WIDE_INT) *op;
1887 714 : write_atom (ATOM_INTEGER, &converted);
1888 : }
1889 : else
1890 : {
1891 630 : require_atom (ATOM_INTEGER);
1892 630 : *op = (gfc_intrinsic_op) atom_int;
1893 : }
1894 1344 : }
1895 :
1896 :
1897 : /* Read or write a character pointer that points to a string on the heap. */
1898 :
1899 : static const char *
1900 9581 : mio_allocated_string (const char *s)
1901 : {
1902 9581 : if (iomode == IO_OUTPUT)
1903 : {
1904 9581 : write_atom (ATOM_STRING, s);
1905 9581 : return s;
1906 : }
1907 : else
1908 : {
1909 0 : require_atom (ATOM_STRING);
1910 0 : return atom_string;
1911 : }
1912 : }
1913 :
1914 :
1915 : /* Functions for quoting and unquoting strings. */
1916 :
1917 : static char *
1918 5667 : quote_string (const gfc_char_t *s, const size_t slength)
1919 : {
1920 5667 : const gfc_char_t *p;
1921 5667 : char *res, *q;
1922 5667 : size_t len = 0, i;
1923 :
1924 : /* Calculate the length we'll need: a backslash takes two ("\\"),
1925 : non-printable characters take 10 ("\Uxxxxxxxx") and others take 1. */
1926 21140 : for (p = s, i = 0; i < slength; p++, i++)
1927 : {
1928 15473 : if (*p == '\\')
1929 1 : len += 2;
1930 15472 : else if (!gfc_wide_is_printable (*p))
1931 4851 : len += 10;
1932 : else
1933 10621 : len++;
1934 : }
1935 :
1936 5667 : q = res = XCNEWVEC (char, len + 1);
1937 26807 : for (p = s, i = 0; i < slength; p++, i++)
1938 : {
1939 15473 : if (*p == '\\')
1940 1 : *q++ = '\\', *q++ = '\\';
1941 15472 : else if (!gfc_wide_is_printable (*p))
1942 : {
1943 4851 : sprintf (q, "\\U%08" HOST_WIDE_INT_PRINT "x",
1944 4851 : (unsigned HOST_WIDE_INT) *p);
1945 4851 : q += 10;
1946 : }
1947 : else
1948 10621 : *q++ = (unsigned char) *p;
1949 : }
1950 :
1951 5667 : res[len] = '\0';
1952 5667 : return res;
1953 : }
1954 :
1955 : static gfc_char_t *
1956 3076 : unquote_string (const char *s)
1957 : {
1958 3076 : size_t len, i;
1959 3076 : const char *p;
1960 3076 : gfc_char_t *res;
1961 :
1962 15124 : for (p = s, len = 0; *p; p++, len++)
1963 : {
1964 12048 : if (*p != '\\')
1965 9846 : continue;
1966 :
1967 2202 : if (p[1] == '\\')
1968 0 : p++;
1969 2202 : else if (p[1] == 'U')
1970 2202 : p += 9; /* That is a "\U????????". */
1971 : else
1972 0 : gfc_internal_error ("unquote_string(): got bad string");
1973 : }
1974 :
1975 3076 : res = gfc_get_wide_string (len + 1);
1976 18200 : for (i = 0, p = s; i < len; i++, p++)
1977 : {
1978 12048 : gcc_assert (*p);
1979 :
1980 12048 : if (*p != '\\')
1981 9846 : res[i] = (unsigned char) *p;
1982 2202 : else if (p[1] == '\\')
1983 : {
1984 0 : res[i] = (unsigned char) '\\';
1985 0 : p++;
1986 : }
1987 : else
1988 : {
1989 : /* We read the 8-digits hexadecimal constant that follows. */
1990 2202 : int j;
1991 2202 : unsigned n;
1992 2202 : gfc_char_t c = 0;
1993 :
1994 2202 : gcc_assert (p[1] == 'U');
1995 19818 : for (j = 0; j < 8; j++)
1996 : {
1997 17616 : c = c << 4;
1998 17616 : gcc_assert (sscanf (&p[j+2], "%01x", &n) == 1);
1999 17616 : c += n;
2000 : }
2001 :
2002 2202 : res[i] = c;
2003 2202 : p += 9;
2004 : }
2005 : }
2006 :
2007 3076 : res[len] = '\0';
2008 3076 : return res;
2009 : }
2010 :
2011 :
2012 : /* Read or write a character pointer that points to a wide string on the
2013 : heap, performing quoting/unquoting of nonprintable characters using the
2014 : form \U???????? (where each ? is a hexadecimal digit).
2015 : Length is the length of the string, only known and used in output mode. */
2016 :
2017 : static const gfc_char_t *
2018 8743 : mio_allocated_wide_string (const gfc_char_t *s, const size_t length)
2019 : {
2020 8743 : if (iomode == IO_OUTPUT)
2021 : {
2022 5667 : char *quoted = quote_string (s, length);
2023 5667 : write_atom (ATOM_STRING, quoted);
2024 5667 : free (quoted);
2025 5667 : return s;
2026 : }
2027 : else
2028 : {
2029 3076 : gfc_char_t *unquoted;
2030 :
2031 3076 : require_atom (ATOM_STRING);
2032 3076 : unquoted = unquote_string (atom_string);
2033 3076 : free (atom_string);
2034 3076 : return unquoted;
2035 : }
2036 : }
2037 :
2038 :
2039 : /* Read or write a string that is in static memory. */
2040 :
2041 : static void
2042 1074992 : mio_pool_string (const char **stringp)
2043 : {
2044 : /* TODO: one could write the string only once, and refer to it via a
2045 : fixup pointer. */
2046 :
2047 : /* As a special case we have to deal with a NULL string. This
2048 : happens for the 'module' member of 'gfc_symbol's that are not in a
2049 : module. We read / write these as the empty string. */
2050 1074992 : if (iomode == IO_OUTPUT)
2051 : {
2052 833332 : const char *p = *stringp == NULL ? "" : *stringp;
2053 833332 : write_atom (ATOM_STRING, p);
2054 : }
2055 : else
2056 : {
2057 241660 : require_atom (ATOM_STRING);
2058 483320 : *stringp = (atom_string[0] == '\0'
2059 241660 : ? NULL : gfc_get_string ("%s", atom_string));
2060 241660 : free (atom_string);
2061 : }
2062 1074992 : }
2063 :
2064 :
2065 : /* Read or write a string that is inside of some already-allocated
2066 : structure. */
2067 :
2068 : static void
2069 668547 : mio_internal_string (char *string)
2070 : {
2071 668547 : if (iomode == IO_OUTPUT)
2072 0 : write_atom (ATOM_STRING, string);
2073 : else
2074 : {
2075 668547 : require_atom (ATOM_STRING);
2076 668547 : strcpy (string, atom_string);
2077 668547 : free (atom_string);
2078 : }
2079 668547 : }
2080 :
2081 :
2082 : enum ab_attribute
2083 : { AB_ALLOCATABLE, AB_DIMENSION, AB_EXTERNAL, AB_INTRINSIC, AB_OPTIONAL,
2084 : AB_POINTER, AB_TARGET, AB_DUMMY, AB_RESULT, AB_DATA,
2085 : AB_IN_NAMELIST, AB_IN_COMMON, AB_FUNCTION, AB_SUBROUTINE, AB_SEQUENCE,
2086 : AB_ELEMENTAL, AB_PURE, AB_RECURSIVE, AB_GENERIC, AB_ALWAYS_EXPLICIT,
2087 : AB_CRAY_POINTER, AB_CRAY_POINTEE, AB_THREADPRIVATE,
2088 : AB_ALLOC_COMP, AB_POINTER_COMP, AB_PROC_POINTER_COMP, AB_PRIVATE_COMP,
2089 : AB_VALUE, AB_VOLATILE, AB_PROTECTED, AB_LOCK_COMP, AB_EVENT_COMP,
2090 : AB_IS_BIND_C, AB_IS_C_INTEROP, AB_IS_ISO_C, AB_ABSTRACT, AB_ZERO_COMP,
2091 : AB_IS_CLASS, AB_PROCEDURE, AB_PROC_POINTER, AB_ASYNCHRONOUS, AB_CODIMENSION,
2092 : AB_COARRAY_COMP, AB_VTYPE, AB_VTAB, AB_CONTIGUOUS, AB_CLASS_POINTER,
2093 : AB_IMPLICIT_PURE, AB_ARTIFICIAL, AB_UNLIMITED_POLY, AB_OMP_DECLARE_TARGET,
2094 : AB_ARRAY_OUTER_DEPENDENCY, AB_MODULE_PROCEDURE, AB_OACC_DECLARE_CREATE,
2095 : AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
2096 : AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK,
2097 : AB_OMP_DECLARE_TARGET_LINK, AB_OMP_DECLARE_TARGET_LOCAL,
2098 : AB_PDT_KIND, AB_PDT_LEN, AB_PDT_TYPE,
2099 : AB_PDT_COMP, AB_PDT_TEMPLATE, AB_PDT_ARRAY, AB_PDT_STRING,
2100 : AB_OACC_ROUTINE_LOP_GANG, AB_OACC_ROUTINE_LOP_WORKER,
2101 : AB_OACC_ROUTINE_LOP_VECTOR, AB_OACC_ROUTINE_LOP_SEQ,
2102 : AB_OACC_ROUTINE_NOHOST,
2103 : AB_OMP_REQ_REVERSE_OFFLOAD, AB_OMP_REQ_UNIFIED_ADDRESS, AB_OMP_REQ_SELF_MAPS,
2104 : AB_OMP_REQ_UNIFIED_SHARED_MEMORY, AB_OMP_REQ_DYNAMIC_ALLOCATORS,
2105 : AB_OMP_REQ_MEM_ORDER_SEQ_CST, AB_OMP_REQ_MEM_ORDER_ACQ_REL,
2106 : AB_OMP_REQ_MEM_ORDER_ACQUIRE, AB_OMP_REQ_MEM_ORDER_RELEASE,
2107 : AB_OMP_REQ_MEM_ORDER_RELAXED, AB_OMP_DEVICE_TYPE_NOHOST,
2108 : AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_ANY, AB_OMP_GROUPPRIVATE
2109 : };
2110 :
2111 : static const mstring attr_bits[] =
2112 : {
2113 : minit ("ALLOCATABLE", AB_ALLOCATABLE),
2114 : minit ("ARTIFICIAL", AB_ARTIFICIAL),
2115 : minit ("ASYNCHRONOUS", AB_ASYNCHRONOUS),
2116 : minit ("DIMENSION", AB_DIMENSION),
2117 : minit ("CODIMENSION", AB_CODIMENSION),
2118 : minit ("CONTIGUOUS", AB_CONTIGUOUS),
2119 : minit ("EXTERNAL", AB_EXTERNAL),
2120 : minit ("INTRINSIC", AB_INTRINSIC),
2121 : minit ("OPTIONAL", AB_OPTIONAL),
2122 : minit ("POINTER", AB_POINTER),
2123 : minit ("VOLATILE", AB_VOLATILE),
2124 : minit ("TARGET", AB_TARGET),
2125 : minit ("THREADPRIVATE", AB_THREADPRIVATE),
2126 : minit ("DUMMY", AB_DUMMY),
2127 : minit ("RESULT", AB_RESULT),
2128 : minit ("DATA", AB_DATA),
2129 : minit ("IN_NAMELIST", AB_IN_NAMELIST),
2130 : minit ("IN_COMMON", AB_IN_COMMON),
2131 : minit ("FUNCTION", AB_FUNCTION),
2132 : minit ("SUBROUTINE", AB_SUBROUTINE),
2133 : minit ("SEQUENCE", AB_SEQUENCE),
2134 : minit ("ELEMENTAL", AB_ELEMENTAL),
2135 : minit ("PURE", AB_PURE),
2136 : minit ("RECURSIVE", AB_RECURSIVE),
2137 : minit ("GENERIC", AB_GENERIC),
2138 : minit ("ALWAYS_EXPLICIT", AB_ALWAYS_EXPLICIT),
2139 : minit ("CRAY_POINTER", AB_CRAY_POINTER),
2140 : minit ("CRAY_POINTEE", AB_CRAY_POINTEE),
2141 : minit ("IS_BIND_C", AB_IS_BIND_C),
2142 : minit ("IS_C_INTEROP", AB_IS_C_INTEROP),
2143 : minit ("IS_ISO_C", AB_IS_ISO_C),
2144 : minit ("VALUE", AB_VALUE),
2145 : minit ("ALLOC_COMP", AB_ALLOC_COMP),
2146 : minit ("COARRAY_COMP", AB_COARRAY_COMP),
2147 : minit ("LOCK_COMP", AB_LOCK_COMP),
2148 : minit ("EVENT_COMP", AB_EVENT_COMP),
2149 : minit ("POINTER_COMP", AB_POINTER_COMP),
2150 : minit ("PROC_POINTER_COMP", AB_PROC_POINTER_COMP),
2151 : minit ("PRIVATE_COMP", AB_PRIVATE_COMP),
2152 : minit ("ZERO_COMP", AB_ZERO_COMP),
2153 : minit ("PROTECTED", AB_PROTECTED),
2154 : minit ("ABSTRACT", AB_ABSTRACT),
2155 : minit ("IS_CLASS", AB_IS_CLASS),
2156 : minit ("PROCEDURE", AB_PROCEDURE),
2157 : minit ("PROC_POINTER", AB_PROC_POINTER),
2158 : minit ("VTYPE", AB_VTYPE),
2159 : minit ("VTAB", AB_VTAB),
2160 : minit ("CLASS_POINTER", AB_CLASS_POINTER),
2161 : minit ("IMPLICIT_PURE", AB_IMPLICIT_PURE),
2162 : minit ("UNLIMITED_POLY", AB_UNLIMITED_POLY),
2163 : minit ("OMP_DECLARE_TARGET", AB_OMP_DECLARE_TARGET),
2164 : minit ("ARRAY_OUTER_DEPENDENCY", AB_ARRAY_OUTER_DEPENDENCY),
2165 : minit ("MODULE_PROCEDURE", AB_MODULE_PROCEDURE),
2166 : minit ("OACC_DECLARE_CREATE", AB_OACC_DECLARE_CREATE),
2167 : minit ("OACC_DECLARE_COPYIN", AB_OACC_DECLARE_COPYIN),
2168 : minit ("OACC_DECLARE_DEVICEPTR", AB_OACC_DECLARE_DEVICEPTR),
2169 : minit ("OACC_DECLARE_DEVICE_RESIDENT", AB_OACC_DECLARE_DEVICE_RESIDENT),
2170 : minit ("OACC_DECLARE_LINK", AB_OACC_DECLARE_LINK),
2171 : minit ("OMP_DECLARE_TARGET_LINK", AB_OMP_DECLARE_TARGET_LINK),
2172 : minit ("OMP_DECLARE_TARGET_LOCAL", AB_OMP_DECLARE_TARGET_LOCAL),
2173 : minit ("OMP_GROUPPRIVATE", AB_OMP_GROUPPRIVATE),
2174 : minit ("PDT_KIND", AB_PDT_KIND),
2175 : minit ("PDT_LEN", AB_PDT_LEN),
2176 : minit ("PDT_TYPE", AB_PDT_TYPE),
2177 : minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE),
2178 : minit ("PDT_ARRAY", AB_PDT_ARRAY),
2179 : minit ("PDT_STRING", AB_PDT_STRING),
2180 : minit ("PDT_COMP", AB_PDT_COMP),
2181 : minit ("OACC_ROUTINE_LOP_GANG", AB_OACC_ROUTINE_LOP_GANG),
2182 : minit ("OACC_ROUTINE_LOP_WORKER", AB_OACC_ROUTINE_LOP_WORKER),
2183 : minit ("OACC_ROUTINE_LOP_VECTOR", AB_OACC_ROUTINE_LOP_VECTOR),
2184 : minit ("OACC_ROUTINE_LOP_SEQ", AB_OACC_ROUTINE_LOP_SEQ),
2185 : minit ("OACC_ROUTINE_NOHOST", AB_OACC_ROUTINE_NOHOST),
2186 : minit ("OMP_REQ_REVERSE_OFFLOAD", AB_OMP_REQ_REVERSE_OFFLOAD),
2187 : minit ("OMP_REQ_UNIFIED_ADDRESS", AB_OMP_REQ_UNIFIED_ADDRESS),
2188 : minit ("OMP_REQ_UNIFIED_SHARED_MEMORY", AB_OMP_REQ_UNIFIED_SHARED_MEMORY),
2189 : minit ("OMP_REQ_SELF_MAPS", AB_OMP_REQ_SELF_MAPS),
2190 : minit ("OMP_REQ_DYNAMIC_ALLOCATORS", AB_OMP_REQ_DYNAMIC_ALLOCATORS),
2191 : minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST),
2192 : minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL),
2193 : minit ("OMP_REQ_MEM_ORDER_ACQUIRE", AB_OMP_REQ_MEM_ORDER_ACQUIRE),
2194 : minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED),
2195 : minit ("OMP_REQ_MEM_ORDER_RELEASE", AB_OMP_REQ_MEM_ORDER_RELEASE),
2196 : minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST),
2197 : minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST),
2198 : minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY),
2199 : minit (NULL, -1)
2200 : };
2201 :
2202 : /* For binding attributes. */
2203 : static const mstring binding_passing[] =
2204 : {
2205 : minit ("PASS", 0),
2206 : minit ("NOPASS", 1),
2207 : minit (NULL, -1)
2208 : };
2209 : static const mstring binding_overriding[] =
2210 : {
2211 : minit ("OVERRIDABLE", 0),
2212 : minit ("NON_OVERRIDABLE", 1),
2213 : minit ("DEFERRED", 2),
2214 : minit (NULL, -1)
2215 : };
2216 : static const mstring binding_generic[] =
2217 : {
2218 : minit ("SPECIFIC", 0),
2219 : minit ("GENERIC", 1),
2220 : minit (NULL, -1)
2221 : };
2222 : static const mstring binding_ppc[] =
2223 : {
2224 : minit ("NO_PPC", 0),
2225 : minit ("PPC", 1),
2226 : minit (NULL, -1)
2227 : };
2228 :
2229 : /* Specialization of mio_name. */
2230 655990 : DECL_MIO_NAME (ab_attribute)
2231 3614 : DECL_MIO_NAME (ar_type)
2232 177820 : DECL_MIO_NAME (array_type)
2233 6259509 : DECL_MIO_NAME (bt)
2234 107131 : DECL_MIO_NAME (expr_t)
2235 644340 : DECL_MIO_NAME (gfc_access)
2236 1721 : DECL_MIO_NAME (gfc_intrinsic_op)
2237 1625181 : DECL_MIO_NAME (ifsrc)
2238 1625181 : DECL_MIO_NAME (save_state)
2239 1625181 : DECL_MIO_NAME (procedure_type)
2240 5530 : DECL_MIO_NAME (ref_type)
2241 1625181 : DECL_MIO_NAME (sym_flavor)
2242 1625181 : DECL_MIO_NAME (sym_intent)
2243 0 : DECL_MIO_NAME (inquiry_type)
2244 : #undef DECL_MIO_NAME
2245 :
2246 : /* Verify OACC_ROUTINE_LOP_NONE. */
2247 :
2248 : static void
2249 96 : verify_OACC_ROUTINE_LOP_NONE (enum oacc_routine_lop lop)
2250 : {
2251 0 : if (lop != OACC_ROUTINE_LOP_NONE)
2252 0 : bad_module ("Unsupported: multiple OpenACC 'routine' levels of parallelism");
2253 0 : }
2254 :
2255 : /* Symbol attributes are stored in list with the first three elements
2256 : being the enumerated fields, while the remaining elements (if any)
2257 : indicate the individual attribute bits. The access field is not
2258 : saved-- it controls what symbols are exported when a module is
2259 : written. */
2260 :
2261 : static void
2262 1625181 : mio_symbol_attribute (symbol_attribute *attr)
2263 : {
2264 1625181 : atom_type t;
2265 1625181 : unsigned ext_attr,extension_level;
2266 :
2267 1625181 : mio_lparen ();
2268 :
2269 1625181 : attr->flavor = MIO_NAME (sym_flavor) (attr->flavor, flavors);
2270 1625181 : attr->intent = MIO_NAME (sym_intent) (attr->intent, intents);
2271 1625181 : attr->proc = MIO_NAME (procedure_type) (attr->proc, procedures);
2272 1625181 : attr->if_source = MIO_NAME (ifsrc) (attr->if_source, ifsrc_types);
2273 1625181 : attr->save = MIO_NAME (save_state) (attr->save, save_status);
2274 :
2275 1625181 : ext_attr = attr->ext_attr;
2276 1625181 : mio_integer ((int *) &ext_attr);
2277 1625181 : attr->ext_attr = ext_attr;
2278 :
2279 1625181 : extension_level = attr->extension;
2280 1625181 : mio_integer ((int *) &extension_level);
2281 1625181 : attr->extension = extension_level;
2282 :
2283 1625181 : if (iomode == IO_OUTPUT)
2284 : {
2285 367059 : if (attr->allocatable)
2286 5247 : MIO_NAME (ab_attribute) (AB_ALLOCATABLE, attr_bits);
2287 367059 : if (attr->artificial)
2288 108943 : MIO_NAME (ab_attribute) (AB_ARTIFICIAL, attr_bits);
2289 367059 : if (attr->asynchronous)
2290 0 : MIO_NAME (ab_attribute) (AB_ASYNCHRONOUS, attr_bits);
2291 367059 : if (attr->dimension)
2292 19927 : MIO_NAME (ab_attribute) (AB_DIMENSION, attr_bits);
2293 367059 : if (attr->codimension)
2294 113 : MIO_NAME (ab_attribute) (AB_CODIMENSION, attr_bits);
2295 367059 : if (attr->contiguous)
2296 3432 : MIO_NAME (ab_attribute) (AB_CONTIGUOUS, attr_bits);
2297 367059 : if (attr->external)
2298 15948 : MIO_NAME (ab_attribute) (AB_EXTERNAL, attr_bits);
2299 367059 : if (attr->intrinsic)
2300 5603 : MIO_NAME (ab_attribute) (AB_INTRINSIC, attr_bits);
2301 367059 : if (attr->optional)
2302 5405 : MIO_NAME (ab_attribute) (AB_OPTIONAL, attr_bits);
2303 367059 : if (attr->pointer)
2304 34177 : MIO_NAME (ab_attribute) (AB_POINTER, attr_bits);
2305 367059 : if (attr->class_pointer)
2306 495 : MIO_NAME (ab_attribute) (AB_CLASS_POINTER, attr_bits);
2307 367059 : if (attr->is_protected)
2308 70 : MIO_NAME (ab_attribute) (AB_PROTECTED, attr_bits);
2309 367059 : if (attr->value)
2310 11978 : MIO_NAME (ab_attribute) (AB_VALUE, attr_bits);
2311 367059 : if (attr->volatile_)
2312 14 : MIO_NAME (ab_attribute) (AB_VOLATILE, attr_bits);
2313 367059 : if (attr->target)
2314 21019 : MIO_NAME (ab_attribute) (AB_TARGET, attr_bits);
2315 367059 : if (attr->threadprivate)
2316 42 : MIO_NAME (ab_attribute) (AB_THREADPRIVATE, attr_bits);
2317 367059 : if (attr->dummy)
2318 86706 : MIO_NAME (ab_attribute) (AB_DUMMY, attr_bits);
2319 367059 : if (attr->result)
2320 7630 : MIO_NAME (ab_attribute) (AB_RESULT, attr_bits);
2321 : /* We deliberately don't preserve the "entry" flag. */
2322 :
2323 367059 : if (attr->data)
2324 22 : MIO_NAME (ab_attribute) (AB_DATA, attr_bits);
2325 367059 : if (attr->in_namelist)
2326 78 : MIO_NAME (ab_attribute) (AB_IN_NAMELIST, attr_bits);
2327 367059 : if (attr->in_common)
2328 392 : MIO_NAME (ab_attribute) (AB_IN_COMMON, attr_bits);
2329 :
2330 367059 : if (attr->function)
2331 36120 : MIO_NAME (ab_attribute) (AB_FUNCTION, attr_bits);
2332 367059 : if (attr->subroutine)
2333 30758 : MIO_NAME (ab_attribute) (AB_SUBROUTINE, attr_bits);
2334 367059 : if (attr->generic)
2335 10261 : MIO_NAME (ab_attribute) (AB_GENERIC, attr_bits);
2336 367059 : if (attr->abstract)
2337 3109 : MIO_NAME (ab_attribute) (AB_ABSTRACT, attr_bits);
2338 :
2339 367059 : if (attr->sequence)
2340 125 : MIO_NAME (ab_attribute) (AB_SEQUENCE, attr_bits);
2341 367059 : if (attr->elemental)
2342 16527 : MIO_NAME (ab_attribute) (AB_ELEMENTAL, attr_bits);
2343 367059 : if (attr->pure)
2344 20082 : MIO_NAME (ab_attribute) (AB_PURE, attr_bits);
2345 367059 : if (attr->implicit_pure)
2346 4598 : MIO_NAME (ab_attribute) (AB_IMPLICIT_PURE, attr_bits);
2347 367059 : if (attr->unlimited_polymorphic)
2348 376 : MIO_NAME (ab_attribute) (AB_UNLIMITED_POLY, attr_bits);
2349 367059 : if (attr->recursive)
2350 3158 : MIO_NAME (ab_attribute) (AB_RECURSIVE, attr_bits);
2351 367059 : if (attr->always_explicit)
2352 31977 : MIO_NAME (ab_attribute) (AB_ALWAYS_EXPLICIT, attr_bits);
2353 367059 : if (attr->cray_pointer)
2354 13 : MIO_NAME (ab_attribute) (AB_CRAY_POINTER, attr_bits);
2355 367059 : if (attr->cray_pointee)
2356 13 : MIO_NAME (ab_attribute) (AB_CRAY_POINTEE, attr_bits);
2357 367059 : if (attr->is_bind_c)
2358 6858 : MIO_NAME(ab_attribute) (AB_IS_BIND_C, attr_bits);
2359 367059 : if (attr->is_c_interop)
2360 30890 : MIO_NAME(ab_attribute) (AB_IS_C_INTEROP, attr_bits);
2361 367059 : if (attr->is_iso_c)
2362 26757 : MIO_NAME(ab_attribute) (AB_IS_ISO_C, attr_bits);
2363 367059 : if (attr->alloc_comp)
2364 3254 : MIO_NAME (ab_attribute) (AB_ALLOC_COMP, attr_bits);
2365 367059 : if (attr->pointer_comp)
2366 952 : MIO_NAME (ab_attribute) (AB_POINTER_COMP, attr_bits);
2367 367059 : if (attr->proc_pointer_comp)
2368 299 : MIO_NAME (ab_attribute) (AB_PROC_POINTER_COMP, attr_bits);
2369 367059 : if (attr->private_comp)
2370 3306 : MIO_NAME (ab_attribute) (AB_PRIVATE_COMP, attr_bits);
2371 367059 : if (attr->coarray_comp)
2372 33 : MIO_NAME (ab_attribute) (AB_COARRAY_COMP, attr_bits);
2373 367059 : if (attr->lock_comp)
2374 4 : MIO_NAME (ab_attribute) (AB_LOCK_COMP, attr_bits);
2375 367059 : if (attr->event_comp)
2376 0 : MIO_NAME (ab_attribute) (AB_EVENT_COMP, attr_bits);
2377 367059 : if (attr->zero_comp)
2378 2243 : MIO_NAME (ab_attribute) (AB_ZERO_COMP, attr_bits);
2379 367059 : if (attr->is_class)
2380 4997 : MIO_NAME (ab_attribute) (AB_IS_CLASS, attr_bits);
2381 367059 : if (attr->procedure)
2382 5852 : MIO_NAME (ab_attribute) (AB_PROCEDURE, attr_bits);
2383 367059 : if (attr->proc_pointer)
2384 39335 : MIO_NAME (ab_attribute) (AB_PROC_POINTER, attr_bits);
2385 367059 : if (attr->vtype)
2386 11300 : MIO_NAME (ab_attribute) (AB_VTYPE, attr_bits);
2387 367059 : if (attr->vtab)
2388 10755 : MIO_NAME (ab_attribute) (AB_VTAB, attr_bits);
2389 367059 : if (attr->omp_declare_target)
2390 427 : MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET, attr_bits);
2391 367059 : if (attr->array_outer_dependency)
2392 18832 : MIO_NAME (ab_attribute) (AB_ARRAY_OUTER_DEPENDENCY, attr_bits);
2393 367059 : if (attr->module_procedure)
2394 1744 : MIO_NAME (ab_attribute) (AB_MODULE_PROCEDURE, attr_bits);
2395 367059 : if (attr->oacc_declare_create)
2396 39 : MIO_NAME (ab_attribute) (AB_OACC_DECLARE_CREATE, attr_bits);
2397 367059 : if (attr->oacc_declare_copyin)
2398 7 : MIO_NAME (ab_attribute) (AB_OACC_DECLARE_COPYIN, attr_bits);
2399 367059 : if (attr->oacc_declare_deviceptr)
2400 1 : MIO_NAME (ab_attribute) (AB_OACC_DECLARE_DEVICEPTR, attr_bits);
2401 367059 : if (attr->oacc_declare_device_resident)
2402 33 : MIO_NAME (ab_attribute) (AB_OACC_DECLARE_DEVICE_RESIDENT, attr_bits);
2403 367059 : if (attr->oacc_declare_link)
2404 1 : MIO_NAME (ab_attribute) (AB_OACC_DECLARE_LINK, attr_bits);
2405 367059 : if (attr->omp_declare_target_link)
2406 15 : MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET_LINK, attr_bits);
2407 367059 : if (attr->omp_declare_target_local)
2408 12 : MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET_LOCAL, attr_bits);
2409 367059 : if (attr->omp_groupprivate)
2410 12 : MIO_NAME (ab_attribute) (AB_OMP_GROUPPRIVATE, attr_bits);
2411 367059 : if (attr->pdt_kind)
2412 1120 : MIO_NAME (ab_attribute) (AB_PDT_KIND, attr_bits);
2413 367059 : if (attr->pdt_len)
2414 860 : MIO_NAME (ab_attribute) (AB_PDT_LEN, attr_bits);
2415 367059 : if (attr->pdt_type)
2416 480 : MIO_NAME (ab_attribute) (AB_PDT_TYPE, attr_bits);
2417 367059 : if (attr->pdt_comp)
2418 27 : MIO_NAME (ab_attribute) (AB_PDT_COMP , attr_bits);
2419 367059 : if (attr->pdt_template)
2420 541 : MIO_NAME (ab_attribute) (AB_PDT_TEMPLATE, attr_bits);
2421 367059 : if (attr->pdt_array)
2422 153 : MIO_NAME (ab_attribute) (AB_PDT_ARRAY, attr_bits);
2423 367059 : if (attr->pdt_string)
2424 2 : MIO_NAME (ab_attribute) (AB_PDT_STRING, attr_bits);
2425 367059 : switch (attr->oacc_routine_lop)
2426 : {
2427 : case OACC_ROUTINE_LOP_NONE:
2428 : /* This is the default anyway, and for maintaining compatibility with
2429 : the current MOD_VERSION, we're not emitting anything in that
2430 : case. */
2431 : break;
2432 12 : case OACC_ROUTINE_LOP_GANG:
2433 12 : MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_GANG, attr_bits);
2434 12 : break;
2435 10 : case OACC_ROUTINE_LOP_WORKER:
2436 10 : MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_WORKER, attr_bits);
2437 10 : break;
2438 8 : case OACC_ROUTINE_LOP_VECTOR:
2439 8 : MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_VECTOR, attr_bits);
2440 8 : break;
2441 81 : case OACC_ROUTINE_LOP_SEQ:
2442 81 : MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_SEQ, attr_bits);
2443 81 : break;
2444 0 : case OACC_ROUTINE_LOP_ERROR:
2445 : /* ... intentionally omitted here; it's only used internally. */
2446 0 : default:
2447 0 : gcc_unreachable ();
2448 : }
2449 367059 : if (attr->oacc_routine_nohost)
2450 21 : MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_NOHOST, attr_bits);
2451 :
2452 367059 : if (attr->flavor == FL_MODULE && gfc_current_ns->omp_requires)
2453 : {
2454 33 : if (gfc_current_ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD)
2455 19 : MIO_NAME (ab_attribute) (AB_OMP_REQ_REVERSE_OFFLOAD, attr_bits);
2456 33 : if (gfc_current_ns->omp_requires & OMP_REQ_UNIFIED_ADDRESS)
2457 2 : MIO_NAME (ab_attribute) (AB_OMP_REQ_UNIFIED_ADDRESS, attr_bits);
2458 33 : if (gfc_current_ns->omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
2459 4 : MIO_NAME (ab_attribute) (AB_OMP_REQ_UNIFIED_SHARED_MEMORY, attr_bits);
2460 33 : if (gfc_current_ns->omp_requires & OMP_REQ_SELF_MAPS)
2461 2 : MIO_NAME (ab_attribute) (AB_OMP_REQ_SELF_MAPS, attr_bits);
2462 33 : if (gfc_current_ns->omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
2463 6 : MIO_NAME (ab_attribute) (AB_OMP_REQ_DYNAMIC_ALLOCATORS, attr_bits);
2464 33 : if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
2465 : == OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST)
2466 3 : MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_SEQ_CST, attr_bits);
2467 33 : if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
2468 : == OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL)
2469 3 : MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_ACQ_REL, attr_bits);
2470 33 : if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
2471 : == OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE)
2472 0 : MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_ACQUIRE, attr_bits);
2473 33 : if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
2474 : == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED)
2475 3 : MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits);
2476 33 : if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
2477 : == OMP_REQ_ATOMIC_MEM_ORDER_RELEASE)
2478 0 : MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELEASE, attr_bits);
2479 : }
2480 367059 : switch (attr->omp_device_type)
2481 : {
2482 : case OMP_DEVICE_TYPE_UNSET:
2483 : break;
2484 16 : case OMP_DEVICE_TYPE_HOST:
2485 16 : MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_HOST, attr_bits);
2486 16 : break;
2487 9 : case OMP_DEVICE_TYPE_NOHOST:
2488 9 : MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits);
2489 9 : break;
2490 292 : case OMP_DEVICE_TYPE_ANY:
2491 292 : MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_ANY, attr_bits);
2492 292 : break;
2493 0 : default:
2494 0 : gcc_unreachable ();
2495 : }
2496 367059 : mio_rparen ();
2497 : }
2498 : else
2499 : {
2500 3561335 : for (;;)
2501 : {
2502 3561335 : t = parse_atom ();
2503 3561335 : if (t == ATOM_RPAREN)
2504 : break;
2505 2303213 : if (t != ATOM_NAME)
2506 0 : bad_module ("Expected attribute bit name");
2507 :
2508 2303213 : switch ((ab_attribute) find_enum (attr_bits))
2509 : {
2510 5059 : case AB_ALLOCATABLE:
2511 5059 : attr->allocatable = 1;
2512 5059 : break;
2513 149064 : case AB_ARTIFICIAL:
2514 149064 : attr->artificial = 1;
2515 149064 : break;
2516 0 : case AB_ASYNCHRONOUS:
2517 0 : attr->asynchronous = 1;
2518 0 : break;
2519 68823 : case AB_DIMENSION:
2520 68823 : attr->dimension = 1;
2521 68823 : break;
2522 109 : case AB_CODIMENSION:
2523 109 : attr->codimension = 1;
2524 109 : break;
2525 8912 : case AB_CONTIGUOUS:
2526 8912 : attr->contiguous = 1;
2527 8912 : break;
2528 201568 : case AB_EXTERNAL:
2529 201568 : attr->external = 1;
2530 201568 : break;
2531 3684 : case AB_INTRINSIC:
2532 3684 : attr->intrinsic = 1;
2533 3684 : break;
2534 10326 : case AB_OPTIONAL:
2535 10326 : attr->optional = 1;
2536 10326 : break;
2537 46135 : case AB_POINTER:
2538 46135 : attr->pointer = 1;
2539 46135 : break;
2540 435 : case AB_CLASS_POINTER:
2541 435 : attr->class_pointer = 1;
2542 435 : break;
2543 62 : case AB_PROTECTED:
2544 62 : attr->is_protected = 1;
2545 62 : break;
2546 96043 : case AB_VALUE:
2547 96043 : attr->value = 1;
2548 96043 : break;
2549 15 : case AB_VOLATILE:
2550 15 : attr->volatile_ = 1;
2551 15 : break;
2552 29050 : case AB_TARGET:
2553 29050 : attr->target = 1;
2554 29050 : break;
2555 52 : case AB_THREADPRIVATE:
2556 52 : attr->threadprivate = 1;
2557 52 : break;
2558 444443 : case AB_DUMMY:
2559 444443 : attr->dummy = 1;
2560 444443 : break;
2561 34423 : case AB_RESULT:
2562 34423 : attr->result = 1;
2563 34423 : break;
2564 22 : case AB_DATA:
2565 22 : attr->data = 1;
2566 22 : break;
2567 83 : case AB_IN_NAMELIST:
2568 83 : attr->in_namelist = 1;
2569 83 : break;
2570 301 : case AB_IN_COMMON:
2571 301 : attr->in_common = 1;
2572 301 : break;
2573 195410 : case AB_FUNCTION:
2574 195410 : attr->function = 1;
2575 195410 : break;
2576 90509 : case AB_SUBROUTINE:
2577 90509 : attr->subroutine = 1;
2578 90509 : break;
2579 29152 : case AB_GENERIC:
2580 29152 : attr->generic = 1;
2581 29152 : break;
2582 2388 : case AB_ABSTRACT:
2583 2388 : attr->abstract = 1;
2584 2388 : break;
2585 137 : case AB_SEQUENCE:
2586 137 : attr->sequence = 1;
2587 137 : break;
2588 93695 : case AB_ELEMENTAL:
2589 93695 : attr->elemental = 1;
2590 93695 : break;
2591 119195 : case AB_PURE:
2592 119195 : attr->pure = 1;
2593 119195 : break;
2594 4599 : case AB_IMPLICIT_PURE:
2595 4599 : attr->implicit_pure = 1;
2596 4599 : break;
2597 341 : case AB_UNLIMITED_POLY:
2598 341 : attr->unlimited_polymorphic = 1;
2599 341 : break;
2600 3126 : case AB_RECURSIVE:
2601 3126 : attr->recursive = 1;
2602 3126 : break;
2603 158760 : case AB_ALWAYS_EXPLICIT:
2604 158760 : attr->always_explicit = 1;
2605 158760 : break;
2606 13 : case AB_CRAY_POINTER:
2607 13 : attr->cray_pointer = 1;
2608 13 : break;
2609 13 : case AB_CRAY_POINTEE:
2610 13 : attr->cray_pointee = 1;
2611 13 : break;
2612 50801 : case AB_IS_BIND_C:
2613 50801 : attr->is_bind_c = 1;
2614 50801 : break;
2615 85122 : case AB_IS_C_INTEROP:
2616 85122 : attr->is_c_interop = 1;
2617 85122 : break;
2618 30133 : case AB_IS_ISO_C:
2619 30133 : attr->is_iso_c = 1;
2620 30133 : break;
2621 3064 : case AB_ALLOC_COMP:
2622 3064 : attr->alloc_comp = 1;
2623 3064 : break;
2624 22 : case AB_COARRAY_COMP:
2625 22 : attr->coarray_comp = 1;
2626 22 : break;
2627 4 : case AB_LOCK_COMP:
2628 4 : attr->lock_comp = 1;
2629 4 : break;
2630 0 : case AB_EVENT_COMP:
2631 0 : attr->event_comp = 1;
2632 0 : break;
2633 890 : case AB_POINTER_COMP:
2634 890 : attr->pointer_comp = 1;
2635 890 : break;
2636 287 : case AB_PROC_POINTER_COMP:
2637 287 : attr->proc_pointer_comp = 1;
2638 287 : break;
2639 20775 : case AB_PRIVATE_COMP:
2640 20775 : attr->private_comp = 1;
2641 20775 : break;
2642 1889 : case AB_ZERO_COMP:
2643 1889 : attr->zero_comp = 1;
2644 1889 : break;
2645 4464 : case AB_IS_CLASS:
2646 4464 : attr->is_class = 1;
2647 4464 : break;
2648 5225 : case AB_PROCEDURE:
2649 5225 : attr->procedure = 1;
2650 5225 : break;
2651 52227 : case AB_PROC_POINTER:
2652 52227 : attr->proc_pointer = 1;
2653 52227 : break;
2654 15783 : case AB_VTYPE:
2655 15783 : attr->vtype = 1;
2656 15783 : break;
2657 15477 : case AB_VTAB:
2658 15477 : attr->vtab = 1;
2659 15477 : break;
2660 444 : case AB_OMP_DECLARE_TARGET:
2661 444 : attr->omp_declare_target = 1;
2662 444 : break;
2663 10 : case AB_OMP_DECLARE_TARGET_LINK:
2664 10 : attr->omp_declare_target_link = 1;
2665 10 : break;
2666 0 : case AB_OMP_DECLARE_TARGET_LOCAL:
2667 0 : attr->omp_declare_target_local = 1;
2668 0 : break;
2669 0 : case AB_OMP_GROUPPRIVATE:
2670 0 : attr->omp_groupprivate = 1;
2671 0 : break;
2672 215845 : case AB_ARRAY_OUTER_DEPENDENCY:
2673 215845 : attr->array_outer_dependency =1;
2674 215845 : break;
2675 1164 : case AB_MODULE_PROCEDURE:
2676 1164 : attr->module_procedure =1;
2677 1164 : break;
2678 110 : case AB_OACC_DECLARE_CREATE:
2679 110 : attr->oacc_declare_create = 1;
2680 110 : break;
2681 2 : case AB_OACC_DECLARE_COPYIN:
2682 2 : attr->oacc_declare_copyin = 1;
2683 2 : break;
2684 0 : case AB_OACC_DECLARE_DEVICEPTR:
2685 0 : attr->oacc_declare_deviceptr = 1;
2686 0 : break;
2687 34 : case AB_OACC_DECLARE_DEVICE_RESIDENT:
2688 34 : attr->oacc_declare_device_resident = 1;
2689 34 : break;
2690 2 : case AB_OACC_DECLARE_LINK:
2691 2 : attr->oacc_declare_link = 1;
2692 2 : break;
2693 1072 : case AB_PDT_KIND:
2694 1072 : attr->pdt_kind = 1;
2695 1072 : break;
2696 856 : case AB_PDT_LEN:
2697 856 : attr->pdt_len = 1;
2698 856 : break;
2699 428 : case AB_PDT_TYPE:
2700 428 : attr->pdt_type = 1;
2701 428 : break;
2702 16 : case AB_PDT_COMP:
2703 16 : attr->pdt_comp = 1;
2704 16 : break;
2705 516 : case AB_PDT_TEMPLATE:
2706 516 : attr->pdt_template = 1;
2707 516 : break;
2708 147 : case AB_PDT_ARRAY:
2709 147 : attr->pdt_array = 1;
2710 147 : break;
2711 0 : case AB_PDT_STRING:
2712 0 : attr->pdt_string = 1;
2713 0 : break;
2714 8 : case AB_OACC_ROUTINE_LOP_GANG:
2715 8 : verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
2716 8 : attr->oacc_routine_lop = OACC_ROUTINE_LOP_GANG;
2717 8 : break;
2718 8 : case AB_OACC_ROUTINE_LOP_WORKER:
2719 8 : verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
2720 8 : attr->oacc_routine_lop = OACC_ROUTINE_LOP_WORKER;
2721 8 : break;
2722 8 : case AB_OACC_ROUTINE_LOP_VECTOR:
2723 8 : verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
2724 8 : attr->oacc_routine_lop = OACC_ROUTINE_LOP_VECTOR;
2725 8 : break;
2726 72 : case AB_OACC_ROUTINE_LOP_SEQ:
2727 72 : verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
2728 72 : attr->oacc_routine_lop = OACC_ROUTINE_LOP_SEQ;
2729 72 : break;
2730 20 : case AB_OACC_ROUTINE_NOHOST:
2731 20 : attr->oacc_routine_nohost = 1;
2732 20 : break;
2733 24 : case AB_OMP_REQ_REVERSE_OFFLOAD:
2734 24 : gfc_omp_requires_add_clause (OMP_REQ_REVERSE_OFFLOAD,
2735 : "reverse_offload",
2736 : &gfc_current_locus,
2737 : module_name);
2738 24 : break;
2739 0 : case AB_OMP_REQ_UNIFIED_ADDRESS:
2740 0 : gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_ADDRESS,
2741 : "unified_address",
2742 : &gfc_current_locus,
2743 : module_name);
2744 0 : break;
2745 0 : case AB_OMP_REQ_UNIFIED_SHARED_MEMORY:
2746 0 : gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_SHARED_MEMORY,
2747 : "unified_shared_memory",
2748 : &gfc_current_locus,
2749 : module_name);
2750 0 : break;
2751 1 : case AB_OMP_REQ_SELF_MAPS:
2752 1 : gfc_omp_requires_add_clause (OMP_REQ_SELF_MAPS,
2753 : "self_maps",
2754 : &gfc_current_locus,
2755 : module_name);
2756 1 : break;
2757 0 : case AB_OMP_REQ_DYNAMIC_ALLOCATORS:
2758 0 : gfc_omp_requires_add_clause (OMP_REQ_DYNAMIC_ALLOCATORS,
2759 : "dynamic_allocators",
2760 : &gfc_current_locus,
2761 : module_name);
2762 0 : break;
2763 2 : case AB_OMP_REQ_MEM_ORDER_SEQ_CST:
2764 2 : gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST,
2765 : "seq_cst", &gfc_current_locus,
2766 : module_name);
2767 2 : break;
2768 2 : case AB_OMP_REQ_MEM_ORDER_ACQ_REL:
2769 2 : gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL,
2770 : "acq_rel", &gfc_current_locus,
2771 : module_name);
2772 2 : break;
2773 0 : case AB_OMP_REQ_MEM_ORDER_ACQUIRE:
2774 0 : gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE,
2775 : "acquires", &gfc_current_locus,
2776 : module_name);
2777 0 : break;
2778 2 : case AB_OMP_REQ_MEM_ORDER_RELAXED:
2779 2 : gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELAXED,
2780 : "relaxed", &gfc_current_locus,
2781 : module_name);
2782 2 : break;
2783 0 : case AB_OMP_REQ_MEM_ORDER_RELEASE:
2784 0 : gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELEASE,
2785 : "release", &gfc_current_locus,
2786 : module_name);
2787 0 : break;
2788 8 : case AB_OMP_DEVICE_TYPE_HOST:
2789 8 : attr->omp_device_type = OMP_DEVICE_TYPE_HOST;
2790 8 : break;
2791 5 : case AB_OMP_DEVICE_TYPE_NOHOST:
2792 5 : attr->omp_device_type = OMP_DEVICE_TYPE_NOHOST;
2793 5 : break;
2794 297 : case AB_OMP_DEVICE_TYPE_ANY:
2795 297 : attr->omp_device_type = OMP_DEVICE_TYPE_ANY;
2796 297 : break;
2797 : }
2798 : }
2799 : }
2800 1625181 : }
2801 :
2802 :
2803 : static const mstring bt_types[] = {
2804 : minit ("INTEGER", BT_INTEGER),
2805 : minit ("REAL", BT_REAL),
2806 : minit ("COMPLEX", BT_COMPLEX),
2807 : minit ("LOGICAL", BT_LOGICAL),
2808 : minit ("CHARACTER", BT_CHARACTER),
2809 : minit ("UNION", BT_UNION),
2810 : minit ("DERIVED", BT_DERIVED),
2811 : minit ("CLASS", BT_CLASS),
2812 : minit ("PROCEDURE", BT_PROCEDURE),
2813 : minit ("UNKNOWN", BT_UNKNOWN),
2814 : minit ("VOID", BT_VOID),
2815 : minit ("ASSUMED", BT_ASSUMED),
2816 : minit ("UNSIGNED", BT_UNSIGNED),
2817 : minit (NULL, -1)
2818 : };
2819 :
2820 :
2821 : static void
2822 42393 : mio_charlen (gfc_charlen **clp)
2823 : {
2824 42393 : gfc_charlen *cl;
2825 :
2826 42393 : mio_lparen ();
2827 :
2828 42393 : if (iomode == IO_OUTPUT)
2829 : {
2830 19935 : cl = *clp;
2831 19935 : if (cl != NULL)
2832 19157 : mio_expr (&cl->length);
2833 : }
2834 : else
2835 : {
2836 22458 : if (peek_atom () != ATOM_RPAREN)
2837 : {
2838 21994 : cl = gfc_new_charlen (gfc_current_ns, NULL);
2839 21994 : mio_expr (&cl->length);
2840 21994 : *clp = cl;
2841 : }
2842 : }
2843 :
2844 42393 : mio_rparen ();
2845 42393 : }
2846 :
2847 :
2848 : /* See if a name is a generated name. */
2849 :
2850 : static int
2851 805504 : check_unique_name (const char *name)
2852 : {
2853 805504 : return *name == '@';
2854 : }
2855 :
2856 :
2857 : static void
2858 2086503 : mio_typespec (gfc_typespec *ts)
2859 : {
2860 2086503 : mio_lparen ();
2861 :
2862 2086503 : ts->type = MIO_NAME (bt) (ts->type, bt_types);
2863 :
2864 2086503 : if (!gfc_bt_struct (ts->type) && ts->type != BT_CLASS)
2865 1767420 : mio_integer (&ts->kind);
2866 : else
2867 319083 : mio_symbol_ref (&ts->u.derived);
2868 :
2869 2086503 : mio_symbol_ref (&ts->interface);
2870 :
2871 : /* Add info for C interop and is_iso_c. */
2872 2086503 : mio_integer (&ts->is_c_interop);
2873 2086503 : mio_integer (&ts->is_iso_c);
2874 :
2875 : /* If the typespec is for an identifier either from iso_c_binding, or
2876 : a constant that was initialized to an identifier from it, use the
2877 : f90_type. Otherwise, use the ts->type, since it shouldn't matter. */
2878 2086503 : if (ts->is_iso_c)
2879 130297 : ts->f90_type = MIO_NAME (bt) (ts->f90_type, bt_types);
2880 : else
2881 1956206 : ts->f90_type = MIO_NAME (bt) (ts->type, bt_types);
2882 :
2883 2086503 : if (ts->type != BT_CHARACTER)
2884 : {
2885 : /* ts->u.cl is only valid for BT_CHARACTER. */
2886 2044116 : mio_lparen ();
2887 2044116 : mio_rparen ();
2888 : }
2889 : else
2890 42387 : mio_charlen (&ts->u.cl);
2891 :
2892 : /* So as not to disturb the existing API, use an ATOM_NAME to
2893 : transmit deferred characteristic for characters (F2003). */
2894 2086503 : if (iomode == IO_OUTPUT)
2895 : {
2896 474297 : if (ts->type == BT_CHARACTER && ts->deferred)
2897 760 : write_atom (ATOM_NAME, "DEFERRED_CL");
2898 : }
2899 1612206 : else if (peek_atom () != ATOM_RPAREN)
2900 : {
2901 4945 : if (parse_atom () != ATOM_NAME)
2902 0 : bad_module ("Expected string");
2903 4945 : ts->deferred = 1;
2904 : }
2905 :
2906 2086503 : mio_rparen ();
2907 2086503 : }
2908 :
2909 :
2910 : static const mstring array_spec_types[] = {
2911 : minit ("EXPLICIT", AS_EXPLICIT),
2912 : minit ("ASSUMED_RANK", AS_ASSUMED_RANK),
2913 : minit ("ASSUMED_SHAPE", AS_ASSUMED_SHAPE),
2914 : minit ("DEFERRED", AS_DEFERRED),
2915 : minit ("ASSUMED_SIZE", AS_ASSUMED_SIZE),
2916 : minit (NULL, -1)
2917 : };
2918 :
2919 :
2920 : static void
2921 1625161 : mio_array_spec (gfc_array_spec **asp)
2922 : {
2923 1625161 : gfc_array_spec *as;
2924 1625161 : int i;
2925 :
2926 1625161 : mio_lparen ();
2927 :
2928 1625161 : if (iomode == IO_OUTPUT)
2929 : {
2930 367059 : int rank;
2931 :
2932 367059 : if (*asp == NULL)
2933 347055 : goto done;
2934 20004 : as = *asp;
2935 :
2936 : /* mio_integer expects nonnegative values. */
2937 20004 : rank = as->rank > 0 ? as->rank : 0;
2938 20004 : mio_integer (&rank);
2939 : }
2940 : else
2941 : {
2942 1258102 : if (peek_atom () == ATOM_RPAREN)
2943 : {
2944 1189196 : *asp = NULL;
2945 1189196 : goto done;
2946 : }
2947 :
2948 68906 : *asp = as = gfc_get_array_spec ();
2949 68906 : mio_integer (&as->rank);
2950 : }
2951 :
2952 88910 : mio_integer (&as->corank);
2953 88910 : as->type = MIO_NAME (array_type) (as->type, array_spec_types);
2954 :
2955 88910 : if (iomode == IO_INPUT && as->type == AS_ASSUMED_RANK)
2956 25053 : as->rank = -1;
2957 88910 : if (iomode == IO_INPUT && as->corank)
2958 172 : as->cotype = (as->type == AS_DEFERRED) ? AS_DEFERRED : AS_EXPLICIT;
2959 :
2960 88910 : if (as->rank + as->corank > 0)
2961 124880 : for (i = 0; i < as->rank + as->corank; i++)
2962 : {
2963 65321 : mio_expr (&as->lower[i]);
2964 65321 : mio_expr (&as->upper[i]);
2965 : }
2966 :
2967 29351 : done:
2968 1625161 : mio_rparen ();
2969 1625161 : }
2970 :
2971 :
2972 : /* Given a pointer to an array reference structure (which lives in a
2973 : gfc_ref structure), find the corresponding array specification
2974 : structure. Storing the pointer in the ref structure doesn't quite
2975 : work when loading from a module. Generating code for an array
2976 : reference also needs more information than just the array spec. */
2977 :
2978 : static const mstring array_ref_types[] = {
2979 : minit ("FULL", AR_FULL),
2980 : minit ("ELEMENT", AR_ELEMENT),
2981 : minit ("SECTION", AR_SECTION),
2982 : minit (NULL, -1)
2983 : };
2984 :
2985 :
2986 : static void
2987 1807 : mio_array_ref (gfc_array_ref *ar)
2988 : {
2989 1807 : int i;
2990 :
2991 1807 : mio_lparen ();
2992 1807 : ar->type = MIO_NAME (ar_type) (ar->type, array_ref_types);
2993 1807 : mio_integer (&ar->dimen);
2994 :
2995 1807 : switch (ar->type)
2996 : {
2997 : case AR_FULL:
2998 : break;
2999 :
3000 : case AR_ELEMENT:
3001 982 : for (i = 0; i < ar->dimen; i++)
3002 505 : mio_expr (&ar->start[i]);
3003 :
3004 : break;
3005 :
3006 : case AR_SECTION:
3007 0 : for (i = 0; i < ar->dimen; i++)
3008 : {
3009 0 : mio_expr (&ar->start[i]);
3010 0 : mio_expr (&ar->end[i]);
3011 0 : mio_expr (&ar->stride[i]);
3012 : }
3013 :
3014 : break;
3015 :
3016 0 : case AR_UNKNOWN:
3017 0 : gfc_internal_error ("mio_array_ref(): Unknown array ref");
3018 : }
3019 :
3020 : /* Unfortunately, ar->dimen_type is an anonymous enumerated type so
3021 : we can't call mio_integer directly. Instead loop over each element
3022 : and cast it to/from an integer. */
3023 1807 : if (iomode == IO_OUTPUT)
3024 : {
3025 2030 : for (i = 0; i < ar->dimen; i++)
3026 : {
3027 1132 : HOST_WIDE_INT tmp = (HOST_WIDE_INT)ar->dimen_type[i];
3028 1132 : write_atom (ATOM_INTEGER, &tmp);
3029 : }
3030 : }
3031 : else
3032 : {
3033 2084 : for (i = 0; i < ar->dimen; i++)
3034 : {
3035 1175 : require_atom (ATOM_INTEGER);
3036 1175 : ar->dimen_type[i] = (enum gfc_array_ref_dimen_type) atom_int;
3037 : }
3038 : }
3039 :
3040 1807 : if (iomode == IO_INPUT)
3041 : {
3042 909 : ar->where = gfc_current_locus;
3043 :
3044 2084 : for (i = 0; i < ar->dimen; i++)
3045 1175 : ar->c_where[i] = gfc_current_locus;
3046 : }
3047 :
3048 1807 : mio_rparen ();
3049 1807 : }
3050 :
3051 :
3052 : /* Saves or restores a pointer. The pointer is converted back and
3053 : forth from an integer. We return the pointer_info pointer so that
3054 : the caller can take additional action based on the pointer type. */
3055 :
3056 : static pointer_info *
3057 7444191 : mio_pointer_ref (void *gp)
3058 : {
3059 7444191 : pointer_info *p;
3060 :
3061 7444191 : if (iomode == IO_OUTPUT)
3062 : {
3063 1727173 : p = get_pointer (*((char **) gp));
3064 1727173 : HOST_WIDE_INT hwi = p->integer;
3065 1727173 : write_atom (ATOM_INTEGER, &hwi);
3066 : }
3067 : else
3068 : {
3069 5717018 : require_atom (ATOM_INTEGER);
3070 5717018 : p = add_fixup (atom_int, gp);
3071 : }
3072 :
3073 7444191 : return p;
3074 : }
3075 :
3076 :
3077 : /* Save and load references to components that occur within
3078 : expressions. We have to describe these references by a number and
3079 : by name. The number is necessary for forward references during
3080 : reading, and the name is necessary if the symbol already exists in
3081 : the namespace and is not loaded again. */
3082 :
3083 : static void
3084 952 : mio_component_ref (gfc_component **cp)
3085 : {
3086 952 : pointer_info *p;
3087 :
3088 952 : p = mio_pointer_ref (cp);
3089 952 : if (p->type == P_UNKNOWN)
3090 182 : p->type = P_COMPONENT;
3091 952 : }
3092 :
3093 :
3094 : static void mio_namespace_ref (gfc_namespace **nsp);
3095 : static void mio_formal_arglist (gfc_formal_arglist **formal);
3096 : static void mio_typebound_proc (gfc_typebound_proc** proc);
3097 : static void mio_actual_arglist (gfc_actual_arglist **ap, bool pdt);
3098 :
3099 : static void
3100 278126 : mio_component (gfc_component *c, int vtype)
3101 : {
3102 278126 : pointer_info *p;
3103 :
3104 278126 : mio_lparen ();
3105 :
3106 278126 : if (iomode == IO_OUTPUT)
3107 : {
3108 111648 : p = get_pointer (c);
3109 111648 : mio_hwi (&p->integer);
3110 : }
3111 : else
3112 : {
3113 166478 : HOST_WIDE_INT n;
3114 166478 : mio_hwi (&n);
3115 166478 : p = get_integer (n);
3116 166478 : associate_integer_pointer (p, c);
3117 : }
3118 :
3119 278126 : if (p->type == P_UNKNOWN)
3120 277974 : p->type = P_COMPONENT;
3121 :
3122 278126 : mio_pool_string (&c->name);
3123 278126 : mio_typespec (&c->ts);
3124 278126 : mio_array_spec (&c->as);
3125 :
3126 : /* PDT templates store the expression for the kind of a component here. */
3127 278126 : mio_expr (&c->kind_expr);
3128 :
3129 : /* PDT types store the component specification list here. */
3130 278126 : mio_actual_arglist (&c->param_list, true);
3131 :
3132 278126 : mio_symbol_attribute (&c->attr);
3133 278126 : if (c->ts.type == BT_CLASS)
3134 2333 : c->attr.class_ok = 1;
3135 278126 : c->attr.access = MIO_NAME (gfc_access) (c->attr.access, access_types);
3136 :
3137 278126 : if (!vtype || strcmp (c->name, "_final") == 0
3138 171948 : || strcmp (c->name, "_hash") == 0)
3139 133261 : mio_expr (&c->initializer);
3140 :
3141 278126 : if (c->attr.proc_pointer)
3142 91201 : mio_typebound_proc (&c->tb);
3143 :
3144 278126 : c->loc = gfc_current_locus;
3145 :
3146 278126 : mio_rparen ();
3147 278126 : }
3148 :
3149 :
3150 : static void
3151 1347035 : mio_component_list (gfc_component **cp, int vtype)
3152 : {
3153 1347035 : gfc_component *c, *tail;
3154 :
3155 1347035 : mio_lparen ();
3156 :
3157 1347035 : if (iomode == IO_OUTPUT)
3158 : {
3159 367059 : for (c = *cp; c; c = c->next)
3160 111648 : mio_component (c, vtype);
3161 : }
3162 : else
3163 : {
3164 1091624 : *cp = NULL;
3165 1091624 : tail = NULL;
3166 :
3167 1424580 : for (;;)
3168 : {
3169 1258102 : if (peek_atom () == ATOM_RPAREN)
3170 : break;
3171 :
3172 166478 : c = gfc_get_component ();
3173 166478 : mio_component (c, vtype);
3174 :
3175 166478 : if (tail == NULL)
3176 52056 : *cp = c;
3177 : else
3178 114422 : tail->next = c;
3179 :
3180 166478 : tail = c;
3181 : }
3182 : }
3183 :
3184 1347035 : mio_rparen ();
3185 1347035 : }
3186 :
3187 :
3188 : static void
3189 8937 : mio_actual_arg (gfc_actual_arglist *a, bool pdt)
3190 : {
3191 8937 : mio_lparen ();
3192 8937 : mio_pool_string (&a->name);
3193 8937 : mio_expr (&a->expr);
3194 8937 : if (pdt)
3195 2663 : mio_integer ((int *)&a->spec_type);
3196 8937 : mio_rparen ();
3197 8937 : }
3198 :
3199 :
3200 : static void
3201 2089311 : mio_actual_arglist (gfc_actual_arglist **ap, bool pdt)
3202 : {
3203 2089311 : gfc_actual_arglist *a, *tail;
3204 :
3205 2089311 : mio_lparen ();
3206 :
3207 2089311 : if (iomode == IO_OUTPUT)
3208 : {
3209 480314 : for (a = *ap; a; a = a->next)
3210 4577 : mio_actual_arg (a, pdt);
3211 :
3212 : }
3213 : else
3214 : {
3215 : tail = NULL;
3216 :
3217 1622294 : for (;;)
3218 : {
3219 1617934 : if (peek_atom () != ATOM_LPAREN)
3220 : break;
3221 :
3222 4360 : a = gfc_get_actual_arglist ();
3223 :
3224 4360 : if (tail == NULL)
3225 2395 : *ap = a;
3226 : else
3227 1965 : tail->next = a;
3228 :
3229 4360 : tail = a;
3230 4360 : mio_actual_arg (a, pdt);
3231 : }
3232 : }
3233 :
3234 2089311 : mio_rparen ();
3235 2089311 : }
3236 :
3237 :
3238 : /* Read and write formal argument lists. */
3239 :
3240 : static void
3241 1347035 : mio_formal_arglist (gfc_formal_arglist **formal)
3242 : {
3243 1347035 : gfc_formal_arglist *f, *tail;
3244 :
3245 1347035 : mio_lparen ();
3246 :
3247 1347035 : if (iomode == IO_OUTPUT)
3248 : {
3249 342395 : for (f = *formal; f; f = f->next)
3250 86984 : mio_symbol_ref (&f->sym);
3251 : }
3252 : else
3253 : {
3254 1091624 : *formal = tail = NULL;
3255 :
3256 1536280 : while (peek_atom () != ATOM_RPAREN)
3257 : {
3258 444656 : f = gfc_get_formal_arglist ();
3259 444656 : mio_symbol_ref (&f->sym);
3260 :
3261 444656 : if (*formal == NULL)
3262 235746 : *formal = f;
3263 : else
3264 208910 : tail->next = f;
3265 :
3266 444656 : tail = f;
3267 : }
3268 : }
3269 :
3270 1347035 : mio_rparen ();
3271 1347035 : }
3272 :
3273 :
3274 : /* Save or restore a reference to a symbol node. */
3275 :
3276 : pointer_info *
3277 5840763 : mio_symbol_ref (gfc_symbol **symp)
3278 : {
3279 5840763 : pointer_info *p;
3280 :
3281 5840763 : p = mio_pointer_ref (symp);
3282 5840763 : if (p->type == P_UNKNOWN)
3283 147477 : p->type = P_SYMBOL;
3284 :
3285 5840763 : if (iomode == IO_OUTPUT)
3286 : {
3287 1215763 : if (p->u.wsym.state == UNREFERENCED)
3288 165881 : p->u.wsym.state = NEEDS_WRITE;
3289 : }
3290 : else
3291 : {
3292 4625000 : if (p->u.rsym.state == UNUSED)
3293 656178 : p->u.rsym.state = NEEDED;
3294 : }
3295 5840763 : return p;
3296 : }
3297 :
3298 :
3299 : /* Save or restore a reference to a symtree node. */
3300 :
3301 : static void
3302 32523 : mio_symtree_ref (gfc_symtree **stp)
3303 : {
3304 32523 : pointer_info *p;
3305 32523 : fixup_t *f;
3306 :
3307 32523 : if (iomode == IO_OUTPUT)
3308 16266 : mio_symbol_ref (&(*stp)->n.sym);
3309 : else
3310 : {
3311 16257 : require_atom (ATOM_INTEGER);
3312 16257 : p = get_integer (atom_int);
3313 :
3314 : /* An unused equivalence member; make a symbol and a symtree
3315 : for it. */
3316 16257 : if (in_load_equiv && p->u.rsym.symtree == NULL)
3317 : {
3318 : /* Since this is not used, it must have a unique name. */
3319 87 : p->u.rsym.symtree = gfc_get_unique_symtree (gfc_current_ns);
3320 :
3321 : /* Make the symbol. */
3322 87 : if (p->u.rsym.sym == NULL)
3323 : {
3324 75 : p->u.rsym.sym = gfc_new_symbol (p->u.rsym.true_name,
3325 : gfc_current_ns);
3326 75 : p->u.rsym.sym->module = gfc_get_string ("%s", p->u.rsym.module);
3327 : }
3328 :
3329 87 : p->u.rsym.symtree->n.sym = p->u.rsym.sym;
3330 87 : p->u.rsym.symtree->n.sym->refs++;
3331 87 : p->u.rsym.referenced = 1;
3332 :
3333 : /* If the symbol is PRIVATE and in COMMON, load_commons will
3334 : generate a fixup symbol, which must be associated. */
3335 87 : if (p->fixup)
3336 2 : resolve_fixups (p->fixup, p->u.rsym.sym);
3337 87 : p->fixup = NULL;
3338 : }
3339 :
3340 16257 : if (p->type == P_UNKNOWN)
3341 0 : p->type = P_SYMBOL;
3342 :
3343 16257 : if (p->u.rsym.state == UNUSED)
3344 3018 : p->u.rsym.state = NEEDED;
3345 :
3346 16257 : if (p->u.rsym.symtree != NULL)
3347 : {
3348 3828 : *stp = p->u.rsym.symtree;
3349 : }
3350 : else
3351 : {
3352 12429 : f = XCNEW (fixup_t);
3353 :
3354 12429 : f->next = p->u.rsym.stfixup;
3355 12429 : p->u.rsym.stfixup = f;
3356 :
3357 12429 : f->pointer = (void **) stp;
3358 : }
3359 : }
3360 32523 : }
3361 :
3362 :
3363 : static void
3364 35927 : mio_iterator (gfc_iterator **ip)
3365 : {
3366 35927 : gfc_iterator *iter;
3367 :
3368 35927 : mio_lparen ();
3369 :
3370 35927 : if (iomode == IO_OUTPUT)
3371 : {
3372 10415 : if (*ip == NULL)
3373 10409 : goto done;
3374 : }
3375 : else
3376 : {
3377 25512 : if (peek_atom () == ATOM_RPAREN)
3378 : {
3379 25506 : *ip = NULL;
3380 25506 : goto done;
3381 : }
3382 :
3383 6 : *ip = gfc_get_iterator ();
3384 : }
3385 :
3386 12 : iter = *ip;
3387 :
3388 12 : mio_expr (&iter->var);
3389 12 : mio_expr (&iter->start);
3390 12 : mio_expr (&iter->end);
3391 12 : mio_expr (&iter->step);
3392 :
3393 35927 : done:
3394 35927 : mio_rparen ();
3395 35927 : }
3396 :
3397 :
3398 : static void
3399 21845 : mio_constructor (gfc_constructor_base *cp)
3400 : {
3401 21845 : gfc_constructor *c;
3402 :
3403 21845 : mio_lparen ();
3404 :
3405 21845 : if (iomode == IO_OUTPUT)
3406 : {
3407 14886 : for (c = gfc_constructor_first (*cp); c; c = gfc_constructor_next (c))
3408 : {
3409 10415 : mio_lparen ();
3410 10415 : mio_expr (&c->expr);
3411 10415 : mio_iterator (&c->iterator);
3412 10415 : mio_rparen ();
3413 : }
3414 : }
3415 : else
3416 : {
3417 42886 : while (peek_atom () != ATOM_RPAREN)
3418 : {
3419 25512 : c = gfc_constructor_append_expr (cp, NULL, NULL);
3420 :
3421 25512 : mio_lparen ();
3422 25512 : mio_expr (&c->expr);
3423 25512 : mio_iterator (&c->iterator);
3424 25512 : mio_rparen ();
3425 : }
3426 : }
3427 :
3428 21845 : mio_rparen ();
3429 21845 : }
3430 :
3431 :
3432 : static const mstring ref_types[] = {
3433 : minit ("ARRAY", REF_ARRAY),
3434 : minit ("COMPONENT", REF_COMPONENT),
3435 : minit ("SUBSTRING", REF_SUBSTRING),
3436 : minit ("INQUIRY", REF_INQUIRY),
3437 : minit (NULL, -1)
3438 : };
3439 :
3440 : static const mstring inquiry_types[] = {
3441 : minit ("RE", INQUIRY_RE),
3442 : minit ("IM", INQUIRY_IM),
3443 : minit ("KIND", INQUIRY_KIND),
3444 : minit ("LEN", INQUIRY_LEN),
3445 : minit (NULL, -1)
3446 : };
3447 :
3448 :
3449 : static void
3450 2765 : mio_ref (gfc_ref **rp)
3451 : {
3452 2765 : gfc_ref *r;
3453 :
3454 2765 : mio_lparen ();
3455 :
3456 2765 : r = *rp;
3457 2765 : r->type = MIO_NAME (ref_type) (r->type, ref_types);
3458 :
3459 2765 : switch (r->type)
3460 : {
3461 1807 : case REF_ARRAY:
3462 1807 : mio_array_ref (&r->u.ar);
3463 1807 : break;
3464 :
3465 952 : case REF_COMPONENT:
3466 952 : mio_symbol_ref (&r->u.c.sym);
3467 952 : mio_component_ref (&r->u.c.component);
3468 952 : break;
3469 :
3470 6 : case REF_SUBSTRING:
3471 6 : mio_expr (&r->u.ss.start);
3472 6 : mio_expr (&r->u.ss.end);
3473 6 : mio_charlen (&r->u.ss.length);
3474 6 : break;
3475 :
3476 0 : case REF_INQUIRY:
3477 0 : r->u.i = MIO_NAME (inquiry_type) (r->u.i, inquiry_types);
3478 0 : break;
3479 : }
3480 :
3481 2765 : mio_rparen ();
3482 2765 : }
3483 :
3484 :
3485 : static void
3486 18158 : mio_ref_list (gfc_ref **rp)
3487 : {
3488 18158 : gfc_ref *ref, *head, *tail;
3489 :
3490 18158 : mio_lparen ();
3491 :
3492 18158 : if (iomode == IO_OUTPUT)
3493 : {
3494 10158 : for (ref = *rp; ref; ref = ref->next)
3495 1467 : mio_ref (&ref);
3496 : }
3497 : else
3498 : {
3499 9467 : head = tail = NULL;
3500 :
3501 10765 : while (peek_atom () != ATOM_RPAREN)
3502 : {
3503 1298 : if (head == NULL)
3504 1141 : head = tail = gfc_get_ref ();
3505 : else
3506 : {
3507 157 : tail->next = gfc_get_ref ();
3508 157 : tail = tail->next;
3509 : }
3510 :
3511 1298 : mio_ref (&tail);
3512 : }
3513 :
3514 9467 : *rp = head;
3515 : }
3516 :
3517 18158 : mio_rparen ();
3518 18158 : }
3519 :
3520 :
3521 : /* Read and write an integer value. */
3522 :
3523 : static void
3524 382540 : mio_gmp_integer (mpz_t *integer)
3525 : {
3526 382540 : char *p;
3527 :
3528 382540 : if (iomode == IO_INPUT)
3529 : {
3530 307498 : if (parse_atom () != ATOM_STRING)
3531 0 : bad_module ("Expected integer string");
3532 :
3533 307498 : mpz_init (*integer);
3534 307498 : if (mpz_set_str (*integer, atom_string, 10))
3535 0 : bad_module ("Error converting integer");
3536 :
3537 307498 : free (atom_string);
3538 : }
3539 : else
3540 : {
3541 75042 : p = mpz_get_str (NULL, 10, *integer);
3542 75042 : write_atom (ATOM_STRING, p);
3543 75042 : free (p);
3544 : }
3545 382540 : }
3546 :
3547 :
3548 : static void
3549 2213 : mio_gmp_real (mpfr_t *real)
3550 : {
3551 2213 : mpfr_exp_t exponent;
3552 2213 : char *p;
3553 :
3554 2213 : if (iomode == IO_INPUT)
3555 : {
3556 1034 : if (parse_atom () != ATOM_STRING)
3557 0 : bad_module ("Expected real string");
3558 :
3559 1034 : mpfr_init (*real);
3560 1034 : mpfr_set_str (*real, atom_string, 16, GFC_RND_MODE);
3561 1034 : free (atom_string);
3562 : }
3563 : else
3564 : {
3565 1179 : p = mpfr_get_str (NULL, &exponent, 16, 0, *real, GFC_RND_MODE);
3566 :
3567 1179 : if (mpfr_nan_p (*real) || mpfr_inf_p (*real))
3568 : {
3569 18 : write_atom (ATOM_STRING, p);
3570 18 : free (p);
3571 18 : return;
3572 : }
3573 :
3574 1161 : atom_string = XCNEWVEC (char, strlen (p) + 20);
3575 :
3576 1161 : sprintf (atom_string, "0.%s@%ld", p, exponent);
3577 :
3578 : /* Fix negative numbers. */
3579 1161 : if (atom_string[2] == '-')
3580 : {
3581 45 : atom_string[0] = '-';
3582 45 : atom_string[1] = '0';
3583 45 : atom_string[2] = '.';
3584 : }
3585 :
3586 1161 : write_atom (ATOM_STRING, atom_string);
3587 :
3588 1161 : free (atom_string);
3589 1161 : free (p);
3590 : }
3591 : }
3592 :
3593 :
3594 : /* Save and restore the shape of an array constructor. */
3595 :
3596 : static void
3597 21845 : mio_shape (mpz_t **pshape, int rank)
3598 : {
3599 21845 : mpz_t *shape;
3600 21845 : atom_type t;
3601 21845 : int n;
3602 :
3603 : /* A NULL shape is represented by (). */
3604 21845 : mio_lparen ();
3605 :
3606 21845 : if (iomode == IO_OUTPUT)
3607 : {
3608 4471 : shape = *pshape;
3609 4471 : if (!shape)
3610 : {
3611 3846 : mio_rparen ();
3612 3846 : return;
3613 : }
3614 : }
3615 : else
3616 : {
3617 17374 : t = peek_atom ();
3618 17374 : if (t == ATOM_RPAREN)
3619 : {
3620 15983 : *pshape = NULL;
3621 15983 : mio_rparen ();
3622 15983 : return;
3623 : }
3624 :
3625 1391 : shape = gfc_get_shape (rank);
3626 1391 : *pshape = shape;
3627 : }
3628 :
3629 4184 : for (n = 0; n < rank; n++)
3630 2168 : mio_gmp_integer (&shape[n]);
3631 :
3632 2016 : mio_rparen ();
3633 : }
3634 :
3635 :
3636 : static const mstring expr_types[] = {
3637 : minit ("OP", EXPR_OP),
3638 : minit ("FUNCTION", EXPR_FUNCTION),
3639 : minit ("CONSTANT", EXPR_CONSTANT),
3640 : minit ("VARIABLE", EXPR_VARIABLE),
3641 : minit ("SUBSTRING", EXPR_SUBSTRING),
3642 : minit ("STRUCTURE", EXPR_STRUCTURE),
3643 : minit ("ARRAY", EXPR_ARRAY),
3644 : minit ("NULL", EXPR_NULL),
3645 : minit ("COMPCALL", EXPR_COMPCALL),
3646 : minit ("PPC", EXPR_PPC),
3647 : minit ("CONDITIONAL", EXPR_CONDITIONAL),
3648 : minit (NULL, -1),
3649 : };
3650 :
3651 : /* INTRINSIC_ASSIGN is missing because it is used as an index for
3652 : generic operators, not in expressions. INTRINSIC_USER is also
3653 : replaced by the correct function name by the time we see it. */
3654 :
3655 : static const mstring intrinsics[] =
3656 : {
3657 : minit ("UPLUS", INTRINSIC_UPLUS),
3658 : minit ("UMINUS", INTRINSIC_UMINUS),
3659 : minit ("PLUS", INTRINSIC_PLUS),
3660 : minit ("MINUS", INTRINSIC_MINUS),
3661 : minit ("TIMES", INTRINSIC_TIMES),
3662 : minit ("DIVIDE", INTRINSIC_DIVIDE),
3663 : minit ("POWER", INTRINSIC_POWER),
3664 : minit ("CONCAT", INTRINSIC_CONCAT),
3665 : minit ("AND", INTRINSIC_AND),
3666 : minit ("OR", INTRINSIC_OR),
3667 : minit ("EQV", INTRINSIC_EQV),
3668 : minit ("NEQV", INTRINSIC_NEQV),
3669 : minit ("EQ_SIGN", INTRINSIC_EQ),
3670 : minit ("EQ", INTRINSIC_EQ_OS),
3671 : minit ("NE_SIGN", INTRINSIC_NE),
3672 : minit ("NE", INTRINSIC_NE_OS),
3673 : minit ("GT_SIGN", INTRINSIC_GT),
3674 : minit ("GT", INTRINSIC_GT_OS),
3675 : minit ("GE_SIGN", INTRINSIC_GE),
3676 : minit ("GE", INTRINSIC_GE_OS),
3677 : minit ("LT_SIGN", INTRINSIC_LT),
3678 : minit ("LT", INTRINSIC_LT_OS),
3679 : minit ("LE_SIGN", INTRINSIC_LE),
3680 : minit ("LE", INTRINSIC_LE_OS),
3681 : minit ("NOT", INTRINSIC_NOT),
3682 : minit ("PARENTHESES", INTRINSIC_PARENTHESES),
3683 : minit ("USER", INTRINSIC_USER),
3684 : minit (NULL, -1)
3685 : };
3686 :
3687 :
3688 : /* Remedy a couple of situations where the gfc_expr's can be defective. */
3689 :
3690 : static void
3691 461132 : fix_mio_expr (gfc_expr *e)
3692 : {
3693 461132 : gfc_symtree *ns_st = NULL;
3694 461132 : const char *fname;
3695 :
3696 461132 : if (iomode != IO_OUTPUT)
3697 : return;
3698 :
3699 107131 : if (e->symtree)
3700 : {
3701 : /* If this is a symtree for a symbol that came from a contained module
3702 : namespace, it has a unique name and we should look in the current
3703 : namespace to see if the required, non-contained symbol is available
3704 : yet. If so, the latter should be written. */
3705 11546 : if (e->symtree->n.sym && check_unique_name (e->symtree->name))
3706 : {
3707 794 : const char *name = e->symtree->n.sym->name;
3708 794 : if (gfc_fl_struct (e->symtree->n.sym->attr.flavor))
3709 0 : name = gfc_dt_upper_string (name);
3710 794 : ns_st = gfc_find_symtree (gfc_current_ns->sym_root, name);
3711 : }
3712 :
3713 : /* On the other hand, if the existing symbol is the module name or the
3714 : new symbol is a dummy argument, do not do the promotion. */
3715 794 : if (ns_st && ns_st->n.sym
3716 23 : && ns_st->n.sym->attr.flavor != FL_MODULE
3717 22 : && !e->symtree->n.sym->attr.dummy)
3718 21 : e->symtree = ns_st;
3719 : }
3720 95585 : else if (e->expr_type == EXPR_FUNCTION
3721 2 : && (e->value.function.name || e->value.function.isym))
3722 : {
3723 2 : gfc_symbol *sym;
3724 :
3725 : /* In some circumstances, a function used in an initialization
3726 : expression, in one use associated module, can fail to be
3727 : coupled to its symtree when used in a specification
3728 : expression in another module. */
3729 2 : fname = e->value.function.esym ? e->value.function.esym->name
3730 2 : : e->value.function.isym->name;
3731 2 : e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
3732 :
3733 2 : if (e->symtree)
3734 1 : return;
3735 :
3736 : /* This is probably a reference to a private procedure from another
3737 : module. To prevent a segfault, make a generic with no specific
3738 : instances. If this module is used, without the required
3739 : specific coming from somewhere, the appropriate error message
3740 : is issued. */
3741 1 : gfc_get_symbol (fname, gfc_current_ns, &sym);
3742 1 : sym->attr.flavor = FL_PROCEDURE;
3743 1 : sym->attr.generic = 1;
3744 1 : e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
3745 1 : gfc_commit_symbol (sym);
3746 : }
3747 : }
3748 :
3749 :
3750 : /* Read and write expressions. The form "()" is allowed to indicate a
3751 : NULL expression. */
3752 :
3753 : static void
3754 897721 : mio_expr (gfc_expr **ep)
3755 : {
3756 897721 : HOST_WIDE_INT hwi;
3757 897721 : gfc_expr *e;
3758 897721 : atom_type t;
3759 897721 : int flag;
3760 :
3761 897721 : mio_lparen ();
3762 :
3763 897721 : if (iomode == IO_OUTPUT)
3764 : {
3765 270404 : if (*ep == NULL)
3766 : {
3767 163273 : mio_rparen ();
3768 599862 : return;
3769 : }
3770 :
3771 107131 : e = *ep;
3772 107131 : MIO_NAME (expr_t) (e->expr_type, expr_types);
3773 : }
3774 : else
3775 : {
3776 627317 : t = parse_atom ();
3777 627317 : if (t == ATOM_RPAREN)
3778 : {
3779 273316 : *ep = NULL;
3780 273316 : return;
3781 : }
3782 :
3783 354001 : if (t != ATOM_NAME)
3784 0 : bad_module ("Expected expression type");
3785 :
3786 354001 : e = *ep = gfc_get_expr ();
3787 354001 : e->where = gfc_current_locus;
3788 354001 : e->expr_type = (expr_t) find_enum (expr_types);
3789 : }
3790 :
3791 461132 : mio_typespec (&e->ts);
3792 461132 : mio_integer (&e->rank);
3793 :
3794 461132 : fix_mio_expr (e);
3795 :
3796 461132 : switch (e->expr_type)
3797 : {
3798 1721 : case EXPR_OP:
3799 1721 : e->value.op.op
3800 1721 : = MIO_NAME (gfc_intrinsic_op) (e->value.op.op, intrinsics);
3801 :
3802 1721 : switch (e->value.op.op)
3803 : {
3804 447 : case INTRINSIC_UPLUS:
3805 447 : case INTRINSIC_UMINUS:
3806 447 : case INTRINSIC_NOT:
3807 447 : case INTRINSIC_PARENTHESES:
3808 447 : mio_expr (&e->value.op.op1);
3809 447 : break;
3810 :
3811 1204 : case INTRINSIC_PLUS:
3812 1204 : case INTRINSIC_MINUS:
3813 1204 : case INTRINSIC_TIMES:
3814 1204 : case INTRINSIC_DIVIDE:
3815 1204 : case INTRINSIC_POWER:
3816 1204 : case INTRINSIC_CONCAT:
3817 1204 : case INTRINSIC_AND:
3818 1204 : case INTRINSIC_OR:
3819 1204 : case INTRINSIC_EQV:
3820 1204 : case INTRINSIC_NEQV:
3821 1204 : case INTRINSIC_EQ:
3822 1204 : case INTRINSIC_EQ_OS:
3823 1204 : case INTRINSIC_NE:
3824 1204 : case INTRINSIC_NE_OS:
3825 1204 : case INTRINSIC_GT:
3826 1204 : case INTRINSIC_GT_OS:
3827 1204 : case INTRINSIC_GE:
3828 1204 : case INTRINSIC_GE_OS:
3829 1204 : case INTRINSIC_LT:
3830 1204 : case INTRINSIC_LT_OS:
3831 1204 : case INTRINSIC_LE:
3832 1204 : case INTRINSIC_LE_OS:
3833 1204 : mio_expr (&e->value.op.op1);
3834 1204 : mio_expr (&e->value.op.op2);
3835 1204 : break;
3836 :
3837 70 : case INTRINSIC_USER:
3838 : /* INTRINSIC_USER should not appear in resolved expressions,
3839 : though for UDRs we need to stream unresolved ones. */
3840 70 : if (iomode == IO_OUTPUT)
3841 34 : write_atom (ATOM_STRING, e->value.op.uop->name);
3842 : else
3843 : {
3844 36 : char *name = read_string ();
3845 36 : const char *uop_name = find_use_name (name, true);
3846 36 : if (uop_name == NULL)
3847 : {
3848 0 : size_t len = strlen (name);
3849 0 : char *name2 = XCNEWVEC (char, len + 2);
3850 0 : memcpy (name2, name, len);
3851 0 : name2[len] = ' ';
3852 0 : name2[len + 1] = '\0';
3853 0 : free (name);
3854 0 : uop_name = name = name2;
3855 : }
3856 36 : e->value.op.uop = gfc_get_uop (uop_name);
3857 36 : free (name);
3858 : }
3859 70 : mio_expr (&e->value.op.op1);
3860 70 : mio_expr (&e->value.op.op2);
3861 70 : break;
3862 :
3863 0 : default:
3864 0 : bad_module ("Bad operator");
3865 : }
3866 :
3867 : break;
3868 :
3869 2 : case EXPR_CONDITIONAL:
3870 2 : mio_expr (&e->value.conditional.condition);
3871 2 : mio_expr (&e->value.conditional.true_expr);
3872 2 : mio_expr (&e->value.conditional.false_expr);
3873 2 : break;
3874 :
3875 2910 : case EXPR_FUNCTION:
3876 2910 : mio_symtree_ref (&e->symtree);
3877 2910 : mio_actual_arglist (&e->value.function.actual, false);
3878 :
3879 2910 : if (iomode == IO_OUTPUT)
3880 : {
3881 1493 : e->value.function.name
3882 1493 : = mio_allocated_string (e->value.function.name);
3883 1493 : if (e->value.function.esym)
3884 131 : flag = 1;
3885 1362 : else if (e->ref)
3886 104 : flag = 2;
3887 1258 : else if (e->value.function.isym == NULL)
3888 358 : flag = 3;
3889 : else
3890 900 : flag = 0;
3891 1493 : mio_integer (&flag);
3892 1493 : switch (flag)
3893 : {
3894 131 : case 1:
3895 131 : mio_symbol_ref (&e->value.function.esym);
3896 131 : break;
3897 104 : case 2:
3898 104 : mio_ref_list (&e->ref);
3899 104 : break;
3900 : case 3:
3901 : break;
3902 900 : default:
3903 900 : write_atom (ATOM_STRING, e->value.function.isym->name);
3904 : }
3905 : }
3906 : else
3907 : {
3908 1417 : require_atom (ATOM_STRING);
3909 1417 : if (atom_string[0] == '\0')
3910 : e->value.function.name = NULL;
3911 : else
3912 568 : e->value.function.name = gfc_get_string ("%s", atom_string);
3913 1417 : free (atom_string);
3914 :
3915 1417 : mio_integer (&flag);
3916 1417 : switch (flag)
3917 : {
3918 138 : case 1:
3919 138 : mio_symbol_ref (&e->value.function.esym);
3920 138 : break;
3921 72 : case 2:
3922 72 : mio_ref_list (&e->ref);
3923 72 : break;
3924 : case 3:
3925 : break;
3926 882 : default:
3927 882 : require_atom (ATOM_STRING);
3928 882 : e->value.function.isym = gfc_find_function (atom_string);
3929 882 : free (atom_string);
3930 : }
3931 : }
3932 :
3933 : break;
3934 :
3935 17982 : case EXPR_VARIABLE:
3936 17982 : mio_symtree_ref (&e->symtree);
3937 17982 : mio_ref_list (&e->ref);
3938 17982 : break;
3939 :
3940 0 : case EXPR_SUBSTRING:
3941 0 : e->value.character.string = const_cast<gfc_char_t *>
3942 0 : (mio_allocated_wide_string (e->value.character.string,
3943 0 : e->value.character.length));
3944 0 : mio_ref_list (&e->ref);
3945 0 : break;
3946 :
3947 21845 : case EXPR_STRUCTURE:
3948 21845 : case EXPR_ARRAY:
3949 21845 : mio_constructor (&e->value.constructor);
3950 21845 : mio_shape (&e->shape, e->rank);
3951 21845 : break;
3952 :
3953 391505 : case EXPR_CONSTANT:
3954 391505 : switch (e->ts.type)
3955 : {
3956 380372 : case BT_INTEGER:
3957 380372 : case BT_UNSIGNED:
3958 380372 : mio_gmp_integer (&e->value.integer);
3959 380372 : break;
3960 :
3961 2049 : case BT_REAL:
3962 2049 : gfc_set_model_kind (e->ts.kind);
3963 2049 : mio_gmp_real (&e->value.real);
3964 2049 : break;
3965 :
3966 82 : case BT_COMPLEX:
3967 82 : gfc_set_model_kind (e->ts.kind);
3968 82 : mio_gmp_real (&mpc_realref (e->value.complex));
3969 82 : mio_gmp_real (&mpc_imagref (e->value.complex));
3970 82 : break;
3971 :
3972 315 : case BT_LOGICAL:
3973 315 : mio_integer (&e->value.logical);
3974 315 : break;
3975 :
3976 8687 : case BT_CHARACTER:
3977 8687 : hwi = e->value.character.length;
3978 8687 : mio_hwi (&hwi);
3979 8687 : e->value.character.length = hwi;
3980 17374 : e->value.character.string = const_cast<gfc_char_t *>
3981 8687 : (mio_allocated_wide_string (e->value.character.string,
3982 : e->value.character.length));
3983 8687 : break;
3984 :
3985 0 : default:
3986 0 : bad_module ("Bad type in constant expression");
3987 : }
3988 :
3989 : break;
3990 :
3991 : case EXPR_NULL:
3992 : break;
3993 :
3994 0 : case EXPR_COMPCALL:
3995 0 : case EXPR_PPC:
3996 0 : case EXPR_UNKNOWN:
3997 0 : gcc_unreachable ();
3998 461132 : break;
3999 : }
4000 :
4001 : /* PDT types store the expression specification list here. */
4002 461132 : mio_actual_arglist (&e->param_list, true);
4003 :
4004 461132 : mio_rparen ();
4005 : }
4006 :
4007 :
4008 : /* Read and write namelists. */
4009 :
4010 : static void
4011 1347035 : mio_namelist (gfc_symbol *sym)
4012 : {
4013 1347035 : gfc_namelist *n, *m;
4014 :
4015 1347035 : mio_lparen ();
4016 :
4017 1347035 : if (iomode == IO_OUTPUT)
4018 : {
4019 255495 : for (n = sym->namelist; n; n = n->next)
4020 84 : mio_symbol_ref (&n->sym);
4021 : }
4022 : else
4023 : {
4024 : m = NULL;
4025 1091713 : while (peek_atom () != ATOM_RPAREN)
4026 : {
4027 89 : n = gfc_get_namelist ();
4028 89 : mio_symbol_ref (&n->sym);
4029 :
4030 89 : if (sym->namelist == NULL)
4031 53 : sym->namelist = n;
4032 : else
4033 36 : m->next = n;
4034 :
4035 89 : m = n;
4036 : }
4037 1091624 : sym->namelist_tail = m;
4038 : }
4039 :
4040 1347035 : mio_rparen ();
4041 1347035 : }
4042 :
4043 :
4044 : /* Save/restore lists of gfc_interface structures. When loading an
4045 : interface, we are really appending to the existing list of
4046 : interfaces. Checking for duplicate and ambiguous interfaces has to
4047 : be done later when all symbols have been loaded. */
4048 :
4049 : pointer_info *
4050 684219 : mio_interface_rest (gfc_interface **ip)
4051 : {
4052 684219 : gfc_interface *tail, *p;
4053 684219 : pointer_info *pi = NULL;
4054 :
4055 684219 : if (iomode == IO_OUTPUT)
4056 : {
4057 291547 : if (ip != NULL)
4058 283047 : for (p = *ip; p; p = p->next)
4059 17677 : mio_symbol_ref (&p->sym);
4060 : }
4061 : else
4062 : {
4063 392672 : if (*ip == NULL)
4064 392672 : tail = NULL;
4065 : else
4066 : {
4067 : tail = *ip;
4068 5182 : while (tail->next)
4069 : tail = tail->next;
4070 : }
4071 :
4072 738168 : for (;;)
4073 : {
4074 565420 : if (peek_atom () == ATOM_RPAREN)
4075 : break;
4076 :
4077 172748 : p = gfc_get_interface ();
4078 172748 : p->where = gfc_current_locus;
4079 172748 : pi = mio_symbol_ref (&p->sym);
4080 :
4081 172748 : if (tail == NULL)
4082 59798 : *ip = p;
4083 : else
4084 112950 : tail->next = p;
4085 :
4086 172748 : tail = p;
4087 : }
4088 : }
4089 :
4090 684219 : mio_rparen ();
4091 684219 : return pi;
4092 : }
4093 :
4094 :
4095 : /* Save/restore a nameless operator interface. */
4096 :
4097 : static void
4098 611754 : mio_interface (gfc_interface **ip)
4099 : {
4100 279666 : mio_lparen ();
4101 332088 : mio_interface_rest (ip);
4102 0 : }
4103 :
4104 :
4105 : /* Save/restore a named operator interface. */
4106 :
4107 : static void
4108 11881 : mio_symbol_interface (const char **name, const char **module,
4109 : gfc_interface **ip)
4110 : {
4111 11881 : mio_lparen ();
4112 11881 : mio_pool_string (name);
4113 11881 : mio_pool_string (module);
4114 11881 : mio_interface_rest (ip);
4115 11881 : }
4116 :
4117 :
4118 : static void
4119 1347035 : mio_namespace_ref (gfc_namespace **nsp)
4120 : {
4121 1347035 : gfc_namespace *ns;
4122 1347035 : pointer_info *p;
4123 :
4124 1347035 : p = mio_pointer_ref (nsp);
4125 :
4126 1347035 : if (p->type == P_UNKNOWN)
4127 273468 : p->type = P_NAMESPACE;
4128 :
4129 1347035 : if (iomode == IO_INPUT && p->integer != 0)
4130 : {
4131 242659 : ns = (gfc_namespace *) p->u.pointer;
4132 242659 : if (ns == NULL)
4133 : {
4134 242298 : ns = gfc_get_namespace (NULL, 0);
4135 242298 : associate_integer_pointer (p, ns);
4136 : }
4137 : else
4138 361 : ns->refs++;
4139 : }
4140 1347035 : }
4141 :
4142 :
4143 : /* Save/restore the f2k_derived namespace of a derived-type symbol. */
4144 :
4145 : static gfc_namespace* current_f2k_derived;
4146 :
4147 : static void
4148 103819 : mio_typebound_proc (gfc_typebound_proc** proc)
4149 : {
4150 103819 : int flag;
4151 103819 : int overriding_flag;
4152 :
4153 103819 : if (iomode == IO_INPUT)
4154 : {
4155 57960 : *proc = gfc_get_typebound_proc (NULL);
4156 57960 : (*proc)->where = gfc_current_locus;
4157 : }
4158 103819 : gcc_assert (*proc);
4159 :
4160 103819 : mio_lparen ();
4161 :
4162 103819 : (*proc)->access = MIO_NAME (gfc_access) ((*proc)->access, access_types);
4163 :
4164 : /* IO the NON_OVERRIDABLE/DEFERRED combination. */
4165 103819 : gcc_assert (!((*proc)->deferred && (*proc)->non_overridable));
4166 103819 : overriding_flag = ((*proc)->deferred << 1) | (*proc)->non_overridable;
4167 103819 : overriding_flag = mio_name (overriding_flag, binding_overriding);
4168 103819 : (*proc)->deferred = ((overriding_flag & 2) != 0);
4169 103819 : (*proc)->non_overridable = ((overriding_flag & 1) != 0);
4170 103819 : gcc_assert (!((*proc)->deferred && (*proc)->non_overridable));
4171 :
4172 103819 : (*proc)->nopass = mio_name ((*proc)->nopass, binding_passing);
4173 103819 : (*proc)->is_generic = mio_name ((*proc)->is_generic, binding_generic);
4174 103819 : (*proc)->ppc = mio_name((*proc)->ppc, binding_ppc);
4175 :
4176 103819 : mio_pool_string (&((*proc)->pass_arg));
4177 :
4178 103819 : flag = (int) (*proc)->pass_arg_num;
4179 103819 : mio_integer (&flag);
4180 103819 : (*proc)->pass_arg_num = (unsigned) flag;
4181 :
4182 103819 : if ((*proc)->is_generic)
4183 : {
4184 2890 : gfc_tbp_generic* g;
4185 2890 : int iop;
4186 :
4187 2890 : mio_lparen ();
4188 :
4189 2890 : if (iomode == IO_OUTPUT)
4190 3452 : for (g = (*proc)->u.generic; g; g = g->next)
4191 : {
4192 1931 : iop = (int) g->is_operator;
4193 1931 : mio_integer (&iop);
4194 1931 : mio_allocated_string (g->specific_st->name);
4195 : }
4196 : else
4197 : {
4198 1369 : (*proc)->u.generic = NULL;
4199 3051 : while (peek_atom () != ATOM_RPAREN)
4200 : {
4201 1682 : gfc_symtree** sym_root;
4202 :
4203 1682 : g = gfc_get_tbp_generic ();
4204 1682 : g->specific = NULL;
4205 :
4206 1682 : mio_integer (&iop);
4207 1682 : g->is_operator = (bool) iop;
4208 :
4209 1682 : require_atom (ATOM_STRING);
4210 1682 : sym_root = ¤t_f2k_derived->tb_sym_root;
4211 1682 : g->specific_st = gfc_get_tbp_symtree (sym_root, atom_string);
4212 1682 : free (atom_string);
4213 :
4214 1682 : g->next = (*proc)->u.generic;
4215 1682 : (*proc)->u.generic = g;
4216 : }
4217 : }
4218 :
4219 2890 : mio_rparen ();
4220 : }
4221 100929 : else if (!(*proc)->ppc)
4222 9728 : mio_symtree_ref (&(*proc)->u.specific);
4223 :
4224 103819 : mio_rparen ();
4225 103819 : }
4226 :
4227 : /* Walker-callback function for this purpose. */
4228 : static void
4229 11274 : mio_typebound_symtree (gfc_symtree* st)
4230 : {
4231 11274 : if (iomode == IO_OUTPUT && !st->n.tb)
4232 : return;
4233 :
4234 11274 : if (iomode == IO_OUTPUT)
4235 : {
4236 5993 : mio_lparen ();
4237 5993 : mio_allocated_string (st->name);
4238 : }
4239 : /* For IO_INPUT, the above is done in mio_f2k_derived. */
4240 :
4241 11274 : mio_typebound_proc (&st->n.tb);
4242 11274 : mio_rparen ();
4243 : }
4244 :
4245 : /* IO a full symtree (in all depth). */
4246 : static void
4247 69106 : mio_full_typebound_tree (gfc_symtree** root)
4248 : {
4249 69106 : mio_lparen ();
4250 :
4251 69106 : if (iomode == IO_OUTPUT)
4252 29938 : gfc_traverse_symtree (*root, &mio_typebound_symtree);
4253 : else
4254 : {
4255 44449 : while (peek_atom () == ATOM_LPAREN)
4256 : {
4257 5281 : gfc_symtree* st;
4258 :
4259 5281 : mio_lparen ();
4260 :
4261 5281 : require_atom (ATOM_STRING);
4262 5281 : st = gfc_get_tbp_symtree (root, atom_string);
4263 5281 : free (atom_string);
4264 :
4265 5281 : mio_typebound_symtree (st);
4266 : }
4267 : }
4268 :
4269 69106 : mio_rparen ();
4270 69106 : }
4271 :
4272 : static void
4273 1449 : mio_finalizer (gfc_finalizer **f)
4274 : {
4275 1449 : if (iomode == IO_OUTPUT)
4276 : {
4277 696 : gcc_assert (*f);
4278 696 : gcc_assert ((*f)->proc_tree); /* Should already be resolved. */
4279 696 : mio_symtree_ref (&(*f)->proc_tree);
4280 : }
4281 : else
4282 : {
4283 753 : *f = gfc_get_finalizer ();
4284 753 : (*f)->where = gfc_current_locus; /* Value should not matter. */
4285 753 : (*f)->next = NULL;
4286 :
4287 753 : mio_symtree_ref (&(*f)->proc_tree);
4288 753 : (*f)->proc_sym = NULL;
4289 : }
4290 1449 : }
4291 :
4292 : static void
4293 34553 : mio_f2k_derived (gfc_namespace *f2k)
4294 : {
4295 34553 : current_f2k_derived = f2k;
4296 :
4297 : /* Handle the list of finalizer procedures. */
4298 34553 : mio_lparen ();
4299 34553 : if (iomode == IO_OUTPUT)
4300 : {
4301 14969 : gfc_finalizer *f;
4302 15665 : for (f = f2k->finalizers; f; f = f->next)
4303 696 : mio_finalizer (&f);
4304 : }
4305 : else
4306 : {
4307 19584 : f2k->finalizers = NULL;
4308 20337 : while (peek_atom () != ATOM_RPAREN)
4309 : {
4310 753 : gfc_finalizer *cur = NULL;
4311 753 : mio_finalizer (&cur);
4312 753 : cur->next = f2k->finalizers;
4313 753 : f2k->finalizers = cur;
4314 : }
4315 : }
4316 34553 : mio_rparen ();
4317 :
4318 : /* Handle type-bound procedures. */
4319 34553 : mio_full_typebound_tree (&f2k->tb_sym_root);
4320 :
4321 : /* Type-bound user operators. */
4322 34553 : mio_full_typebound_tree (&f2k->tb_uop_root);
4323 :
4324 : /* Type-bound intrinsic operators. */
4325 34553 : mio_lparen ();
4326 34553 : if (iomode == IO_OUTPUT)
4327 : {
4328 : int op;
4329 434101 : for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
4330 : {
4331 419132 : gfc_intrinsic_op realop;
4332 :
4333 419132 : if (op == INTRINSIC_USER || !f2k->tb_op[op])
4334 418418 : continue;
4335 :
4336 714 : mio_lparen ();
4337 714 : realop = (gfc_intrinsic_op) op;
4338 714 : mio_intrinsic_op (&realop);
4339 714 : mio_typebound_proc (&f2k->tb_op[op]);
4340 714 : mio_rparen ();
4341 : }
4342 : }
4343 : else
4344 20214 : while (peek_atom () != ATOM_RPAREN)
4345 : {
4346 630 : gfc_intrinsic_op op = GFC_INTRINSIC_BEGIN; /* Silence GCC. */
4347 :
4348 630 : mio_lparen ();
4349 630 : mio_intrinsic_op (&op);
4350 630 : mio_typebound_proc (&f2k->tb_op[op]);
4351 630 : mio_rparen ();
4352 : }
4353 34553 : mio_rparen ();
4354 34553 : }
4355 :
4356 :
4357 : static void
4358 1347035 : mio_full_f2k_derived (gfc_symbol *sym)
4359 : {
4360 1347035 : mio_lparen ();
4361 :
4362 1347035 : if (iomode == IO_OUTPUT)
4363 : {
4364 255411 : if (sym->f2k_derived)
4365 14969 : mio_f2k_derived (sym->f2k_derived);
4366 : }
4367 : else
4368 : {
4369 1091624 : if (peek_atom () != ATOM_RPAREN)
4370 : {
4371 19584 : sym->f2k_derived = gfc_get_namespace (NULL, 0);
4372 :
4373 : /* PDT type-parameter namespaces are reconstructed
4374 : after all needed module symbols are loaded. */
4375 19584 : mio_f2k_derived (sym->f2k_derived);
4376 : }
4377 : else
4378 1072040 : gcc_assert (!sym->f2k_derived);
4379 : }
4380 :
4381 1347035 : mio_rparen ();
4382 1347035 : }
4383 :
4384 : static const mstring omp_declare_simd_clauses[] =
4385 : {
4386 : minit ("INBRANCH", 0),
4387 : minit ("NOTINBRANCH", 1),
4388 : minit ("SIMDLEN", 2),
4389 : minit ("UNIFORM", 3),
4390 : minit ("LINEAR", 4),
4391 : minit ("ALIGNED", 5),
4392 : minit ("SIMDLEN_TYP", 6),
4393 : minit ("SIMDLEN_DIV", 7),
4394 : minit ("LINEAR_REF", 33),
4395 : minit ("LINEAR_VAL", 34),
4396 : minit ("LINEAR_UVAL", 35),
4397 : minit (NULL, -1)
4398 : };
4399 :
4400 : /* Handle OpenMP's declare-simd clauses. */
4401 :
4402 : static void
4403 176 : mio_omp_declare_simd_clauses (gfc_omp_clauses **clausesp)
4404 : {
4405 176 : if (iomode == IO_OUTPUT)
4406 : {
4407 114 : gfc_omp_clauses *clauses = *clausesp;
4408 114 : gfc_omp_namelist *n;
4409 :
4410 114 : write_atom (ATOM_NAME, "OMP_DECLARE_SIMD");
4411 114 : if (clauses->inbranch)
4412 10 : mio_name (0, omp_declare_simd_clauses);
4413 114 : if (clauses->notinbranch)
4414 23 : mio_name (1, omp_declare_simd_clauses);
4415 114 : if (clauses->simdlen_expr)
4416 : {
4417 50 : mio_name (2, omp_declare_simd_clauses);
4418 50 : mio_expr (&clauses->simdlen_expr);
4419 : }
4420 171 : for (n = clauses->lists[OMP_LIST_UNIFORM]; n; n = n->next)
4421 : {
4422 57 : mio_name (3, omp_declare_simd_clauses);
4423 57 : mio_symbol_ref (&n->sym);
4424 : }
4425 179 : for (n = clauses->lists[OMP_LIST_LINEAR]; n; n = n->next)
4426 : {
4427 65 : if (n->u.linear.op == OMP_LINEAR_DEFAULT)
4428 40 : mio_name (4, omp_declare_simd_clauses);
4429 : else
4430 25 : mio_name (32 + n->u.linear.op, omp_declare_simd_clauses);
4431 65 : mio_symbol_ref (&n->sym);
4432 65 : mio_expr (&n->expr);
4433 : }
4434 120 : for (n = clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next)
4435 : {
4436 6 : mio_name (5, omp_declare_simd_clauses);
4437 6 : mio_symbol_ref (&n->sym);
4438 6 : mio_expr (&n->expr);
4439 : }
4440 114 : if (clauses->simdlen_type.type != BT_UNKNOWN)
4441 : {
4442 11 : gfc_typespec ts = {};
4443 11 : ts.type = clauses->simdlen_type.type;
4444 11 : ts.kind = clauses->simdlen_type.kind;
4445 11 : mio_name (6, omp_declare_simd_clauses);
4446 11 : mio_typespec (&ts);
4447 11 : if (clauses->simdlen_divisor)
4448 : {
4449 7 : mio_name (7, omp_declare_simd_clauses);
4450 7 : mio_expr (&clauses->simdlen_divisor);
4451 : }
4452 : }
4453 : }
4454 : else
4455 : {
4456 62 : if (peek_atom () != ATOM_NAME)
4457 0 : return;
4458 :
4459 62 : require_atom (ATOM_NAME);
4460 62 : gfc_omp_namelist **ptrs[3] = { NULL, NULL, NULL };
4461 62 : gfc_omp_clauses *clauses = *clausesp = gfc_get_omp_clauses ();
4462 62 : ptrs[0] = &clauses->lists[OMP_LIST_UNIFORM];
4463 62 : ptrs[1] = &clauses->lists[OMP_LIST_LINEAR];
4464 62 : ptrs[2] = &clauses->lists[OMP_LIST_ALIGNED];
4465 :
4466 251 : while (peek_atom () == ATOM_NAME)
4467 : {
4468 127 : gfc_omp_namelist *n;
4469 127 : int t = mio_name (0, omp_declare_simd_clauses);
4470 :
4471 127 : switch (t)
4472 : {
4473 0 : case 0: clauses->inbranch = true; break;
4474 10 : case 1: clauses->notinbranch = true; break;
4475 27 : case 2: mio_expr (&clauses->simdlen_expr); break;
4476 77 : case 3:
4477 77 : case 4:
4478 77 : case 5:
4479 77 : *ptrs[t - 3] = n = gfc_get_omp_namelist ();
4480 80 : finish_namelist:
4481 80 : n->where = gfc_current_locus;
4482 80 : ptrs[t - 3] = &n->next;
4483 80 : mio_symbol_ref (&n->sym);
4484 80 : if (t != 3)
4485 32 : mio_expr (&n->expr);
4486 : break;
4487 6 : case 6:
4488 6 : {
4489 6 : gfc_typespec ts = {};
4490 6 : mio_typespec (&ts);
4491 6 : clauses->simdlen_type.type = ts.type;
4492 6 : clauses->simdlen_type.kind = ts.kind;
4493 6 : break;
4494 : }
4495 4 : case 7: mio_expr (&clauses->simdlen_divisor); break;
4496 3 : case 33:
4497 3 : case 34:
4498 3 : case 35:
4499 3 : *ptrs[1] = n = gfc_get_omp_namelist ();
4500 3 : n->u.linear.op = (enum gfc_omp_linear_op) (t - 32);
4501 3 : t = 4;
4502 3 : goto finish_namelist;
4503 : }
4504 : }
4505 : }
4506 : }
4507 :
4508 :
4509 : /* Handle !$omp declare simd. */
4510 :
4511 : static void
4512 273285 : mio_omp_declare_simd (gfc_namespace *ns, gfc_omp_declare_simd **odsp)
4513 : {
4514 273285 : if (iomode == IO_OUTPUT)
4515 : {
4516 30572 : if (*odsp == NULL)
4517 : {
4518 30480 : if (ns->omp_declare_variant)
4519 : {
4520 100 : mio_lparen ();
4521 100 : mio_rparen ();
4522 : }
4523 : return;
4524 : }
4525 : }
4526 242713 : else if (peek_atom () != ATOM_LPAREN)
4527 : return;
4528 :
4529 183 : gfc_omp_declare_simd *ods = *odsp;
4530 :
4531 183 : mio_lparen ();
4532 183 : if (iomode == IO_OUTPUT)
4533 : {
4534 92 : if (ods->clauses)
4535 92 : mio_omp_declare_simd_clauses (&ods->clauses);
4536 : }
4537 : else
4538 : {
4539 91 : if (peek_atom () == ATOM_RPAREN)
4540 : {
4541 37 : mio_rparen ();
4542 37 : return;
4543 : }
4544 :
4545 54 : *odsp = ods = gfc_get_omp_declare_simd ();
4546 54 : ods->where = gfc_current_locus;
4547 54 : ods->proc_name = ns->proc_name;
4548 54 : mio_omp_declare_simd_clauses (&ods->clauses);
4549 : }
4550 :
4551 146 : mio_omp_declare_simd (ns, &ods->next);
4552 :
4553 146 : mio_rparen ();
4554 : }
4555 :
4556 : /* Handle !$omp declare variant. */
4557 :
4558 : static void
4559 294038 : mio_omp_declare_variant (gfc_namespace *ns, gfc_omp_declare_variant **odvp)
4560 : {
4561 294038 : if (iomode == IO_OUTPUT)
4562 : {
4563 51328 : if (*odvp == NULL)
4564 : return;
4565 : }
4566 242710 : else if (peek_atom () != ATOM_LPAREN)
4567 : return;
4568 :
4569 173 : gfc_omp_declare_variant *odv;
4570 :
4571 173 : mio_lparen ();
4572 173 : if (iomode == IO_OUTPUT)
4573 : {
4574 125 : odv = *odvp;
4575 125 : write_atom (ATOM_NAME, "OMP_DECLARE_VARIANT");
4576 125 : gfc_symtree *st;
4577 250 : st = (odv->base_proc_symtree
4578 125 : ? odv->base_proc_symtree
4579 116 : : gfc_find_symtree (ns->sym_root, ns->proc_name->name));
4580 125 : mio_symtree_ref (&st);
4581 250 : st = (st->n.sym->attr.if_source == IFSRC_IFBODY
4582 31 : && st->n.sym->formal_ns == ns
4583 126 : ? gfc_find_symtree (ns->parent->sym_root,
4584 30 : odv->variant_proc_symtree->name)
4585 : : odv->variant_proc_symtree);
4586 125 : mio_symtree_ref (&st);
4587 :
4588 125 : mio_lparen ();
4589 125 : write_atom (ATOM_NAME, "SEL");
4590 269 : for (gfc_omp_set_selector *set = odv->set_selectors; set; set = set->next)
4591 : {
4592 144 : int set_code = set->code;
4593 144 : mio_integer (&set_code);
4594 144 : mio_lparen ();
4595 330 : for (gfc_omp_selector *sel = set->trait_selectors; sel;
4596 186 : sel = sel->next)
4597 : {
4598 186 : int sel_code = sel->code;
4599 186 : mio_integer (&sel_code);
4600 186 : mio_expr (&sel->score);
4601 186 : mio_lparen ();
4602 250 : for (gfc_omp_trait_property *prop = sel->properties; prop;
4603 64 : prop = prop->next)
4604 : {
4605 64 : int kind = prop->property_kind;
4606 64 : mio_integer (&kind);
4607 64 : int is_name = prop->is_name;
4608 64 : mio_integer (&is_name);
4609 64 : switch (prop->property_kind)
4610 : {
4611 11 : case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
4612 11 : case OMP_TRAIT_PROPERTY_BOOL_EXPR:
4613 11 : mio_expr (&prop->expr);
4614 11 : break;
4615 3 : case OMP_TRAIT_PROPERTY_ID:
4616 3 : write_atom (ATOM_STRING, prop->name);
4617 3 : break;
4618 28 : case OMP_TRAIT_PROPERTY_NAME_LIST:
4619 28 : if (prop->is_name)
4620 25 : write_atom (ATOM_STRING, prop->name);
4621 : else
4622 3 : mio_expr (&prop->expr);
4623 : break;
4624 22 : case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
4625 22 : {
4626 : /* Currently only declare simd. */
4627 22 : mio_lparen ();
4628 22 : mio_omp_declare_simd_clauses (&prop->clauses);
4629 22 : mio_rparen ();
4630 : }
4631 22 : break;
4632 0 : default:
4633 0 : gcc_unreachable ();
4634 : }
4635 : }
4636 186 : mio_rparen ();
4637 : }
4638 144 : mio_rparen ();
4639 : }
4640 125 : mio_rparen ();
4641 :
4642 125 : mio_lparen ();
4643 125 : write_atom (ATOM_NAME, "ADJ");
4644 233 : for (gfc_omp_namelist *arg = odv->adjust_args_list; arg; arg = arg->next)
4645 : {
4646 108 : int need_ptr = arg->u.adj_args.need_ptr;
4647 108 : int need_addr = arg->u.adj_args.need_addr;
4648 108 : int range_start = arg->u.adj_args.range_start;
4649 108 : int omp_num_args_plus = arg->u.adj_args.omp_num_args_plus;
4650 108 : int omp_num_args_minus = arg->u.adj_args.omp_num_args_minus;
4651 108 : mio_integer (&need_ptr);
4652 108 : mio_integer (&need_addr);
4653 108 : mio_integer (&range_start);
4654 108 : mio_integer (&omp_num_args_plus);
4655 108 : mio_integer (&omp_num_args_minus);
4656 108 : mio_expr (&arg->expr);
4657 : }
4658 125 : mio_rparen ();
4659 :
4660 125 : mio_lparen ();
4661 125 : write_atom (ATOM_NAME, "APP");
4662 163 : for (gfc_omp_namelist *arg = odv->append_args_list; arg; arg = arg->next)
4663 : {
4664 38 : int target = arg->u.init.target;
4665 38 : int targetsync = arg->u.init.targetsync;
4666 38 : mio_integer (&target);
4667 38 : mio_integer (&targetsync);
4668 38 : mio_integer (&arg->u.init.len);
4669 38 : gfc_char_t *p = XALLOCAVEC (gfc_char_t, arg->u.init.len);
4670 409 : for (int i = 0; i < arg->u.init.len; i++)
4671 371 : p[i] = arg->u2.init_interop[i];
4672 38 : mio_allocated_wide_string (p, arg->u.init.len);
4673 : }
4674 125 : mio_rparen ();
4675 : }
4676 : else
4677 : {
4678 48 : if (peek_atom () == ATOM_RPAREN)
4679 : {
4680 0 : mio_rparen ();
4681 0 : return;
4682 : }
4683 :
4684 48 : require_atom (ATOM_NAME);
4685 48 : odv = *odvp = gfc_get_omp_declare_variant ();
4686 48 : odv->where = gfc_current_locus;
4687 :
4688 48 : mio_symtree_ref (&odv->base_proc_symtree);
4689 48 : mio_symtree_ref (&odv->variant_proc_symtree);
4690 :
4691 48 : mio_lparen ();
4692 48 : require_atom (ATOM_NAME); /* SEL */
4693 48 : gfc_omp_set_selector **set = &odv->set_selectors;
4694 98 : while (peek_atom () != ATOM_RPAREN)
4695 : {
4696 50 : *set = gfc_get_omp_set_selector ();
4697 50 : int set_code;
4698 50 : mio_integer (&set_code);
4699 50 : (*set)->code = (enum omp_tss_code) set_code;
4700 :
4701 50 : mio_lparen ();
4702 50 : gfc_omp_selector **sel = &(*set)->trait_selectors;
4703 104 : while (peek_atom () != ATOM_RPAREN)
4704 : {
4705 54 : *sel = gfc_get_omp_selector ();
4706 54 : int sel_code = 0;
4707 54 : mio_integer (&sel_code);
4708 54 : (*sel)->code = (enum omp_ts_code) sel_code;
4709 54 : mio_expr (&(*sel)->score);
4710 :
4711 54 : mio_lparen ();
4712 54 : gfc_omp_trait_property **prop = &(*sel)->properties;
4713 65 : while (peek_atom () != ATOM_RPAREN)
4714 : {
4715 11 : *prop = gfc_get_omp_trait_property ();
4716 11 : int kind = 0, is_name = 0;
4717 11 : mio_integer (&kind);
4718 11 : mio_integer (&is_name);
4719 11 : (*prop)->property_kind = (enum omp_tp_type) kind;
4720 11 : (*prop)->is_name = is_name;
4721 11 : switch ((*prop)->property_kind)
4722 : {
4723 0 : case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
4724 0 : case OMP_TRAIT_PROPERTY_BOOL_EXPR:
4725 0 : mio_expr (&(*prop)->expr);
4726 0 : break;
4727 0 : case OMP_TRAIT_PROPERTY_ID:
4728 0 : (*prop)->name = read_string ();
4729 0 : break;
4730 3 : case OMP_TRAIT_PROPERTY_NAME_LIST:
4731 3 : if ((*prop)->is_name)
4732 2 : (*prop)->name = read_string ();
4733 : else
4734 1 : mio_expr (&(*prop)->expr);
4735 : break;
4736 8 : case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
4737 8 : {
4738 : /* Currently only declare simd. */
4739 8 : mio_lparen ();
4740 8 : mio_omp_declare_simd_clauses (&(*prop)->clauses);
4741 8 : mio_rparen ();
4742 : }
4743 8 : break;
4744 0 : default:
4745 0 : gcc_unreachable ();
4746 : }
4747 11 : prop = &(*prop)->next;
4748 : }
4749 54 : mio_rparen ();
4750 54 : sel = &(*sel)->next;
4751 : }
4752 50 : mio_rparen ();
4753 50 : set = &(*set)->next;
4754 : }
4755 48 : mio_rparen ();
4756 :
4757 48 : mio_lparen ();
4758 48 : require_atom (ATOM_NAME); /* ADJ */
4759 48 : gfc_omp_namelist **nl = &odv->adjust_args_list;
4760 130 : while (peek_atom () != ATOM_RPAREN)
4761 : {
4762 82 : *nl = gfc_get_omp_namelist ();
4763 82 : (*nl)->where = gfc_current_locus;
4764 82 : int need_ptr, need_addr, range_start;
4765 82 : int omp_num_args_plus, omp_num_args_minus;
4766 82 : mio_integer (&need_ptr);
4767 82 : mio_integer (&need_addr);
4768 82 : mio_integer (&range_start);
4769 82 : mio_integer (&omp_num_args_plus);
4770 82 : mio_integer (&omp_num_args_minus);
4771 82 : (*nl)->u.adj_args.need_ptr = need_ptr;
4772 82 : (*nl)->u.adj_args.need_addr = need_addr;
4773 82 : (*nl)->u.adj_args.range_start = range_start;
4774 82 : (*nl)->u.adj_args.omp_num_args_plus = omp_num_args_minus;
4775 82 : (*nl)->u.adj_args.omp_num_args_plus = omp_num_args_minus;
4776 82 : mio_expr (&(*nl)->expr);
4777 82 : nl = &(*nl)->next;
4778 : }
4779 48 : mio_rparen ();
4780 :
4781 48 : mio_lparen ();
4782 48 : require_atom (ATOM_NAME); /* APP */
4783 48 : nl = &odv->append_args_list;
4784 66 : while (peek_atom () != ATOM_RPAREN)
4785 : {
4786 18 : *nl = gfc_get_omp_namelist ();
4787 18 : (*nl)->where = gfc_current_locus;
4788 18 : int target, targetsync;
4789 18 : mio_integer (&target);
4790 18 : mio_integer (&targetsync);
4791 18 : mio_integer (&(*nl)->u.init.len);
4792 18 : (*nl)->u.init.target = target;
4793 18 : (*nl)->u.init.targetsync = targetsync;
4794 18 : const gfc_char_t *p = XALLOCAVEC (gfc_char_t, (*nl)->u.init.len); // FIXME: memory handling?
4795 18 : (*nl)->u2.init_interop = XCNEWVEC (char, (*nl)->u.init.len);
4796 18 : p = mio_allocated_wide_string (NULL, (*nl)->u.init.len);
4797 119 : for (int i = 0; i < (*nl)->u.init.len; i++)
4798 83 : (*nl)->u2.init_interop[i] = p[i];
4799 18 : nl = &(*nl)->next;
4800 : }
4801 48 : mio_rparen ();
4802 : }
4803 :
4804 173 : mio_omp_declare_variant (ns, &odv->next);
4805 :
4806 173 : mio_rparen ();
4807 : }
4808 :
4809 : static const mstring omp_declare_reduction_stmt[] =
4810 : {
4811 : minit ("ASSIGN", 0),
4812 : minit ("CALL", 1),
4813 : minit (NULL, -1)
4814 : };
4815 :
4816 :
4817 : static void
4818 293 : mio_omp_udr_expr (gfc_omp_udr *udr, gfc_symbol **sym1, gfc_symbol **sym2,
4819 : gfc_namespace *ns, bool is_initializer)
4820 : {
4821 293 : if (iomode == IO_OUTPUT)
4822 : {
4823 144 : if ((*sym1)->module == NULL)
4824 : {
4825 108 : (*sym1)->module = module_name;
4826 108 : (*sym2)->module = module_name;
4827 : }
4828 144 : mio_symbol_ref (sym1);
4829 144 : mio_symbol_ref (sym2);
4830 144 : if (ns->code->op == EXEC_ASSIGN)
4831 : {
4832 90 : mio_name (0, omp_declare_reduction_stmt);
4833 90 : mio_expr (&ns->code->expr1);
4834 90 : mio_expr (&ns->code->expr2);
4835 : }
4836 : else
4837 : {
4838 54 : int flag;
4839 54 : mio_name (1, omp_declare_reduction_stmt);
4840 54 : mio_symtree_ref (&ns->code->symtree);
4841 54 : mio_actual_arglist (&ns->code->ext.actual, false);
4842 :
4843 54 : flag = ns->code->resolved_isym != NULL;
4844 54 : mio_integer (&flag);
4845 54 : if (flag)
4846 0 : write_atom (ATOM_STRING, ns->code->resolved_isym->name);
4847 : else
4848 54 : mio_symbol_ref (&ns->code->resolved_sym);
4849 : }
4850 : }
4851 : else
4852 : {
4853 149 : pointer_info *p1 = mio_symbol_ref (sym1);
4854 149 : pointer_info *p2 = mio_symbol_ref (sym2);
4855 149 : gfc_symbol *sym;
4856 149 : gcc_assert (p1->u.rsym.ns == p2->u.rsym.ns);
4857 149 : gcc_assert (p1->u.rsym.sym == NULL);
4858 : /* Add hidden symbols to the symtree. */
4859 149 : pointer_info *q = get_integer (p1->u.rsym.ns);
4860 149 : q->u.pointer = (void *) ns;
4861 231 : sym = gfc_new_symbol (is_initializer ? "omp_priv" : "omp_out", ns);
4862 149 : sym->ts = udr->ts;
4863 149 : sym->module = gfc_get_string ("%s", p1->u.rsym.module);
4864 149 : associate_integer_pointer (p1, sym);
4865 149 : sym->attr.omp_udr_artificial_var = 1;
4866 149 : gcc_assert (p2->u.rsym.sym == NULL);
4867 231 : sym = gfc_new_symbol (is_initializer ? "omp_orig" : "omp_in", ns);
4868 149 : sym->ts = udr->ts;
4869 149 : sym->module = gfc_get_string ("%s", p2->u.rsym.module);
4870 149 : associate_integer_pointer (p2, sym);
4871 149 : sym->attr.omp_udr_artificial_var = 1;
4872 149 : if (mio_name (0, omp_declare_reduction_stmt) == 0)
4873 : {
4874 95 : ns->code = gfc_get_code (EXEC_ASSIGN);
4875 95 : mio_expr (&ns->code->expr1);
4876 95 : mio_expr (&ns->code->expr2);
4877 : }
4878 : else
4879 : {
4880 54 : int flag;
4881 54 : ns->code = gfc_get_code (EXEC_CALL);
4882 54 : mio_symtree_ref (&ns->code->symtree);
4883 54 : mio_actual_arglist (&ns->code->ext.actual, false);
4884 :
4885 54 : mio_integer (&flag);
4886 54 : if (flag)
4887 : {
4888 0 : require_atom (ATOM_STRING);
4889 0 : ns->code->resolved_isym = gfc_find_subroutine (atom_string);
4890 0 : free (atom_string);
4891 : }
4892 : else
4893 54 : mio_symbol_ref (&ns->code->resolved_sym);
4894 : }
4895 149 : ns->code->loc = gfc_current_locus;
4896 149 : ns->omp_udr_ns = 1;
4897 : }
4898 293 : }
4899 :
4900 :
4901 : /* Unlike most other routines, the address of the symbol node is already
4902 : fixed on input and the name/module has already been filled in.
4903 : If you update the symbol format here, don't forget to update read_module
4904 : as well (look for "seek to the symbol's component list"). */
4905 :
4906 : static void
4907 1347035 : mio_symbol (gfc_symbol *sym)
4908 : {
4909 1347035 : int intmod = INTMOD_NONE;
4910 :
4911 1347035 : mio_lparen ();
4912 :
4913 1347035 : mio_symbol_attribute (&sym->attr);
4914 :
4915 1347035 : if (sym->attr.pdt_type)
4916 908 : sym->name = gfc_dt_upper_string (sym->name);
4917 :
4918 : /* Note that components are always saved, even if they are supposed
4919 : to be private. Component access is checked during searching. */
4920 1347035 : mio_component_list (&sym->components, sym->attr.vtype);
4921 1347035 : if (sym->components != NULL)
4922 79288 : sym->component_access
4923 79288 : = MIO_NAME (gfc_access) (sym->component_access, access_types);
4924 :
4925 1347035 : mio_typespec (&sym->ts);
4926 1347035 : if (sym->ts.type == BT_CLASS)
4927 15831 : sym->attr.class_ok = 1;
4928 :
4929 1347035 : if (iomode == IO_OUTPUT)
4930 255411 : mio_namespace_ref (&sym->formal_ns);
4931 : else
4932 : {
4933 1091624 : mio_namespace_ref (&sym->formal_ns);
4934 1091624 : if (sym->formal_ns)
4935 242659 : sym->formal_ns->proc_name = sym;
4936 : }
4937 :
4938 : /* Save/restore common block links. */
4939 1347035 : mio_symbol_ref (&sym->common_next);
4940 :
4941 1347035 : mio_formal_arglist (&sym->formal);
4942 :
4943 1347035 : if (sym->attr.flavor == FL_PARAMETER)
4944 264634 : mio_expr (&sym->value);
4945 :
4946 1347035 : mio_array_spec (&sym->as);
4947 :
4948 1347035 : mio_symbol_ref (&sym->result);
4949 :
4950 1347035 : if (sym->attr.cray_pointee)
4951 26 : mio_symbol_ref (&sym->cp_pointer);
4952 :
4953 : /* Load/save the f2k_derived namespace of a derived-type symbol. */
4954 1347035 : mio_full_f2k_derived (sym);
4955 :
4956 : /* PDT types store the symbol specification list here. */
4957 1347035 : mio_actual_arglist (&sym->param_list, true);
4958 :
4959 1347035 : mio_namelist (sym);
4960 :
4961 : /* Add the fields that say whether this is from an intrinsic module,
4962 : and if so, what symbol it is within the module. */
4963 : /* mio_integer (&(sym->from_intmod)); */
4964 1347035 : if (iomode == IO_OUTPUT)
4965 : {
4966 255411 : intmod = sym->from_intmod;
4967 255411 : mio_integer (&intmod);
4968 : }
4969 : else
4970 : {
4971 1091624 : mio_integer (&intmod);
4972 1091624 : if (current_intmod)
4973 317189 : sym->from_intmod = current_intmod;
4974 : else
4975 774435 : sym->from_intmod = (intmod_id) intmod;
4976 : }
4977 :
4978 1347035 : mio_integer (&(sym->intmod_sym_id));
4979 :
4980 1347035 : if (gfc_fl_struct (sym->attr.flavor))
4981 82727 : mio_integer (&(sym->hash_value));
4982 :
4983 1347035 : if (sym->formal_ns
4984 273892 : && sym->formal_ns->proc_name == sym
4985 273139 : && sym->formal_ns->entries == NULL)
4986 : {
4987 273139 : mio_omp_declare_simd (sym->formal_ns, &sym->formal_ns->omp_declare_simd);
4988 273139 : mio_omp_declare_variant (sym->formal_ns,
4989 273139 : &sym->formal_ns->omp_declare_variant);
4990 : }
4991 224931 : else if ((iomode == IO_OUTPUT && sym->ns->proc_name == sym)
4992 1278104 : || (iomode == IO_INPUT && peek_atom () == ATOM_LPAREN))
4993 20726 : mio_omp_declare_variant (sym->ns, &sym->ns->omp_declare_variant);
4994 :
4995 1347035 : mio_rparen ();
4996 1347035 : }
4997 :
4998 :
4999 : /************************* Top level subroutines *************************/
5000 :
5001 : /* A recursive function to look for a specific symbol by name and by
5002 : module. Whilst several symtrees might point to one symbol, its
5003 : is sufficient for the purposes here than one exist. Note that
5004 : generic interfaces are distinguished as are symbols that have been
5005 : renamed in another module. */
5006 : static gfc_symtree *
5007 49779714 : find_symbol (gfc_symtree *st, const char *name,
5008 : const char *module, int generic)
5009 : {
5010 99022099 : int c;
5011 99022099 : gfc_symtree *retval, *s;
5012 :
5013 99022099 : if (st == NULL || st->n.sym == NULL)
5014 : return NULL;
5015 :
5016 49244798 : c = strcmp (name, st->n.sym->name);
5017 100505 : if (c == 0 && st->n.sym->module
5018 100499 : && strcmp (module, st->n.sym->module) == 0
5019 49288014 : && !check_unique_name (st->name))
5020 : {
5021 43132 : s = gfc_find_symtree (gfc_current_ns->sym_root, name);
5022 :
5023 : /* Detect symbols that are renamed by use association in another
5024 : module by the absence of a symtree and null attr.use_rename,
5025 : since the latter is not transmitted in the module file. */
5026 43132 : if (((!generic && !st->n.sym->attr.generic)
5027 34357 : || (generic && st->n.sym->attr.generic))
5028 8815 : && !(s == NULL && !st->n.sym->attr.use_rename))
5029 : return st;
5030 : }
5031 :
5032 49244204 : retval = find_symbol (st->left, name, module, generic);
5033 :
5034 49244204 : if (retval == NULL)
5035 49242385 : retval = find_symbol (st->right, name, module, generic);
5036 :
5037 : return retval;
5038 : }
5039 :
5040 :
5041 : /* Skip a list between balanced left and right parens.
5042 : By setting NEST_LEVEL one assumes that a number of NEST_LEVEL opening parens
5043 : have been already parsed by hand, and the remaining of the content is to be
5044 : skipped here. The default value is 0 (balanced parens). */
5045 :
5046 : static void
5047 1450037 : skip_list (int nest_level = 0)
5048 : {
5049 1450037 : int level;
5050 :
5051 1450037 : level = nest_level;
5052 68398420 : do
5053 : {
5054 68398420 : switch (parse_atom ())
5055 : {
5056 16922049 : case ATOM_LPAREN:
5057 16922049 : level++;
5058 16922049 : break;
5059 :
5060 16939391 : case ATOM_RPAREN:
5061 16939391 : level--;
5062 16939391 : break;
5063 :
5064 751180 : case ATOM_STRING:
5065 751180 : free (atom_string);
5066 751180 : break;
5067 :
5068 : case ATOM_NAME:
5069 : case ATOM_INTEGER:
5070 : break;
5071 : }
5072 : }
5073 68398420 : while (level > 0);
5074 1450037 : }
5075 :
5076 :
5077 : /* Load operator interfaces from the module. Interfaces are unusual
5078 : in that they attach themselves to existing symbols. */
5079 :
5080 : static void
5081 14142 : load_operator_interfaces (void)
5082 : {
5083 14142 : const char *p;
5084 : /* "module" must be large enough for the case of submodules in which the name
5085 : has the form module.submodule */
5086 14142 : char name[GFC_MAX_SYMBOL_LEN + 1], module[2 * GFC_MAX_SYMBOL_LEN + 2];
5087 14142 : gfc_user_op *uop;
5088 14142 : pointer_info *pi = NULL;
5089 14142 : int n, i;
5090 :
5091 14142 : mio_lparen ();
5092 :
5093 28448 : while (peek_atom () != ATOM_RPAREN)
5094 : {
5095 164 : mio_lparen ();
5096 :
5097 164 : mio_internal_string (name);
5098 164 : mio_internal_string (module);
5099 :
5100 164 : n = number_use_names (name, true);
5101 164 : n = n ? n : 1;
5102 :
5103 346 : for (i = 1; i <= n; i++)
5104 : {
5105 : /* Decide if we need to load this one or not. */
5106 182 : p = find_use_name_n (name, &i, true);
5107 :
5108 182 : if (p == NULL)
5109 : {
5110 14 : while (parse_atom () != ATOM_RPAREN);
5111 7 : continue;
5112 : }
5113 :
5114 175 : if (i == 1)
5115 : {
5116 157 : uop = gfc_get_uop (p);
5117 157 : pi = mio_interface_rest (&uop->op);
5118 : }
5119 : else
5120 : {
5121 18 : if (gfc_find_uop (p, NULL))
5122 6 : continue;
5123 12 : uop = gfc_get_uop (p);
5124 12 : uop->op = gfc_get_interface ();
5125 12 : uop->op->where = gfc_current_locus;
5126 12 : add_fixup (pi->integer, &uop->op->sym);
5127 : }
5128 : }
5129 : }
5130 :
5131 14142 : mio_rparen ();
5132 14142 : }
5133 :
5134 :
5135 : /* Load interfaces from the module. Interfaces are unusual in that
5136 : they attach themselves to existing symbols. */
5137 :
5138 : static void
5139 14142 : load_generic_interfaces (void)
5140 : {
5141 14142 : const char *p;
5142 : /* "module" must be large enough for the case of submodules in which the name
5143 : has the form module.submodule */
5144 14142 : char name[GFC_MAX_SYMBOL_LEN + 1], module[2 * GFC_MAX_SYMBOL_LEN + 2];
5145 14142 : gfc_symbol *sym;
5146 14142 : gfc_interface *generic = NULL, *gen = NULL;
5147 14142 : int n, i, renamed;
5148 14142 : bool ambiguous_set = false;
5149 :
5150 14142 : mio_lparen ();
5151 :
5152 90539 : while (peek_atom () != ATOM_RPAREN)
5153 : {
5154 62255 : mio_lparen ();
5155 :
5156 62255 : mio_internal_string (name);
5157 62255 : mio_internal_string (module);
5158 :
5159 62255 : n = number_use_names (name, false);
5160 62255 : renamed = n ? 1 : 0;
5161 61442 : n = n ? n : 1;
5162 :
5163 124514 : for (i = 1; i <= n; i++)
5164 : {
5165 62259 : gfc_symtree *st;
5166 : /* Decide if we need to load this one or not. */
5167 62259 : p = find_use_name_n (name, &i, false);
5168 :
5169 62259 : if (!p || gfc_find_symbol (p, NULL, 0, &sym))
5170 : {
5171 : /* Skip the specific names for these cases. */
5172 9787 : while (i == 1 && parse_atom () != ATOM_RPAREN);
5173 :
5174 1828 : continue;
5175 : }
5176 :
5177 60431 : st = find_symbol (gfc_current_ns->sym_root,
5178 : name, module_name, 1);
5179 :
5180 : /* If the symbol exists already and is being USEd without being
5181 : in an ONLY clause, do not load a new symtree(11.3.2). */
5182 60431 : if (!only_flag && st)
5183 44 : sym = st->n.sym;
5184 :
5185 60431 : if (!sym)
5186 : {
5187 28961 : if (st)
5188 : {
5189 1 : sym = st->n.sym;
5190 1 : if (strcmp (st->name, p) != 0)
5191 : {
5192 1 : st = gfc_new_symtree (&gfc_current_ns->sym_root, p);
5193 1 : st->n.sym = sym;
5194 1 : sym->refs++;
5195 : }
5196 : }
5197 :
5198 : /* Since we haven't found a valid generic interface, we had
5199 : better make one. */
5200 28961 : if (!sym)
5201 : {
5202 28960 : gfc_get_symbol (p, NULL, &sym);
5203 28960 : sym->name = gfc_get_string ("%s", name);
5204 28960 : sym->module = module_name;
5205 28960 : sym->attr.flavor = FL_PROCEDURE;
5206 28960 : sym->attr.generic = 1;
5207 28960 : sym->attr.use_assoc = 1;
5208 : }
5209 : }
5210 : else
5211 : {
5212 : /* Unless sym is a generic interface, this reference
5213 : is ambiguous. */
5214 31470 : if (st == NULL)
5215 31425 : st = gfc_find_symtree (gfc_current_ns->sym_root, p);
5216 :
5217 31470 : sym = st->n.sym;
5218 :
5219 31470 : if (st && !sym->attr.generic
5220 29097 : && !st->ambiguous
5221 29097 : && sym->module
5222 29096 : && strcmp (module, sym->module))
5223 : {
5224 1 : ambiguous_set = true;
5225 1 : st->ambiguous = 1;
5226 : }
5227 : }
5228 :
5229 60431 : sym->attr.use_only = only_flag;
5230 60431 : sym->attr.use_rename = renamed;
5231 :
5232 60431 : if (i == 1)
5233 : {
5234 60427 : mio_interface_rest (&sym->generic);
5235 60427 : generic = sym->generic;
5236 : }
5237 4 : else if (!sym->generic)
5238 : {
5239 0 : sym->generic = generic;
5240 0 : sym->attr.generic_copy = 1;
5241 : }
5242 :
5243 : /* If a procedure that is not generic has generic interfaces
5244 : that include itself, it is generic! We need to take care
5245 : to retain symbols ambiguous that were already so. */
5246 60431 : if (sym->attr.use_assoc
5247 31335 : && !sym->attr.generic
5248 2 : && sym->attr.flavor == FL_PROCEDURE)
5249 : {
5250 4 : for (gen = generic; gen; gen = gen->next)
5251 : {
5252 3 : if (gen->sym == sym)
5253 : {
5254 1 : sym->attr.generic = 1;
5255 1 : if (ambiguous_set)
5256 0 : st->ambiguous = 0;
5257 : break;
5258 : }
5259 : }
5260 : }
5261 :
5262 : }
5263 : }
5264 :
5265 14142 : mio_rparen ();
5266 14142 : }
5267 :
5268 :
5269 : /* Load common blocks. */
5270 :
5271 : static void
5272 14142 : load_commons (void)
5273 : {
5274 14142 : char name[GFC_MAX_SYMBOL_LEN + 1];
5275 14142 : gfc_common_head *p;
5276 :
5277 14142 : mio_lparen ();
5278 :
5279 28454 : while (peek_atom () != ATOM_RPAREN)
5280 : {
5281 170 : int flags = 0;
5282 170 : char* label;
5283 170 : mio_lparen ();
5284 170 : mio_internal_string (name);
5285 :
5286 170 : p = gfc_get_common (name, 1);
5287 :
5288 170 : mio_symbol_ref (&p->head);
5289 170 : mio_integer (&flags);
5290 170 : if (flags & 1)
5291 0 : p->saved = 1;
5292 170 : if (flags & 2)
5293 0 : p->threadprivate = 1;
5294 170 : p->omp_device_type = (gfc_omp_device_type) ((flags >> 2) & 3);
5295 170 : if ((flags >> 4) & 1)
5296 0 : p->omp_groupprivate = 1;
5297 170 : p->use_assoc = 1;
5298 :
5299 : /* Get whether this was a bind(c) common or not. */
5300 170 : mio_integer (&p->is_bind_c);
5301 : /* Get the binding label. */
5302 170 : label = read_string ();
5303 170 : if (strlen (label))
5304 22 : p->binding_label = IDENTIFIER_POINTER (get_identifier (label));
5305 170 : XDELETEVEC (label);
5306 :
5307 170 : mio_rparen ();
5308 : }
5309 :
5310 14142 : mio_rparen ();
5311 14142 : }
5312 :
5313 :
5314 : /* Load equivalences. The flag in_load_equiv informs mio_expr_ref of this
5315 : so that unused variables are not loaded and so that the expression can
5316 : be safely freed. */
5317 :
5318 : static void
5319 14142 : load_equiv (void)
5320 : {
5321 14142 : gfc_equiv *head, *tail, *end, *eq, *equiv;
5322 14142 : bool duplicate;
5323 :
5324 14142 : mio_lparen ();
5325 14142 : in_load_equiv = true;
5326 :
5327 14142 : end = gfc_current_ns->equiv;
5328 14148 : while (end != NULL && end->next != NULL)
5329 : end = end->next;
5330 :
5331 14275 : while (peek_atom () != ATOM_RPAREN) {
5332 133 : mio_lparen ();
5333 133 : head = tail = NULL;
5334 :
5335 532 : while(peek_atom () != ATOM_RPAREN)
5336 : {
5337 266 : if (head == NULL)
5338 133 : head = tail = gfc_get_equiv ();
5339 : else
5340 : {
5341 133 : tail->eq = gfc_get_equiv ();
5342 133 : tail = tail->eq;
5343 : }
5344 :
5345 266 : mio_pool_string (&tail->module);
5346 266 : mio_expr (&tail->expr);
5347 : }
5348 :
5349 : /* Check for duplicate equivalences being loaded from different modules */
5350 133 : duplicate = false;
5351 192 : for (equiv = gfc_current_ns->equiv; equiv; equiv = equiv->next)
5352 : {
5353 65 : if (equiv->module && head->module
5354 65 : && strcmp (equiv->module, head->module) == 0)
5355 : {
5356 : duplicate = true;
5357 : break;
5358 : }
5359 : }
5360 :
5361 133 : if (duplicate)
5362 : {
5363 18 : for (eq = head; eq; eq = head)
5364 : {
5365 12 : head = eq->eq;
5366 12 : gfc_free_expr (eq->expr);
5367 12 : free (eq);
5368 : }
5369 : }
5370 :
5371 133 : if (end == NULL)
5372 80 : gfc_current_ns->equiv = head;
5373 : else
5374 53 : end->next = head;
5375 :
5376 133 : if (head != NULL)
5377 127 : end = head;
5378 :
5379 133 : mio_rparen ();
5380 : }
5381 :
5382 14142 : mio_rparen ();
5383 14142 : in_load_equiv = false;
5384 14142 : }
5385 :
5386 :
5387 : /* This function loads OpenMP user defined reductions. */
5388 : static void
5389 14142 : load_omp_udrs (void)
5390 : {
5391 14142 : mio_lparen ();
5392 28372 : while (peek_atom () != ATOM_RPAREN)
5393 : {
5394 88 : const char *name = NULL, *newname;
5395 88 : char *altname;
5396 88 : gfc_typespec ts;
5397 88 : gfc_symtree *st;
5398 88 : gfc_omp_reduction_op rop = OMP_REDUCTION_USER;
5399 :
5400 88 : mio_lparen ();
5401 88 : mio_pool_string (&name);
5402 88 : gfc_clear_ts (&ts);
5403 88 : mio_typespec (&ts);
5404 88 : if (startswith (name, "operator "))
5405 : {
5406 38 : const char *p = name + sizeof ("operator ") - 1;
5407 38 : if (strcmp (p, "+") == 0)
5408 : rop = OMP_REDUCTION_PLUS;
5409 0 : else if (strcmp (p, "*") == 0)
5410 : rop = OMP_REDUCTION_TIMES;
5411 0 : else if (strcmp (p, "-") == 0)
5412 : rop = OMP_REDUCTION_MINUS;
5413 0 : else if (strcmp (p, ".and.") == 0)
5414 : rop = OMP_REDUCTION_AND;
5415 0 : else if (strcmp (p, ".or.") == 0)
5416 : rop = OMP_REDUCTION_OR;
5417 0 : else if (strcmp (p, ".eqv.") == 0)
5418 : rop = OMP_REDUCTION_EQV;
5419 0 : else if (strcmp (p, ".neqv.") == 0)
5420 : rop = OMP_REDUCTION_NEQV;
5421 : }
5422 50 : altname = NULL;
5423 50 : if (rop == OMP_REDUCTION_USER && name[0] == '.')
5424 : {
5425 50 : size_t len = strlen (name + 1);
5426 50 : altname = XALLOCAVEC (char, len);
5427 50 : gcc_assert (name[len] == '.');
5428 50 : memcpy (altname, name + 1, len - 1);
5429 50 : altname[len - 1] = '\0';
5430 : }
5431 88 : newname = name;
5432 88 : if (rop == OMP_REDUCTION_USER)
5433 100 : newname = find_use_name (altname ? altname : name, !!altname);
5434 44 : else if (only_flag && find_use_operator ((gfc_intrinsic_op) rop) == NULL)
5435 : newname = NULL;
5436 88 : if (newname == NULL)
5437 : {
5438 0 : skip_list (1);
5439 6 : continue;
5440 : }
5441 88 : if (altname && newname != altname)
5442 : {
5443 18 : size_t len = strlen (newname);
5444 18 : altname = XALLOCAVEC (char, len + 3);
5445 18 : altname[0] = '.';
5446 18 : memcpy (altname + 1, newname, len);
5447 18 : altname[len + 1] = '.';
5448 18 : altname[len + 2] = '\0';
5449 18 : name = gfc_get_string ("%s", altname);
5450 : }
5451 88 : st = gfc_find_symtree (gfc_current_ns->omp_udr_root, name);
5452 88 : gfc_omp_udr *udr = gfc_omp_udr_find (st, &ts);
5453 88 : if (udr)
5454 : {
5455 6 : require_atom (ATOM_INTEGER);
5456 6 : pointer_info *p = get_integer (atom_int);
5457 6 : if (strcmp (p->u.rsym.module, udr->omp_out->module))
5458 : {
5459 6 : gcc_assert (!gfc_buffered_p ()); /* Cf. PR80012 comment 15. */
5460 6 : auto_diagnostic_group d;
5461 6 : gfc_error ("Ambiguous !$OMP DECLARE REDUCTION %qs for type %qs "
5462 : "from module %qs at %L", udr->name,
5463 : gfc_typename (&ts), module_name, &gfc_current_locus);
5464 6 : inform (gfc_get_location (&udr->where),
5465 : "Previous !$OMP DECLARE REDUCTION from module %qs",
5466 6 : udr->omp_out->module);
5467 6 : }
5468 6 : skip_list (1);
5469 6 : continue;
5470 6 : }
5471 82 : udr = gfc_get_omp_udr ();
5472 82 : udr->name = name;
5473 82 : udr->rop = rop;
5474 82 : udr->ts = ts;
5475 82 : udr->where = gfc_current_locus;
5476 82 : udr->combiner_ns = gfc_get_namespace (gfc_current_ns, 1);
5477 82 : udr->combiner_ns->proc_name = gfc_current_ns->proc_name;
5478 82 : mio_omp_udr_expr (udr, &udr->omp_out, &udr->omp_in, udr->combiner_ns,
5479 : false);
5480 82 : if (peek_atom () != ATOM_RPAREN)
5481 : {
5482 67 : udr->initializer_ns = gfc_get_namespace (gfc_current_ns, 1);
5483 67 : udr->initializer_ns->proc_name = gfc_current_ns->proc_name;
5484 67 : mio_omp_udr_expr (udr, &udr->omp_priv, &udr->omp_orig,
5485 : udr->initializer_ns, true);
5486 : }
5487 82 : if (st)
5488 : {
5489 1 : udr->next = st->n.omp_udr;
5490 1 : st->n.omp_udr = udr;
5491 : }
5492 : else
5493 : {
5494 81 : st = gfc_new_symtree (&gfc_current_ns->omp_udr_root, name);
5495 81 : st->n.omp_udr = udr;
5496 : }
5497 82 : mio_rparen ();
5498 : }
5499 14142 : mio_rparen ();
5500 14142 : }
5501 :
5502 :
5503 : /* In declare mapper, not all map types are permitted; hence, only
5504 : a subset is needed. */
5505 :
5506 : static const mstring omp_map_clause_ops[] =
5507 : {
5508 : minit ("ALLOC", OMP_MAP_ALLOC),
5509 : minit ("TO", OMP_MAP_TO),
5510 : minit ("FROM", OMP_MAP_FROM),
5511 : minit ("TOFROM", OMP_MAP_TOFROM),
5512 : minit ("ALWAYS_TO", OMP_MAP_ALWAYS_TO),
5513 : minit ("ALWAYS_FROM", OMP_MAP_ALWAYS_FROM),
5514 : minit ("ALWAYS_TOFROM", OMP_MAP_ALWAYS_TOFROM),
5515 : minit ("UNSET", OMP_MAP_UNSET),
5516 : minit (NULL, -1)
5517 : };
5518 :
5519 : /* This function loads OpenMP user-defined mappers. */
5520 :
5521 : static void
5522 8 : load_omp_udms (void)
5523 : {
5524 17 : while (peek_atom () != ATOM_RPAREN)
5525 : {
5526 9 : const char *mapper_id = NULL;
5527 9 : gfc_symtree *st;
5528 :
5529 9 : mio_lparen ();
5530 9 : gfc_omp_udm *udm = gfc_get_omp_udm ();
5531 :
5532 9 : require_atom (ATOM_INTEGER);
5533 9 : pointer_info *udmpi = get_integer (atom_int);
5534 9 : associate_integer_pointer (udmpi, udm);
5535 :
5536 9 : mio_pool_string (&mapper_id);
5537 :
5538 : /* Note: for a derived-type typespec, we might not have loaded the
5539 : "u.derived" symbol yet. Defer checking duplicates until
5540 : check_omp_declare_mappers is called after loading all symbols. */
5541 9 : mio_typespec (&udm->ts);
5542 :
5543 9 : if (mapper_id == NULL)
5544 8 : mapper_id = gfc_get_string ("%s", "");
5545 :
5546 9 : st = gfc_find_symtree (gfc_current_ns->omp_udm_root, mapper_id);
5547 :
5548 9 : pointer_info *p = mio_symbol_ref (&udm->var_sym);
5549 9 : pointer_info *q = get_integer (p->u.rsym.ns);
5550 :
5551 9 : udm->where = gfc_current_locus;
5552 9 : udm->mapper_id = mapper_id;
5553 9 : udm->mapper_ns = gfc_get_namespace (gfc_current_ns, 1);
5554 9 : udm->mapper_ns->proc_name = gfc_current_ns->proc_name;
5555 9 : udm->mapper_ns->omp_udm_ns = 1;
5556 :
5557 9 : associate_integer_pointer (q, udm->mapper_ns);
5558 :
5559 9 : gfc_omp_namelist *clauses = NULL;
5560 9 : gfc_omp_namelist **clausep = &clauses;
5561 :
5562 9 : mio_lparen ();
5563 35 : while (peek_atom () != ATOM_RPAREN)
5564 : {
5565 : /* Read each map clause. */
5566 17 : gfc_omp_namelist *n = gfc_get_omp_namelist ();
5567 :
5568 17 : mio_lparen ();
5569 :
5570 17 : n->u.map.op = (gfc_omp_map_op) mio_name (0, omp_map_clause_ops);
5571 17 : mio_symbol_ref (&n->sym);
5572 17 : mio_expr (&n->expr);
5573 :
5574 17 : mio_lparen ();
5575 :
5576 17 : if (peek_atom () != ATOM_RPAREN)
5577 : {
5578 7 : n->u3.udm = gfc_get_omp_namelist_udm ();
5579 7 : mio_pool_string (&n->u3.udm->requested_mapper_id);
5580 :
5581 7 : if (n->u3.udm->requested_mapper_id == NULL)
5582 7 : n->u3.udm->requested_mapper_id = gfc_get_string ("%s", "");
5583 :
5584 7 : mio_pointer_ref (&n->u3.udm->resolved_udm);
5585 : }
5586 :
5587 17 : mio_rparen ();
5588 :
5589 17 : n->where = gfc_current_locus;
5590 :
5591 17 : mio_rparen ();
5592 :
5593 17 : *clausep = n;
5594 17 : clausep = &n->next;
5595 : }
5596 9 : mio_rparen ();
5597 :
5598 9 : udm->clauses = gfc_get_omp_clauses ();
5599 9 : udm->clauses->lists[OMP_LIST_MAP] = clauses;
5600 :
5601 9 : if (st)
5602 : {
5603 3 : udm->next = st->n.omp_udm;
5604 3 : st->n.omp_udm = udm;
5605 : }
5606 : else
5607 : {
5608 6 : st = gfc_new_symtree (&gfc_current_ns->omp_udm_root, mapper_id);
5609 6 : st->n.omp_udm = udm;
5610 : }
5611 :
5612 9 : mio_rparen ();
5613 : }
5614 8 : }
5615 :
5616 :
5617 : /* Recursive function to traverse the pointer_info tree and load a
5618 : needed symbol. We return nonzero if we load a symbol and stop the
5619 : traversal, because the act of loading can alter the tree. */
5620 :
5621 : static int
5622 10283848 : load_needed (pointer_info *p)
5623 : {
5624 10283848 : gfc_namespace *ns;
5625 10283848 : pointer_info *q;
5626 10283848 : gfc_symbol *sym;
5627 10283848 : int rv;
5628 :
5629 10283848 : rv = 0;
5630 10283848 : if (p == NULL)
5631 : return rv;
5632 :
5633 5122070 : rv |= load_needed (p->left);
5634 5122070 : rv |= load_needed (p->right);
5635 :
5636 5122070 : if (p->type != P_SYMBOL || p->u.rsym.state != NEEDED)
5637 : return rv;
5638 :
5639 1091624 : p->u.rsym.state = USED;
5640 :
5641 1091624 : set_module_locus (&p->u.rsym.where);
5642 :
5643 1091624 : sym = p->u.rsym.sym;
5644 1091624 : if (sym == NULL)
5645 : {
5646 644724 : q = get_integer (p->u.rsym.ns);
5647 :
5648 644724 : ns = (gfc_namespace *) q->u.pointer;
5649 644724 : if (ns == NULL)
5650 : {
5651 : /* Create an interface namespace if necessary. These are
5652 : the namespaces that hold the formal parameters of module
5653 : procedures. */
5654 :
5655 22859 : ns = gfc_get_namespace (NULL, 0);
5656 22859 : associate_integer_pointer (q, ns);
5657 : }
5658 :
5659 : /* Use the module sym as 'proc_name' so that gfc_get_symbol_decl
5660 : doesn't go pear-shaped if the symbol is used. */
5661 644724 : if (!ns->proc_name)
5662 31658 : gfc_find_symbol (p->u.rsym.module, gfc_current_ns,
5663 : 1, &ns->proc_name);
5664 :
5665 644724 : sym = gfc_new_symbol (p->u.rsym.true_name, ns);
5666 644724 : sym->name = gfc_dt_lower_string (p->u.rsym.true_name);
5667 644724 : sym->module = gfc_get_string ("%s", p->u.rsym.module);
5668 644724 : if (p->u.rsym.binding_label)
5669 21 : sym->binding_label = IDENTIFIER_POINTER (get_identifier
5670 : (p->u.rsym.binding_label));
5671 :
5672 644724 : associate_integer_pointer (p, sym);
5673 : }
5674 :
5675 1091624 : mio_symbol (sym);
5676 1091624 : sym->attr.use_assoc = 1;
5677 :
5678 : /* Unliked derived types, a STRUCTURE may share names with other symbols.
5679 : We greedily converted the symbol name to lowercase before we knew its
5680 : type, so now we must fix it. */
5681 1091624 : if (sym->attr.flavor == FL_STRUCT)
5682 60 : sym->name = gfc_dt_upper_string (sym->name);
5683 :
5684 : /* Mark as only or rename for later diagnosis for explicitly imported
5685 : but not used warnings; don't mark internal symbols such as __vtab,
5686 : __def_init etc. Only mark them if they have been explicitly loaded. */
5687 :
5688 1091624 : if (only_flag
5689 17500 : && sym->name[0] != '\0'
5690 17500 : && !(sym->name[0] == '_' && sym->name[1] == '_'))
5691 : {
5692 13332 : gfc_use_rename *u;
5693 :
5694 : /* Search the use/rename list for the variable; if the variable is
5695 : found, mark it. */
5696 33833 : for (u = gfc_rename_list; u; u = u->next)
5697 : {
5698 23723 : if (strcmp (u->use_name, sym->name) == 0)
5699 : {
5700 3222 : sym->attr.use_only = 1;
5701 3222 : break;
5702 : }
5703 : }
5704 : }
5705 :
5706 1091624 : if (p->u.rsym.renamed)
5707 3558 : sym->attr.use_rename = 1;
5708 :
5709 : return 1;
5710 : }
5711 :
5712 :
5713 : /* Recursive function for cleaning up things after a module has been read. */
5714 :
5715 : static void
5716 3555984 : read_cleanup (pointer_info *p)
5717 : {
5718 3555984 : gfc_symtree *st;
5719 3555984 : pointer_info *q;
5720 :
5721 3555984 : if (p == NULL)
5722 : return;
5723 :
5724 1770921 : read_cleanup (p->left);
5725 1770921 : read_cleanup (p->right);
5726 :
5727 1770921 : if (p->type == P_SYMBOL && p->u.rsym.state == USED
5728 1141588 : && (!p->u.rsym.referenced
5729 448444 : || (p->u.rsym.sym && (p->u.rsym.sym->attr.pdt_kind
5730 448444 : || p->u.rsym.sym->attr.pdt_len))))
5731 : {
5732 693144 : gfc_namespace *ns;
5733 :
5734 : /* Add hidden symbols and PDT parameters to the symtree. */
5735 693144 : q = get_integer (p->u.rsym.ns);
5736 693144 : ns = (gfc_namespace *) q->u.pointer;
5737 :
5738 : /* PDT parameters have no namespace so return. */
5739 693144 : if (ns == NULL)
5740 : {
5741 0 : gcc_assert (p->u.rsym.sym->attr.pdt_kind
5742 : || p->u.rsym.sym->attr.pdt_len);
5743 : return;
5744 : }
5745 :
5746 693144 : if (p->u.rsym.sym->attr.pdt_kind || p->u.rsym.sym->attr.pdt_len
5747 692428 : || p->u.rsym.sym->attr.vtype || p->u.rsym.sym->attr.vtab)
5748 : {
5749 : /* There is no reason to use 'unique_symtrees' for vtabs or
5750 : vtypes - their name is fine for a symtree and reduces the
5751 : namespace pollution. PDT parameters need their source name. */
5752 4346 : st = gfc_find_symtree (ns->sym_root, p->u.rsym.sym->name);
5753 4346 : if (!st)
5754 2628 : st = gfc_new_symtree (&ns->sym_root, p->u.rsym.sym->name);
5755 : }
5756 : else
5757 688798 : st = gfc_get_unique_symtree (ns);
5758 :
5759 693144 : st->n.sym = p->u.rsym.sym;
5760 693144 : st->n.sym->refs++;
5761 :
5762 : /* Fixup any symtree references. */
5763 693144 : p->u.rsym.symtree = st;
5764 693144 : resolve_fixups (p->u.rsym.stfixup, st);
5765 693144 : p->u.rsym.stfixup = NULL;
5766 : }
5767 :
5768 : /* Free unused symbols. */
5769 1770921 : if (p->type == P_SYMBOL && p->u.rsym.state == UNUSED)
5770 156501 : gfc_free_symbol (p->u.rsym.sym);
5771 : }
5772 :
5773 :
5774 : /* Reconstruct PDT parameter namespaces after all needed module symbols have
5775 : been loaded. read_cleanup installs named symtrees for the type-parameter
5776 : symbols first. */
5777 :
5778 : static void
5779 3555984 : fixup_pdt_parameter_namespaces (pointer_info *p)
5780 : {
5781 3555984 : gfc_symbol *sym;
5782 3555984 : gfc_formal_arglist *f, *fp;
5783 3555984 : gfc_namespace *ns;
5784 3555984 : gfc_symbol *super;
5785 :
5786 3555984 : if (p == NULL)
5787 3555486 : return;
5788 :
5789 1770921 : fixup_pdt_parameter_namespaces (p->left);
5790 1770921 : fixup_pdt_parameter_namespaces (p->right);
5791 :
5792 1770921 : if (p->type != P_SYMBOL || p->u.rsym.state != USED)
5793 : return;
5794 :
5795 1141588 : sym = p->u.rsym.sym;
5796 :
5797 : /* Transfer the sym_root of the namespace containing locally-declared PDT
5798 : type-parameter symbols to that the derived type's namespace. */
5799 1141588 : if (sym == NULL
5800 1141588 : || !sym->attr.pdt_template
5801 534 : || sym->f2k_derived == NULL
5802 534 : || sym->f2k_derived->sym_root != NULL)
5803 : return;
5804 :
5805 516 : f = sym->formal;
5806 516 : super = gfc_get_derived_super_type (sym);
5807 516 : if (super && super->attr.pdt_template)
5808 282 : for (fp = super->formal; fp && f; fp = fp->next)
5809 186 : f = f->next;
5810 :
5811 516 : if (f == NULL || f->sym == NULL || f->sym->ns == NULL
5812 498 : || f->sym->ns->sym_root == NULL)
5813 : return;
5814 :
5815 498 : ns = f->sym->ns;
5816 498 : sym->f2k_derived->sym_root = ns->sym_root;
5817 498 : ns->sym_root = NULL;
5818 498 : ns->refs++;
5819 498 : gfc_free_namespace (ns);
5820 : }
5821 :
5822 :
5823 : /* It is not quite enough to check for ambiguity in the symbols by
5824 : the loaded symbol and the new symbol not being identical. */
5825 : static bool
5826 43631 : check_for_ambiguous (gfc_symtree *st, pointer_info *info)
5827 : {
5828 43631 : gfc_symbol *rsym;
5829 43631 : module_locus locus;
5830 43631 : symbol_attribute attr;
5831 43631 : gfc_symbol *st_sym;
5832 :
5833 43631 : if (gfc_current_ns->proc_name && st->name == gfc_current_ns->proc_name->name)
5834 : {
5835 6 : gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
5836 : "current program unit", st->name, module_name);
5837 6 : return true;
5838 : }
5839 :
5840 43625 : st_sym = st->n.sym;
5841 43625 : rsym = info->u.rsym.sym;
5842 43625 : if (st_sym == rsym)
5843 : return false;
5844 :
5845 516 : if (st_sym->attr.vtab || st_sym->attr.vtype)
5846 : return false;
5847 :
5848 : /* If the existing symbol is generic from a different module and
5849 : the new symbol is generic there can be no ambiguity. */
5850 416 : if (st_sym->attr.generic
5851 20 : && st_sym->module
5852 20 : && st_sym->module != module_name)
5853 : {
5854 : /* The new symbol's attributes have not yet been read. Since
5855 : we need attr.generic, read it directly. */
5856 20 : get_module_locus (&locus);
5857 20 : set_module_locus (&info->u.rsym.where);
5858 20 : mio_lparen ();
5859 20 : attr.generic = 0;
5860 20 : mio_symbol_attribute (&attr);
5861 20 : set_module_locus (&locus);
5862 20 : if (attr.generic)
5863 19 : return false;
5864 : }
5865 :
5866 : return true;
5867 : }
5868 :
5869 :
5870 : static void
5871 14160 : check_omp_declare_mappers (gfc_symtree *st)
5872 : {
5873 14160 : if (!st)
5874 14151 : return;
5875 :
5876 9 : check_omp_declare_mappers (st->left);
5877 9 : check_omp_declare_mappers (st->right);
5878 :
5879 9 : gfc_omp_udm **udmp = &st->n.omp_udm;
5880 9 : gfc_symtree tmp_st;
5881 :
5882 21 : while (*udmp)
5883 : {
5884 12 : gfc_omp_udm *udm = *udmp;
5885 12 : tmp_st.n.omp_udm = udm->next;
5886 12 : gfc_omp_udm *prev_udm = gfc_omp_udm_find (&tmp_st, &udm->ts);
5887 12 : if (prev_udm)
5888 : {
5889 2 : gcc_assert (!gfc_buffered_p ()); /* Cf. PR80012 comment 15. */
5890 2 : auto_diagnostic_group d;
5891 2 : gfc_error ("Ambiguous !$OMP DECLARE MAPPER %qs for type %qs from "
5892 : "module %qs at %L",
5893 2 : st->n.omp_udm->mapper_id[0] != '\0'
5894 : ? st->n.omp_udm->mapper_id : "default",
5895 2 : udm->ts.u.derived->name, module_name,
5896 : &udm->where);
5897 2 : inform (gfc_get_location (&prev_udm->where),
5898 : "Previous !$OMP DECLARE MAPPER from module %qs",
5899 2 : prev_udm->var_sym->module);
5900 : /* Delete the duplicate. */
5901 2 : *udmp = (*udmp)->next;
5902 2 : }
5903 : else
5904 10 : udmp = &(*udmp)->next;
5905 : }
5906 : }
5907 :
5908 :
5909 : /* Read a module file. */
5910 :
5911 : static void
5912 14142 : read_module (void)
5913 : {
5914 14142 : module_locus operator_interfaces, user_operators, omp_udrs, omp_udms;
5915 14142 : bool has_omp_udms = false;
5916 14142 : const char *p;
5917 14142 : char name[GFC_MAX_SYMBOL_LEN + 1];
5918 14142 : int i;
5919 : /* Workaround -Wmaybe-uninitialized false positive during
5920 : profiledbootstrap by initializing them. */
5921 14142 : int ambiguous = 0, j, nuse, symbol = 0;
5922 14142 : pointer_info *info, *q;
5923 14142 : gfc_use_rename *u = NULL;
5924 14142 : gfc_symtree *st;
5925 14142 : gfc_symbol *sym;
5926 :
5927 14142 : get_module_locus (&operator_interfaces); /* Skip these for now. */
5928 14142 : skip_list ();
5929 :
5930 14142 : get_module_locus (&user_operators);
5931 14142 : skip_list ();
5932 14142 : skip_list ();
5933 :
5934 : /* Skip commons and equivalences for now. */
5935 14142 : skip_list ();
5936 14142 : skip_list ();
5937 :
5938 : /* Skip OpenMP UDRs. */
5939 14142 : get_module_locus (&omp_udrs);
5940 14142 : skip_list ();
5941 :
5942 : /* Skip OpenMP's user-defined 'declare mapper' (UDM); some extra code is
5943 : required to permit reading files without USM; see write_module for
5944 : details. */
5945 14142 : get_module_locus (&omp_udms);
5946 14142 : if (peek_atom () == ATOM_LPAREN
5947 14142 : && parse_atom ()
5948 14142 : && module_char () == 'U'
5949 8 : && module_char () == 'D'
5950 14150 : && module_char () == 'M')
5951 : has_omp_udms = true;
5952 14142 : set_module_locus (&omp_udms);
5953 14142 : if (has_omp_udms)
5954 8 : skip_list ();
5955 :
5956 14142 : mio_lparen ();
5957 :
5958 : /* Create the fixup nodes for all the symbols. */
5959 :
5960 1326373 : while (peek_atom () != ATOM_RPAREN)
5961 : {
5962 1298089 : char* bind_label;
5963 1298089 : require_atom (ATOM_INTEGER);
5964 1298089 : info = get_integer (atom_int);
5965 :
5966 1298089 : info->type = P_SYMBOL;
5967 1298089 : info->u.rsym.state = UNUSED;
5968 :
5969 1298089 : info->u.rsym.true_name = read_string ();
5970 1298089 : info->u.rsym.module = read_string ();
5971 1298089 : bind_label = read_string ();
5972 1298089 : if (strlen (bind_label))
5973 42708 : info->u.rsym.binding_label = bind_label;
5974 : else
5975 1255381 : XDELETEVEC (bind_label);
5976 :
5977 1298089 : require_atom (ATOM_INTEGER);
5978 1298089 : info->u.rsym.ns = atom_int;
5979 :
5980 1298089 : get_module_locus (&info->u.rsym.where);
5981 :
5982 : /* See if the symbol has already been loaded by a previous module.
5983 : If so, we reference the existing symbol and prevent it from
5984 : being loaded again. This should not happen if the symbol being
5985 : read is an index for an assumed shape dummy array (ns != 1). */
5986 :
5987 1298089 : sym = find_true_name (info->u.rsym.true_name, info->u.rsym.module);
5988 :
5989 1298089 : if (sym == NULL
5990 49989 : || (sym->attr.flavor == FL_VARIABLE && info->u.rsym.ns !=1))
5991 : {
5992 1248125 : skip_list ();
5993 1248125 : continue;
5994 : }
5995 :
5996 49964 : info->u.rsym.state = USED;
5997 49964 : info->u.rsym.sym = sym;
5998 : /* The current symbol has already been loaded, so we can avoid loading
5999 : it again. However, if it is a derived type, some of its components
6000 : can be used in expressions in the module. To avoid the module loading
6001 : failing, we need to associate the module's component pointer indexes
6002 : with the existing symbol's component pointers. */
6003 49964 : if (gfc_fl_struct (sym->attr.flavor))
6004 : {
6005 4844 : gfc_component *c;
6006 :
6007 : /* First seek to the symbol's component list. */
6008 4844 : mio_lparen (); /* symbol opening. */
6009 4844 : skip_list (); /* skip symbol attribute. */
6010 :
6011 4844 : mio_lparen (); /* component list opening. */
6012 17336 : for (c = sym->components; c; c = c->next)
6013 : {
6014 12492 : pointer_info *p;
6015 12492 : const char *comp_name = NULL;
6016 12492 : int n = 0;
6017 :
6018 12492 : mio_lparen (); /* component opening. */
6019 12492 : mio_integer (&n);
6020 12492 : p = get_integer (n);
6021 12492 : if (p->u.pointer == NULL)
6022 12492 : associate_integer_pointer (p, c);
6023 12492 : mio_pool_string (&comp_name);
6024 12492 : if (comp_name != c->name)
6025 : {
6026 0 : gfc_fatal_error ("Mismatch in components of derived type "
6027 : "%qs from %qs at %C: expecting %qs, "
6028 : "but got %qs", sym->name, sym->module,
6029 : c->name, comp_name);
6030 : }
6031 12492 : skip_list (1); /* component end. */
6032 : }
6033 4844 : mio_rparen (); /* component list closing. */
6034 :
6035 4844 : skip_list (1); /* symbol end. */
6036 4844 : }
6037 : else
6038 45120 : skip_list ();
6039 :
6040 : /* Some symbols do not have a namespace (eg. formal arguments),
6041 : so the automatic "unique symtree" mechanism must be suppressed
6042 : by marking them as referenced. */
6043 49964 : q = get_integer (info->u.rsym.ns);
6044 49964 : if (q->u.pointer == NULL)
6045 : {
6046 1718 : info->u.rsym.referenced = 1;
6047 1718 : continue;
6048 : }
6049 : }
6050 :
6051 14142 : mio_rparen ();
6052 :
6053 : /* Parse the symtree lists. This lets us mark which symbols need to
6054 : be loaded. Renaming is also done at this point by replacing the
6055 : symtree name. */
6056 :
6057 14142 : mio_lparen ();
6058 :
6059 571823 : while (peek_atom () != ATOM_RPAREN)
6060 : {
6061 543539 : mio_internal_string (name);
6062 543539 : mio_integer (&ambiguous);
6063 543539 : mio_integer (&symbol);
6064 :
6065 543539 : info = get_integer (symbol);
6066 :
6067 : /* See how many use names there are. If none, go through the start
6068 : of the loop at least once. */
6069 543539 : nuse = number_use_names (name, false);
6070 543539 : info->u.rsym.renamed = nuse ? 1 : 0;
6071 :
6072 539958 : if (nuse == 0)
6073 539958 : nuse = 1;
6074 :
6075 1087113 : for (j = 1; j <= nuse; j++)
6076 : {
6077 : /* Get the jth local name for this symbol. */
6078 543574 : p = find_use_name_n (name, &j, false);
6079 :
6080 543574 : if (p == NULL && strcmp (name, module_name) == 0)
6081 : p = name;
6082 :
6083 : /* Exception: Always import vtabs & vtypes. */
6084 52721 : if (p == NULL && name[0] == '_'
6085 3601 : && (startswith (name, "__vtab_")
6086 2372 : || startswith (name, "__vtype_")))
6087 : p = name;
6088 :
6089 : /* Include pdt_types if their associated pdt_template is in a
6090 : USE, ONLY list. */
6091 50263 : if (p == NULL && name[0] == 'P'
6092 136 : && startswith (name, PDT_PREFIX)
6093 541186 : && module_list)
6094 : {
6095 158 : gfc_use_list *ml = module_list;
6096 158 : for (; ml; ml = ml->next)
6097 88 : if (ml->rename
6098 88 : && !strncmp (&name[PDT_PREFIX_LEN],
6099 : ml->rename->use_name,
6100 88 : strlen (ml->rename->use_name)))
6101 88 : p = name;
6102 : }
6103 :
6104 : /* Skip symtree nodes not in an ONLY clause, unless there
6105 : is an existing symtree loaded from another USE statement. */
6106 543574 : if (p == NULL)
6107 : {
6108 50235 : st = gfc_find_symtree (gfc_current_ns->sym_root, name);
6109 50235 : if (st != NULL
6110 582 : && strcmp (st->n.sym->name, info->u.rsym.true_name) == 0
6111 516 : && st->n.sym->module != NULL
6112 214 : && strcmp (st->n.sym->module, info->u.rsym.module) == 0)
6113 : {
6114 206 : info->u.rsym.symtree = st;
6115 206 : info->u.rsym.sym = st->n.sym;
6116 : }
6117 50235 : continue;
6118 : }
6119 :
6120 : /* If a symbol of the same name and module exists already,
6121 : this symbol, which is not in an ONLY clause, must not be
6122 : added to the namespace(11.3.2). Note that find_symbol
6123 : only returns the first occurrence that it finds. */
6124 486128 : if (!only_flag && !info->u.rsym.renamed
6125 485775 : && strcmp (name, module_name) != 0
6126 968418 : && find_symbol (gfc_current_ns->sym_root, name,
6127 : module_name, 0))
6128 548 : continue;
6129 :
6130 : /* Skip re-importing a derived type already visible via host
6131 : association from the same module. Walk the symtree since
6132 : using gfc_find_symbol can give a wrong error. */
6133 492791 : if (!only_flag && !info->u.rsym.renamed
6134 485227 : && strcmp (name, module_name) != 0
6135 474531 : && gfc_current_ns->parent)
6136 : {
6137 374163 : gfc_symbol *host_sym = NULL;
6138 374163 : for (gfc_namespace *pns = gfc_current_ns; pns; pns = pns->parent)
6139 : {
6140 336122 : gfc_symtree *host_st = gfc_find_symtree (pns->sym_root, name);
6141 336122 : if (host_st)
6142 : {
6143 140048 : host_sym = host_st->n.sym;
6144 140048 : break;
6145 : }
6146 : }
6147 178089 : if (host_sym && host_sym->attr.flavor == FL_DERIVED
6148 4239 : && host_sym->module
6149 3512 : && strcmp (host_sym->module, module_name) == 0)
6150 2470 : continue;
6151 : }
6152 :
6153 490321 : st = gfc_find_symtree (gfc_current_ns->sym_root, p);
6154 :
6155 490321 : if (st != NULL
6156 43667 : && !(st->n.sym && st->n.sym->attr.used_in_submodule))
6157 : {
6158 : /* Check for ambiguous symbols. */
6159 43631 : if (check_for_ambiguous (st, info))
6160 403 : st->ambiguous = 1;
6161 : else
6162 43228 : info->u.rsym.symtree = st;
6163 : }
6164 : else
6165 : {
6166 446690 : if (st)
6167 : {
6168 : /* This symbol is host associated from a module in a
6169 : submodule. Hide it with a unique symtree. */
6170 36 : gfc_symtree *s = gfc_get_unique_symtree (gfc_current_ns);
6171 36 : s->n.sym = st->n.sym;
6172 36 : st->n.sym = NULL;
6173 : }
6174 : else
6175 : {
6176 : /* Create a symtree node in the current namespace for this
6177 : symbol. */
6178 446654 : st = check_unique_name (p)
6179 446654 : ? gfc_get_unique_symtree (gfc_current_ns)
6180 446654 : : gfc_new_symtree (&gfc_current_ns->sym_root, p);
6181 446654 : st->ambiguous = ambiguous;
6182 : }
6183 :
6184 446690 : sym = info->u.rsym.sym;
6185 :
6186 : /* Create a symbol node if it doesn't already exist. */
6187 446690 : if (sym == NULL)
6188 : {
6189 446527 : info->u.rsym.sym = gfc_new_symbol (info->u.rsym.true_name,
6190 : gfc_current_ns);
6191 446527 : info->u.rsym.sym->name = gfc_dt_lower_string (info->u.rsym.true_name);
6192 446527 : sym = info->u.rsym.sym;
6193 446527 : sym->module = gfc_get_string ("%s", info->u.rsym.module);
6194 :
6195 446527 : if (info->u.rsym.binding_label)
6196 : {
6197 31779 : tree id = get_identifier (info->u.rsym.binding_label);
6198 31779 : sym->binding_label = IDENTIFIER_POINTER (id);
6199 : }
6200 : }
6201 :
6202 446690 : st->n.sym = sym;
6203 446690 : st->n.sym->refs++;
6204 :
6205 446690 : if (strcmp (name, p) != 0)
6206 536 : sym->attr.use_rename = 1;
6207 :
6208 446690 : if (name[0] != '_'
6209 446690 : || (!startswith (name, "__vtab_")
6210 30944 : && !startswith (name, "__vtype_")))
6211 417348 : sym->attr.use_only = only_flag;
6212 :
6213 : /* Store the symtree pointing to this symbol. */
6214 446690 : info->u.rsym.symtree = st;
6215 :
6216 446690 : if (info->u.rsym.state == UNUSED)
6217 446527 : info->u.rsym.state = NEEDED;
6218 446690 : info->u.rsym.referenced = 1;
6219 : }
6220 : }
6221 : }
6222 :
6223 14142 : mio_rparen ();
6224 :
6225 : /* Load intrinsic operator interfaces. */
6226 14142 : set_module_locus (&operator_interfaces);
6227 14142 : mio_lparen ();
6228 :
6229 424260 : for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
6230 : {
6231 395976 : gfc_use_rename *u = NULL, *v = NULL;
6232 395976 : int j = i;
6233 :
6234 395976 : if (i == INTRINSIC_USER)
6235 14142 : continue;
6236 :
6237 381834 : if (only_flag)
6238 : {
6239 49896 : u = find_use_operator ((gfc_intrinsic_op) i);
6240 :
6241 : /* F2018:10.1.5.5.1 requires same interpretation of old and new-style
6242 : relational operators. Special handling for USE, ONLY. */
6243 49896 : switch (i)
6244 : {
6245 : case INTRINSIC_EQ:
6246 : j = INTRINSIC_EQ_OS;
6247 : break;
6248 : case INTRINSIC_EQ_OS:
6249 : j = INTRINSIC_EQ;
6250 : break;
6251 : case INTRINSIC_NE:
6252 : j = INTRINSIC_NE_OS;
6253 : break;
6254 : case INTRINSIC_NE_OS:
6255 : j = INTRINSIC_NE;
6256 : break;
6257 : case INTRINSIC_GT:
6258 : j = INTRINSIC_GT_OS;
6259 : break;
6260 : case INTRINSIC_GT_OS:
6261 : j = INTRINSIC_GT;
6262 : break;
6263 : case INTRINSIC_GE:
6264 : j = INTRINSIC_GE_OS;
6265 : break;
6266 : case INTRINSIC_GE_OS:
6267 : j = INTRINSIC_GE;
6268 : break;
6269 : case INTRINSIC_LT:
6270 : j = INTRINSIC_LT_OS;
6271 : break;
6272 : case INTRINSIC_LT_OS:
6273 : j = INTRINSIC_LT;
6274 : break;
6275 : case INTRINSIC_LE:
6276 : j = INTRINSIC_LE_OS;
6277 : break;
6278 : case INTRINSIC_LE_OS:
6279 : j = INTRINSIC_LE;
6280 : break;
6281 : default:
6282 : break;
6283 : }
6284 :
6285 : if (j != i)
6286 22176 : v = find_use_operator ((gfc_intrinsic_op) j);
6287 :
6288 49896 : if (u == NULL && v == NULL)
6289 : {
6290 49746 : skip_list ();
6291 49746 : continue;
6292 : }
6293 :
6294 150 : if (u)
6295 113 : u->found = 1;
6296 150 : if (v)
6297 89 : v->found = 1;
6298 : }
6299 :
6300 332088 : mio_interface (&gfc_current_ns->op[i]);
6301 332088 : if (!gfc_current_ns->op[i] && !gfc_current_ns->op[j])
6302 : {
6303 330382 : if (u)
6304 15 : u->found = 0;
6305 330382 : if (v)
6306 26 : v->found = 0;
6307 : }
6308 : }
6309 :
6310 14142 : mio_rparen ();
6311 :
6312 : /* Load generic and user operator interfaces. These must follow the
6313 : loading of symtree because otherwise symbols can be marked as
6314 : ambiguous. */
6315 :
6316 14142 : set_module_locus (&user_operators);
6317 :
6318 14142 : load_operator_interfaces ();
6319 14142 : load_generic_interfaces ();
6320 :
6321 14142 : load_commons ();
6322 14142 : load_equiv ();
6323 :
6324 : /* Load OpenMP user defined reductions. */
6325 14142 : set_module_locus (&omp_udrs);
6326 14142 : load_omp_udrs ();
6327 :
6328 : /* Load OpenMP user defined mappers. */
6329 14142 : if (has_omp_udms)
6330 : {
6331 8 : set_module_locus (&omp_udms);
6332 8 : mio_lparen ();
6333 : /* Skip 'UDM' marker, cf. above. */
6334 8 : (void) module_char ();
6335 8 : (void) module_char ();
6336 8 : (void) module_char ();
6337 8 : load_omp_udms ();
6338 8 : mio_rparen ();
6339 : }
6340 :
6341 : /* At this point, we read those symbols that are needed but haven't
6342 : been loaded yet. If one symbol requires another, the other gets
6343 : marked as NEEDED if its previous state was UNUSED. */
6344 :
6345 39708 : while (load_needed (pi_root));
6346 :
6347 : /* Make sure all elements of the rename-list were found in the module. */
6348 :
6349 17252 : for (u = gfc_rename_list; u; u = u->next)
6350 : {
6351 3110 : if (u->found)
6352 3102 : continue;
6353 :
6354 8 : if (u->op == INTRINSIC_NONE)
6355 : {
6356 3 : gfc_error ("Symbol %qs referenced at %L not found in module %qs",
6357 3 : u->use_name, &u->where, module_name);
6358 3 : continue;
6359 : }
6360 :
6361 5 : if (u->op == INTRINSIC_USER)
6362 : {
6363 2 : gfc_error ("User operator %qs referenced at %L not found "
6364 2 : "in module %qs", u->use_name, &u->where, module_name);
6365 2 : continue;
6366 : }
6367 :
6368 3 : gfc_error ("Intrinsic operator %qs referenced at %L not found "
6369 : "in module %qs", gfc_op2string (u->op), &u->where,
6370 : module_name);
6371 : }
6372 :
6373 : /* Check "omp declare mappers" for duplicates from different modules. */
6374 14142 : check_omp_declare_mappers (gfc_current_ns->omp_udm_root);
6375 :
6376 : /* Clean up symbol nodes that were never loaded, create references
6377 : to hidden symbols. */
6378 :
6379 14142 : read_cleanup (pi_root);
6380 :
6381 : /* Reconstruct PDT type-parameter namespaces now that inherited
6382 : and local formal parameter lists have been loaded completely. */
6383 14142 : fixup_pdt_parameter_namespaces (pi_root);
6384 14142 : }
6385 :
6386 :
6387 : /* Given an access type that is specific to an entity and the default
6388 : access, return nonzero if the entity is publicly accessible. If the
6389 : element is declared as PUBLIC, then it is public; if declared
6390 : PRIVATE, then private, and otherwise it is public unless the default
6391 : access in this context has been declared PRIVATE. */
6392 :
6393 : static bool dump_smod = false;
6394 :
6395 : static bool
6396 1102496 : check_access (gfc_access specific_access, gfc_access default_access)
6397 : {
6398 1102496 : if (dump_smod)
6399 : return true;
6400 :
6401 1076971 : if (specific_access == ACCESS_PUBLIC)
6402 : return true;
6403 1045446 : if (specific_access == ACCESS_PRIVATE)
6404 : return false;
6405 :
6406 1043097 : if (flag_module_private)
6407 91 : return default_access == ACCESS_PUBLIC;
6408 : else
6409 1043006 : return default_access != ACCESS_PRIVATE;
6410 : }
6411 :
6412 :
6413 : bool
6414 918989 : gfc_check_symbol_access (gfc_symbol *sym)
6415 : {
6416 918989 : if (sym->attr.vtab || sym->attr.vtype)
6417 : return true;
6418 : else
6419 822626 : return check_access (sym->attr.access, sym->ns->default_access);
6420 : }
6421 :
6422 :
6423 : /* A structure to remember which commons we've already written. */
6424 :
6425 : struct written_common
6426 : {
6427 : BBT_HEADER(written_common);
6428 : const char *name, *label;
6429 : };
6430 :
6431 : static struct written_common *written_commons = NULL;
6432 :
6433 : /* Comparison function used for balancing the binary tree. */
6434 :
6435 : static int
6436 127 : compare_written_commons (void *a1, void *b1)
6437 : {
6438 127 : const char *aname = ((struct written_common *) a1)->name;
6439 127 : const char *alabel = ((struct written_common *) a1)->label;
6440 127 : const char *bname = ((struct written_common *) b1)->name;
6441 127 : const char *blabel = ((struct written_common *) b1)->label;
6442 127 : int c = strcmp (aname, bname);
6443 :
6444 127 : return (c != 0 ? c : strcmp (alabel, blabel));
6445 : }
6446 :
6447 : /* Free a list of written commons. */
6448 :
6449 : static void
6450 10427 : free_written_common (struct written_common *w)
6451 : {
6452 10427 : if (!w)
6453 : return;
6454 :
6455 211 : if (w->left)
6456 27 : free_written_common (w->left);
6457 211 : if (w->right)
6458 42 : free_written_common (w->right);
6459 :
6460 211 : free (w);
6461 : }
6462 :
6463 : /* Write a common block to the module -- recursive helper function. */
6464 :
6465 : static void
6466 21186 : write_common_0 (gfc_symtree *st, bool this_module)
6467 : {
6468 21656 : gfc_common_head *p;
6469 21656 : const char * name;
6470 21656 : int flags;
6471 21656 : const char *label;
6472 21656 : struct written_common *w;
6473 21656 : bool write_me = true;
6474 :
6475 21656 : if (st == NULL)
6476 21186 : return;
6477 :
6478 470 : write_common_0 (st->left, this_module);
6479 :
6480 : /* We will write out the binding label, or "" if no label given. */
6481 470 : name = st->n.common->name;
6482 470 : p = st->n.common;
6483 470 : label = (p->is_bind_c && p->binding_label) ? p->binding_label : "";
6484 :
6485 : /* Check if we've already output this common. */
6486 470 : w = written_commons;
6487 988 : while (w)
6488 : {
6489 518 : int c = strcmp (name, w->name);
6490 518 : c = (c != 0 ? c : strcmp (label, w->label));
6491 206 : if (c == 0)
6492 : write_me = false;
6493 :
6494 518 : w = (c < 0) ? w->left : w->right;
6495 : }
6496 :
6497 470 : if (this_module && p->use_assoc)
6498 : write_me = false;
6499 :
6500 417 : if (write_me)
6501 : {
6502 : /* Write the common to the module. */
6503 211 : mio_lparen ();
6504 211 : mio_pool_string (&name);
6505 :
6506 211 : mio_symbol_ref (&p->head);
6507 211 : flags = p->saved ? 1 : 0;
6508 211 : if (p->threadprivate)
6509 0 : flags |= 2;
6510 211 : flags |= p->omp_device_type << 2;
6511 211 : flags |= p->omp_groupprivate << 4;
6512 211 : mio_integer (&flags);
6513 :
6514 : /* Write out whether the common block is bind(c) or not. */
6515 211 : mio_integer (&(p->is_bind_c));
6516 :
6517 211 : mio_pool_string (&label);
6518 211 : mio_rparen ();
6519 :
6520 : /* Record that we have written this common. */
6521 211 : w = XCNEW (struct written_common);
6522 211 : w->name = p->name;
6523 211 : w->label = label;
6524 211 : gfc_insert_bbt (&written_commons, w, compare_written_commons);
6525 : }
6526 :
6527 470 : write_common_0 (st->right, this_module);
6528 : }
6529 :
6530 :
6531 : /* Write a common, by initializing the list of written commons, calling
6532 : the recursive function write_common_0() and cleaning up afterwards. */
6533 :
6534 : static void
6535 10358 : write_common (gfc_symtree *st)
6536 : {
6537 10358 : written_commons = NULL;
6538 10358 : write_common_0 (st, true);
6539 10358 : write_common_0 (st, false);
6540 10358 : free_written_common (written_commons);
6541 10358 : written_commons = NULL;
6542 10358 : }
6543 :
6544 :
6545 : /* Write the blank common block to the module. */
6546 :
6547 : static void
6548 10358 : write_blank_common (void)
6549 : {
6550 10358 : const char * name = BLANK_COMMON_NAME;
6551 10358 : int saved;
6552 : /* TODO: Blank commons are not bind(c). The F2003 standard probably says
6553 : this, but it hasn't been checked. Just making it so for now. */
6554 10358 : int is_bind_c = 0;
6555 :
6556 10358 : if (gfc_current_ns->blank_common.head == NULL)
6557 : return;
6558 :
6559 7 : mio_lparen ();
6560 :
6561 7 : mio_pool_string (&name);
6562 :
6563 7 : mio_symbol_ref (&gfc_current_ns->blank_common.head);
6564 7 : saved = gfc_current_ns->blank_common.saved;
6565 7 : mio_integer (&saved);
6566 :
6567 : /* Write out whether the common block is bind(c) or not. */
6568 7 : mio_integer (&is_bind_c);
6569 :
6570 : /* Write out an empty binding label. */
6571 7 : write_atom (ATOM_STRING, "");
6572 :
6573 7 : mio_rparen ();
6574 : }
6575 :
6576 :
6577 : /* Write equivalences to the module. */
6578 :
6579 : static void
6580 10358 : write_equiv (void)
6581 : {
6582 10358 : gfc_equiv *eq, *e;
6583 10358 : int num;
6584 :
6585 10358 : num = 0;
6586 10440 : for (eq = gfc_current_ns->equiv; eq; eq = eq->next)
6587 : {
6588 82 : mio_lparen ();
6589 :
6590 328 : for (e = eq; e; e = e->eq)
6591 : {
6592 164 : if (e->module == NULL)
6593 142 : e->module = gfc_get_string ("%s.eq.%d", module_name, num);
6594 164 : mio_allocated_string (e->module);
6595 164 : mio_expr (&e->expr);
6596 : }
6597 :
6598 82 : num++;
6599 82 : mio_rparen ();
6600 : }
6601 10358 : }
6602 :
6603 :
6604 : /* Write a symbol to the module. */
6605 :
6606 : static void
6607 255411 : write_symbol (int n, gfc_symbol *sym)
6608 : {
6609 255411 : const char *label;
6610 :
6611 255411 : if (sym->attr.flavor == FL_UNKNOWN || sym->attr.flavor == FL_LABEL)
6612 0 : gfc_internal_error ("write_symbol(): bad module symbol %qs", sym->name);
6613 :
6614 255411 : mio_integer (&n);
6615 :
6616 255411 : if (gfc_fl_struct (sym->attr.flavor))
6617 : {
6618 29106 : const char *name;
6619 29106 : name = gfc_dt_upper_string (sym->name);
6620 29106 : mio_pool_string (&name);
6621 29106 : }
6622 : else
6623 226305 : mio_pool_string (&sym->name);
6624 :
6625 255411 : mio_pool_string (&sym->module);
6626 255411 : if ((sym->attr.is_bind_c || sym->attr.is_iso_c) && sym->binding_label)
6627 : {
6628 3103 : label = sym->binding_label;
6629 3103 : mio_pool_string (&label);
6630 : }
6631 : else
6632 252308 : write_atom (ATOM_STRING, "");
6633 :
6634 255411 : mio_pointer_ref (&sym->ns);
6635 :
6636 255411 : mio_symbol (sym);
6637 255411 : write_char ('\n');
6638 255411 : }
6639 :
6640 :
6641 : /* Recursive traversal function to write the initial set of symbols to
6642 : the module. We check to see if the symbol should be written
6643 : according to the access specification. */
6644 :
6645 : static void
6646 172591 : write_symbol0 (gfc_symtree *st)
6647 : {
6648 334824 : gfc_symbol *sym;
6649 334824 : pointer_info *p;
6650 334824 : bool dont_write = false;
6651 :
6652 334824 : if (st == NULL)
6653 172591 : return;
6654 :
6655 162233 : write_symbol0 (st->left);
6656 :
6657 162233 : sym = st->n.sym;
6658 162233 : if (sym->module == NULL)
6659 74810 : sym->module = module_name;
6660 :
6661 162233 : if (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
6662 12761 : && !sym->attr.subroutine && !sym->attr.function)
6663 162233 : dont_write = true;
6664 :
6665 162233 : if (!gfc_check_symbol_access (sym))
6666 : dont_write = true;
6667 :
6668 143333 : if (!dont_write)
6669 : {
6670 141855 : p = get_pointer (sym);
6671 141855 : if (p->type == P_UNKNOWN)
6672 107934 : p->type = P_SYMBOL;
6673 :
6674 141855 : if (p->u.wsym.state != WRITTEN)
6675 : {
6676 138984 : write_symbol (p->integer, sym);
6677 138984 : p->u.wsym.state = WRITTEN;
6678 : }
6679 : }
6680 :
6681 162233 : write_symbol0 (st->right);
6682 : }
6683 :
6684 :
6685 : static void
6686 107 : write_omp_udr (gfc_omp_udr *udr)
6687 : {
6688 107 : switch (udr->rop)
6689 : {
6690 72 : case OMP_REDUCTION_USER:
6691 : /* Non-operators can't be used outside of the module. */
6692 72 : if (udr->name[0] != '.')
6693 : return;
6694 : else
6695 : {
6696 47 : gfc_symtree *st;
6697 47 : size_t len = strlen (udr->name + 1);
6698 47 : char *name = XALLOCAVEC (char, len);
6699 47 : memcpy (name, udr->name, len - 1);
6700 47 : name[len - 1] = '\0';
6701 47 : st = gfc_find_symtree (gfc_current_ns->uop_root, name);
6702 : /* If corresponding user operator is private, don't write
6703 : the UDR. */
6704 47 : if (st != NULL)
6705 : {
6706 0 : gfc_user_op *uop = st->n.uop;
6707 0 : if (!check_access (uop->access, uop->ns->default_access))
6708 : return;
6709 : }
6710 : }
6711 : break;
6712 35 : case OMP_REDUCTION_PLUS:
6713 35 : case OMP_REDUCTION_MINUS:
6714 35 : case OMP_REDUCTION_TIMES:
6715 35 : case OMP_REDUCTION_AND:
6716 35 : case OMP_REDUCTION_OR:
6717 35 : case OMP_REDUCTION_EQV:
6718 35 : case OMP_REDUCTION_NEQV:
6719 : /* If corresponding operator is private, don't write the UDR. */
6720 35 : if (!check_access (gfc_current_ns->operator_access[udr->rop],
6721 : gfc_current_ns->default_access))
6722 : return;
6723 : break;
6724 : default:
6725 : break;
6726 : }
6727 81 : if (udr->ts.type == BT_DERIVED || udr->ts.type == BT_CLASS)
6728 : {
6729 : /* If derived type is private, don't write the UDR. */
6730 45 : if (!gfc_check_symbol_access (udr->ts.u.derived))
6731 : return;
6732 : }
6733 :
6734 80 : mio_lparen ();
6735 80 : mio_pool_string (&udr->name);
6736 80 : mio_typespec (&udr->ts);
6737 80 : mio_omp_udr_expr (udr, &udr->omp_out, &udr->omp_in, udr->combiner_ns, false);
6738 80 : if (udr->initializer_ns)
6739 64 : mio_omp_udr_expr (udr, &udr->omp_priv, &udr->omp_orig,
6740 : udr->initializer_ns, true);
6741 80 : mio_rparen ();
6742 : }
6743 :
6744 :
6745 : /* Write OpenMP's declare reduction (used defined reductions). */
6746 :
6747 : static void
6748 10465 : write_omp_udrs (gfc_symtree *st)
6749 : {
6750 10572 : if (st == NULL)
6751 10465 : return;
6752 :
6753 107 : write_omp_udrs (st->left);
6754 107 : gfc_omp_udr *udr;
6755 214 : for (udr = st->n.omp_udr; udr; udr = udr->next)
6756 107 : write_omp_udr (udr);
6757 107 : write_omp_udrs (st->right);
6758 : }
6759 :
6760 :
6761 : /* Write OpenMP's declare mapper (used defined mapper). */
6762 :
6763 : static void
6764 16 : write_omp_udm (gfc_omp_udm *udm)
6765 : {
6766 16 : mio_lparen ();
6767 : /* We need this pointer ref to identify this mapper so that other mappers
6768 : can refer to it. */
6769 16 : mio_pointer_ref (&udm);
6770 16 : mio_pool_string (&udm->mapper_id);
6771 16 : mio_typespec (&udm->ts);
6772 :
6773 16 : if (udm->var_sym->module == NULL)
6774 16 : udm->var_sym->module = module_name;
6775 :
6776 16 : mio_symbol_ref (&udm->var_sym);
6777 16 : mio_lparen ();
6778 16 : gfc_omp_namelist *n;
6779 40 : for (n = udm->clauses->lists[OMP_LIST_MAP]; n; n = n->next)
6780 : {
6781 24 : mio_lparen ();
6782 :
6783 24 : mio_name (n->u.map.op, omp_map_clause_ops);
6784 24 : mio_symbol_ref (&n->sym);
6785 24 : mio_expr (&n->expr);
6786 :
6787 24 : mio_lparen ();
6788 :
6789 24 : if (n->u3.udm)
6790 : {
6791 7 : mio_pool_string (&n->u3.udm->requested_mapper_id);
6792 7 : mio_pointer_ref (&n->u3.udm->resolved_udm);
6793 : }
6794 :
6795 24 : mio_rparen ();
6796 :
6797 24 : mio_rparen ();
6798 : }
6799 16 : mio_rparen ();
6800 16 : mio_rparen ();
6801 16 : }
6802 :
6803 :
6804 : static void
6805 26 : write_omp_udms (gfc_symtree *st)
6806 : {
6807 42 : if (st == NULL)
6808 26 : return;
6809 :
6810 16 : write_omp_udms (st->left);
6811 16 : gfc_omp_udm *udm;
6812 32 : for (udm = st->n.omp_udm; udm; udm = udm->next)
6813 16 : write_omp_udm (udm);
6814 16 : write_omp_udms (st->right);
6815 : }
6816 :
6817 :
6818 : /* Type for the temporary tree used when writing secondary symbols. */
6819 :
6820 : struct sorted_pointer_info
6821 : {
6822 : BBT_HEADER (sorted_pointer_info);
6823 :
6824 : pointer_info *p;
6825 : };
6826 :
6827 : #define gfc_get_sorted_pointer_info() XCNEW (sorted_pointer_info)
6828 :
6829 : /* Recursively traverse the temporary tree, free its contents. */
6830 :
6831 : static void
6832 248882 : free_sorted_pointer_info_tree (sorted_pointer_info *p)
6833 : {
6834 248882 : if (!p)
6835 : return;
6836 :
6837 116427 : free_sorted_pointer_info_tree (p->left);
6838 116427 : free_sorted_pointer_info_tree (p->right);
6839 :
6840 116427 : free (p);
6841 : }
6842 :
6843 : /* Comparison function for the temporary tree. */
6844 :
6845 : static int
6846 393799 : compare_sorted_pointer_info (void *_spi1, void *_spi2)
6847 : {
6848 393799 : sorted_pointer_info *spi1, *spi2;
6849 393799 : spi1 = (sorted_pointer_info *)_spi1;
6850 393799 : spi2 = (sorted_pointer_info *)_spi2;
6851 :
6852 393799 : if (spi1->p->integer < spi2->p->integer)
6853 : return -1;
6854 224913 : if (spi1->p->integer > spi2->p->integer)
6855 224913 : return 1;
6856 : return 0;
6857 : }
6858 :
6859 :
6860 : /* Finds the symbols that need to be written and collects them in the
6861 : sorted_pi tree so that they can be traversed in an order
6862 : independent of memory addresses. */
6863 :
6864 : static void
6865 1302504 : find_symbols_to_write(sorted_pointer_info **tree, pointer_info *p)
6866 : {
6867 2578622 : if (!p)
6868 1302504 : return;
6869 :
6870 1276118 : if (p->type == P_SYMBOL && p->u.wsym.state == NEEDS_WRITE)
6871 : {
6872 116427 : sorted_pointer_info *sp = gfc_get_sorted_pointer_info();
6873 116427 : sp->p = p;
6874 :
6875 116427 : gfc_insert_bbt (tree, sp, compare_sorted_pointer_info);
6876 : }
6877 :
6878 1276118 : find_symbols_to_write (tree, p->left);
6879 1276118 : find_symbols_to_write (tree, p->right);
6880 : }
6881 :
6882 :
6883 : /* Recursive function that traverses the tree of symbols that need to be
6884 : written and writes them in order. */
6885 :
6886 : static void
6887 132455 : write_symbol1_recursion (sorted_pointer_info *sp)
6888 : {
6889 248882 : if (!sp)
6890 132455 : return;
6891 :
6892 116427 : write_symbol1_recursion (sp->left);
6893 :
6894 116427 : pointer_info *p1 = sp->p;
6895 116427 : gcc_assert (p1->type == P_SYMBOL && p1->u.wsym.state == NEEDS_WRITE);
6896 :
6897 116427 : p1->u.wsym.state = WRITTEN;
6898 116427 : write_symbol (p1->integer, p1->u.wsym.sym);
6899 116427 : p1->u.wsym.sym->attr.public_used = 1;
6900 :
6901 116427 : write_symbol1_recursion (sp->right);
6902 : }
6903 :
6904 :
6905 : /* Write the secondary set of symbols to the module file. These are
6906 : symbols that were not public yet are needed by the public symbols
6907 : or another dependent symbol. The act of writing a symbol can add
6908 : symbols to the pointer_info tree, so we return nonzero if a symbol
6909 : was written and pass that information upwards. The caller will
6910 : then call this function again until nothing was written. It uses
6911 : the utility functions and a temporary tree to ensure a reproducible
6912 : ordering of the symbol output and thus the module file. */
6913 :
6914 : static int
6915 26386 : write_symbol1 (pointer_info *p)
6916 : {
6917 26386 : if (!p)
6918 : return 0;
6919 :
6920 : /* Put symbols that need to be written into a tree sorted on the
6921 : integer field. */
6922 :
6923 26386 : sorted_pointer_info *spi_root = NULL;
6924 26386 : find_symbols_to_write (&spi_root, p);
6925 :
6926 : /* No symbols to write, return. */
6927 26386 : if (!spi_root)
6928 : return 0;
6929 :
6930 : /* Otherwise, write and free the tree again. */
6931 16028 : write_symbol1_recursion (spi_root);
6932 16028 : free_sorted_pointer_info_tree (spi_root);
6933 :
6934 16028 : return 1;
6935 : }
6936 :
6937 :
6938 : /* Write operator interfaces associated with a symbol. */
6939 :
6940 : static void
6941 169 : write_operator (gfc_user_op *uop)
6942 : {
6943 169 : static char nullstring[] = "";
6944 169 : const char *p = nullstring;
6945 :
6946 169 : if (uop->op == NULL || !check_access (uop->access, uop->ns->default_access))
6947 1 : return;
6948 :
6949 168 : mio_symbol_interface (&uop->name, &p, &uop->op);
6950 : }
6951 :
6952 :
6953 : /* Write generic interfaces from the namespace sym_root. */
6954 :
6955 : static void
6956 172591 : write_generic (gfc_symtree *st)
6957 : {
6958 334824 : gfc_symbol *sym;
6959 :
6960 334824 : if (st == NULL)
6961 172591 : return;
6962 :
6963 162233 : write_generic (st->left);
6964 :
6965 162233 : sym = st->n.sym;
6966 162233 : if (sym && !check_unique_name (st->name)
6967 317037 : && sym->generic && gfc_check_symbol_access (sym))
6968 : {
6969 11713 : if (!sym->module)
6970 7784 : sym->module = module_name;
6971 :
6972 11713 : mio_symbol_interface (&st->name, &sym->module, &sym->generic);
6973 : }
6974 :
6975 162233 : write_generic (st->right);
6976 : }
6977 :
6978 :
6979 : static void
6980 162234 : write_symtree (gfc_symtree *st)
6981 : {
6982 162234 : gfc_symbol *sym;
6983 162234 : pointer_info *p;
6984 :
6985 162234 : sym = st->n.sym;
6986 :
6987 : /* A symbol in an interface body must not be visible in the
6988 : module file. */
6989 162234 : if (sym->ns != gfc_current_ns
6990 450 : && sym->ns->proc_name
6991 450 : && sym->ns->proc_name->attr.if_source == IFSRC_IFBODY)
6992 : return;
6993 :
6994 162234 : if ((!gfc_check_symbol_access (sym)
6995 18900 : && (!sym->attr.public_used || submodule_name == NULL))
6996 162234 : || (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
6997 11853 : && !sym->attr.subroutine && !sym->attr.function))
6998 : return;
6999 :
7000 141855 : if (check_unique_name (st->name))
7001 : return;
7002 :
7003 : /* From F2003 onwards, intrinsic procedures are no longer subject to
7004 : the restriction, "that an elemental intrinsic function here be of
7005 : type integer or character and each argument must be an initialization
7006 : expr of type integer or character" is lifted so that intrinsic
7007 : procedures can be over-ridden. This requires that the intrinsic
7008 : symbol not appear in the module file, thereby preventing ambiguity
7009 : when USEd. */
7010 135399 : if (strcmp (sym->module, "(intrinsic)") == 0
7011 2371 : && (gfc_option.allow_std & GFC_STD_F2003))
7012 : return;
7013 :
7014 133029 : p = find_pointer (sym);
7015 133029 : if (p == NULL)
7016 0 : gfc_internal_error ("write_symtree(): Symbol not written");
7017 :
7018 133029 : mio_pool_string (&st->name);
7019 133029 : mio_integer (&st->ambiguous);
7020 133029 : mio_hwi (&p->integer);
7021 : }
7022 :
7023 :
7024 : static void
7025 10358 : write_module (void)
7026 : {
7027 10358 : int i;
7028 :
7029 : /* Initialize the column counter. */
7030 10358 : module_column = 1;
7031 :
7032 : /* Write the operator interfaces. */
7033 10358 : mio_lparen ();
7034 :
7035 310740 : for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
7036 : {
7037 290024 : if (i == INTRINSIC_USER)
7038 10358 : continue;
7039 :
7040 559332 : mio_interface (check_access (gfc_current_ns->operator_access[i],
7041 : gfc_current_ns->default_access)
7042 : ? &gfc_current_ns->op[i] : NULL);
7043 : }
7044 :
7045 10358 : mio_rparen ();
7046 10358 : write_char ('\n');
7047 10358 : write_char ('\n');
7048 :
7049 10358 : mio_lparen ();
7050 10358 : gfc_traverse_user_op (gfc_current_ns, write_operator);
7051 10358 : mio_rparen ();
7052 10358 : write_char ('\n');
7053 10358 : write_char ('\n');
7054 :
7055 10358 : mio_lparen ();
7056 10358 : write_generic (gfc_current_ns->sym_root);
7057 10358 : mio_rparen ();
7058 10358 : write_char ('\n');
7059 10358 : write_char ('\n');
7060 :
7061 10358 : mio_lparen ();
7062 10358 : write_blank_common ();
7063 10358 : write_common (gfc_current_ns->common_root);
7064 10358 : mio_rparen ();
7065 10358 : write_char ('\n');
7066 10358 : write_char ('\n');
7067 :
7068 10358 : mio_lparen ();
7069 10358 : write_equiv ();
7070 10358 : mio_rparen ();
7071 10358 : write_char ('\n');
7072 10358 : write_char ('\n');
7073 :
7074 10358 : mio_lparen ();
7075 10358 : write_omp_udrs (gfc_current_ns->omp_udr_root);
7076 10358 : mio_rparen ();
7077 10358 : write_char ('\n');
7078 10358 : write_char ('\n');
7079 :
7080 : /* Condition can be removed if version is bumped. Note that
7081 : write_symbol0 starts with an integer. Keep in sync with read_module;
7082 : The 'UDM' tag can be only removed when changing COMPAT_MOD_VERSIONS. */
7083 10358 : STATIC_ASSERT (MOD_VERSION_NUMERIC == 16);
7084 10358 : if (gfc_current_ns->omp_udm_root)
7085 : {
7086 10 : mio_lparen ();
7087 10 : write_atom (ATOM_NAME, "UDM"); /* Marker. */
7088 10 : write_omp_udms (gfc_current_ns->omp_udm_root);
7089 10 : mio_rparen ();
7090 10 : write_char ('\n');
7091 10 : write_char ('\n');
7092 : }
7093 :
7094 : /* Write symbol information. First we traverse all symbols in the
7095 : primary namespace, writing those that need to be written.
7096 : Sometimes writing one symbol will cause another to need to be
7097 : written. A list of these symbols ends up on the write stack, and
7098 : we end by popping the bottom of the stack and writing the symbol
7099 : until the stack is empty. */
7100 :
7101 10358 : mio_lparen ();
7102 :
7103 10358 : write_symbol0 (gfc_current_ns->sym_root);
7104 36744 : while (write_symbol1 (pi_root))
7105 : /* Nothing. */;
7106 :
7107 10358 : mio_rparen ();
7108 :
7109 10358 : write_char ('\n');
7110 10358 : write_char ('\n');
7111 :
7112 10358 : mio_lparen ();
7113 10358 : gfc_traverse_symtree (gfc_current_ns->sym_root, write_symtree);
7114 10358 : mio_rparen ();
7115 10358 : }
7116 :
7117 :
7118 : /* Read a CRC32 sum from the gzip trailer of a module file. Returns
7119 : true on success, false on failure. */
7120 :
7121 : static bool
7122 20716 : read_crc32_from_module_file (const char* filename, uLong* crc)
7123 : {
7124 20716 : FILE *file;
7125 20716 : char buf[4];
7126 20716 : unsigned int val;
7127 :
7128 : /* Open the file in binary mode. */
7129 20716 : if ((file = fopen (filename, "rb")) == NULL)
7130 : return false;
7131 :
7132 : /* The gzip crc32 value is found in the [END-8, END-4] bytes of the
7133 : file. See RFC 1952. */
7134 10575 : if (fseek (file, -8, SEEK_END) != 0)
7135 : {
7136 0 : fclose (file);
7137 0 : return false;
7138 : }
7139 :
7140 : /* Read the CRC32. */
7141 10575 : if (fread (buf, 1, 4, file) != 4)
7142 : {
7143 0 : fclose (file);
7144 0 : return false;
7145 : }
7146 :
7147 : /* Close the file. */
7148 10575 : fclose (file);
7149 :
7150 10575 : val = (buf[0] & 0xFF) + ((buf[1] & 0xFF) << 8) + ((buf[2] & 0xFF) << 16)
7151 10575 : + ((buf[3] & 0xFF) << 24);
7152 10575 : *crc = val;
7153 :
7154 : /* For debugging, the CRC value printed in hexadecimal should match
7155 : the CRC printed by "zcat -l -v filename".
7156 : printf("CRC of file %s is %x\n", filename, val); */
7157 :
7158 10575 : return true;
7159 : }
7160 :
7161 :
7162 : /* Given module, dump it to disk. If there was an error while
7163 : processing the module, dump_flag will be set to zero and we delete
7164 : the module file, even if it was already there. */
7165 :
7166 : static void
7167 10849 : dump_module (const char *name, int dump_flag)
7168 : {
7169 10849 : int n;
7170 10849 : char *filename, *filename_tmp;
7171 10849 : uLong crc, crc_old;
7172 :
7173 10849 : module_name = gfc_get_string ("%s", name);
7174 :
7175 10849 : if (dump_smod)
7176 : {
7177 575 : name = submodule_name;
7178 575 : n = strlen (name) + strlen (SUBMODULE_EXTENSION) + 1;
7179 : }
7180 : else
7181 10274 : n = strlen (name) + strlen (MODULE_EXTENSION) + 1;
7182 :
7183 10849 : if (gfc_option.module_dir != NULL)
7184 : {
7185 0 : n += strlen (gfc_option.module_dir);
7186 0 : filename = (char *) alloca (n);
7187 0 : strcpy (filename, gfc_option.module_dir);
7188 0 : strcat (filename, name);
7189 : }
7190 : else
7191 : {
7192 10849 : filename = (char *) alloca (n);
7193 10849 : strcpy (filename, name);
7194 : }
7195 :
7196 10849 : if (dump_smod)
7197 575 : strcat (filename, SUBMODULE_EXTENSION);
7198 : else
7199 10274 : strcat (filename, MODULE_EXTENSION);
7200 :
7201 : /* Name of the temporary file used to write the module. */
7202 10849 : filename_tmp = (char *) alloca (n + 1);
7203 10849 : strcpy (filename_tmp, filename);
7204 10849 : strcat (filename_tmp, "0");
7205 :
7206 : /* There was an error while processing the module. We delete the
7207 : module file, even if it was already there. */
7208 10849 : if (!dump_flag)
7209 : {
7210 491 : remove (filename);
7211 491 : return;
7212 : }
7213 :
7214 10358 : if (gfc_cpp_makedep ())
7215 0 : gfc_cpp_add_target (filename);
7216 :
7217 : /* Write the module to the temporary file. */
7218 10358 : module_fp = gzopen (filename_tmp, "w");
7219 10358 : if (module_fp == NULL)
7220 0 : gfc_fatal_error ("Cannot open module file %qs for writing at %C: %s",
7221 0 : filename_tmp, xstrerror (errno));
7222 :
7223 : /* Use lbasename to ensure module files are reproducible regardless
7224 : of the build path (see the reproducible builds project). */
7225 10358 : gzprintf (module_fp, "GFORTRAN module version '%s' created from %s\n",
7226 : MOD_VERSION, lbasename (gfc_source_file));
7227 :
7228 : /* Write the module itself. */
7229 10358 : iomode = IO_OUTPUT;
7230 :
7231 10358 : init_pi_tree ();
7232 :
7233 10358 : write_module ();
7234 :
7235 10358 : free_pi_tree (pi_root);
7236 10358 : pi_root = NULL;
7237 :
7238 10358 : write_char ('\n');
7239 :
7240 10358 : if (gzclose (module_fp))
7241 0 : gfc_fatal_error ("Error writing module file %qs for writing: %s",
7242 0 : filename_tmp, xstrerror (errno));
7243 :
7244 : /* Read the CRC32 from the gzip trailers of the module files and
7245 : compare. */
7246 10358 : if (!read_crc32_from_module_file (filename_tmp, &crc)
7247 10358 : || !read_crc32_from_module_file (filename, &crc_old)
7248 10575 : || crc_old != crc)
7249 : {
7250 : /* Module file have changed, replace the old one. */
7251 10146 : if (remove (filename) && errno != ENOENT)
7252 0 : gfc_fatal_error ("Cannot delete module file %qs: %s", filename,
7253 : xstrerror (errno));
7254 10146 : if (rename (filename_tmp, filename))
7255 0 : gfc_fatal_error ("Cannot rename module file %qs to %qs: %s",
7256 0 : filename_tmp, filename, xstrerror (errno));
7257 : }
7258 : else
7259 : {
7260 212 : if (remove (filename_tmp))
7261 0 : gfc_fatal_error ("Cannot delete temporary module file %qs: %s",
7262 0 : filename_tmp, xstrerror (errno));
7263 : }
7264 : }
7265 :
7266 :
7267 : /* Suppress the output of a .smod file by module, if no module
7268 : procedures have been seen. */
7269 : static bool no_module_procedures;
7270 :
7271 : static void
7272 162016 : check_for_module_procedures (gfc_symbol *sym)
7273 : {
7274 162016 : if (sym && sym->attr.module_procedure)
7275 1234 : no_module_procedures = false;
7276 162016 : }
7277 :
7278 :
7279 : void
7280 10544 : gfc_dump_module (const char *name, int dump_flag)
7281 : {
7282 10544 : if (gfc_state_stack->state == COMP_SUBMODULE)
7283 : dump_smod = true;
7284 : else
7285 10274 : dump_smod =false;
7286 :
7287 10544 : no_module_procedures = true;
7288 10544 : gfc_traverse_ns (gfc_current_ns, check_for_module_procedures);
7289 :
7290 10544 : dump_module (name, dump_flag);
7291 :
7292 10544 : if (no_module_procedures || dump_smod)
7293 : return;
7294 :
7295 : /* Write a submodule file from a module. The 'dump_smod' flag switches
7296 : off the check for PRIVATE entities. */
7297 305 : dump_smod = true;
7298 305 : submodule_name = module_name;
7299 305 : dump_module (name, dump_flag);
7300 305 : dump_smod = false;
7301 : }
7302 :
7303 : static void
7304 27023 : create_intrinsic_function (const char *name, int id,
7305 : const char *modname, intmod_id module,
7306 : bool subroutine, gfc_symbol *result_type)
7307 : {
7308 27023 : gfc_intrinsic_sym *isym;
7309 27023 : gfc_symtree *tmp_symtree;
7310 27023 : gfc_symbol *sym;
7311 :
7312 27023 : tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
7313 27023 : if (tmp_symtree)
7314 : {
7315 48 : if (tmp_symtree->n.sym && tmp_symtree->n.sym->module
7316 48 : && strcmp (modname, tmp_symtree->n.sym->module) == 0)
7317 48 : return;
7318 0 : gfc_error ("Symbol %qs at %C already declared", name);
7319 0 : return;
7320 : }
7321 :
7322 26975 : gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
7323 26975 : sym = tmp_symtree->n.sym;
7324 :
7325 26975 : if (subroutine)
7326 : {
7327 9798 : gfc_isym_id isym_id = gfc_isym_id_by_intmod (module, id);
7328 9798 : isym = gfc_intrinsic_subroutine_by_id (isym_id);
7329 9798 : sym->attr.subroutine = 1;
7330 : }
7331 : else
7332 : {
7333 17177 : gfc_isym_id isym_id = gfc_isym_id_by_intmod (module, id);
7334 17177 : isym = gfc_intrinsic_function_by_id (isym_id);
7335 :
7336 17177 : sym->attr.function = 1;
7337 17177 : if (result_type)
7338 : {
7339 6688 : sym->ts.type = BT_DERIVED;
7340 6688 : sym->ts.u.derived = result_type;
7341 6688 : sym->ts.is_c_interop = 1;
7342 6688 : isym->ts.f90_type = BT_VOID;
7343 6688 : isym->ts.type = BT_DERIVED;
7344 6688 : isym->ts.f90_type = BT_VOID;
7345 6688 : isym->ts.u.derived = result_type;
7346 6688 : isym->ts.is_c_interop = 1;
7347 : }
7348 : }
7349 26975 : gcc_assert (isym);
7350 :
7351 26975 : sym->attr.flavor = FL_PROCEDURE;
7352 26975 : sym->attr.intrinsic = 1;
7353 :
7354 26975 : sym->module = gfc_get_string ("%s", modname);
7355 26975 : sym->attr.use_assoc = 1;
7356 26975 : sym->from_intmod = module;
7357 26975 : sym->intmod_sym_id = id;
7358 : }
7359 :
7360 :
7361 : /* Import the intrinsic ISO_C_BINDING module, generating symbols in
7362 : the current namespace for all named constants, pointer types, and
7363 : procedures in the module unless the only clause was used or a rename
7364 : list was provided. */
7365 :
7366 : static void
7367 10233 : import_iso_c_binding_module (void)
7368 : {
7369 10233 : gfc_symbol *mod_sym = NULL, *return_type;
7370 10233 : gfc_symtree *mod_symtree = NULL, *tmp_symtree;
7371 10233 : gfc_symtree *c_ptr = NULL, *c_funptr = NULL;
7372 10233 : const char *iso_c_module_name = "__iso_c_binding";
7373 10233 : gfc_use_rename *u;
7374 10233 : int i;
7375 10233 : bool want_c_ptr = false, want_c_funptr = false;
7376 :
7377 : /* Look only in the current namespace. */
7378 10233 : mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, iso_c_module_name);
7379 :
7380 10233 : if (mod_symtree == NULL)
7381 : {
7382 : /* symtree doesn't already exist in current namespace. */
7383 10158 : gfc_get_sym_tree (iso_c_module_name, gfc_current_ns, &mod_symtree,
7384 : false);
7385 :
7386 10158 : if (mod_symtree != NULL)
7387 10158 : mod_sym = mod_symtree->n.sym;
7388 : else
7389 0 : gfc_internal_error ("import_iso_c_binding_module(): Unable to "
7390 : "create symbol for %s", iso_c_module_name);
7391 :
7392 10158 : mod_sym->attr.flavor = FL_MODULE;
7393 10158 : mod_sym->attr.intrinsic = 1;
7394 10158 : mod_sym->module = gfc_get_string ("%s", iso_c_module_name);
7395 10158 : mod_sym->from_intmod = INTMOD_ISO_C_BINDING;
7396 : }
7397 :
7398 : /* Check whether C_PTR or C_FUNPTR are in the include list, if so, load it;
7399 : check also whether C_NULL_(FUN)PTR or C_(FUN)LOC are requested, which
7400 : need C_(FUN)PTR. */
7401 20791 : for (u = gfc_rename_list; u; u = u->next)
7402 : {
7403 10558 : if (strcmp (c_interop_kinds_table[ISOCBINDING_NULL_PTR].name,
7404 10558 : u->use_name) == 0)
7405 : want_c_ptr = true;
7406 10497 : else if (strcmp (c_interop_kinds_table[ISOCBINDING_LOC].name,
7407 : u->use_name) == 0)
7408 : want_c_ptr = true;
7409 10367 : else if (strcmp (c_interop_kinds_table[ISOCBINDING_NULL_FUNPTR].name,
7410 : u->use_name) == 0)
7411 : want_c_funptr = true;
7412 10358 : else if (strcmp (c_interop_kinds_table[ISOCBINDING_FUNLOC].name,
7413 : u->use_name) == 0)
7414 : want_c_funptr = true;
7415 10322 : else if (strcmp (c_interop_kinds_table[ISOCBINDING_PTR].name,
7416 : u->use_name) == 0)
7417 : {
7418 2268 : c_ptr = generate_isocbinding_symbol (iso_c_module_name,
7419 : (iso_c_binding_symbol)
7420 : ISOCBINDING_PTR,
7421 2268 : u->local_name[0] ? u->local_name
7422 : : u->use_name,
7423 : NULL, false);
7424 : }
7425 8054 : else if (strcmp (c_interop_kinds_table[ISOCBINDING_FUNPTR].name,
7426 : u->use_name) == 0)
7427 : {
7428 107 : c_funptr
7429 107 : = generate_isocbinding_symbol (iso_c_module_name,
7430 : (iso_c_binding_symbol)
7431 : ISOCBINDING_FUNPTR,
7432 107 : u->local_name[0] ? u->local_name
7433 : : u->use_name,
7434 : NULL, false);
7435 : }
7436 : }
7437 :
7438 10233 : if ((want_c_ptr || !only_flag) && !c_ptr)
7439 3304 : c_ptr = generate_isocbinding_symbol (iso_c_module_name,
7440 : (iso_c_binding_symbol)
7441 : ISOCBINDING_PTR,
7442 : NULL, NULL, only_flag);
7443 10233 : if ((want_c_funptr || !only_flag) && !c_funptr)
7444 3268 : c_funptr = generate_isocbinding_symbol (iso_c_module_name,
7445 : (iso_c_binding_symbol)
7446 : ISOCBINDING_FUNPTR,
7447 : NULL, NULL, only_flag);
7448 :
7449 : /* Generate the symbols for the named constants representing
7450 : the kinds for intrinsic data types. */
7451 777708 : for (i = 0; i < ISOCBINDING_NUMBER; i++)
7452 : {
7453 767475 : bool found = false;
7454 1559325 : for (u = gfc_rename_list; u; u = u->next)
7455 791850 : if (strcmp (c_interop_kinds_table[i].name, u->use_name) == 0)
7456 : {
7457 10556 : bool not_in_std;
7458 10556 : const char *name;
7459 10556 : u->found = 1;
7460 10556 : found = true;
7461 :
7462 10556 : switch (i)
7463 : {
7464 : #define NAMED_FUNCTION(a,b,c,d) \
7465 : case a: \
7466 : not_in_std = (gfc_option.allow_std & d) == 0; \
7467 : name = b; \
7468 : break;
7469 : #define NAMED_SUBROUTINE(a,b,c,d) \
7470 : case a: \
7471 : not_in_std = (gfc_option.allow_std & d) == 0; \
7472 : name = b; \
7473 : break;
7474 : #define NAMED_INTCST(a,b,c,d) \
7475 : case a: \
7476 : not_in_std = (gfc_option.allow_std & d) == 0; \
7477 : name = b; \
7478 : break;
7479 : #define NAMED_UINTCST(a,b,c,d) \
7480 : case a: \
7481 : not_in_std = (gfc_option.allow_std & d) == 0; \
7482 : name = b; \
7483 : break;
7484 : #define NAMED_REALCST(a,b,c,d) \
7485 : case a: \
7486 : not_in_std = (gfc_option.allow_std & d) == 0; \
7487 : name = b; \
7488 : break;
7489 : #define NAMED_CMPXCST(a,b,c,d) \
7490 : case a: \
7491 : not_in_std = (gfc_option.allow_std & d) == 0; \
7492 : name = b; \
7493 : break;
7494 : #include "iso-c-binding.def"
7495 : default:
7496 : not_in_std = false;
7497 : name = "";
7498 : }
7499 :
7500 7759 : if (not_in_std)
7501 : {
7502 6 : gfc_error ("The symbol %qs, referenced at %L, is not "
7503 : "in the selected standard", name, &u->where);
7504 6 : continue;
7505 : }
7506 :
7507 10550 : switch (i)
7508 : {
7509 : #define NAMED_FUNCTION(a,b,c,d) \
7510 : case a: \
7511 : if (a == ISOCBINDING_LOC) \
7512 : return_type = c_ptr->n.sym; \
7513 : else if (a == ISOCBINDING_FUNLOC) \
7514 : return_type = c_funptr->n.sym; \
7515 : else \
7516 : return_type = NULL; \
7517 : create_intrinsic_function (u->local_name[0] \
7518 : ? u->local_name : u->use_name, \
7519 : a, iso_c_module_name, \
7520 : INTMOD_ISO_C_BINDING, false, \
7521 : return_type); \
7522 : break;
7523 : #define NAMED_SUBROUTINE(a,b,c,d) \
7524 : case a: \
7525 : create_intrinsic_function (u->local_name[0] ? u->local_name \
7526 : : u->use_name, \
7527 : a, iso_c_module_name, \
7528 : INTMOD_ISO_C_BINDING, true, NULL); \
7529 : break;
7530 : #include "iso-c-binding.def"
7531 :
7532 : case ISOCBINDING_PTR:
7533 : case ISOCBINDING_FUNPTR:
7534 : /* Already handled above. */
7535 : break;
7536 7802 : default:
7537 7802 : if (i == ISOCBINDING_NULL_PTR)
7538 : tmp_symtree = c_ptr;
7539 7741 : else if (i == ISOCBINDING_NULL_FUNPTR)
7540 : tmp_symtree = c_funptr;
7541 : else
7542 7732 : tmp_symtree = NULL;
7543 7802 : generate_isocbinding_symbol (iso_c_module_name,
7544 : (iso_c_binding_symbol) i,
7545 7802 : u->local_name[0]
7546 : ? u->local_name : u->use_name,
7547 : tmp_symtree, false);
7548 : }
7549 : }
7550 :
7551 767475 : if (!found && !only_flag)
7552 : {
7553 : /* Skip, if the symbol is not in the enabled standard. */
7554 244984 : switch (i)
7555 : {
7556 : #define NAMED_FUNCTION(a,b,c,d) \
7557 : case a: \
7558 : if ((gfc_option.allow_std & d) == 0) \
7559 : continue; \
7560 : break;
7561 : #define NAMED_SUBROUTINE(a,b,c,d) \
7562 : case a: \
7563 : if ((gfc_option.allow_std & d) == 0) \
7564 : continue; \
7565 : break;
7566 : #define NAMED_INTCST(a,b,c,d) \
7567 : case a: \
7568 : if ((gfc_option.allow_std & d) == 0) \
7569 : continue; \
7570 : break;
7571 : #define NAMED_UINTCST(a,b,c,d) \
7572 : case a: \
7573 : if ((gfc_option.allow_std & d) == 0) \
7574 : continue; \
7575 : break;
7576 : #define NAMED_REALCST(a,b,c,d) \
7577 : case a: \
7578 : if ((gfc_option.allow_std & d) == 0) \
7579 : continue; \
7580 : break;
7581 : #define NAMED_CMPXCST(a,b,c,d) \
7582 : case a: \
7583 : if ((gfc_option.allow_std & d) == 0) \
7584 : continue; \
7585 : break;
7586 : #include "iso-c-binding.def"
7587 175989 : default:
7588 175989 : ; /* Not GFC_STD_* versioned. */
7589 : }
7590 :
7591 175989 : switch (i)
7592 : {
7593 : #define NAMED_FUNCTION(a,b,c,d) \
7594 : case a: \
7595 : if (a == ISOCBINDING_LOC) \
7596 : return_type = c_ptr->n.sym; \
7597 : else if (a == ISOCBINDING_FUNLOC) \
7598 : return_type = c_funptr->n.sym; \
7599 : else \
7600 : return_type = NULL; \
7601 : create_intrinsic_function (b, a, iso_c_module_name, \
7602 : INTMOD_ISO_C_BINDING, false, \
7603 : return_type); \
7604 : break;
7605 : #define NAMED_SUBROUTINE(a,b,c,d) \
7606 : case a: \
7607 : create_intrinsic_function (b, a, iso_c_module_name, \
7608 : INTMOD_ISO_C_BINDING, true, NULL); \
7609 : break;
7610 : #include "iso-c-binding.def"
7611 :
7612 : case ISOCBINDING_PTR:
7613 : case ISOCBINDING_FUNPTR:
7614 : /* Already handled above. */
7615 : break;
7616 143453 : default:
7617 143453 : if (i == ISOCBINDING_NULL_PTR)
7618 : tmp_symtree = c_ptr;
7619 140186 : else if (i == ISOCBINDING_NULL_FUNPTR)
7620 : tmp_symtree = c_funptr;
7621 : else
7622 136919 : tmp_symtree = NULL;
7623 143453 : generate_isocbinding_symbol (iso_c_module_name,
7624 : (iso_c_binding_symbol) i, NULL,
7625 : tmp_symtree, false);
7626 : }
7627 : }
7628 : }
7629 :
7630 20791 : for (u = gfc_rename_list; u; u = u->next)
7631 : {
7632 10558 : if (u->found)
7633 10556 : continue;
7634 :
7635 2 : gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
7636 2 : "module ISO_C_BINDING", u->use_name, &u->where);
7637 : }
7638 10233 : }
7639 :
7640 :
7641 : /* Add an integer named constant from a given module. */
7642 :
7643 : static void
7644 10102 : create_int_parameter (const char *name, int value, const char *modname,
7645 : intmod_id module, int id)
7646 : {
7647 10102 : gfc_symtree *tmp_symtree;
7648 10102 : gfc_symbol *sym;
7649 :
7650 10102 : tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
7651 10102 : if (tmp_symtree != NULL)
7652 : {
7653 0 : if (strcmp (modname, tmp_symtree->n.sym->module) == 0)
7654 0 : return;
7655 : else
7656 0 : gfc_error ("Symbol %qs already declared", name);
7657 : }
7658 :
7659 10102 : gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
7660 10102 : sym = tmp_symtree->n.sym;
7661 :
7662 10102 : sym->module = gfc_get_string ("%s", modname);
7663 10102 : sym->attr.flavor = FL_PARAMETER;
7664 10102 : sym->ts.type = BT_INTEGER;
7665 10102 : sym->ts.kind = gfc_default_integer_kind;
7666 10102 : sym->value = gfc_get_int_expr (gfc_default_integer_kind, NULL, value);
7667 10102 : sym->attr.use_assoc = 1;
7668 10102 : sym->from_intmod = module;
7669 10102 : sym->intmod_sym_id = id;
7670 : }
7671 :
7672 :
7673 : /* Value is already contained by the array constructor, but not
7674 : yet the shape. */
7675 :
7676 : static void
7677 1320 : create_int_parameter_array (const char *name, int size, gfc_expr *value,
7678 : const char *modname, intmod_id module, int id)
7679 : {
7680 1320 : gfc_symtree *tmp_symtree;
7681 1320 : gfc_symbol *sym;
7682 :
7683 1320 : tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
7684 1320 : if (tmp_symtree != NULL)
7685 : {
7686 1 : if (tmp_symtree->n.sym->module &&
7687 0 : strcmp (modname, tmp_symtree->n.sym->module) == 0)
7688 0 : return;
7689 : else
7690 1 : gfc_error ("Symbol %qs already declared at %L conflicts with "
7691 : "symbol in %qs at %C", name,
7692 : &tmp_symtree->n.sym->declared_at, modname);
7693 : }
7694 :
7695 1320 : gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
7696 1320 : sym = tmp_symtree->n.sym;
7697 :
7698 1320 : sym->module = gfc_get_string ("%s", modname);
7699 1320 : sym->attr.flavor = FL_PARAMETER;
7700 1320 : sym->ts.type = BT_INTEGER;
7701 1320 : sym->ts.kind = gfc_default_integer_kind;
7702 1320 : sym->attr.use_assoc = 1;
7703 1320 : sym->from_intmod = module;
7704 1320 : sym->intmod_sym_id = id;
7705 1320 : sym->attr.dimension = 1;
7706 1320 : sym->as = gfc_get_array_spec ();
7707 1320 : sym->as->rank = 1;
7708 1320 : sym->as->type = AS_EXPLICIT;
7709 1320 : sym->as->lower[0] = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
7710 1320 : sym->as->upper[0] = gfc_get_int_expr (gfc_default_integer_kind, NULL, size);
7711 :
7712 1320 : sym->value = value;
7713 1320 : sym->value->shape = gfc_get_shape (1);
7714 1320 : mpz_init_set_ui (sym->value->shape[0], size);
7715 : }
7716 :
7717 :
7718 : /* Add an derived type for a given module. */
7719 :
7720 : static void
7721 1056 : create_derived_type (const char *name, const char *modname,
7722 : intmod_id module, int id)
7723 : {
7724 1056 : gfc_symtree *tmp_symtree;
7725 1056 : gfc_symbol *sym, *dt_sym;
7726 1056 : gfc_interface *intr, *head;
7727 :
7728 1056 : tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
7729 1056 : if (tmp_symtree != NULL)
7730 : {
7731 0 : if (strcmp (modname, tmp_symtree->n.sym->module) == 0)
7732 0 : return;
7733 : else
7734 0 : gfc_error ("Symbol %qs already declared", name);
7735 : }
7736 :
7737 1056 : gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
7738 1056 : sym = tmp_symtree->n.sym;
7739 1056 : sym->module = gfc_get_string ("%s", modname);
7740 1056 : sym->from_intmod = module;
7741 1056 : sym->intmod_sym_id = id;
7742 1056 : sym->attr.flavor = FL_PROCEDURE;
7743 1056 : sym->attr.function = 1;
7744 1056 : sym->attr.generic = 1;
7745 :
7746 1056 : gfc_get_sym_tree (gfc_dt_upper_string (sym->name),
7747 : gfc_current_ns, &tmp_symtree, false);
7748 1056 : dt_sym = tmp_symtree->n.sym;
7749 1056 : dt_sym->name = gfc_get_string ("%s", sym->name);
7750 1056 : dt_sym->attr.flavor = FL_DERIVED;
7751 1056 : dt_sym->attr.private_comp = 1;
7752 1056 : dt_sym->attr.zero_comp = 1;
7753 1056 : dt_sym->attr.use_assoc = 1;
7754 1056 : dt_sym->module = gfc_get_string ("%s", modname);
7755 1056 : dt_sym->from_intmod = module;
7756 1056 : dt_sym->intmod_sym_id = id;
7757 :
7758 1056 : head = sym->generic;
7759 1056 : intr = gfc_get_interface ();
7760 1056 : intr->sym = dt_sym;
7761 1056 : intr->where = gfc_current_locus;
7762 1056 : intr->next = head;
7763 1056 : sym->generic = intr;
7764 1056 : sym->attr.if_source = IFSRC_DECL;
7765 : }
7766 :
7767 :
7768 : /* Read the contents of the module file into a temporary buffer. */
7769 :
7770 : static void
7771 14142 : read_module_to_tmpbuf ()
7772 : {
7773 : /* We don't know the uncompressed size, so enlarge the buffer as
7774 : needed. */
7775 14142 : int cursz = 4096;
7776 14142 : int rsize = cursz;
7777 14142 : int len = 0;
7778 :
7779 14142 : module_content = XNEWVEC (char, cursz);
7780 :
7781 59322 : while (1)
7782 : {
7783 36732 : int nread = gzread (module_fp, module_content + len, rsize);
7784 36732 : len += nread;
7785 36732 : if (nread < rsize)
7786 : break;
7787 22590 : cursz *= 2;
7788 22590 : module_content = XRESIZEVEC (char, module_content, cursz);
7789 22590 : rsize = cursz - len;
7790 22590 : }
7791 :
7792 14142 : module_content = XRESIZEVEC (char, module_content, len + 1);
7793 14142 : module_content[len] = '\0';
7794 :
7795 14142 : module_pos = 0;
7796 14142 : }
7797 :
7798 :
7799 : /* USE the ISO_FORTRAN_ENV intrinsic module. */
7800 :
7801 : static void
7802 704 : use_iso_fortran_env_module (void)
7803 : {
7804 704 : static char mod[] = "iso_fortran_env";
7805 704 : gfc_use_rename *u;
7806 704 : gfc_symbol *mod_sym;
7807 704 : gfc_symtree *mod_symtree;
7808 704 : gfc_expr *expr;
7809 704 : int i, j;
7810 :
7811 704 : intmod_sym symbol[] = {
7812 : #define NAMED_INTCST(a,b,c,d) { a, b, 0, d },
7813 : #define NAMED_UINTCST(a,b,c,d) { a, b, 0, d },
7814 : #define NAMED_KINDARRAY(a,b,c,d) { a, b, 0, d },
7815 : #define NAMED_DERIVED_TYPE(a,b,c,d) { a, b, 0, d },
7816 : #define NAMED_FUNCTION(a,b,c,d) { a, b, c, d },
7817 : #define NAMED_SUBROUTINE(a,b,c,d) { a, b, c, d },
7818 : #include "iso-fortran-env.def"
7819 : { ISOFORTRANENV_INVALID, NULL, -1234, 0 } };
7820 :
7821 : /* We could have used c in the NAMED_{,U}INTCST macros
7822 : instead of 0, but then current g++ expands the initialization
7823 : as clearing the whole object followed by explicit stores of
7824 : all the non-zero elements (over 150), while by using 0s for
7825 : the non-constant initializers and initializing them afterwards
7826 : g++ will often copy everything from .rodata and then only override
7827 : over 30 non-constant ones. */
7828 704 : i = 0;
7829 : #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c;
7830 : #define NAMED_UINTCST(a,b,c,d) symbol[i++].value = c;
7831 : #define NAMED_KINDARRAY(a,b,c,d) i++;
7832 : #define NAMED_DERIVED_TYPE(a,b,c,d) i++;
7833 : #define NAMED_FUNCTION(a,b,c,d) i++;
7834 : #define NAMED_SUBROUTINE(a,b,c,d) i++;
7835 : #include "iso-fortran-env.def"
7836 704 : gcc_checking_assert (i == (int) ARRAY_SIZE (symbol) - 1);
7837 :
7838 : /* Generate the symbol for the module itself. */
7839 704 : mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, mod);
7840 704 : if (mod_symtree == NULL)
7841 : {
7842 703 : gfc_get_sym_tree (mod, gfc_current_ns, &mod_symtree, false);
7843 703 : gcc_assert (mod_symtree);
7844 703 : mod_sym = mod_symtree->n.sym;
7845 :
7846 703 : mod_sym->attr.flavor = FL_MODULE;
7847 703 : mod_sym->attr.intrinsic = 1;
7848 703 : mod_sym->module = gfc_get_string ("%s", mod);
7849 703 : mod_sym->from_intmod = INTMOD_ISO_FORTRAN_ENV;
7850 : }
7851 : else
7852 1 : if (!mod_symtree->n.sym->attr.intrinsic)
7853 1 : gfc_error ("Use of intrinsic module %qs at %C conflicts with "
7854 : "non-intrinsic module name used previously", mod);
7855 :
7856 : /* Generate the symbols for the module integer named constants. */
7857 :
7858 31680 : for (i = 0; symbol[i].name; i++)
7859 : {
7860 30976 : bool found = false;
7861 59048 : for (u = gfc_rename_list; u; u = u->next)
7862 : {
7863 28072 : if (strcmp (symbol[i].name, u->use_name) == 0)
7864 : {
7865 638 : found = true;
7866 638 : u->found = 1;
7867 :
7868 638 : if (!gfc_notify_std (symbol[i].standard, "The symbol %qs, "
7869 : "referenced at %L, is not in the selected "
7870 : "standard", symbol[i].name, &u->where))
7871 11 : continue;
7872 :
7873 627 : if ((flag_default_integer || flag_default_real_8)
7874 2 : && symbol[i].id == ISOFORTRANENV_NUMERIC_STORAGE_SIZE)
7875 0 : gfc_warning_now (0, "Use of the NUMERIC_STORAGE_SIZE named "
7876 : "constant from intrinsic module "
7877 : "ISO_FORTRAN_ENV at %L is incompatible with "
7878 : "option %qs", &u->where,
7879 : flag_default_integer
7880 : ? "-fdefault-integer-8"
7881 : : "-fdefault-real-8");
7882 627 : switch (symbol[i].id)
7883 : {
7884 : #define NAMED_INTCST(a,b,c,d) \
7885 : case a:
7886 : #include "iso-fortran-env.def"
7887 390 : create_int_parameter (u->local_name[0] ? u->local_name
7888 : : u->use_name,
7889 : symbol[i].value, mod,
7890 : INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
7891 390 : break;
7892 :
7893 : #define NAMED_UINTCST(a,b,c,d) \
7894 : case a:
7895 : #include "iso-fortran-env.def"
7896 30 : create_int_parameter (u->local_name[0] ? u->local_name
7897 : : u->use_name,
7898 : symbol[i].value, mod,
7899 : INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
7900 30 : break;
7901 :
7902 : #define NAMED_KINDARRAY(a,b,KINDS,d) \
7903 : case a:\
7904 : expr = gfc_get_array_expr (BT_INTEGER, \
7905 : gfc_default_integer_kind,\
7906 : NULL); \
7907 : for (j = 0; KINDS[j].kind != 0; j++) \
7908 : gfc_constructor_append_expr (&expr->value.constructor, \
7909 : gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7910 : KINDS[j].kind), NULL); \
7911 : create_int_parameter_array (u->local_name[0] ? u->local_name \
7912 : : u->use_name, \
7913 : j, expr, mod, \
7914 : INTMOD_ISO_FORTRAN_ENV, \
7915 : symbol[i].id); \
7916 : break;
7917 : #include "iso-fortran-env.def"
7918 :
7919 : #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7920 : case a:
7921 : #include "iso-fortran-env.def"
7922 120 : create_derived_type (u->local_name[0] ? u->local_name
7923 : : u->use_name,
7924 : mod, INTMOD_ISO_FORTRAN_ENV,
7925 : symbol[i].id);
7926 120 : break;
7927 :
7928 : #define NAMED_FUNCTION(a,b,c,d) \
7929 : case a:
7930 : #include "iso-fortran-env.def"
7931 15 : create_intrinsic_function (u->local_name[0] ? u->local_name
7932 : : u->use_name,
7933 : symbol[i].id, mod,
7934 : INTMOD_ISO_FORTRAN_ENV, false,
7935 : NULL);
7936 15 : break;
7937 :
7938 0 : default:
7939 0 : gcc_unreachable ();
7940 : }
7941 : }
7942 : }
7943 :
7944 30976 : if (!found && !only_flag)
7945 : {
7946 13845 : if ((gfc_option.allow_std & symbol[i].standard) == 0)
7947 1356 : continue;
7948 :
7949 12489 : if ((flag_default_integer || flag_default_real_8)
7950 0 : && symbol[i].id == ISOFORTRANENV_NUMERIC_STORAGE_SIZE)
7951 0 : gfc_warning_now (0,
7952 : "Use of the NUMERIC_STORAGE_SIZE named constant "
7953 : "from intrinsic module ISO_FORTRAN_ENV at %C is "
7954 : "incompatible with option %s",
7955 : flag_default_integer
7956 : ? "-fdefault-integer-8" : "-fdefault-real-8");
7957 :
7958 12489 : switch (symbol[i].id)
7959 : {
7960 : #define NAMED_INTCST(a,b,c,d) \
7961 : case a:
7962 : #include "iso-fortran-env.def"
7963 9678 : create_int_parameter (symbol[i].name, symbol[i].value, mod,
7964 : INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
7965 9678 : break;
7966 :
7967 : #define NAMED_UINTCST(a,b,c,d) \
7968 : case a:
7969 : #include "iso-fortran-env.def"
7970 4 : create_int_parameter (symbol[i].name, symbol[i].value, mod,
7971 : INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
7972 4 : break;
7973 :
7974 : #define NAMED_KINDARRAY(a,b,KINDS,d) \
7975 : case a:\
7976 : expr = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind, \
7977 : NULL); \
7978 : for (j = 0; KINDS[j].kind != 0; j++) \
7979 : gfc_constructor_append_expr (&expr->value.constructor, \
7980 : gfc_get_int_expr (gfc_default_integer_kind, NULL, \
7981 : KINDS[j].kind), NULL); \
7982 : create_int_parameter_array (symbol[i].name, j, expr, mod, \
7983 : INTMOD_ISO_FORTRAN_ENV, symbol[i].id);\
7984 : break;
7985 : #include "iso-fortran-env.def"
7986 :
7987 : #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
7988 : case a:
7989 : #include "iso-fortran-env.def"
7990 936 : create_derived_type (symbol[i].name, mod, INTMOD_ISO_FORTRAN_ENV,
7991 : symbol[i].id);
7992 936 : break;
7993 :
7994 : #define NAMED_FUNCTION(a,b,c,d) \
7995 : case a:
7996 : #include "iso-fortran-env.def"
7997 623 : create_intrinsic_function (symbol[i].name, symbol[i].id, mod,
7998 : INTMOD_ISO_FORTRAN_ENV, false, NULL);
7999 623 : break;
8000 :
8001 0 : default:
8002 0 : gcc_unreachable ();
8003 : }
8004 : }
8005 : }
8006 :
8007 1342 : for (u = gfc_rename_list; u; u = u->next)
8008 : {
8009 638 : if (u->found)
8010 638 : continue;
8011 :
8012 0 : gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
8013 0 : "module ISO_FORTRAN_ENV", u->use_name, &u->where);
8014 : }
8015 704 : }
8016 :
8017 :
8018 : /* Process a USE directive. */
8019 :
8020 : static void
8021 25083 : gfc_use_module (gfc_use_list *module)
8022 : {
8023 25083 : char *filename;
8024 25083 : gfc_state_data *p;
8025 25083 : int c, line, start;
8026 25083 : gfc_symtree *mod_symtree;
8027 25083 : gfc_use_list *use_stmt;
8028 25083 : locus old_locus = gfc_current_locus;
8029 :
8030 25083 : gfc_current_locus = module->where;
8031 25083 : module_name = module->module_name;
8032 25083 : gfc_rename_list = module->rename;
8033 25083 : only_flag = module->only_flag;
8034 25083 : current_intmod = INTMOD_NONE;
8035 :
8036 25083 : if (!only_flag && gfc_state_stack->state != COMP_SUBMODULE)
8037 15589 : gfc_warning_now (OPT_Wuse_without_only,
8038 : "USE statement at %C has no ONLY qualifier");
8039 :
8040 25083 : if (gfc_state_stack->state == COMP_MODULE
8041 22455 : || module->submodule_name == NULL)
8042 : {
8043 24812 : filename = XALLOCAVEC (char, strlen (module_name)
8044 : + strlen (MODULE_EXTENSION) + 1);
8045 24812 : strcpy (filename, module_name);
8046 24812 : strcat (filename, MODULE_EXTENSION);
8047 : }
8048 : else
8049 : {
8050 271 : filename = XALLOCAVEC (char, strlen (module->submodule_name)
8051 : + strlen (SUBMODULE_EXTENSION) + 1);
8052 271 : strcpy (filename, module->submodule_name);
8053 271 : strcat (filename, SUBMODULE_EXTENSION);
8054 : }
8055 :
8056 : /* First, try to find an non-intrinsic module, unless the USE statement
8057 : specified that the module is intrinsic. */
8058 25083 : module_fp = NULL;
8059 25083 : if (!module->intrinsic)
8060 21088 : module_fp = gzopen_included_file (filename, true, true);
8061 :
8062 : /* Then, see if it's an intrinsic one, unless the USE statement
8063 : specified that the module is non-intrinsic. */
8064 25083 : if (module_fp == NULL && !module->non_intrinsic)
8065 : {
8066 12175 : if (strcmp (module_name, "iso_fortran_env") == 0
8067 12175 : && gfc_notify_std (GFC_STD_F2003, "ISO_FORTRAN_ENV "
8068 : "intrinsic module at %C"))
8069 : {
8070 704 : use_iso_fortran_env_module ();
8071 704 : free_rename (module->rename);
8072 704 : module->rename = NULL;
8073 704 : gfc_current_locus = old_locus;
8074 704 : module->intrinsic = true;
8075 10937 : return;
8076 : }
8077 :
8078 11471 : if (strcmp (module_name, "iso_c_binding") == 0
8079 11471 : && gfc_notify_std (GFC_STD_F2003, "ISO_C_BINDING module at %C"))
8080 : {
8081 10233 : import_iso_c_binding_module();
8082 10233 : free_rename (module->rename);
8083 10233 : module->rename = NULL;
8084 10233 : gfc_current_locus = old_locus;
8085 10233 : module->intrinsic = true;
8086 10233 : return;
8087 : }
8088 :
8089 1238 : module_fp = gzopen_intrinsic_module (filename);
8090 :
8091 1238 : if (module_fp == NULL && module->intrinsic)
8092 0 : gfc_fatal_error ("Cannot find an intrinsic module named %qs at %C",
8093 : module_name);
8094 :
8095 : /* Check for the IEEE modules, so we can mark their symbols
8096 : accordingly when we read them. */
8097 1238 : if (strcmp (module_name, "ieee_features") == 0
8098 1238 : && gfc_notify_std (GFC_STD_F2003, "IEEE_FEATURES module at %C"))
8099 : {
8100 52 : current_intmod = INTMOD_IEEE_FEATURES;
8101 : }
8102 1186 : else if (strcmp (module_name, "ieee_exceptions") == 0
8103 1186 : && gfc_notify_std (GFC_STD_F2003,
8104 : "IEEE_EXCEPTIONS module at %C"))
8105 : {
8106 60 : current_intmod = INTMOD_IEEE_EXCEPTIONS;
8107 : }
8108 1126 : else if (strcmp (module_name, "ieee_arithmetic") == 0
8109 1126 : && gfc_notify_std (GFC_STD_F2003,
8110 : "IEEE_ARITHMETIC module at %C"))
8111 : {
8112 405 : current_intmod = INTMOD_IEEE_ARITHMETIC;
8113 : }
8114 : }
8115 :
8116 14146 : if (module_fp == NULL)
8117 : {
8118 4 : if (gfc_state_stack->state != COMP_SUBMODULE
8119 3 : && module->submodule_name == NULL)
8120 3 : gfc_fatal_error ("Cannot open module file %qs for reading at %C: %s",
8121 3 : filename, xstrerror (errno));
8122 : else
8123 1 : gfc_fatal_error ("Module file %qs has not been generated, either "
8124 : "because the module does not contain a MODULE "
8125 : "PROCEDURE or there is an error in the module.",
8126 : filename);
8127 : }
8128 :
8129 : /* Check that we haven't already USEd an intrinsic module with the
8130 : same name. */
8131 :
8132 14142 : mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, module_name);
8133 14142 : if (mod_symtree && mod_symtree->n.sym->attr.intrinsic)
8134 1 : gfc_error ("Use of non-intrinsic module %qs at %C conflicts with "
8135 : "intrinsic module name used previously", module_name);
8136 :
8137 14142 : iomode = IO_INPUT;
8138 14142 : module_line = 1;
8139 14142 : module_column = 1;
8140 14142 : start = 0;
8141 :
8142 14142 : read_module_to_tmpbuf ();
8143 14142 : gzclose (module_fp);
8144 :
8145 : /* Skip the first line of the module, after checking that this is
8146 : a gfortran module file. */
8147 14142 : line = 0;
8148 522208 : while (line < 1)
8149 : {
8150 493924 : c = module_char ();
8151 493924 : if (c == EOF)
8152 0 : bad_module ("Unexpected end of module");
8153 493924 : if (start++ < 3)
8154 42426 : parse_name (c);
8155 493924 : if ((start == 1 && strcmp (atom_name, "GFORTRAN") != 0)
8156 493924 : || (start == 2 && strcmp (atom_name, " module") != 0))
8157 0 : gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran"
8158 : " module file", module_fullpath);
8159 493924 : if (start == 3)
8160 : {
8161 14142 : bool fatal = false;
8162 14142 : if (strcmp (atom_name, " version") != 0
8163 14142 : || module_char () != ' '
8164 28284 : || parse_atom () != ATOM_STRING)
8165 : fatal = true;
8166 14142 : else if (strcmp (atom_string, MOD_VERSION))
8167 : {
8168 : static const char *compat_mod_versions[] = COMPAT_MOD_VERSIONS;
8169 0 : fatal = true;
8170 0 : for (unsigned i = 0; i < ARRAY_SIZE (compat_mod_versions); ++i)
8171 0 : if (!strcmp (atom_string, compat_mod_versions[i]))
8172 : {
8173 : fatal = false;
8174 : break;
8175 : }
8176 : }
8177 0 : if (fatal)
8178 0 : gfc_fatal_error ("Cannot read module file %qs opened at %C,"
8179 : " because it was created by a different"
8180 : " version of GNU Fortran", module_fullpath);
8181 :
8182 14142 : free (atom_string);
8183 : }
8184 :
8185 493924 : if (c == '\n')
8186 14142 : line++;
8187 : }
8188 :
8189 : /* Make sure we're not reading the same module that we may be building. */
8190 47559 : for (p = gfc_state_stack; p; p = p->previous)
8191 33417 : if ((p->state == COMP_MODULE || p->state == COMP_SUBMODULE)
8192 2405 : && strcmp (p->sym->name, module_name) == 0)
8193 : {
8194 0 : if (p->state == COMP_SUBMODULE)
8195 0 : gfc_fatal_error ("Cannot USE a submodule that is currently built");
8196 : else
8197 0 : gfc_fatal_error ("Cannot USE a module that is currently built");
8198 : }
8199 :
8200 14142 : init_pi_tree ();
8201 14142 : init_true_name_tree ();
8202 :
8203 14142 : read_module ();
8204 :
8205 14142 : free_true_name (true_name_root);
8206 14142 : true_name_root = NULL;
8207 :
8208 14142 : free_pi_tree (pi_root);
8209 14142 : pi_root = NULL;
8210 :
8211 14142 : XDELETEVEC (module_content);
8212 14142 : module_content = NULL;
8213 :
8214 14142 : use_stmt = gfc_get_use_list ();
8215 14142 : *use_stmt = *module;
8216 14142 : use_stmt->next = gfc_current_ns->use_stmts;
8217 14142 : gfc_current_ns->use_stmts = use_stmt;
8218 :
8219 14142 : gfc_current_locus = old_locus;
8220 : }
8221 :
8222 :
8223 : /* Remove duplicated intrinsic operators from the rename list. */
8224 :
8225 : static void
8226 25083 : rename_list_remove_duplicate (gfc_use_rename *list)
8227 : {
8228 25083 : gfc_use_rename *seek, *last;
8229 :
8230 39389 : for (; list; list = list->next)
8231 14306 : if (list->op != INTRINSIC_USER && list->op != INTRINSIC_NONE)
8232 : {
8233 113 : last = list;
8234 459 : for (seek = list->next; seek; seek = last->next)
8235 : {
8236 346 : if (list->op == seek->op)
8237 : {
8238 2 : last->next = seek->next;
8239 2 : free (seek);
8240 : }
8241 : else
8242 : last = seek;
8243 : }
8244 : }
8245 25083 : }
8246 :
8247 :
8248 : /* Process all USE directives. */
8249 :
8250 : void
8251 21899 : gfc_use_modules (void)
8252 : {
8253 21899 : gfc_use_list *next, *seek, *last;
8254 :
8255 46982 : for (next = module_list; next; next = next->next)
8256 : {
8257 25083 : bool non_intrinsic = next->non_intrinsic;
8258 25083 : bool intrinsic = next->intrinsic;
8259 25083 : bool neither = !non_intrinsic && !intrinsic;
8260 :
8261 29091 : for (seek = next->next; seek; seek = seek->next)
8262 : {
8263 4008 : if (next->module_name != seek->module_name)
8264 3809 : continue;
8265 :
8266 199 : if (seek->non_intrinsic)
8267 : non_intrinsic = true;
8268 198 : else if (seek->intrinsic)
8269 : intrinsic = true;
8270 : else
8271 158 : neither = true;
8272 : }
8273 :
8274 25083 : if (intrinsic && neither && !non_intrinsic)
8275 : {
8276 1 : char *filename;
8277 1 : FILE *fp;
8278 :
8279 1 : filename = XALLOCAVEC (char,
8280 : strlen (next->module_name)
8281 : + strlen (MODULE_EXTENSION) + 1);
8282 1 : strcpy (filename, next->module_name);
8283 1 : strcat (filename, MODULE_EXTENSION);
8284 1 : fp = gfc_open_included_file (filename, true, true);
8285 1 : if (fp != NULL)
8286 : {
8287 0 : non_intrinsic = true;
8288 0 : fclose (fp);
8289 : }
8290 : }
8291 :
8292 25083 : last = next;
8293 29091 : for (seek = next->next; seek; seek = last->next)
8294 : {
8295 4008 : if (next->module_name != seek->module_name)
8296 : {
8297 3809 : last = seek;
8298 3809 : continue;
8299 : }
8300 :
8301 199 : if ((!next->intrinsic && !seek->intrinsic)
8302 41 : || (next->intrinsic && seek->intrinsic)
8303 3 : || !non_intrinsic)
8304 : {
8305 197 : if (!seek->only_flag)
8306 18 : next->only_flag = false;
8307 197 : if (seek->rename)
8308 : {
8309 : gfc_use_rename *r = seek->rename;
8310 406 : while (r->next)
8311 : r = r->next;
8312 192 : r->next = next->rename;
8313 192 : next->rename = seek->rename;
8314 : }
8315 197 : last->next = seek->next;
8316 197 : free (seek);
8317 197 : }
8318 : else
8319 : last = seek;
8320 : }
8321 : }
8322 :
8323 46978 : for (; module_list; module_list = next)
8324 : {
8325 25083 : next = module_list->next;
8326 25083 : rename_list_remove_duplicate (module_list->rename);
8327 25083 : gfc_use_module (module_list);
8328 25079 : free (module_list);
8329 : }
8330 21895 : module_list = NULL;
8331 21895 : old_module_list_tail = &module_list;
8332 21895 : gfc_rename_list = NULL;
8333 21895 : }
8334 :
8335 :
8336 : void
8337 9944733 : gfc_free_use_stmts (gfc_use_list *use_stmts)
8338 : {
8339 9944733 : gfc_use_list *next;
8340 9958879 : for (; use_stmts; use_stmts = next)
8341 : {
8342 : gfc_use_rename *next_rename;
8343 :
8344 17256 : for (; use_stmts->rename; use_stmts->rename = next_rename)
8345 : {
8346 3110 : next_rename = use_stmts->rename->next;
8347 3110 : free (use_stmts->rename);
8348 : }
8349 14146 : next = use_stmts->next;
8350 14146 : free (use_stmts);
8351 : }
8352 9944733 : }
8353 :
8354 :
8355 : /* Remember the end of the MODULE_LIST list, so that the list can be restored
8356 : to its previous state if the current statement is erroneous. */
8357 :
8358 : void
8359 1497311 : gfc_save_module_list ()
8360 : {
8361 1497311 : gfc_use_list **tail = &module_list;
8362 1528508 : while (*tail != NULL)
8363 31197 : tail = &(*tail)->next;
8364 1497311 : old_module_list_tail = tail;
8365 1497311 : }
8366 :
8367 :
8368 : /* Restore the MODULE_LIST list to its previous value and free the use
8369 : statements that are no longer part of the list. */
8370 :
8371 : void
8372 9385740 : gfc_restore_old_module_list ()
8373 : {
8374 9385740 : gfc_free_use_stmts (*old_module_list_tail);
8375 9385740 : *old_module_list_tail = NULL;
8376 9385740 : }
8377 :
8378 :
8379 : void
8380 83807 : gfc_module_init_2 (void)
8381 : {
8382 83807 : last_atom = ATOM_LPAREN;
8383 83807 : gfc_rename_list = NULL;
8384 83807 : module_list = NULL;
8385 83807 : }
8386 :
8387 :
8388 : void
8389 84170 : gfc_module_done_2 (void)
8390 : {
8391 84170 : free_rename (gfc_rename_list);
8392 84170 : gfc_rename_list = NULL;
8393 84170 : }
|