OSDN Git Service

2010-09-06 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / fortran / dump-parse-tree.c
index 26a8e08..14cd3bc 100644 (file)
@@ -1,5 +1,5 @@
 /* Parse tree dumper
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Steven Bosscher
 
@@ -32,7 +32,9 @@ along with GCC; see the file COPYING3.  If not see
    TODO: Dump DATA.  */
 
 #include "config.h"
+#include "system.h"
 #include "gfortran.h"
+#include "constructor.h"
 
 /* Keep track of indentation for symbol tree dumps.  */
 static int show_level = 0;
@@ -47,6 +49,20 @@ static void show_code_node (int, gfc_code *);
 static void show_namespace (gfc_namespace *ns);
 
 
+/* Allow dumping of an expression in the debugger.  */
+void gfc_debug_expr (gfc_expr *);
+
+void
+gfc_debug_expr (gfc_expr *e)
+{
+  FILE *tmp = dumpfile;
+  dumpfile = stderr;
+  show_expr (e);
+  fputc ('\n', dumpfile);
+  dumpfile = tmp;
+}
+
+
 /* Do indentation for a specific level.  */
 
 static inline void
@@ -85,11 +101,11 @@ show_typespec (gfc_typespec *ts)
   switch (ts->type)
     {
     case BT_DERIVED:
-      fprintf (dumpfile, "%s", ts->derived->name);
+      fprintf (dumpfile, "%s", ts->u.derived->name);
       break;
 
     case BT_CHARACTER:
-      show_expr (ts->cl->length);
+      show_expr (ts->u.cl->length);
       break;
 
     default:
@@ -141,9 +157,9 @@ show_array_spec (gfc_array_spec *as)
       return;
     }
 
-  fprintf (dumpfile, "(%d", as->rank);
+  fprintf (dumpfile, "(%d [%d]", as->rank, as->corank);
 
-  if (as->rank != 0)
+  if (as->rank + as->corank > 0)
     {
       switch (as->type)
       {
@@ -157,7 +173,7 @@ show_array_spec (gfc_array_spec *as)
       }
       fprintf (dumpfile, " %s ", c);
 
-      for (i = 0; i < as->rank; i++)
+      for (i = 0; i < as->rank + as->corank; i++)
        {
          show_expr (as->lower[i]);
          fputc (' ', dumpfile);
@@ -271,9 +287,10 @@ show_ref (gfc_ref *p)
 /* Display a constructor.  Works recursively for array constructors.  */
 
 static void
-show_constructor (gfc_constructor *c)
+show_constructor (gfc_constructor_base base)
 {
-  for (; c; c = c->next)
+  gfc_constructor *c;
+  for (c = gfc_constructor_first (base); c; c = gfc_constructor_next (c))
     {
       if (c->iterator == NULL)
        show_expr (c->expr);
@@ -294,7 +311,7 @@ show_constructor (gfc_constructor *c)
          fputc (')', dumpfile);
        }
 
-      if (c->next != NULL)
+      if (gfc_constructor_next (c) != NULL)
        fputs (" , ", dumpfile);
     }
 }
@@ -354,7 +371,7 @@ show_expr (gfc_expr *p)
       break;
 
     case EXPR_STRUCTURE:
-      fprintf (dumpfile, "%s(", p->ts.derived->name);
+      fprintf (dumpfile, "%s(", p->ts.u.derived->name);
       show_constructor (p->value.constructor);
       fputc (')', dumpfile);
       break;
@@ -402,13 +419,15 @@ show_expr (gfc_expr *p)
        case BT_COMPLEX:
          fputs ("(complex ", dumpfile);
 
-         mpfr_out_str (stdout, 10, 0, p->value.complex.r, GFC_RND_MODE);
+         mpfr_out_str (stdout, 10, 0, mpc_realref (p->value.complex),
+                       GFC_RND_MODE);
          if (p->ts.kind != gfc_default_complex_kind)
            fprintf (dumpfile, "_%d", p->ts.kind);
 
          fputc (' ', dumpfile);
 
-         mpfr_out_str (stdout, 10, 0, p->value.complex.i, GFC_RND_MODE);
+         mpfr_out_str (stdout, 10, 0, mpc_imagref (p->value.complex),
+                       GFC_RND_MODE);
          if (p->ts.kind != gfc_default_complex_kind)
            fprintf (dumpfile, "_%d", p->ts.kind);
 
@@ -542,7 +561,7 @@ show_expr (gfc_expr *p)
       if (p->value.function.name == NULL)
        {
          fprintf (dumpfile, "%s", p->symtree->n.sym->name);
-         if (is_proc_ptr_comp (p, NULL))
+         if (gfc_is_proc_ptr_comp (p, NULL))
            show_ref (p->ref);
          fputc ('[', dumpfile);
          show_actual_arglist (p->value.function.actual);
@@ -551,7 +570,7 @@ show_expr (gfc_expr *p)
       else
        {
          fprintf (dumpfile, "%s", p->value.function.name);
-         if (is_proc_ptr_comp (p, NULL))
+         if (gfc_is_proc_ptr_comp (p, NULL))
            show_ref (p->ref);
          fputc ('[', dumpfile);
          fputc ('[', dumpfile);
@@ -587,8 +606,14 @@ show_attr (symbol_attribute *attr)
 
   if (attr->allocatable)
     fputs (" ALLOCATABLE", dumpfile);
+  if (attr->asynchronous)
+    fputs (" ASYNCHRONOUS", dumpfile);
+  if (attr->codimension)
+    fputs (" CODIMENSION", dumpfile);
   if (attr->dimension)
     fputs (" DIMENSION", dumpfile);
+  if (attr->contiguous)
+    fputs (" CONTIGUOUS", dumpfile);
   if (attr->external)
     fputs (" EXTERNAL", dumpfile);
   if (attr->intrinsic)
@@ -678,40 +703,39 @@ show_components (gfc_symbol *sym)
 /* Show the f2k_derived namespace with procedure bindings.  */
 
 static void
-show_typebound (gfc_symtree* st)
+show_typebound_proc (gfc_typebound_proc* tb, const char* name)
 {
-  gcc_assert (st->n.tb);
   show_indent ();
 
-  if (st->n.tb->is_generic)
+  if (tb->is_generic)
     fputs ("GENERIC", dumpfile);
   else
     {
       fputs ("PROCEDURE, ", dumpfile);
-      if (st->n.tb->nopass)
+      if (tb->nopass)
        fputs ("NOPASS", dumpfile);
       else
        {
-         if (st->n.tb->pass_arg)
-           fprintf (dumpfile, "PASS(%s)", st->n.tb->pass_arg);
+         if (tb->pass_arg)
+           fprintf (dumpfile, "PASS(%s)", tb->pass_arg);
          else
            fputs ("PASS", dumpfile);
        }
-      if (st->n.tb->non_overridable)
+      if (tb->non_overridable)
        fputs (", NON_OVERRIDABLE", dumpfile);
     }
 
-  if (st->n.tb->access == ACCESS_PUBLIC)
+  if (tb->access == ACCESS_PUBLIC)
     fputs (", PUBLIC", dumpfile);
   else
     fputs (", PRIVATE", dumpfile);
 
-  fprintf (dumpfile, " :: %s => ", st->name);
+  fprintf (dumpfile, " :: %s => ", name);
 
-  if (st->n.tb->is_generic)
+  if (tb->is_generic)
     {
       gfc_tbp_generic* g;
-      for (g = st->n.tb->u.generic; g; g = g->next)
+      for (g = tb->u.generic; g; g = g->next)
        {
          fputs (g->specific_st->name, dumpfile);
          if (g->next)
@@ -719,14 +743,24 @@ show_typebound (gfc_symtree* st)
        }
     }
   else
-    fputs (st->n.tb->u.specific->n.sym->name, dumpfile);
+    fputs (tb->u.specific->n.sym->name, dumpfile);
+}
+
+static void
+show_typebound_symtree (gfc_symtree* st)
+{
+  gcc_assert (st->n.tb);
+  show_typebound_proc (st->n.tb, st->name);
 }
 
 static void
 show_f2k_derived (gfc_namespace* f2k)
 {
   gfc_finalizer* f;
+  int op;
 
+  show_indent ();
+  fputs ("Procedure bindings:", dumpfile);
   ++show_level;
 
   /* Finalizer bindings.  */
@@ -737,7 +771,22 @@ show_f2k_derived (gfc_namespace* f2k)
     }
 
   /* Type-bound procedures.  */
-  gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound);
+  gfc_traverse_symtree (f2k->tb_sym_root, &show_typebound_symtree);
+
+  --show_level;
+
+  show_indent ();
+  fputs ("Operator bindings:", dumpfile);
+  ++show_level;
+
+  /* User-defined operators.  */
+  gfc_traverse_symtree (f2k->tb_uop_root, &show_typebound_symtree);
+
+  /* Intrinsic operators.  */
+  for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
+    if (f2k->tb_op[op])
+      show_typebound_proc (f2k->tb_op[op],
+                          gfc_op2string ((gfc_intrinsic_op) op));
 
   --show_level;
 }
@@ -761,6 +810,15 @@ show_symbol (gfc_symbol *sym)
 
   fprintf (dumpfile, "symbol %s ", sym->name);
   show_typespec (&sym->ts);
+
+  /* If this symbol is an associate-name, show its target expression.  */
+  if (sym->assoc)
+    {
+      fputs (" => ", dumpfile);
+      show_expr (sym->assoc->target);
+      fputs (" ", dumpfile);
+    }
+
   show_attr (&sym->attr);
 
   if (sym->value)
@@ -801,7 +859,8 @@ show_symbol (gfc_symbol *sym)
   if (sym->f2k_derived)
     {
       show_indent ();
-      fputs ("Procedure bindings:\n", dumpfile);
+      if (sym->hash_value)
+       fprintf (dumpfile, "hash: %d", sym->hash_value);
       show_f2k_derived (sym->f2k_derived);
     }
 
@@ -819,7 +878,7 @@ show_symbol (gfc_symbol *sym)
        }
     }
 
-  if (sym->formal_ns)
+  if (sym->formal_ns && (sym->formal_ns->proc_name != sym))
     {
       show_indent ();
       fputs ("Formal namespace", dumpfile);
@@ -1141,6 +1200,7 @@ show_code_node (int level, gfc_code *c)
   gfc_filepos *fp;
   gfc_inquire *i;
   gfc_dt *dt;
+  gfc_namespace *ns;
 
   code_indent (level, c->here);
 
@@ -1244,6 +1304,10 @@ show_code_node (int level, gfc_code *c)
 
       break;
 
+    case EXEC_ERROR_STOP:
+      fputs ("ERROR ", dumpfile);
+      /* Fall through.  */
+
     case EXEC_STOP:
       fputs ("STOP ", dumpfile);
 
@@ -1254,6 +1318,52 @@ show_code_node (int level, gfc_code *c)
 
       break;
 
+    case EXEC_SYNC_ALL:
+      fputs ("SYNC ALL ", dumpfile);
+      if (c->expr2 != NULL)
+       {
+         fputs (" stat=", dumpfile);
+         show_expr (c->expr2);
+       }
+      if (c->expr3 != NULL)
+       {
+         fputs (" errmsg=", dumpfile);
+         show_expr (c->expr3);
+       }
+      break;
+
+    case EXEC_SYNC_MEMORY:
+      fputs ("SYNC MEMORY ", dumpfile);
+      if (c->expr2 != NULL)
+       {
+         fputs (" stat=", dumpfile);
+         show_expr (c->expr2);
+       }
+      if (c->expr3 != NULL)
+       {
+         fputs (" errmsg=", dumpfile);
+         show_expr (c->expr3);
+       }
+      break;
+
+    case EXEC_SYNC_IMAGES:
+      fputs ("SYNC IMAGES  image-set=", dumpfile);
+      if (c->expr1 != NULL)
+       show_expr (c->expr1);
+      else
+       fputs ("* ", dumpfile);
+      if (c->expr2 != NULL)
+       {
+         fputs (" stat=", dumpfile);
+         show_expr (c->expr2);
+       }
+      if (c->expr3 != NULL)
+       {
+         fputs (" errmsg=", dumpfile);
+         show_expr (c->expr3);
+       }
+      break;
+
     case EXEC_ARITHMETIC_IF:
       fputs ("IF ", dumpfile);
       show_expr (c->expr1);
@@ -1290,6 +1400,22 @@ show_code_node (int level, gfc_code *c)
       fputs ("ENDIF", dumpfile);
       break;
 
+    case EXEC_BLOCK:
+      {
+       const char* blocktype;
+       if (c->ext.block.assoc)
+         blocktype = "ASSOCIATE";
+       else
+         blocktype = "BLOCK";
+       show_indent ();
+       fprintf (dumpfile, "%s ", blocktype);
+       ns = c->ext.block.ns;
+       show_namespace (ns);
+       show_indent ();
+       fprintf (dumpfile, "END %s ", blocktype);
+       break;
+      }
+
     case EXEC_SELECT:
       d = c->block;
       fputs ("SELECT CASE ", dumpfile);
@@ -1371,6 +1497,13 @@ show_code_node (int level, gfc_code *c)
       fputs ("END FORALL", dumpfile);
       break;
 
+    case EXEC_CRITICAL:
+      fputs ("CRITICAL\n", dumpfile);
+      show_code (level + 1, c->block->next);
+      code_indent (level, 0);
+      fputs ("END CRITICAL", dumpfile);
+      break;
+
     case EXEC_DO:
       fputs ("DO ", dumpfile);
 
@@ -1420,7 +1553,13 @@ show_code_node (int level, gfc_code *c)
          show_expr (c->expr1);
        }
 
-      for (a = c->ext.alloc_list; a; a = a->next)
+      if (c->expr2)
+       {
+         fputs (" ERRMSG=", dumpfile);
+         show_expr (c->expr2);
+       }
+
+      for (a = c->ext.alloc.list; a; a = a->next)
        {
          fputc (' ', dumpfile);
          show_expr (a->expr);
@@ -1436,7 +1575,13 @@ show_code_node (int level, gfc_code *c)
          show_expr (c->expr1);
        }
 
-      for (a = c->ext.alloc_list; a; a = a->next)
+      if (c->expr2)
+       {
+         fputs (" ERRMSG=", dumpfile);
+         show_expr (c->expr2);
+       }
+
+      for (a = c->ext.alloc.list; a; a = a->next)
        {
          fputc (' ', dumpfile);
          show_expr (a->expr);
@@ -2041,7 +2186,7 @@ show_namespace (gfc_namespace *ns)
   fputc ('\n', dumpfile);
   fputc ('\n', dumpfile);
 
-  show_code (0, ns->code);
+  show_code (show_level, ns->code);
 
   for (ns = ns->contained; ns; ns = ns->sibling)
     {