This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] minor readability tweaks to print_node


This is a small readability tweak to the tree printer to have
it consistently use dashes and colons in tree attribute names
in favor of spaces.  It's been tested on x86_64-linux.

The tree printer tends to avoid using spaces to separate tree
attribute names (not the __attribute__ kind but things like
needs-constructing or pointer_to_this).  Instead it uses dashes
and underscores to separate words, and colons to separate integer
values from the attribute names.

In a small number of cases it does use a space which can make it
harder to read.  For instance a FUNCTION_DECL might be rendered
like so:

  <function_decl 0x7fffefbde800 g
     type <...>
     public external QI file /build/tmp/a.c line 14 col 13 user align 256>

In the last three attributes "user align 256" it's not completely
clear whether it's user, followed by align, followed by 256, or
user-align:256.

The attached patch replaces the handful of spaces between words
I noticed with dashes, and between words and numbers with colons.
It also fixes the above location to use the prevalent
file:line:column notation.

Martin
gcc/ChangeLog:

	* print-tree.c (print_node): Print location using the established
	format %s:%i%i.
	Replace spaces with colons.
	(debug_raw, debug): Ditto.

diff --git a/gcc/print-tree.c b/gcc/print-tree.c
index 6a237cc..30c8d72 100644
--- a/gcc/print-tree.c
+++ b/gcc/print-tree.c
@@ -444,13 +444,13 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 
 
       xloc = expand_location (DECL_SOURCE_LOCATION (node));
-      fprintf (file, " file %s line %d col %d", xloc.file, xloc.line,
+      fprintf (file, " %s:%d:%d", xloc.file, xloc.line,
 	       xloc.column);
 
       if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
 	{
 	  print_node (file, "size", DECL_SIZE (node), indent + 4);
-	  print_node (file, "unit size", DECL_SIZE_UNIT (node), indent + 4);
+	  print_node (file, "unit-size", DECL_SIZE_UNIT (node), indent + 4);
 
 	  if (code != FUNCTION_DECL || DECL_BUILT_IN (node))
 	    indent_to (file, indent + 3);
@@ -458,7 +458,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	  if (DECL_USER_ALIGN (node))
 	    fprintf (file, " user");
 
-	  fprintf (file, " align %d", DECL_ALIGN (node));
+	  fprintf (file, " align:%d", DECL_ALIGN (node));
 	  if (code == FIELD_DECL)
 	    fprintf (file, " offset_align " HOST_WIDE_INT_PRINT_UNSIGNED,
 		     DECL_OFFSET_ALIGN (node));
@@ -466,9 +466,9 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	  if (code == FUNCTION_DECL && DECL_BUILT_IN (node))
 	    {
 	      if (DECL_BUILT_IN_CLASS (node) == BUILT_IN_MD)
-		fprintf (file, " built-in BUILT_IN_MD %d", DECL_FUNCTION_CODE (node));
+		fprintf (file, " built-in: BUILT_IN_MD:%d", DECL_FUNCTION_CODE (node));
 	      else
-		fprintf (file, " built-in %s:%s",
+		fprintf (file, " built-in: %s:%s",
 			 built_in_class_names[(int) DECL_BUILT_IN_CLASS (node)],
 			 built_in_names[(int) DECL_FUNCTION_CODE (node)]);
 	    }
@@ -476,7 +476,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
       if (code == FIELD_DECL)
 	{
 	  print_node (file, "offset", DECL_FIELD_OFFSET (node), indent + 4);
-	  print_node (file, "bit offset", DECL_FIELD_BIT_OFFSET (node),
+	  print_node (file, "bit-offset", DECL_FIELD_BIT_OFFSET (node),
 		      indent + 4);
 	  if (DECL_BIT_FIELD_TYPE (node))
 	    print_node (file, "bit_field_type", DECL_BIT_FIELD_TYPE (node),
@@ -597,27 +597,27 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
       fprintf (file, " %s", GET_MODE_NAME (mode));
 
       print_node (file, "size", TYPE_SIZE (node), indent + 4);
-      print_node (file, "unit size", TYPE_SIZE_UNIT (node), indent + 4);
+      print_node (file, "unit-size", TYPE_SIZE_UNIT (node), indent + 4);
       indent_to (file, indent + 3);
 
       if (TYPE_USER_ALIGN (node))
 	fprintf (file, " user");
 
-      fprintf (file, " align %d symtab %d alias set " HOST_WIDE_INT_PRINT_DEC,
+      fprintf (file, " align:%d symtab:%d alias-set " HOST_WIDE_INT_PRINT_DEC,
 	       TYPE_ALIGN (node), TYPE_SYMTAB_ADDRESS (node),
 	       (HOST_WIDE_INT) TYPE_ALIAS_SET (node));
 
       if (TYPE_STRUCTURAL_EQUALITY_P (node))
-	fprintf (file, " structural equality");
+	fprintf (file, " structural-equality");
       else
-	dump_addr (file, " canonical type ", TYPE_CANONICAL (node));
+	dump_addr (file, " canonical-type ", TYPE_CANONICAL (node));
 
       print_node (file, "attributes", TYPE_ATTRIBUTES (node), indent + 4);
 
       if (INTEGRAL_TYPE_P (node) || code == REAL_TYPE
 	  || code == FIXED_POINT_TYPE)
 	{
-	  fprintf (file, " precision %d", TYPE_PRECISION (node));
+	  fprintf (file, " precision:%d", TYPE_PRECISION (node));
 	  print_node_brief (file, "min", TYPE_MIN_VALUE (node), indent + 4);
 	  print_node_brief (file, "max", TYPE_MAX_VALUE (node), indent + 4);
 	}
@@ -627,7 +627,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
       else if (code == ARRAY_TYPE)
 	print_node (file, "domain", TYPE_DOMAIN (node), indent + 4);
       else if (code == VECTOR_TYPE)
-	fprintf (file, " nunits %d", (int) TYPE_VECTOR_SUBPARTS (node));
+	fprintf (file, " nunits:%d", (int) TYPE_VECTOR_SUBPARTS (node));
       else if (code == RECORD_TYPE
 	       || code == UNION_TYPE
 	       || code == QUAL_UNION_TYPE)
@@ -686,7 +686,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	      /* Buffer big enough to format a 32-bit UINT_MAX into, plus
 		 the text.  */
 	      char temp[15];
-	      sprintf (temp, "arg %u", i);
+	      sprintf (temp, "arg:%u", i);
 	      print_node (file, temp, arg, indent + 4);
 	      i++;
 	    }
@@ -701,7 +701,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 		 the text.  */
 	      char temp[15];
 
-	      sprintf (temp, "arg %d", i);
+	      sprintf (temp, "arg:%d", i);
 	      print_node (file, temp, TREE_OPERAND (node, i), indent + 4);
 	    }
 	}
@@ -771,9 +771,9 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 		    break;
 		j--;
 		if (i == j)
-		  sprintf (buf, "elt%u: ", i);
+		  sprintf (buf, "elt:%u: ", i);
 		else
-		  sprintf (buf, "elt%u...elt%u: ", i, j);
+		  sprintf (buf, "elt:%u...%u: ", i, j);
 		print_node (file, buf, VECTOR_CST_ELT (node, i), indent + 4);
 		i = j;
 	      }
@@ -814,14 +814,14 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 
 	case TREE_VEC:
 	  len = TREE_VEC_LENGTH (node);
-	  fprintf (file, " length %d", len);
+	  fprintf (file, " length:%d", len);
 	  for (i = 0; i < len; i++)
 	    if (TREE_VEC_ELT (node, i))
 	      {
 	      /* Buffer big enough to format a 32-bit UINT_MAX into, plus
 		 the text.  */
 		char temp[15];
-		sprintf (temp, "elt %d", i);
+		sprintf (temp, "elt:%d", i);
 		print_node (file, temp, TREE_VEC_ELT (node, i), indent + 4);
 	      }
 	  break;
@@ -831,7 +831,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	    unsigned HOST_WIDE_INT cnt;
 	    tree index, value;
 	    len = CONSTRUCTOR_NELTS (node);
-	    fprintf (file, " lngt %d", len);
+	    fprintf (file, " length:%d", len);
 	    FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node),
 				      cnt, index, value)
 	      {
@@ -885,7 +885,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	  }
 
 	  indent_to (file, indent + 4);
-	  fprintf (file, "version %u", SSA_NAME_VERSION (node));
+	  fprintf (file, "version:%u", SSA_NAME_VERSION (node));
 	  if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (node))
 	    fprintf (file, " in-abnormal-phi");
 	  if (SSA_NAME_IN_FREE_LIST (node))
@@ -907,7 +907,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	      for (i = 0; i < omp_clause_num_ops[OMP_CLAUSE_CODE (node)]; i++)
 		{
 		  indent_to (file, indent + 4);
-		  fprintf (file, "op %d:", i);
+		  fprintf (file, "op-%d:", i);
 		  print_node_brief (file, "", OMP_CLAUSE_OPERAND (node, i), 0);
 		}
 	    }
@@ -921,19 +921,19 @@ print_node (FILE *file, const char *prefix, tree node, int indent,
 	  cl_target_option_print (file, indent + 4, TREE_TARGET_OPTION (node));
 	  break;
 	case IMPORTED_DECL:
-	  fprintf (file, " imported declaration");
-	  print_node_brief (file, "associated declaration",
+	  fprintf (file, " imported-declaration");
+	  print_node_brief (file, "associated-declaration",
 			    IMPORTED_DECL_ASSOCIATED_DECL (node),
 			    indent + 4);
 	  break;
 
 	case TREE_BINFO:
-	  fprintf (file, " bases %d",
+	  fprintf (file, " bases:%d",
 		   vec_safe_length (BINFO_BASE_BINFOS (node)));
 	  print_node_brief (file, "offset", BINFO_OFFSET (node), indent + 4);
 	  print_node_brief (file, "virtuals", BINFO_VIRTUALS (node),
 			    indent + 4);
-	  print_node_brief (file, "inheritance chain",
+	  print_node_brief (file, "inheritance-chain",
 			    BINFO_INHERITANCE_CHAIN (node),
 			    indent + 4);
 	  break;
@@ -1086,7 +1086,7 @@ debug_raw (vec<tree, va_gc> &ref)
 
   FOR_EACH_VEC_ELT (ref, ix, elt)
     {
-      fprintf (stderr, "elt %d ", ix);
+      fprintf (stderr, "elt:%d ", ix);
       debug_raw (elt);
     }
 }
@@ -1103,7 +1103,7 @@ debug (vec<tree, va_gc> &ref)
 
   FOR_EACH_VEC_ELT (ref, ix, elt)
     {
-      fprintf (stderr, "elt %d ", ix);
+      fprintf (stderr, "elt:%d ", ix);
       debug (elt);
     }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]