Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / fortran / dump-parse-tree.c
blob41af932565d77aea93fee7133ac53061e1304c38
1 /* Parse tree dumper
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Steven Bosscher
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
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.
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/>. */
23 /* Actually this is just a collection of routines that used to be
24 scattered around the sources. Now that they are all in a single
25 file, almost all of them can be static, and the other files don't
26 have this mess in them.
28 As a nice side-effect, this file can act as documentation of the
29 gfc_code and gfc_expr structures and all their friends and
30 relatives.
32 TODO: Dump DATA. */
34 #include "config.h"
35 #include "system.h"
36 #include "gfortran.h"
37 #include "constructor.h"
39 /* Keep track of indentation for symbol tree dumps. */
40 static int show_level = 0;
42 /* The file handle we're dumping to is kept in a static variable. This
43 is not too cool, but it avoids a lot of passing it around. */
44 static FILE *dumpfile;
46 /* Forward declaration of some of the functions. */
47 static void show_expr (gfc_expr *p);
48 static void show_code_node (int, gfc_code *);
49 static void show_namespace (gfc_namespace *ns);
52 /* Allow dumping of an expression in the debugger. */
53 void gfc_debug_expr (gfc_expr *);
55 void
56 gfc_debug_expr (gfc_expr *e)
58 FILE *tmp = dumpfile;
59 dumpfile = stderr;
60 show_expr (e);
61 fputc ('\n', dumpfile);
62 dumpfile = tmp;
66 /* Do indentation for a specific level. */
68 static inline void
69 code_indent (int level, gfc_st_label *label)
71 int i;
73 if (label != NULL)
74 fprintf (dumpfile, "%-5d ", label->value);
76 for (i = 0; i < (2 * level - (label ? 6 : 0)); i++)
77 fputc (' ', dumpfile);
81 /* Simple indentation at the current level. This one
82 is used to show symbols. */
84 static inline void
85 show_indent (void)
87 fputc ('\n', dumpfile);
88 code_indent (show_level, NULL);
92 /* Show type-specific information. */
94 static void
95 show_typespec (gfc_typespec *ts)
97 fprintf (dumpfile, "(%s ", gfc_basic_typename (ts->type));
99 switch (ts->type)
101 case BT_DERIVED:
102 case BT_CLASS:
103 fprintf (dumpfile, "%s", ts->u.derived->name);
104 break;
106 case BT_CHARACTER:
107 show_expr (ts->u.cl->length);
108 break;
110 default:
111 fprintf (dumpfile, "%d", ts->kind);
112 break;
115 fputc (')', dumpfile);
119 /* Show an actual argument list. */
121 static void
122 show_actual_arglist (gfc_actual_arglist *a)
124 fputc ('(', dumpfile);
126 for (; a; a = a->next)
128 fputc ('(', dumpfile);
129 if (a->name != NULL)
130 fprintf (dumpfile, "%s = ", a->name);
131 if (a->expr != NULL)
132 show_expr (a->expr);
133 else
134 fputs ("(arg not-present)", dumpfile);
136 fputc (')', dumpfile);
137 if (a->next != NULL)
138 fputc (' ', dumpfile);
141 fputc (')', dumpfile);
145 /* Show a gfc_array_spec array specification structure. */
147 static void
148 show_array_spec (gfc_array_spec *as)
150 const char *c;
151 int i;
153 if (as == NULL)
155 fputs ("()", dumpfile);
156 return;
159 fprintf (dumpfile, "(%d [%d]", as->rank, as->corank);
161 if (as->rank + as->corank > 0)
163 switch (as->type)
165 case AS_EXPLICIT: c = "AS_EXPLICIT"; break;
166 case AS_DEFERRED: c = "AS_DEFERRED"; break;
167 case AS_ASSUMED_SIZE: c = "AS_ASSUMED_SIZE"; break;
168 case AS_ASSUMED_SHAPE: c = "AS_ASSUMED_SHAPE"; break;
169 default:
170 gfc_internal_error ("show_array_spec(): Unhandled array shape "
171 "type.");
173 fprintf (dumpfile, " %s ", c);
175 for (i = 0; i < as->rank + as->corank; i++)
177 show_expr (as->lower[i]);
178 fputc (' ', dumpfile);
179 show_expr (as->upper[i]);
180 fputc (' ', dumpfile);
184 fputc (')', dumpfile);
188 /* Show a gfc_array_ref array reference structure. */
190 static void
191 show_array_ref (gfc_array_ref * ar)
193 int i;
195 fputc ('(', dumpfile);
197 switch (ar->type)
199 case AR_FULL:
200 fputs ("FULL", dumpfile);
201 break;
203 case AR_SECTION:
204 for (i = 0; i < ar->dimen; i++)
206 /* There are two types of array sections: either the
207 elements are identified by an integer array ('vector'),
208 or by an index range. In the former case we only have to
209 print the start expression which contains the vector, in
210 the latter case we have to print any of lower and upper
211 bound and the stride, if they're present. */
213 if (ar->start[i] != NULL)
214 show_expr (ar->start[i]);
216 if (ar->dimen_type[i] == DIMEN_RANGE)
218 fputc (':', dumpfile);
220 if (ar->end[i] != NULL)
221 show_expr (ar->end[i]);
223 if (ar->stride[i] != NULL)
225 fputc (':', dumpfile);
226 show_expr (ar->stride[i]);
230 if (i != ar->dimen - 1)
231 fputs (" , ", dumpfile);
233 break;
235 case AR_ELEMENT:
236 for (i = 0; i < ar->dimen; i++)
238 show_expr (ar->start[i]);
239 if (i != ar->dimen - 1)
240 fputs (" , ", dumpfile);
242 break;
244 case AR_UNKNOWN:
245 fputs ("UNKNOWN", dumpfile);
246 break;
248 default:
249 gfc_internal_error ("show_array_ref(): Unknown array reference");
252 fputc (')', dumpfile);
256 /* Show a list of gfc_ref structures. */
258 static void
259 show_ref (gfc_ref *p)
261 for (; p; p = p->next)
262 switch (p->type)
264 case REF_ARRAY:
265 show_array_ref (&p->u.ar);
266 break;
268 case REF_COMPONENT:
269 fprintf (dumpfile, " %% %s", p->u.c.component->name);
270 break;
272 case REF_SUBSTRING:
273 fputc ('(', dumpfile);
274 show_expr (p->u.ss.start);
275 fputc (':', dumpfile);
276 show_expr (p->u.ss.end);
277 fputc (')', dumpfile);
278 break;
280 default:
281 gfc_internal_error ("show_ref(): Bad component code");
286 /* Display a constructor. Works recursively for array constructors. */
288 static void
289 show_constructor (gfc_constructor_base base)
291 gfc_constructor *c;
292 for (c = gfc_constructor_first (base); c; c = gfc_constructor_next (c))
294 if (c->iterator == NULL)
295 show_expr (c->expr);
296 else
298 fputc ('(', dumpfile);
299 show_expr (c->expr);
301 fputc (' ', dumpfile);
302 show_expr (c->iterator->var);
303 fputc ('=', dumpfile);
304 show_expr (c->iterator->start);
305 fputc (',', dumpfile);
306 show_expr (c->iterator->end);
307 fputc (',', dumpfile);
308 show_expr (c->iterator->step);
310 fputc (')', dumpfile);
313 if (gfc_constructor_next (c) != NULL)
314 fputs (" , ", dumpfile);
319 static void
320 show_char_const (const gfc_char_t *c, int length)
322 int i;
324 fputc ('\'', dumpfile);
325 for (i = 0; i < length; i++)
327 if (c[i] == '\'')
328 fputs ("''", dumpfile);
329 else
330 fputs (gfc_print_wide_char (c[i]), dumpfile);
332 fputc ('\'', dumpfile);
336 /* Show a component-call expression. */
338 static void
339 show_compcall (gfc_expr* p)
341 gcc_assert (p->expr_type == EXPR_COMPCALL);
343 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
344 show_ref (p->ref);
345 fprintf (dumpfile, "%s", p->value.compcall.name);
347 show_actual_arglist (p->value.compcall.actual);
351 /* Show an expression. */
353 static void
354 show_expr (gfc_expr *p)
356 const char *c;
357 int i;
359 if (p == NULL)
361 fputs ("()", dumpfile);
362 return;
365 switch (p->expr_type)
367 case EXPR_SUBSTRING:
368 show_char_const (p->value.character.string, p->value.character.length);
369 show_ref (p->ref);
370 break;
372 case EXPR_STRUCTURE:
373 fprintf (dumpfile, "%s(", p->ts.u.derived->name);
374 show_constructor (p->value.constructor);
375 fputc (')', dumpfile);
376 break;
378 case EXPR_ARRAY:
379 fputs ("(/ ", dumpfile);
380 show_constructor (p->value.constructor);
381 fputs (" /)", dumpfile);
383 show_ref (p->ref);
384 break;
386 case EXPR_NULL:
387 fputs ("NULL()", dumpfile);
388 break;
390 case EXPR_CONSTANT:
391 switch (p->ts.type)
393 case BT_INTEGER:
394 mpz_out_str (stdout, 10, p->value.integer);
396 if (p->ts.kind != gfc_default_integer_kind)
397 fprintf (dumpfile, "_%d", p->ts.kind);
398 break;
400 case BT_LOGICAL:
401 if (p->value.logical)
402 fputs (".true.", dumpfile);
403 else
404 fputs (".false.", dumpfile);
405 break;
407 case BT_REAL:
408 mpfr_out_str (stdout, 10, 0, p->value.real, GFC_RND_MODE);
409 if (p->ts.kind != gfc_default_real_kind)
410 fprintf (dumpfile, "_%d", p->ts.kind);
411 break;
413 case BT_CHARACTER:
414 show_char_const (p->value.character.string,
415 p->value.character.length);
416 break;
418 case BT_COMPLEX:
419 fputs ("(complex ", dumpfile);
421 mpfr_out_str (stdout, 10, 0, mpc_realref (p->value.complex),
422 GFC_RND_MODE);
423 if (p->ts.kind != gfc_default_complex_kind)
424 fprintf (dumpfile, "_%d", p->ts.kind);
426 fputc (' ', dumpfile);
428 mpfr_out_str (stdout, 10, 0, mpc_imagref (p->value.complex),
429 GFC_RND_MODE);
430 if (p->ts.kind != gfc_default_complex_kind)
431 fprintf (dumpfile, "_%d", p->ts.kind);
433 fputc (')', dumpfile);
434 break;
436 case BT_HOLLERITH:
437 fprintf (dumpfile, "%dH", p->representation.length);
438 c = p->representation.string;
439 for (i = 0; i < p->representation.length; i++, c++)
441 fputc (*c, dumpfile);
443 break;
445 default:
446 fputs ("???", dumpfile);
447 break;
450 if (p->representation.string)
452 fputs (" {", dumpfile);
453 c = p->representation.string;
454 for (i = 0; i < p->representation.length; i++, c++)
456 fprintf (dumpfile, "%.2x", (unsigned int) *c);
457 if (i < p->representation.length - 1)
458 fputc (',', dumpfile);
460 fputc ('}', dumpfile);
463 break;
465 case EXPR_VARIABLE:
466 if (p->symtree->n.sym->ns && p->symtree->n.sym->ns->proc_name)
467 fprintf (dumpfile, "%s:", p->symtree->n.sym->ns->proc_name->name);
468 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
469 show_ref (p->ref);
470 break;
472 case EXPR_OP:
473 fputc ('(', dumpfile);
474 switch (p->value.op.op)
476 case INTRINSIC_UPLUS:
477 fputs ("U+ ", dumpfile);
478 break;
479 case INTRINSIC_UMINUS:
480 fputs ("U- ", dumpfile);
481 break;
482 case INTRINSIC_PLUS:
483 fputs ("+ ", dumpfile);
484 break;
485 case INTRINSIC_MINUS:
486 fputs ("- ", dumpfile);
487 break;
488 case INTRINSIC_TIMES:
489 fputs ("* ", dumpfile);
490 break;
491 case INTRINSIC_DIVIDE:
492 fputs ("/ ", dumpfile);
493 break;
494 case INTRINSIC_POWER:
495 fputs ("** ", dumpfile);
496 break;
497 case INTRINSIC_CONCAT:
498 fputs ("// ", dumpfile);
499 break;
500 case INTRINSIC_AND:
501 fputs ("AND ", dumpfile);
502 break;
503 case INTRINSIC_OR:
504 fputs ("OR ", dumpfile);
505 break;
506 case INTRINSIC_EQV:
507 fputs ("EQV ", dumpfile);
508 break;
509 case INTRINSIC_NEQV:
510 fputs ("NEQV ", dumpfile);
511 break;
512 case INTRINSIC_EQ:
513 case INTRINSIC_EQ_OS:
514 fputs ("= ", dumpfile);
515 break;
516 case INTRINSIC_NE:
517 case INTRINSIC_NE_OS:
518 fputs ("/= ", dumpfile);
519 break;
520 case INTRINSIC_GT:
521 case INTRINSIC_GT_OS:
522 fputs ("> ", dumpfile);
523 break;
524 case INTRINSIC_GE:
525 case INTRINSIC_GE_OS:
526 fputs (">= ", dumpfile);
527 break;
528 case INTRINSIC_LT:
529 case INTRINSIC_LT_OS:
530 fputs ("< ", dumpfile);
531 break;
532 case INTRINSIC_LE:
533 case INTRINSIC_LE_OS:
534 fputs ("<= ", dumpfile);
535 break;
536 case INTRINSIC_NOT:
537 fputs ("NOT ", dumpfile);
538 break;
539 case INTRINSIC_PARENTHESES:
540 fputs ("parens", dumpfile);
541 break;
543 default:
544 gfc_internal_error
545 ("show_expr(): Bad intrinsic in expression!");
548 show_expr (p->value.op.op1);
550 if (p->value.op.op2)
552 fputc (' ', dumpfile);
553 show_expr (p->value.op.op2);
556 fputc (')', dumpfile);
557 break;
559 case EXPR_FUNCTION:
560 if (p->value.function.name == NULL)
562 fprintf (dumpfile, "%s", p->symtree->n.sym->name);
563 if (gfc_is_proc_ptr_comp (p, NULL))
564 show_ref (p->ref);
565 fputc ('[', dumpfile);
566 show_actual_arglist (p->value.function.actual);
567 fputc (']', dumpfile);
569 else
571 fprintf (dumpfile, "%s", p->value.function.name);
572 if (gfc_is_proc_ptr_comp (p, NULL))
573 show_ref (p->ref);
574 fputc ('[', dumpfile);
575 fputc ('[', dumpfile);
576 show_actual_arglist (p->value.function.actual);
577 fputc (']', dumpfile);
578 fputc (']', dumpfile);
581 break;
583 case EXPR_COMPCALL:
584 show_compcall (p);
585 break;
587 default:
588 gfc_internal_error ("show_expr(): Don't know how to show expr");
592 /* Show symbol attributes. The flavor and intent are followed by
593 whatever single bit attributes are present. */
595 static void
596 show_attr (symbol_attribute *attr, const char * module)
598 if (attr->flavor != FL_UNKNOWN)
599 fprintf (dumpfile, "(%s ", gfc_code2string (flavors, attr->flavor));
600 if (attr->access != ACCESS_UNKNOWN)
601 fprintf (dumpfile, "%s ", gfc_code2string (access_types, attr->access));
602 if (attr->proc != PROC_UNKNOWN)
603 fprintf (dumpfile, "%s ", gfc_code2string (procedures, attr->proc));
604 if (attr->save != SAVE_NONE)
605 fprintf (dumpfile, "%s", gfc_code2string (save_status, attr->save));
607 if (attr->allocatable)
608 fputs (" ALLOCATABLE", dumpfile);
609 if (attr->asynchronous)
610 fputs (" ASYNCHRONOUS", dumpfile);
611 if (attr->codimension)
612 fputs (" CODIMENSION", dumpfile);
613 if (attr->dimension)
614 fputs (" DIMENSION", dumpfile);
615 if (attr->contiguous)
616 fputs (" CONTIGUOUS", dumpfile);
617 if (attr->external)
618 fputs (" EXTERNAL", dumpfile);
619 if (attr->intrinsic)
620 fputs (" INTRINSIC", dumpfile);
621 if (attr->optional)
622 fputs (" OPTIONAL", dumpfile);
623 if (attr->pointer)
624 fputs (" POINTER", dumpfile);
625 if (attr->is_protected)
626 fputs (" PROTECTED", dumpfile);
627 if (attr->value)
628 fputs (" VALUE", dumpfile);
629 if (attr->volatile_)
630 fputs (" VOLATILE", dumpfile);
631 if (attr->threadprivate)
632 fputs (" THREADPRIVATE", dumpfile);
633 if (attr->target)
634 fputs (" TARGET", dumpfile);
635 if (attr->dummy)
637 fputs (" DUMMY", dumpfile);
638 if (attr->intent != INTENT_UNKNOWN)
639 fprintf (dumpfile, "(%s)", gfc_intent_string (attr->intent));
642 if (attr->result)
643 fputs (" RESULT", dumpfile);
644 if (attr->entry)
645 fputs (" ENTRY", dumpfile);
646 if (attr->is_bind_c)
647 fputs (" BIND(C)", dumpfile);
649 if (attr->data)
650 fputs (" DATA", dumpfile);
651 if (attr->use_assoc)
653 fputs (" USE-ASSOC", dumpfile);
654 if (module != NULL)
655 fprintf (dumpfile, "(%s)", module);
658 if (attr->in_namelist)
659 fputs (" IN-NAMELIST", dumpfile);
660 if (attr->in_common)
661 fputs (" IN-COMMON", dumpfile);
663 if (attr->abstract)
664 fputs (" ABSTRACT", dumpfile);
665 if (attr->function)
666 fputs (" FUNCTION", dumpfile);
667 if (attr->subroutine)
668 fputs (" SUBROUTINE", dumpfile);
669 if (attr->implicit_type)
670 fputs (" IMPLICIT-TYPE", dumpfile);
672 if (attr->sequence)
673 fputs (" SEQUENCE", dumpfile);
674 if (attr->elemental)
675 fputs (" ELEMENTAL", dumpfile);
676 if (attr->pure)
677 fputs (" PURE", dumpfile);
678 if (attr->recursive)
679 fputs (" RECURSIVE", dumpfile);
681 fputc (')', dumpfile);
685 /* Show components of a derived type. */
687 static void
688 show_components (gfc_symbol *sym)
690 gfc_component *c;
692 for (c = sym->components; c; c = c->next)
694 fprintf (dumpfile, "(%s ", c->name);
695 show_typespec (&c->ts);
696 if (c->attr.pointer)
697 fputs (" POINTER", dumpfile);
698 if (c->attr.proc_pointer)
699 fputs (" PPC", dumpfile);
700 if (c->attr.dimension)
701 fputs (" DIMENSION", dumpfile);
702 fputc (' ', dumpfile);
703 show_array_spec (c->as);
704 if (c->attr.access)
705 fprintf (dumpfile, " %s", gfc_code2string (access_types, c->attr.access));
706 fputc (')', dumpfile);
707 if (c->next != NULL)
708 fputc (' ', dumpfile);
713 /* Show the f2k_derived namespace with procedure bindings. */
715 static void
716 show_typebound_proc (gfc_typebound_proc* tb, const char* name)
718 show_indent ();
720 if (tb->is_generic)
721 fputs ("GENERIC", dumpfile);
722 else
724 fputs ("PROCEDURE, ", dumpfile);
725 if (tb->nopass)
726 fputs ("NOPASS", dumpfile);
727 else
729 if (tb->pass_arg)
730 fprintf (dumpfile, "PASS(%s)", tb->pass_arg);
731 else
732 fputs ("PASS", dumpfile);
734 if (tb->non_overridable)
735 fputs (", NON_OVERRIDABLE", dumpfile);
738 if (tb->access == ACCESS_PUBLIC)
739 fputs (", PUBLIC", dumpfile);
740 else
741 fputs (", PRIVATE", dumpfile);
743 fprintf (dumpfile, " :: %s => ", name);
745 if (tb->is_generic)
747 gfc_tbp_generic* g;
748 for (g = tb->u.generic; g; g = g->next)
750 fputs (g->specific_st->name, dumpfile);
751 if (g->next)
752 fputs (", ", dumpfile);
755 else
756 fputs (tb->u.specific->n.sym->name, dumpfile);
759 static void
760 show_typebound_symtree (gfc_symtree* st)
762 gcc_assert (st->n.tb);
763 show_typebound_proc (st->n.tb, st->name);
766 static void
767 show_f2k_derived (gfc_namespace* f2k)
769 gfc_finalizer* f;
770 int op;
772 show_indent ();
773 fputs ("Procedure bindings:", dumpfile);
774 ++show_level;
776 /* Finalizer bindings. */
777 for (f = f2k->finalizers; f; f = f->next)
779 show_indent ();
780 fprintf (dumpfile, "FINAL %s", f->proc_sym->name);
783 /* Type-bound procedures. */
784 gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound_symtree);
786 --show_level;
788 show_indent ();
789 fputs ("Operator bindings:", dumpfile);
790 ++show_level;
792 /* User-defined operators. */
793 gfc_traverse_symtree (f2k->tb_uop_root, &show_typebound_symtree);
795 /* Intrinsic operators. */
796 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
797 if (f2k->tb_op[op])
798 show_typebound_proc (f2k->tb_op[op],
799 gfc_op2string ((gfc_intrinsic_op) op));
801 --show_level;
805 /* Show a symbol. If a symbol is an ENTRY, SUBROUTINE or FUNCTION, we
806 show the interface. Information needed to reconstruct the list of
807 specific interfaces associated with a generic symbol is done within
808 that symbol. */
810 static void
811 show_symbol (gfc_symbol *sym)
813 gfc_formal_arglist *formal;
814 gfc_interface *intr;
815 int i,len;
817 if (sym == NULL)
818 return;
820 fprintf (dumpfile, "|| symbol: '%s' ", sym->name);
821 len = strlen (sym->name);
822 for (i=len; i<12; i++)
823 fputc(' ', dumpfile);
825 ++show_level;
827 show_indent ();
828 fputs ("type spec : ", dumpfile);
829 show_typespec (&sym->ts);
831 show_indent ();
832 fputs ("attributes: ", dumpfile);
833 show_attr (&sym->attr, sym->module);
835 if (sym->value)
837 show_indent ();
838 fputs ("value: ", dumpfile);
839 show_expr (sym->value);
842 if (sym->as)
844 show_indent ();
845 fputs ("Array spec:", dumpfile);
846 show_array_spec (sym->as);
849 if (sym->generic)
851 show_indent ();
852 fputs ("Generic interfaces:", dumpfile);
853 for (intr = sym->generic; intr; intr = intr->next)
854 fprintf (dumpfile, " %s", intr->sym->name);
857 if (sym->result)
859 show_indent ();
860 fprintf (dumpfile, "result: %s", sym->result->name);
863 if (sym->components)
865 show_indent ();
866 fputs ("components: ", dumpfile);
867 show_components (sym);
870 if (sym->f2k_derived)
872 show_indent ();
873 if (sym->hash_value)
874 fprintf (dumpfile, "hash: %d", sym->hash_value);
875 show_f2k_derived (sym->f2k_derived);
878 if (sym->formal)
880 show_indent ();
881 fputs ("Formal arglist:", dumpfile);
883 for (formal = sym->formal; formal; formal = formal->next)
885 if (formal->sym != NULL)
886 fprintf (dumpfile, " %s", formal->sym->name);
887 else
888 fputs (" [Alt Return]", dumpfile);
892 if (sym->formal_ns && (sym->formal_ns->proc_name != sym))
894 show_indent ();
895 fputs ("Formal namespace", dumpfile);
896 show_namespace (sym->formal_ns);
898 --show_level;
902 /* Show a user-defined operator. Just prints an operator
903 and the name of the associated subroutine, really. */
905 static void
906 show_uop (gfc_user_op *uop)
908 gfc_interface *intr;
910 show_indent ();
911 fprintf (dumpfile, "%s:", uop->name);
913 for (intr = uop->op; intr; intr = intr->next)
914 fprintf (dumpfile, " %s", intr->sym->name);
918 /* Workhorse function for traversing the user operator symtree. */
920 static void
921 traverse_uop (gfc_symtree *st, void (*func) (gfc_user_op *))
923 if (st == NULL)
924 return;
926 (*func) (st->n.uop);
928 traverse_uop (st->left, func);
929 traverse_uop (st->right, func);
933 /* Traverse the tree of user operator nodes. */
935 void
936 gfc_traverse_user_op (gfc_namespace *ns, void (*func) (gfc_user_op *))
938 traverse_uop (ns->uop_root, func);
942 /* Function to display a common block. */
944 static void
945 show_common (gfc_symtree *st)
947 gfc_symbol *s;
949 show_indent ();
950 fprintf (dumpfile, "common: /%s/ ", st->name);
952 s = st->n.common->head;
953 while (s)
955 fprintf (dumpfile, "%s", s->name);
956 s = s->common_next;
957 if (s)
958 fputs (", ", dumpfile);
960 fputc ('\n', dumpfile);
964 /* Worker function to display the symbol tree. */
966 static void
967 show_symtree (gfc_symtree *st)
969 int len, i;
971 show_indent ();
973 len = strlen(st->name);
974 fprintf (dumpfile, "symtree: '%s'", st->name);
976 for (i=len; i<12; i++)
977 fputc(' ', dumpfile);
979 if (st->ambiguous)
980 fputs( " Ambiguous", dumpfile);
982 if (st->n.sym->ns != gfc_current_ns)
983 fprintf (dumpfile, "|| symbol: '%s' from namespace '%s'", st->n.sym->name,
984 st->n.sym->ns->proc_name->name);
985 else
986 show_symbol (st->n.sym);
990 /******************* Show gfc_code structures **************/
993 /* Show a list of code structures. Mutually recursive with
994 show_code_node(). */
996 static void
997 show_code (int level, gfc_code *c)
999 for (; c; c = c->next)
1000 show_code_node (level, c);
1003 static void
1004 show_namelist (gfc_namelist *n)
1006 for (; n->next; n = n->next)
1007 fprintf (dumpfile, "%s,", n->sym->name);
1008 fprintf (dumpfile, "%s", n->sym->name);
1011 /* Show a single OpenMP directive node and everything underneath it
1012 if necessary. */
1014 static void
1015 show_omp_node (int level, gfc_code *c)
1017 gfc_omp_clauses *omp_clauses = NULL;
1018 const char *name = NULL;
1020 switch (c->op)
1022 case EXEC_OMP_ATOMIC: name = "ATOMIC"; break;
1023 case EXEC_OMP_BARRIER: name = "BARRIER"; break;
1024 case EXEC_OMP_CRITICAL: name = "CRITICAL"; break;
1025 case EXEC_OMP_FLUSH: name = "FLUSH"; break;
1026 case EXEC_OMP_DO: name = "DO"; break;
1027 case EXEC_OMP_MASTER: name = "MASTER"; break;
1028 case EXEC_OMP_ORDERED: name = "ORDERED"; break;
1029 case EXEC_OMP_PARALLEL: name = "PARALLEL"; break;
1030 case EXEC_OMP_PARALLEL_DO: name = "PARALLEL DO"; break;
1031 case EXEC_OMP_PARALLEL_SECTIONS: name = "PARALLEL SECTIONS"; break;
1032 case EXEC_OMP_PARALLEL_WORKSHARE: name = "PARALLEL WORKSHARE"; break;
1033 case EXEC_OMP_SECTIONS: name = "SECTIONS"; break;
1034 case EXEC_OMP_SINGLE: name = "SINGLE"; break;
1035 case EXEC_OMP_TASK: name = "TASK"; break;
1036 case EXEC_OMP_TASKWAIT: name = "TASKWAIT"; break;
1037 case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
1038 default:
1039 gcc_unreachable ();
1041 fprintf (dumpfile, "!$OMP %s", name);
1042 switch (c->op)
1044 case EXEC_OMP_DO:
1045 case EXEC_OMP_PARALLEL:
1046 case EXEC_OMP_PARALLEL_DO:
1047 case EXEC_OMP_PARALLEL_SECTIONS:
1048 case EXEC_OMP_SECTIONS:
1049 case EXEC_OMP_SINGLE:
1050 case EXEC_OMP_WORKSHARE:
1051 case EXEC_OMP_PARALLEL_WORKSHARE:
1052 case EXEC_OMP_TASK:
1053 omp_clauses = c->ext.omp_clauses;
1054 break;
1055 case EXEC_OMP_CRITICAL:
1056 if (c->ext.omp_name)
1057 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1058 break;
1059 case EXEC_OMP_FLUSH:
1060 if (c->ext.omp_namelist)
1062 fputs (" (", dumpfile);
1063 show_namelist (c->ext.omp_namelist);
1064 fputc (')', dumpfile);
1066 return;
1067 case EXEC_OMP_BARRIER:
1068 case EXEC_OMP_TASKWAIT:
1069 return;
1070 default:
1071 break;
1073 if (omp_clauses)
1075 int list_type;
1077 if (omp_clauses->if_expr)
1079 fputs (" IF(", dumpfile);
1080 show_expr (omp_clauses->if_expr);
1081 fputc (')', dumpfile);
1083 if (omp_clauses->num_threads)
1085 fputs (" NUM_THREADS(", dumpfile);
1086 show_expr (omp_clauses->num_threads);
1087 fputc (')', dumpfile);
1089 if (omp_clauses->sched_kind != OMP_SCHED_NONE)
1091 const char *type;
1092 switch (omp_clauses->sched_kind)
1094 case OMP_SCHED_STATIC: type = "STATIC"; break;
1095 case OMP_SCHED_DYNAMIC: type = "DYNAMIC"; break;
1096 case OMP_SCHED_GUIDED: type = "GUIDED"; break;
1097 case OMP_SCHED_RUNTIME: type = "RUNTIME"; break;
1098 case OMP_SCHED_AUTO: type = "AUTO"; break;
1099 default:
1100 gcc_unreachable ();
1102 fprintf (dumpfile, " SCHEDULE (%s", type);
1103 if (omp_clauses->chunk_size)
1105 fputc (',', dumpfile);
1106 show_expr (omp_clauses->chunk_size);
1108 fputc (')', dumpfile);
1110 if (omp_clauses->default_sharing != OMP_DEFAULT_UNKNOWN)
1112 const char *type;
1113 switch (omp_clauses->default_sharing)
1115 case OMP_DEFAULT_NONE: type = "NONE"; break;
1116 case OMP_DEFAULT_PRIVATE: type = "PRIVATE"; break;
1117 case OMP_DEFAULT_SHARED: type = "SHARED"; break;
1118 case OMP_DEFAULT_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1119 default:
1120 gcc_unreachable ();
1122 fprintf (dumpfile, " DEFAULT(%s)", type);
1124 if (omp_clauses->ordered)
1125 fputs (" ORDERED", dumpfile);
1126 if (omp_clauses->untied)
1127 fputs (" UNTIED", dumpfile);
1128 if (omp_clauses->collapse)
1129 fprintf (dumpfile, " COLLAPSE(%d)", omp_clauses->collapse);
1130 for (list_type = 0; list_type < OMP_LIST_NUM; list_type++)
1131 if (omp_clauses->lists[list_type] != NULL
1132 && list_type != OMP_LIST_COPYPRIVATE)
1134 const char *type;
1135 if (list_type >= OMP_LIST_REDUCTION_FIRST)
1137 switch (list_type)
1139 case OMP_LIST_PLUS: type = "+"; break;
1140 case OMP_LIST_MULT: type = "*"; break;
1141 case OMP_LIST_SUB: type = "-"; break;
1142 case OMP_LIST_AND: type = ".AND."; break;
1143 case OMP_LIST_OR: type = ".OR."; break;
1144 case OMP_LIST_EQV: type = ".EQV."; break;
1145 case OMP_LIST_NEQV: type = ".NEQV."; break;
1146 case OMP_LIST_MAX: type = "MAX"; break;
1147 case OMP_LIST_MIN: type = "MIN"; break;
1148 case OMP_LIST_IAND: type = "IAND"; break;
1149 case OMP_LIST_IOR: type = "IOR"; break;
1150 case OMP_LIST_IEOR: type = "IEOR"; break;
1151 default:
1152 gcc_unreachable ();
1154 fprintf (dumpfile, " REDUCTION(%s:", type);
1156 else
1158 switch (list_type)
1160 case OMP_LIST_PRIVATE: type = "PRIVATE"; break;
1161 case OMP_LIST_FIRSTPRIVATE: type = "FIRSTPRIVATE"; break;
1162 case OMP_LIST_LASTPRIVATE: type = "LASTPRIVATE"; break;
1163 case OMP_LIST_SHARED: type = "SHARED"; break;
1164 case OMP_LIST_COPYIN: type = "COPYIN"; break;
1165 default:
1166 gcc_unreachable ();
1168 fprintf (dumpfile, " %s(", type);
1170 show_namelist (omp_clauses->lists[list_type]);
1171 fputc (')', dumpfile);
1174 fputc ('\n', dumpfile);
1175 if (c->op == EXEC_OMP_SECTIONS || c->op == EXEC_OMP_PARALLEL_SECTIONS)
1177 gfc_code *d = c->block;
1178 while (d != NULL)
1180 show_code (level + 1, d->next);
1181 if (d->block == NULL)
1182 break;
1183 code_indent (level, 0);
1184 fputs ("!$OMP SECTION\n", dumpfile);
1185 d = d->block;
1188 else
1189 show_code (level + 1, c->block->next);
1190 if (c->op == EXEC_OMP_ATOMIC)
1191 return;
1192 code_indent (level, 0);
1193 fprintf (dumpfile, "!$OMP END %s", name);
1194 if (omp_clauses != NULL)
1196 if (omp_clauses->lists[OMP_LIST_COPYPRIVATE])
1198 fputs (" COPYPRIVATE(", dumpfile);
1199 show_namelist (omp_clauses->lists[OMP_LIST_COPYPRIVATE]);
1200 fputc (')', dumpfile);
1202 else if (omp_clauses->nowait)
1203 fputs (" NOWAIT", dumpfile);
1205 else if (c->op == EXEC_OMP_CRITICAL && c->ext.omp_name)
1206 fprintf (dumpfile, " (%s)", c->ext.omp_name);
1210 /* Show a single code node and everything underneath it if necessary. */
1212 static void
1213 show_code_node (int level, gfc_code *c)
1215 gfc_forall_iterator *fa;
1216 gfc_open *open;
1217 gfc_case *cp;
1218 gfc_alloc *a;
1219 gfc_code *d;
1220 gfc_close *close;
1221 gfc_filepos *fp;
1222 gfc_inquire *i;
1223 gfc_dt *dt;
1224 gfc_namespace *ns;
1226 if (c->here)
1228 fputc ('\n', dumpfile);
1229 code_indent (level, c->here);
1231 else
1232 show_indent ();
1234 switch (c->op)
1236 case EXEC_END_PROCEDURE:
1237 break;
1239 case EXEC_NOP:
1240 fputs ("NOP", dumpfile);
1241 break;
1243 case EXEC_CONTINUE:
1244 fputs ("CONTINUE", dumpfile);
1245 break;
1247 case EXEC_ENTRY:
1248 fprintf (dumpfile, "ENTRY %s", c->ext.entry->sym->name);
1249 break;
1251 case EXEC_INIT_ASSIGN:
1252 case EXEC_ASSIGN:
1253 fputs ("ASSIGN ", dumpfile);
1254 show_expr (c->expr1);
1255 fputc (' ', dumpfile);
1256 show_expr (c->expr2);
1257 break;
1259 case EXEC_LABEL_ASSIGN:
1260 fputs ("LABEL ASSIGN ", dumpfile);
1261 show_expr (c->expr1);
1262 fprintf (dumpfile, " %d", c->label1->value);
1263 break;
1265 case EXEC_POINTER_ASSIGN:
1266 fputs ("POINTER ASSIGN ", dumpfile);
1267 show_expr (c->expr1);
1268 fputc (' ', dumpfile);
1269 show_expr (c->expr2);
1270 break;
1272 case EXEC_GOTO:
1273 fputs ("GOTO ", dumpfile);
1274 if (c->label1)
1275 fprintf (dumpfile, "%d", c->label1->value);
1276 else
1278 show_expr (c->expr1);
1279 d = c->block;
1280 if (d != NULL)
1282 fputs (", (", dumpfile);
1283 for (; d; d = d ->block)
1285 code_indent (level, d->label1);
1286 if (d->block != NULL)
1287 fputc (',', dumpfile);
1288 else
1289 fputc (')', dumpfile);
1293 break;
1295 case EXEC_CALL:
1296 case EXEC_ASSIGN_CALL:
1297 if (c->resolved_sym)
1298 fprintf (dumpfile, "CALL %s ", c->resolved_sym->name);
1299 else if (c->symtree)
1300 fprintf (dumpfile, "CALL %s ", c->symtree->name);
1301 else
1302 fputs ("CALL ?? ", dumpfile);
1304 show_actual_arglist (c->ext.actual);
1305 break;
1307 case EXEC_COMPCALL:
1308 fputs ("CALL ", dumpfile);
1309 show_compcall (c->expr1);
1310 break;
1312 case EXEC_CALL_PPC:
1313 fputs ("CALL ", dumpfile);
1314 show_expr (c->expr1);
1315 show_actual_arglist (c->ext.actual);
1316 break;
1318 case EXEC_RETURN:
1319 fputs ("RETURN ", dumpfile);
1320 if (c->expr1)
1321 show_expr (c->expr1);
1322 break;
1324 case EXEC_PAUSE:
1325 fputs ("PAUSE ", dumpfile);
1327 if (c->expr1 != NULL)
1328 show_expr (c->expr1);
1329 else
1330 fprintf (dumpfile, "%d", c->ext.stop_code);
1332 break;
1334 case EXEC_ERROR_STOP:
1335 fputs ("ERROR ", dumpfile);
1336 /* Fall through. */
1338 case EXEC_STOP:
1339 fputs ("STOP ", dumpfile);
1341 if (c->expr1 != NULL)
1342 show_expr (c->expr1);
1343 else
1344 fprintf (dumpfile, "%d", c->ext.stop_code);
1346 break;
1348 case EXEC_SYNC_ALL:
1349 fputs ("SYNC ALL ", dumpfile);
1350 if (c->expr2 != NULL)
1352 fputs (" stat=", dumpfile);
1353 show_expr (c->expr2);
1355 if (c->expr3 != NULL)
1357 fputs (" errmsg=", dumpfile);
1358 show_expr (c->expr3);
1360 break;
1362 case EXEC_SYNC_MEMORY:
1363 fputs ("SYNC MEMORY ", dumpfile);
1364 if (c->expr2 != NULL)
1366 fputs (" stat=", dumpfile);
1367 show_expr (c->expr2);
1369 if (c->expr3 != NULL)
1371 fputs (" errmsg=", dumpfile);
1372 show_expr (c->expr3);
1374 break;
1376 case EXEC_SYNC_IMAGES:
1377 fputs ("SYNC IMAGES image-set=", dumpfile);
1378 if (c->expr1 != NULL)
1379 show_expr (c->expr1);
1380 else
1381 fputs ("* ", dumpfile);
1382 if (c->expr2 != NULL)
1384 fputs (" stat=", dumpfile);
1385 show_expr (c->expr2);
1387 if (c->expr3 != NULL)
1389 fputs (" errmsg=", dumpfile);
1390 show_expr (c->expr3);
1392 break;
1394 case EXEC_ARITHMETIC_IF:
1395 fputs ("IF ", dumpfile);
1396 show_expr (c->expr1);
1397 fprintf (dumpfile, " %d, %d, %d",
1398 c->label1->value, c->label2->value, c->label3->value);
1399 break;
1401 case EXEC_IF:
1402 d = c->block;
1403 fputs ("IF ", dumpfile);
1404 show_expr (d->expr1);
1406 ++show_level;
1407 show_code (level + 1, d->next);
1408 --show_level;
1410 d = d->block;
1411 for (; d; d = d->block)
1413 code_indent (level, 0);
1415 if (d->expr1 == NULL)
1416 fputs ("ELSE", dumpfile);
1417 else
1419 fputs ("ELSE IF ", dumpfile);
1420 show_expr (d->expr1);
1423 ++show_level;
1424 show_code (level + 1, d->next);
1425 --show_level;
1428 if (c->label1)
1429 code_indent (level, c->label1);
1430 else
1431 show_indent ();
1433 fputs ("ENDIF", dumpfile);
1434 break;
1436 case EXEC_BLOCK:
1438 const char* blocktype;
1439 if (c->ext.block.assoc)
1440 blocktype = "ASSOCIATE";
1441 else
1442 blocktype = "BLOCK";
1443 show_indent ();
1444 fprintf (dumpfile, "%s ", blocktype);
1445 ++show_level;
1446 ns = c->ext.block.ns;
1447 gfc_traverse_symtree (ns->sym_root, show_symtree);
1448 show_code (show_level, ns->code);
1449 --show_level;
1450 show_indent ();
1451 fprintf (dumpfile, "END %s ", blocktype);
1452 break;
1455 case EXEC_SELECT:
1456 d = c->block;
1457 fputs ("SELECT CASE ", dumpfile);
1458 show_expr (c->expr1);
1459 fputc ('\n', dumpfile);
1461 for (; d; d = d->block)
1463 code_indent (level, 0);
1465 fputs ("CASE ", dumpfile);
1466 for (cp = d->ext.case_list; cp; cp = cp->next)
1468 fputc ('(', dumpfile);
1469 show_expr (cp->low);
1470 fputc (' ', dumpfile);
1471 show_expr (cp->high);
1472 fputc (')', dumpfile);
1473 fputc (' ', dumpfile);
1475 fputc ('\n', dumpfile);
1477 show_code (level + 1, d->next);
1480 code_indent (level, c->label1);
1481 fputs ("END SELECT", dumpfile);
1482 break;
1484 case EXEC_WHERE:
1485 fputs ("WHERE ", dumpfile);
1487 d = c->block;
1488 show_expr (d->expr1);
1489 fputc ('\n', dumpfile);
1491 show_code (level + 1, d->next);
1493 for (d = d->block; d; d = d->block)
1495 code_indent (level, 0);
1496 fputs ("ELSE WHERE ", dumpfile);
1497 show_expr (d->expr1);
1498 fputc ('\n', dumpfile);
1499 show_code (level + 1, d->next);
1502 code_indent (level, 0);
1503 fputs ("END WHERE", dumpfile);
1504 break;
1507 case EXEC_FORALL:
1508 fputs ("FORALL ", dumpfile);
1509 for (fa = c->ext.forall_iterator; fa; fa = fa->next)
1511 show_expr (fa->var);
1512 fputc (' ', dumpfile);
1513 show_expr (fa->start);
1514 fputc (':', dumpfile);
1515 show_expr (fa->end);
1516 fputc (':', dumpfile);
1517 show_expr (fa->stride);
1519 if (fa->next != NULL)
1520 fputc (',', dumpfile);
1523 if (c->expr1 != NULL)
1525 fputc (',', dumpfile);
1526 show_expr (c->expr1);
1528 fputc ('\n', dumpfile);
1530 show_code (level + 1, c->block->next);
1532 code_indent (level, 0);
1533 fputs ("END FORALL", dumpfile);
1534 break;
1536 case EXEC_CRITICAL:
1537 fputs ("CRITICAL\n", dumpfile);
1538 show_code (level + 1, c->block->next);
1539 code_indent (level, 0);
1540 fputs ("END CRITICAL", dumpfile);
1541 break;
1543 case EXEC_DO:
1544 fputs ("DO ", dumpfile);
1545 if (c->label1)
1546 fprintf (dumpfile, " %-5d ", c->label1->value);
1548 show_expr (c->ext.iterator->var);
1549 fputc ('=', dumpfile);
1550 show_expr (c->ext.iterator->start);
1551 fputc (' ', dumpfile);
1552 show_expr (c->ext.iterator->end);
1553 fputc (' ', dumpfile);
1554 show_expr (c->ext.iterator->step);
1556 ++show_level;
1557 show_code (level + 1, c->block->next);
1558 --show_level;
1560 if (c->label1)
1561 break;
1563 show_indent ();
1564 fputs ("END DO", dumpfile);
1565 break;
1567 case EXEC_DO_WHILE:
1568 fputs ("DO WHILE ", dumpfile);
1569 show_expr (c->expr1);
1570 fputc ('\n', dumpfile);
1572 show_code (level + 1, c->block->next);
1574 code_indent (level, c->label1);
1575 fputs ("END DO", dumpfile);
1576 break;
1578 case EXEC_CYCLE:
1579 fputs ("CYCLE", dumpfile);
1580 if (c->symtree)
1581 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1582 break;
1584 case EXEC_EXIT:
1585 fputs ("EXIT", dumpfile);
1586 if (c->symtree)
1587 fprintf (dumpfile, " %s", c->symtree->n.sym->name);
1588 break;
1590 case EXEC_ALLOCATE:
1591 fputs ("ALLOCATE ", dumpfile);
1592 if (c->expr1)
1594 fputs (" STAT=", dumpfile);
1595 show_expr (c->expr1);
1598 if (c->expr2)
1600 fputs (" ERRMSG=", dumpfile);
1601 show_expr (c->expr2);
1604 for (a = c->ext.alloc.list; a; a = a->next)
1606 fputc (' ', dumpfile);
1607 show_expr (a->expr);
1610 break;
1612 case EXEC_DEALLOCATE:
1613 fputs ("DEALLOCATE ", dumpfile);
1614 if (c->expr1)
1616 fputs (" STAT=", dumpfile);
1617 show_expr (c->expr1);
1620 if (c->expr2)
1622 fputs (" ERRMSG=", dumpfile);
1623 show_expr (c->expr2);
1626 for (a = c->ext.alloc.list; a; a = a->next)
1628 fputc (' ', dumpfile);
1629 show_expr (a->expr);
1632 break;
1634 case EXEC_OPEN:
1635 fputs ("OPEN", dumpfile);
1636 open = c->ext.open;
1638 if (open->unit)
1640 fputs (" UNIT=", dumpfile);
1641 show_expr (open->unit);
1643 if (open->iomsg)
1645 fputs (" IOMSG=", dumpfile);
1646 show_expr (open->iomsg);
1648 if (open->iostat)
1650 fputs (" IOSTAT=", dumpfile);
1651 show_expr (open->iostat);
1653 if (open->file)
1655 fputs (" FILE=", dumpfile);
1656 show_expr (open->file);
1658 if (open->status)
1660 fputs (" STATUS=", dumpfile);
1661 show_expr (open->status);
1663 if (open->access)
1665 fputs (" ACCESS=", dumpfile);
1666 show_expr (open->access);
1668 if (open->form)
1670 fputs (" FORM=", dumpfile);
1671 show_expr (open->form);
1673 if (open->recl)
1675 fputs (" RECL=", dumpfile);
1676 show_expr (open->recl);
1678 if (open->blank)
1680 fputs (" BLANK=", dumpfile);
1681 show_expr (open->blank);
1683 if (open->position)
1685 fputs (" POSITION=", dumpfile);
1686 show_expr (open->position);
1688 if (open->action)
1690 fputs (" ACTION=", dumpfile);
1691 show_expr (open->action);
1693 if (open->delim)
1695 fputs (" DELIM=", dumpfile);
1696 show_expr (open->delim);
1698 if (open->pad)
1700 fputs (" PAD=", dumpfile);
1701 show_expr (open->pad);
1703 if (open->decimal)
1705 fputs (" DECIMAL=", dumpfile);
1706 show_expr (open->decimal);
1708 if (open->encoding)
1710 fputs (" ENCODING=", dumpfile);
1711 show_expr (open->encoding);
1713 if (open->round)
1715 fputs (" ROUND=", dumpfile);
1716 show_expr (open->round);
1718 if (open->sign)
1720 fputs (" SIGN=", dumpfile);
1721 show_expr (open->sign);
1723 if (open->convert)
1725 fputs (" CONVERT=", dumpfile);
1726 show_expr (open->convert);
1728 if (open->asynchronous)
1730 fputs (" ASYNCHRONOUS=", dumpfile);
1731 show_expr (open->asynchronous);
1733 if (open->err != NULL)
1734 fprintf (dumpfile, " ERR=%d", open->err->value);
1736 break;
1738 case EXEC_CLOSE:
1739 fputs ("CLOSE", dumpfile);
1740 close = c->ext.close;
1742 if (close->unit)
1744 fputs (" UNIT=", dumpfile);
1745 show_expr (close->unit);
1747 if (close->iomsg)
1749 fputs (" IOMSG=", dumpfile);
1750 show_expr (close->iomsg);
1752 if (close->iostat)
1754 fputs (" IOSTAT=", dumpfile);
1755 show_expr (close->iostat);
1757 if (close->status)
1759 fputs (" STATUS=", dumpfile);
1760 show_expr (close->status);
1762 if (close->err != NULL)
1763 fprintf (dumpfile, " ERR=%d", close->err->value);
1764 break;
1766 case EXEC_BACKSPACE:
1767 fputs ("BACKSPACE", dumpfile);
1768 goto show_filepos;
1770 case EXEC_ENDFILE:
1771 fputs ("ENDFILE", dumpfile);
1772 goto show_filepos;
1774 case EXEC_REWIND:
1775 fputs ("REWIND", dumpfile);
1776 goto show_filepos;
1778 case EXEC_FLUSH:
1779 fputs ("FLUSH", dumpfile);
1781 show_filepos:
1782 fp = c->ext.filepos;
1784 if (fp->unit)
1786 fputs (" UNIT=", dumpfile);
1787 show_expr (fp->unit);
1789 if (fp->iomsg)
1791 fputs (" IOMSG=", dumpfile);
1792 show_expr (fp->iomsg);
1794 if (fp->iostat)
1796 fputs (" IOSTAT=", dumpfile);
1797 show_expr (fp->iostat);
1799 if (fp->err != NULL)
1800 fprintf (dumpfile, " ERR=%d", fp->err->value);
1801 break;
1803 case EXEC_INQUIRE:
1804 fputs ("INQUIRE", dumpfile);
1805 i = c->ext.inquire;
1807 if (i->unit)
1809 fputs (" UNIT=", dumpfile);
1810 show_expr (i->unit);
1812 if (i->file)
1814 fputs (" FILE=", dumpfile);
1815 show_expr (i->file);
1818 if (i->iomsg)
1820 fputs (" IOMSG=", dumpfile);
1821 show_expr (i->iomsg);
1823 if (i->iostat)
1825 fputs (" IOSTAT=", dumpfile);
1826 show_expr (i->iostat);
1828 if (i->exist)
1830 fputs (" EXIST=", dumpfile);
1831 show_expr (i->exist);
1833 if (i->opened)
1835 fputs (" OPENED=", dumpfile);
1836 show_expr (i->opened);
1838 if (i->number)
1840 fputs (" NUMBER=", dumpfile);
1841 show_expr (i->number);
1843 if (i->named)
1845 fputs (" NAMED=", dumpfile);
1846 show_expr (i->named);
1848 if (i->name)
1850 fputs (" NAME=", dumpfile);
1851 show_expr (i->name);
1853 if (i->access)
1855 fputs (" ACCESS=", dumpfile);
1856 show_expr (i->access);
1858 if (i->sequential)
1860 fputs (" SEQUENTIAL=", dumpfile);
1861 show_expr (i->sequential);
1864 if (i->direct)
1866 fputs (" DIRECT=", dumpfile);
1867 show_expr (i->direct);
1869 if (i->form)
1871 fputs (" FORM=", dumpfile);
1872 show_expr (i->form);
1874 if (i->formatted)
1876 fputs (" FORMATTED", dumpfile);
1877 show_expr (i->formatted);
1879 if (i->unformatted)
1881 fputs (" UNFORMATTED=", dumpfile);
1882 show_expr (i->unformatted);
1884 if (i->recl)
1886 fputs (" RECL=", dumpfile);
1887 show_expr (i->recl);
1889 if (i->nextrec)
1891 fputs (" NEXTREC=", dumpfile);
1892 show_expr (i->nextrec);
1894 if (i->blank)
1896 fputs (" BLANK=", dumpfile);
1897 show_expr (i->blank);
1899 if (i->position)
1901 fputs (" POSITION=", dumpfile);
1902 show_expr (i->position);
1904 if (i->action)
1906 fputs (" ACTION=", dumpfile);
1907 show_expr (i->action);
1909 if (i->read)
1911 fputs (" READ=", dumpfile);
1912 show_expr (i->read);
1914 if (i->write)
1916 fputs (" WRITE=", dumpfile);
1917 show_expr (i->write);
1919 if (i->readwrite)
1921 fputs (" READWRITE=", dumpfile);
1922 show_expr (i->readwrite);
1924 if (i->delim)
1926 fputs (" DELIM=", dumpfile);
1927 show_expr (i->delim);
1929 if (i->pad)
1931 fputs (" PAD=", dumpfile);
1932 show_expr (i->pad);
1934 if (i->convert)
1936 fputs (" CONVERT=", dumpfile);
1937 show_expr (i->convert);
1939 if (i->asynchronous)
1941 fputs (" ASYNCHRONOUS=", dumpfile);
1942 show_expr (i->asynchronous);
1944 if (i->decimal)
1946 fputs (" DECIMAL=", dumpfile);
1947 show_expr (i->decimal);
1949 if (i->encoding)
1951 fputs (" ENCODING=", dumpfile);
1952 show_expr (i->encoding);
1954 if (i->pending)
1956 fputs (" PENDING=", dumpfile);
1957 show_expr (i->pending);
1959 if (i->round)
1961 fputs (" ROUND=", dumpfile);
1962 show_expr (i->round);
1964 if (i->sign)
1966 fputs (" SIGN=", dumpfile);
1967 show_expr (i->sign);
1969 if (i->size)
1971 fputs (" SIZE=", dumpfile);
1972 show_expr (i->size);
1974 if (i->id)
1976 fputs (" ID=", dumpfile);
1977 show_expr (i->id);
1980 if (i->err != NULL)
1981 fprintf (dumpfile, " ERR=%d", i->err->value);
1982 break;
1984 case EXEC_IOLENGTH:
1985 fputs ("IOLENGTH ", dumpfile);
1986 show_expr (c->expr1);
1987 goto show_dt_code;
1988 break;
1990 case EXEC_READ:
1991 fputs ("READ", dumpfile);
1992 goto show_dt;
1994 case EXEC_WRITE:
1995 fputs ("WRITE", dumpfile);
1997 show_dt:
1998 dt = c->ext.dt;
1999 if (dt->io_unit)
2001 fputs (" UNIT=", dumpfile);
2002 show_expr (dt->io_unit);
2005 if (dt->format_expr)
2007 fputs (" FMT=", dumpfile);
2008 show_expr (dt->format_expr);
2011 if (dt->format_label != NULL)
2012 fprintf (dumpfile, " FMT=%d", dt->format_label->value);
2013 if (dt->namelist)
2014 fprintf (dumpfile, " NML=%s", dt->namelist->name);
2016 if (dt->iomsg)
2018 fputs (" IOMSG=", dumpfile);
2019 show_expr (dt->iomsg);
2021 if (dt->iostat)
2023 fputs (" IOSTAT=", dumpfile);
2024 show_expr (dt->iostat);
2026 if (dt->size)
2028 fputs (" SIZE=", dumpfile);
2029 show_expr (dt->size);
2031 if (dt->rec)
2033 fputs (" REC=", dumpfile);
2034 show_expr (dt->rec);
2036 if (dt->advance)
2038 fputs (" ADVANCE=", dumpfile);
2039 show_expr (dt->advance);
2041 if (dt->id)
2043 fputs (" ID=", dumpfile);
2044 show_expr (dt->id);
2046 if (dt->pos)
2048 fputs (" POS=", dumpfile);
2049 show_expr (dt->pos);
2051 if (dt->asynchronous)
2053 fputs (" ASYNCHRONOUS=", dumpfile);
2054 show_expr (dt->asynchronous);
2056 if (dt->blank)
2058 fputs (" BLANK=", dumpfile);
2059 show_expr (dt->blank);
2061 if (dt->decimal)
2063 fputs (" DECIMAL=", dumpfile);
2064 show_expr (dt->decimal);
2066 if (dt->delim)
2068 fputs (" DELIM=", dumpfile);
2069 show_expr (dt->delim);
2071 if (dt->pad)
2073 fputs (" PAD=", dumpfile);
2074 show_expr (dt->pad);
2076 if (dt->round)
2078 fputs (" ROUND=", dumpfile);
2079 show_expr (dt->round);
2081 if (dt->sign)
2083 fputs (" SIGN=", dumpfile);
2084 show_expr (dt->sign);
2087 show_dt_code:
2088 for (c = c->block->next; c; c = c->next)
2089 show_code_node (level + (c->next != NULL), c);
2090 return;
2092 case EXEC_TRANSFER:
2093 fputs ("TRANSFER ", dumpfile);
2094 show_expr (c->expr1);
2095 break;
2097 case EXEC_DT_END:
2098 fputs ("DT_END", dumpfile);
2099 dt = c->ext.dt;
2101 if (dt->err != NULL)
2102 fprintf (dumpfile, " ERR=%d", dt->err->value);
2103 if (dt->end != NULL)
2104 fprintf (dumpfile, " END=%d", dt->end->value);
2105 if (dt->eor != NULL)
2106 fprintf (dumpfile, " EOR=%d", dt->eor->value);
2107 break;
2109 case EXEC_OMP_ATOMIC:
2110 case EXEC_OMP_BARRIER:
2111 case EXEC_OMP_CRITICAL:
2112 case EXEC_OMP_FLUSH:
2113 case EXEC_OMP_DO:
2114 case EXEC_OMP_MASTER:
2115 case EXEC_OMP_ORDERED:
2116 case EXEC_OMP_PARALLEL:
2117 case EXEC_OMP_PARALLEL_DO:
2118 case EXEC_OMP_PARALLEL_SECTIONS:
2119 case EXEC_OMP_PARALLEL_WORKSHARE:
2120 case EXEC_OMP_SECTIONS:
2121 case EXEC_OMP_SINGLE:
2122 case EXEC_OMP_TASK:
2123 case EXEC_OMP_TASKWAIT:
2124 case EXEC_OMP_WORKSHARE:
2125 show_omp_node (level, c);
2126 break;
2128 default:
2129 gfc_internal_error ("show_code_node(): Bad statement code");
2134 /* Show an equivalence chain. */
2136 static void
2137 show_equiv (gfc_equiv *eq)
2139 show_indent ();
2140 fputs ("Equivalence: ", dumpfile);
2141 while (eq)
2143 show_expr (eq->expr);
2144 eq = eq->eq;
2145 if (eq)
2146 fputs (", ", dumpfile);
2151 /* Show a freakin' whole namespace. */
2153 static void
2154 show_namespace (gfc_namespace *ns)
2156 gfc_interface *intr;
2157 gfc_namespace *save;
2158 int op;
2159 gfc_equiv *eq;
2160 int i;
2162 save = gfc_current_ns;
2164 show_indent ();
2165 fputs ("Namespace:", dumpfile);
2167 if (ns != NULL)
2169 i = 0;
2172 int l = i;
2173 while (i < GFC_LETTERS - 1
2174 && gfc_compare_types(&ns->default_type[i+1],
2175 &ns->default_type[l]))
2176 i++;
2178 if (i > l)
2179 fprintf (dumpfile, " %c-%c: ", l+'A', i+'A');
2180 else
2181 fprintf (dumpfile, " %c: ", l+'A');
2183 show_typespec(&ns->default_type[l]);
2184 i++;
2185 } while (i < GFC_LETTERS);
2187 if (ns->proc_name != NULL)
2189 show_indent ();
2190 fprintf (dumpfile, "procedure name = %s", ns->proc_name->name);
2193 ++show_level;
2194 gfc_current_ns = ns;
2195 gfc_traverse_symtree (ns->common_root, show_common);
2197 gfc_traverse_symtree (ns->sym_root, show_symtree);
2199 for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; op++)
2201 /* User operator interfaces */
2202 intr = ns->op[op];
2203 if (intr == NULL)
2204 continue;
2206 show_indent ();
2207 fprintf (dumpfile, "Operator interfaces for %s:",
2208 gfc_op2string ((gfc_intrinsic_op) op));
2210 for (; intr; intr = intr->next)
2211 fprintf (dumpfile, " %s", intr->sym->name);
2214 if (ns->uop_root != NULL)
2216 show_indent ();
2217 fputs ("User operators:\n", dumpfile);
2218 gfc_traverse_user_op (ns, show_uop);
2221 else
2222 ++show_level;
2224 for (eq = ns->equiv; eq; eq = eq->next)
2225 show_equiv (eq);
2227 fputc ('\n', dumpfile);
2228 show_indent ();
2229 fputs ("code:", dumpfile);
2230 show_code (show_level, ns->code);
2231 --show_level;
2233 for (ns = ns->contained; ns; ns = ns->sibling)
2235 fputs ("\nCONTAINS\n", dumpfile);
2236 ++show_level;
2237 show_namespace (ns);
2238 --show_level;
2241 fputc ('\n', dumpfile);
2242 gfc_current_ns = save;
2246 /* Main function for dumping a parse tree. */
2248 void
2249 gfc_dump_parse_tree (gfc_namespace *ns, FILE *file)
2251 dumpfile = file;
2252 show_namespace (ns);