[committed][lto merge]: Enhance pretty printer for types

Diego Novillo dnovillo@google.com
Fri Apr 17 21:28:00 GMT 2009


This patch adds some new features to the pretty printer: ability
to print complex types, fixed point, floating point and
structures.  It also fixes the handling of TREE_BINFO.

Bootstrapped and tested on x86_64.  Committed to mainline.


Diego.



	* tree-pretty-print.c (dump_generic_node): Add break
	after TREE_BINFO handler.
	Handle COMPLEX_TYPE, REAL_TYPE and FIXED_POINT_TYPE
	Handle NULL TREE_TYPEs.
	Handle METHOD_TYPE and FUNCTION_TYPE together.
	Call print_struct_decl when printing structures and
	TDF_SLIM is not given.
	(print_struct_decl): Fix logic for detecting recursion.

Index: tree-pretty-print.c
===================================================================
--- tree-pretty-print.c	(revision 146292)
+++ tree-pretty-print.c	(working copy)
@@ -488,6 +488,7 @@ dump_generic_node (pretty_printer *buffe

     case TREE_BINFO:
       dump_generic_node (buffer, BINFO_TYPE (node), spc, flags, false);
+      break;

     case TREE_VEC:
       {
@@ -551,8 +552,7 @@ dump_generic_node (pretty_printer *buffe
 	    else if (TREE_CODE (node) == VECTOR_TYPE)
 	      {
 		pp_string (buffer, "vector ");
-		dump_generic_node (buffer, TREE_TYPE (node),
-				   spc, flags, false);
+		dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
 	      }
 	    else if (TREE_CODE (node) == INTEGER_TYPE)
 	      {
@@ -562,6 +562,24 @@ dump_generic_node (pretty_printer *buffe
 		pp_decimal_int (buffer, TYPE_PRECISION (node));
 		pp_string (buffer, ">");
 	      }
+	    else if (TREE_CODE (node) == COMPLEX_TYPE)
+	      {
+		pp_string (buffer, "__complex__ ");
+		dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
+	      }
+	    else if (TREE_CODE (node) == REAL_TYPE)
+	      {
+		pp_string (buffer, "<float:");
+		pp_decimal_int (buffer, TYPE_PRECISION (node));
+		pp_string (buffer, ">");
+	      }
+	    else if (TREE_CODE (node) == FIXED_POINT_TYPE)
+	      {
+		pp_string (buffer, "<fixed-point-");
+		pp_string (buffer, TYPE_SATURATING (node) ? "sat:" : "nonsat:");
+		pp_decimal_int (buffer, TYPE_PRECISION (node));
+		pp_string (buffer, ">");
+	      }
 	    else
               pp_string (buffer, "<unnamed type>");
 	  }
@@ -572,7 +590,12 @@ dump_generic_node (pretty_printer *buffe
     case REFERENCE_TYPE:
       str = (TREE_CODE (node) == POINTER_TYPE ? "*" : "&");

-      if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
+      if (TREE_TYPE (node) == NULL)
+        {
+	  pp_string (buffer, str);
+          pp_string (buffer, "<null type>");
+        }
+      else if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
         {
 	  tree fnode = TREE_TYPE (node);

@@ -612,11 +635,6 @@ dump_generic_node (pretty_printer *buffe
       NIY;
       break;

-    case METHOD_TYPE:
-      dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)), flags);
-      pp_string (buffer, "::");
-      break;
-
     case TARGET_MEM_REF:
       {
 	const char *sep = "";
@@ -710,7 +728,12 @@ dump_generic_node (pretty_printer *buffe

         if (TYPE_NAME (node))
 	  dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
-        else
+	else if (!(flags & TDF_SLIM))
+	  /* FIXME: If we eliminate the 'else' above and attempt
+	     to show the fields for named types, we may get stuck
+	     following a cycle of pointers to structs.  The alleged
+	     self-reference check in print_struct_decl will not detect
+	     cycles involving more than one pointer or struct type.  */
 	  print_struct_decl (buffer, node, spc, flags);
         break;
       }
@@ -836,6 +859,23 @@ dump_generic_node (pretty_printer *buffe
       break;

     case FUNCTION_TYPE:
+    case METHOD_TYPE:
+      dump_generic_node (buffer, TREE_TYPE (node), spc, flags, false);
+      pp_space (buffer);
+      if (TREE_CODE (node) == METHOD_TYPE)
+	{
+	  if (TYPE_METHOD_BASETYPE (node))
+	    dump_decl_name (buffer, TYPE_NAME (TYPE_METHOD_BASETYPE (node)),
+			    flags);
+	  else
+	    pp_string (buffer, "<null method basetype>");
+	  pp_string (buffer, "::");
+	}
+      if (TYPE_NAME (node) && DECL_NAME (TYPE_NAME (node)))
+	dump_decl_name (buffer, TYPE_NAME (node), flags);
+      else
+	pp_printf (buffer, "<T%x>", TYPE_UID (node));
+      dump_function_declaration (buffer, node, spc, flags);
       break;

     case FUNCTION_DECL:
@@ -2206,8 +2246,8 @@ print_struct_decl (pretty_printer *buffe
 	   Maybe this could be solved by looking at the scope in which the
 	   structure was declared.  */
 	if (TREE_TYPE (tmp) != node
-	    || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE
-		&& TREE_TYPE (TREE_TYPE (tmp)) != node))
+	    && (TREE_CODE (TREE_TYPE (tmp)) != POINTER_TYPE
+		|| TREE_TYPE (TREE_TYPE (tmp)) != node))
 	  {
 	    print_declaration (buffer, tmp, spc+2, flags);
 	    pp_newline (buffer);



More information about the Gcc-patches mailing list