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]

[AST-optimizer-branch] C++ pretty printer


Hi,

This begins the implementation of the pretty-printer for the C++ front-end.

This implementation allows to define specific behaviour for C++ nodes, and in order
to take profit from the existing C pretty-printer, the default behaviour is to call 
the C pretty-printer.  

I looked for a preprocessor variable that allows to determine wether we compile the
C or the C++ frontend, but it seems that it doesn't exist.  So I switched on another
solution : use 2 call back function pointers.  That is a little tricky, but once we 
finished the implementation of pretty printers, we can duplicate code from dump_c_node
into dump_cp_node and avoid so much calls and the 2 function pointers. 

I began to implement some nodes for the C++ front-end, but as said this is only the 
beginning.

This patch fixes also the pretty printing of strings by replacing new lines by "\n", ...
and fixes the printing of function declarations (by including some bytes from c-call-graph.c).

Seb.


2002-04-16  Sebastian Pop  <s.pop@laposte.net>
	* c-pretty-print.c : s/dump_c_node/DUMP_NODE/
	(print_call_name) : New function based on c-call-graph.c.
	(pretty_print_string) : New function.
	(INDENT, NIY) : deleted, declared in pretty-printers.h.
	(pretty-printers.h) : included.
	(dump_c_node, print_declaration, print_function_decl, print_struct_decl) :
	Add 2 function pointers in parameters list.
	* c-tree.h : remove declaration of pretty printers functions.
	* cp/Make-lang.in : Add rules for cp/cp-pretty-print.o.
	* pretty-printers.h : New file.
	* cp/cp-pretty-print.c : New file.


Index: c-pretty-print.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/Attic/c-pretty-print.c,v
retrieving revision 1.1.2.3
diff -d -u -p -r1.1.2.3 c-pretty-print.c
--- c-pretty-print.c	1 Mar 2002 23:56:04 -0000	1.1.2.3
+++ c-pretty-print.c	16 Apr 2002 18:27:31 -0000
@@ -1,5 +1,5 @@
 /* Pretty formatting of a tree in C syntax.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    Contributed by Sebastian Pop <s.pop@laposte.net>
 
 This file is part of GCC.
@@ -26,25 +26,13 @@ Software Foundation, 59 Temple Place - S
 #include "c-tree.h"
 #include "c-common.h"
 #include "diagnostic.h"
+#include "pretty-printers.h"
 
-/* To be declared in a .h after diagnostic.h since output_buffer is used.  
-   Or we can declare them in diagnostic.h ?  */
-extern void dump_c_tree PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
-extern int dump_c_node PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
-extern void print_declaration PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
-extern void print_function_decl PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
-extern void print_struct_decl PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
-
-static int op_prio PARAMS ((tree));
-static const char *op_symbol PARAMS ((tree));
-
-#define INDENT(SPACE) do { \
-  int i; for (i = 0; i<SPACE; i++) output_add_space (buffer); } while (0)
-#define NIY do { \
-  debug_output_buffer (buffer); debug_tree (node); abort (); } while (0)
-
-
-
+static int op_prio                      PARAMS ((tree));
+static const char *op_symbol            PARAMS ((tree));
+static void print_declaration           PARAMS ((output_buffer *, tree, HOST_WIDE_INT, void *, void *));
+static void print_call_name             PARAMS ((output_buffer *, tree));
+static void pretty_print_string         PARAMS ((output_buffer *, const char*));
 /* Print the tree T in full, on file FILE.  */
  
 void 
@@ -73,7 +61,7 @@ print_c_node (file, t)
 
   init_output_buffer (buffer, /* prefix */NULL, /* line-width */0);
   output_clear_message_text (buffer);
-  dump_c_node (buffer, t, 0);
+  dump_c_node (buffer, t, 0, (void *) dump_c_node, (void *) dump_c_tree);
   fprintf (file, "%s", output_finalize_message (buffer));
 }
 
@@ -106,7 +94,7 @@ dump_c_tree (buffer, t, spc)
   tree node = t;
   while (node && node != error_mark_node)
     {
-      spc = dump_c_node (buffer, node, spc);
+      spc = dump_c_node (buffer, node, spc, (void *) dump_c_node, (void *) dump_c_tree);
       switch (TREE_CODE (node))
 	{
 	case TYPE_DECL:
@@ -126,10 +114,11 @@ dump_c_tree (buffer, t, spc)
 /* Dump the node NODE on the output_buffer BUFFER, SPC spaces of indent.  */
 
 int
-dump_c_node (buffer, node, spc)
+dump_c_node (buffer, node, spc, dump_node_fn, dump_tree_fn)
      output_buffer *buffer;
      tree node;
      HOST_WIDE_INT spc;
+     void *dump_node_fn, *dump_tree_fn;
 {
   tree type;
   tree op0, op1;
@@ -153,10 +142,10 @@ dump_c_node (buffer, node, spc)
 	{
 	  if (TREE_PURPOSE (node))
 	    {
-	      dump_c_node (buffer, TREE_PURPOSE (node), spc);
+	      DUMP_NODE (buffer, TREE_PURPOSE (node), spc);
 	      output_add_space (buffer);
 	    }
-	  dump_c_node (buffer, TREE_VALUE (node), spc);
+	  DUMP_NODE (buffer, TREE_VALUE (node), spc);
 	  node = TREE_CHAIN (node);
 	  if (node && TREE_CODE (node) == TREE_LIST)
 	    {
@@ -167,7 +156,7 @@ dump_c_node (buffer, node, spc)
       break;
 
     case TREE_VEC:
-      dump_c_node (buffer, BINFO_TYPE (node), spc);
+      DUMP_NODE (buffer, BINFO_TYPE (node), spc);
       break;
 
     case BLOCK:
@@ -214,7 +203,7 @@ dump_c_node (buffer, node, spc)
 	break;
       }
     case POINTER_TYPE:
-      dump_c_node (buffer, TREE_TYPE (node), spc);
+      DUMP_NODE (buffer, TREE_TYPE (node), spc);
       output_add_string (buffer, " *");
       break;
 
@@ -223,14 +212,11 @@ dump_c_node (buffer, node, spc)
 
     case REFERENCE_TYPE:
       /* FIXME : What is the exact syntax of this node for C? */
-      dump_c_node (buffer, TREE_TYPE (node), spc);
+      DUMP_NODE (buffer, TREE_TYPE (node), spc);
       break;
 
     case METHOD_TYPE:
-      output_add_string (buffer, IDENTIFIER_POINTER 
-			 (DECL_NAME (TYPE_NAME (TYPE_METHOD_BASETYPE (node)))));
-      output_add_string (buffer, "::");
-      break;
+      NIY;
 
     case FILE_TYPE:
       NIY;
@@ -240,7 +226,7 @@ dump_c_node (buffer, node, spc)
 	tree tmp;
 
 	/* Print the array type.  */
-	dump_c_node (buffer, TREE_TYPE (node), spc);
+	DUMP_NODE (buffer, TREE_TYPE (node), spc);
 
 	/* Print the dimensions.  */
 	tmp = node;
@@ -269,7 +255,7 @@ dump_c_node (buffer, node, spc)
 	  else if (TREE_CODE (node) == UNION_TYPE)
 	    output_add_string (buffer, "union ");
 
-	  dump_c_node (buffer, TYPE_NAME (node), spc);
+	  DUMP_NODE (buffer, TYPE_NAME (node), spc);
 	}
       /* Don't print the contents of the structure since the user don't asked 
 	 for explicitly.  */
@@ -329,10 +315,8 @@ dump_c_node (buffer, node, spc)
       NIY;
 
     case STRING_CST:
-      /* FIXME : We have to parse the string and replace new-lines by "\n" 
-	 tabs by "\t", ...  */
       output_add_string (buffer, "\"");
-      output_add_string (buffer, TREE_STRING_POINTER (node));
+      pretty_print_string (buffer, TREE_STRING_POINTER (node));
       output_add_string (buffer, "\"");
       break;
 
@@ -340,14 +324,14 @@ dump_c_node (buffer, node, spc)
       if (!DECL_INITIAL (node))
 	/* Print the prototype of the function.  */
 	{
-	  INDENT (spc);
+	  INDENT (buffer, spc);
 	  
 	  /* Print the return type.  */
-	  dump_c_node (buffer, TREE_TYPE (TREE_TYPE (node)), spc);
+	  DUMP_NODE (buffer, TREE_TYPE (TREE_TYPE (node)), spc);
 	  output_add_space (buffer);
 
 	  /* Print the namespace.  */
-	  dump_c_node (buffer, TREE_TYPE (node), spc);
+	  DUMP_NODE (buffer, TREE_TYPE (node), spc);
 	  	  
 	  /* Print the function name.  */
 	  output_add_string (buffer, IDENTIFIER_POINTER (DECL_NAME (node)));
@@ -360,7 +344,7 @@ dump_c_node (buffer, node, spc)
 	    tree tmp = TYPE_ARG_TYPES (TREE_TYPE (node));
 	    while (tmp && TREE_CHAIN (tmp) && tmp != error_mark_node)
 	      {
-		dump_c_node (buffer, TREE_VALUE (tmp), spc);
+		DUMP_NODE (buffer, TREE_VALUE (tmp), spc);
 		tmp = TREE_CHAIN (tmp);
 		if (TREE_CHAIN (tmp) && TREE_CODE (TREE_CHAIN (tmp)) == TREE_LIST)
 		  {
@@ -373,17 +357,16 @@ dump_c_node (buffer, node, spc)
 	  output_add_character (buffer, ';');
 	}
       else
+	/* Print the function, its arguments and its body.  */
 	{
-	  /* Print the function, its arguments and its body.  */
-
 	  /* Print the return type of the function.  */
-	  INDENT (spc);
-	  dump_c_node (buffer, DECL_RESULT (node), spc);
+	  INDENT (buffer, spc);
+	  DUMP_NODE (buffer, DECL_RESULT (node), spc);
 	  output_add_space (buffer);
 	  
 	  /* In C++ TREE_TYPE (node) could be a METHOD_TYPE containing the
 	     namespace.  Otherwise it's a FUNCTION_TYPE.  */
-	  dump_c_node (buffer, TREE_TYPE (node), spc);
+	  DUMP_NODE (buffer, TREE_TYPE (node), spc);
 	  
 	  /* Print the name of the function.  */
 	  output_add_string (buffer, IDENTIFIER_POINTER (DECL_NAME (node)));
@@ -404,10 +387,10 @@ dump_c_node (buffer, node, spc)
 			TYPE_METHOD_BASETYPE (TREE_TYPE (node))))
 		  {
 		    /* Print the type.  */
-		    dump_c_node (buffer, TREE_TYPE (tmp), spc);
+		    DUMP_NODE (buffer, TREE_TYPE (tmp), spc);
 		    output_add_space (buffer);
 		    /* Print the argument.  */
-		    dump_c_node (buffer, tmp, spc);
+		    DUMP_NODE (buffer, tmp, spc);
 		    tmp = TREE_CHAIN (tmp);
 		    if (tmp)
 		      {
@@ -423,7 +406,7 @@ dump_c_node (buffer, node, spc)
 	  
 	  /* And finally, print the body.  */
 	  output_add_newline (buffer);
-	  dump_c_node (buffer, DECL_SAVED_TREE (node), spc);
+	  DUMP_NODE (buffer, DECL_SAVED_TREE (node), spc);
 	}
       output_add_newline (buffer);
       break;
@@ -454,15 +437,15 @@ dump_c_node (buffer, node, spc)
 	    {
 	      /* The caller is a c++ function : all structures have at least 
 		 4 methods. */
-	      INDENT (spc);
+	      INDENT (buffer, spc);
 	      output_add_string (buffer, "class ");
-	      dump_c_node (buffer, TREE_TYPE (node), spc);
+	      DUMP_NODE (buffer, TREE_TYPE (node), spc);
 	    }
 	  else
 	    {
-	      INDENT (spc);
+	      INDENT (buffer, spc);
 	      output_add_string (buffer, "struct ");
-	      dump_c_node (buffer, TREE_TYPE (node), spc);
+	      DUMP_NODE (buffer, TREE_TYPE (node), spc);
 	      output_add_character (buffer, ';');
 	      output_add_newline (buffer);
 	    }
@@ -476,7 +459,7 @@ dump_c_node (buffer, node, spc)
       break;
 
     case RESULT_DECL:
-      dump_c_node (buffer, TREE_TYPE (node), spc);      
+      DUMP_NODE (buffer, TREE_TYPE (node), spc);      
       break;
 
     case FIELD_DECL:
@@ -490,9 +473,9 @@ dump_c_node (buffer, node, spc)
       break;
 
     case COMPONENT_REF:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_character (buffer, '.');
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       break;
 
     case BIT_FIELD_REF:
@@ -503,9 +486,9 @@ dump_c_node (buffer, node, spc)
 
     case ARRAY_REF:
       op0 = TREE_OPERAND (node, 0);
-      dump_c_node (buffer, op0, spc);
+      DUMP_NODE (buffer, op0, spc);
       output_add_character (buffer, '[');
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_character (buffer, ']');
       break;
 
@@ -514,23 +497,23 @@ dump_c_node (buffer, node, spc)
 
     case CONSTRUCTOR:
       output_add_character (buffer, '{');
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_character (buffer, '}');
       break;
 
     case COMPOUND_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_character (buffer, ',');
       output_add_space (buffer);
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       break;
 
     case MODIFY_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_space (buffer);
       output_add_character (buffer, '=');
       output_add_space (buffer);
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       break;
 
     case INIT_EXPR:
@@ -540,30 +523,31 @@ dump_c_node (buffer, node, spc)
       NIY;
 
     case COND_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_space (buffer);
       output_add_character (buffer, '?');
       output_add_space (buffer);
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_space (buffer);
       output_add_character (buffer, ':');
       output_add_space (buffer);
-      dump_c_node (buffer, TREE_OPERAND (node, 2), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 2), spc);
       break;
 
     case BIND_EXPR:
       NIY;
 
     case CALL_EXPR:
-      output_add_string (buffer, 
-	                 IDENTIFIER_POINTER (DECL_NAME 
-			   (TREE_OPERAND (TREE_OPERAND (node, 0), 0))));
+      print_call_name (buffer, node);
+
+      /* Print parameters.  */
       output_add_space (buffer);
       output_add_character (buffer, '(');
       op1 = TREE_OPERAND (node, 1);
       if (op1)
-	dump_c_node (buffer, op1, 0);
+	DUMP_NODE (buffer, op1, 0);
       output_add_character (buffer, ')');
+
       break;
 
     case METHOD_CALL_EXPR:
@@ -629,11 +613,11 @@ dump_c_node (buffer, node, spc)
 	if (op_prio (op0) < op_prio (node))
 	  {
 	    output_add_character (buffer, '(');
-	    dump_c_node (buffer, op0, spc);
+	    DUMP_NODE (buffer, op0, spc);
 	    output_add_character (buffer, ')');
 	  }
 	else
-	  dump_c_node (buffer, op0, spc);
+	  DUMP_NODE (buffer, op0, spc);
 
 	output_add_space (buffer);
 	output_add_string (buffer, op);
@@ -644,11 +628,11 @@ dump_c_node (buffer, node, spc)
 	if (op_prio (op1) < op_prio (node))
 	  {
 	    output_add_character (buffer, '(');
-	    dump_c_node (buffer, op1, spc);
+	    DUMP_NODE (buffer, op1, spc);
 	    output_add_character (buffer, ')');
 	  }
 	else
-	  dump_c_node (buffer, op1, spc);
+	  DUMP_NODE (buffer, op1, spc);
       }
       break;
 
@@ -657,7 +641,7 @@ dump_c_node (buffer, node, spc)
     case FIX_FLOOR_EXPR:
     case FIX_ROUND_EXPR:
     case FLOAT_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);	  
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);	  
       break;
 
       /* Unary arithmetic and logic expressions.  */
@@ -669,21 +653,27 @@ dump_c_node (buffer, node, spc)
     case PREDECREMENT_EXPR:
     case PREINCREMENT_EXPR:
     case INDIRECT_REF:
-      if (TREE_CODE (node) == ADDR_EXPR
-	  && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
-	      || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
-	;	/* Do not output '&' for strings and function pointers.  */
+      if (
+	  /* Do not output '&' for strings and function pointers.  */
+	  (TREE_CODE (node) == ADDR_EXPR &&
+	   (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST ||
+	    TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL)) ||
+	  /* Don't print '*' for parameters passed by reference in C++.  */
+	  (TREE_CODE (node) == INDIRECT_REF &&
+	   /* TREE_CODE (TREE_OPERAND (node, 0)) == PARM_DECL && */
+	   TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == REFERENCE_TYPE))
+	;	
       else
 	output_add_string (buffer, op_symbol (node));
 
       if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
 	{
 	  output_add_character (buffer, '(');
-	  dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+	  DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
 	  output_add_character (buffer, ')');
 	}
       else
-	dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+	DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case POSTDECREMENT_EXPR:
@@ -691,43 +681,43 @@ dump_c_node (buffer, node, spc)
       if (op_prio (TREE_OPERAND (node, 0)) < op_prio (node))
 	{
 	  output_add_character (buffer, '(');
-	  dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+	  DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
 	  output_add_character (buffer, ')');
 	}
       else
-	dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+	DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, op_symbol (node));
       break;
 
     case MIN_EXPR:
       /* #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))  */
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " < ");
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_string (buffer, " ? ");
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " : ");
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       break;
 
     case MAX_EXPR:
       /* #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))  */
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " > ");
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_string (buffer, " ? ");
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " : ");
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       break;
 
     case ABS_EXPR:
       /* n < 0 ? -n : n */
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " < 0 ? -");
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_string (buffer, " : ");
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
       
     case FFS_EXPR:
@@ -759,22 +749,22 @@ dump_c_node (buffer, node, spc)
 	  /* Get the pointed-to type.  */
 	  type = TREE_TYPE (type);
 	  output_add_character (buffer, '(');
-	  dump_c_node (buffer, type, spc);
+	  DUMP_NODE (buffer, type, spc);
 	  output_add_string (buffer, " *)");
 	}
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case NON_LVALUE_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case SAVE_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case UNSAVE_EXPR:
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case RTL_EXPR:
@@ -808,8 +798,8 @@ dump_c_node (buffer, node, spc)
       NIY;
 
     case LABEL_EXPR:
-      INDENT (spc);
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      INDENT (buffer, spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_character (buffer, ':');
       output_add_character (buffer, ';');
       output_add_newline (buffer);
@@ -831,8 +821,8 @@ dump_c_node (buffer, node, spc)
       NIY;
 
     case EXPR_WITH_FILE_LOCATION:
-      INDENT (spc);
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      INDENT (buffer, spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       break;
 
     case SWITCH_EXPR:
@@ -856,51 +846,51 @@ dump_c_node (buffer, node, spc)
       NIY;
 
     case EXPR_STMT:
-      INDENT (spc);
-      dump_c_node (buffer, EXPR_STMT_EXPR (node), spc);
+      INDENT (buffer, spc);
+      DUMP_NODE (buffer, EXPR_STMT_EXPR (node), spc);
       output_add_character (buffer, ';');
       output_add_newline (buffer);
       break;
 
     case COMPOUND_STMT:
-      dump_c_tree (buffer, COMPOUND_BODY (node), spc);
+      DUMP_TREE (buffer, COMPOUND_BODY (node), spc);
       break;
 
     case DECL_STMT:
       break;
 
     case IF_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "if (");
-      dump_c_node (buffer, IF_COND (node), spc);
+      DUMP_NODE (buffer, IF_COND (node), spc);
       output_add_character (buffer, ')');
       output_add_newline (buffer);
-      dump_c_node (buffer, THEN_CLAUSE (node), spc+2);
+      DUMP_NODE (buffer, THEN_CLAUSE (node), spc+2);
       if (ELSE_CLAUSE (node))
 	{
-	  INDENT (spc);
+	  INDENT (buffer, spc);
 	  output_add_string (buffer, "else");
 	  output_add_newline (buffer);
-	  dump_c_node (buffer, ELSE_CLAUSE (node), spc+2);
+	  DUMP_NODE (buffer, ELSE_CLAUSE (node), spc+2);
 	}
       break;
 
     case FOR_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "for (");
       if (FOR_INIT_STMT (node))
-	dump_c_node (buffer, EXPR_STMT_EXPR (FOR_INIT_STMT (node)), 0);
+	DUMP_NODE (buffer, EXPR_STMT_EXPR (FOR_INIT_STMT (node)), 0);
       output_add_character (buffer, ';');
       output_add_space (buffer);
-      dump_c_node (buffer, FOR_COND (node), 0);
+      DUMP_NODE (buffer, FOR_COND (node), 0);
       output_add_character (buffer, ';');
       output_add_space (buffer);
-      dump_c_node (buffer, FOR_EXPR (node), 0);
+      DUMP_NODE (buffer, FOR_EXPR (node), 0);
       output_add_character (buffer, ')');
       if (FOR_BODY (node))
 	{
 	  output_add_newline (buffer);
-	  dump_c_node (buffer, FOR_BODY (node), spc+2);
+	  DUMP_NODE (buffer, FOR_BODY (node), spc+2);
 	}
       else
 	{ 
@@ -910,90 +900,90 @@ dump_c_node (buffer, node, spc)
       break;
 
     case WHILE_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "while (");
-      dump_c_node (buffer, WHILE_COND (node), spc);
+      DUMP_NODE (buffer, WHILE_COND (node), spc);
       output_add_character (buffer, ')');
       output_add_newline (buffer);
-      dump_c_node (buffer, WHILE_BODY (node), spc+2);
+      DUMP_NODE (buffer, WHILE_BODY (node), spc+2);
       break;
 
     case DO_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "do");
       output_add_newline (buffer);
-      dump_c_node (buffer, DO_BODY (node), spc+2);
-      INDENT (spc);
+      DUMP_NODE (buffer, DO_BODY (node), spc+2);
+      INDENT (buffer, spc);
       output_add_string (buffer, "while (");
-      dump_c_node (buffer, DO_COND (node), spc);
+      DUMP_NODE (buffer, DO_COND (node), spc);
       output_add_character (buffer, ')');
       output_add_character (buffer, ';');
       output_add_newline (buffer);
       break;
 
     case RETURN_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "return");
       if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) != VOID_TYPE)
 	{
 	  output_add_space (buffer);
 	  if (TREE_CODE (RETURN_EXPR (node)) == MODIFY_EXPR)
-	    dump_c_node (buffer, TREE_OPERAND (RETURN_EXPR (node), 1), spc);
+	    DUMP_NODE (buffer, TREE_OPERAND (RETURN_EXPR (node), 1), spc);
 	  else
-	    dump_c_node (buffer, RETURN_EXPR (node), spc);
+	    DUMP_NODE (buffer, RETURN_EXPR (node), spc);
 	}
       output_add_character (buffer, ';');
       output_add_newline (buffer);
       break;
 
     case BREAK_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "break;");
       output_add_newline (buffer);
       break;
 
     case CONTINUE_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "continue;");
       output_add_newline (buffer);
       break;
 
     case SWITCH_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "switch (");
-      dump_c_node (buffer, SWITCH_COND (node), spc);
+      DUMP_NODE (buffer, SWITCH_COND (node), spc);
       output_add_character (buffer, ')');
       output_add_newline (buffer);
-      dump_c_node (buffer, SWITCH_BODY (node), spc+2);
+      DUMP_NODE (buffer, SWITCH_BODY (node), spc+2);
       break;
 
     case GOTO_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "goto ");
-      dump_c_node (buffer, GOTO_DESTINATION (node), spc);
+      DUMP_NODE (buffer, GOTO_DESTINATION (node), spc);
       output_add_character (buffer, ';');
       output_add_newline (buffer);
       break;
 
     case LABEL_STMT:
-      INDENT (spc);
-      dump_c_node (buffer, TREE_OPERAND (node, 0), spc);
+      INDENT (buffer, spc-2);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 0), spc);
       output_add_character (buffer, ':');
       output_add_character (buffer, ';');
       output_add_newline (buffer);
       break;
 
     case ASM_STMT:
-      INDENT (spc);
+      INDENT (buffer, spc);
       output_add_string (buffer, "__asm__");
       if (ASM_VOLATILE_P (node))
 	output_add_string (buffer, " __volatile__");
       output_add_character (buffer, '(');
-      dump_c_node (buffer, TREE_OPERAND (node, 1), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 1), spc);
       output_add_character (buffer, ':');
-      dump_c_node (buffer, TREE_OPERAND (node, 2), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 2), spc);
       output_add_character (buffer, ':');
-      dump_c_node (buffer, TREE_OPERAND (node, 3), spc);
+      DUMP_NODE (buffer, TREE_OPERAND (node, 3), spc);
       output_add_string (buffer, ");");
       output_add_newline (buffer);      
       break;
@@ -1001,7 +991,7 @@ dump_c_node (buffer, node, spc)
     case SCOPE_STMT:
       if (SCOPE_BEGIN_P (node))
 	{
-	  INDENT (spc);
+	  INDENT (buffer, spc);
 	  output_add_character (buffer, '{');
 	  output_add_newline (buffer);
 	  spc += 2;
@@ -1012,7 +1002,7 @@ dump_c_node (buffer, node, spc)
 	      /* Walk through the BLOCK_VARS and print declarations.  */
 	      while (iter)
 		{
-		  print_declaration (buffer, iter, spc);
+		  print_declaration (buffer, iter, spc, dump_node_fn, dump_tree_fn);
 		  iter = TREE_CHAIN (iter);
 		}
 	    }
@@ -1020,25 +1010,25 @@ dump_c_node (buffer, node, spc)
       else
 	{
 	  spc -= 2;
-	  INDENT (spc);
+	  INDENT (buffer, spc);
 	  output_add_character (buffer, '}');
 	  output_add_newline (buffer);
 	}
       break;
 
     case CASE_LABEL:
-      INDENT (spc-2);
+      INDENT (buffer, spc-2);
       if (CASE_LOW (node) && CASE_HIGH (node))
 	{
 	  output_add_string (buffer, "case ");
-	  dump_c_node (buffer, CASE_LOW (node), spc);
+	  DUMP_NODE (buffer, CASE_LOW (node), spc);
 	  output_add_string (buffer, " ... ");
-	  dump_c_node (buffer, CASE_HIGH (node), spc);
+	  DUMP_NODE (buffer, CASE_HIGH (node), spc);
 	}
       else if (CASE_LOW (node))
 	{
 	  output_add_string (buffer, "case ");
-	  dump_c_node (buffer, CASE_LOW (node), spc);
+	  DUMP_NODE (buffer, CASE_LOW (node), spc);
 	}
       else
 	output_add_string (buffer, "default ");
@@ -1049,8 +1039,8 @@ dump_c_node (buffer, node, spc)
     case STMT_EXPR:
       output_add_character (buffer, '(');
       output_add_newline (buffer);
-      dump_c_node (buffer, STMT_EXPR_STMT (node), spc);
-      INDENT (spc);
+      DUMP_NODE (buffer, STMT_EXPR_STMT (node), spc);
+      INDENT (buffer, spc);
       output_add_character (buffer, ')');
       break;
 
@@ -1070,17 +1060,18 @@ dump_c_node (buffer, node, spc)
 
 /* Print the declaration of a variable.  */
 
-void
-print_declaration (buffer, t, spc)
+static void
+print_declaration (buffer, t, spc, dump_node_fn, dump_tree_fn)
      output_buffer *buffer;
      tree t;
      HOST_WIDE_INT spc;
+     void *dump_node_fn, *dump_tree_fn;
 {
   /* Don't print type declarations.  */
   if (TREE_CODE (t) == TYPE_DECL)
     return;
       
-  INDENT (spc);
+  INDENT (buffer, spc);
   
   if (DECL_REGISTER (t))
     output_add_string (buffer, "register ");
@@ -1094,11 +1085,12 @@ print_declaration (buffer, t, spc)
       tmp = TREE_TYPE (t);
       while (TREE_CODE (TREE_TYPE (tmp)) == ARRAY_TYPE)
 	tmp = TREE_TYPE (tmp);
-      dump_c_node (buffer, TREE_TYPE (tmp), spc);
+
+      DUMP_NODE (buffer, TREE_TYPE (tmp), spc);
       
       /* Print variable's name.  */
       output_add_space (buffer);
-      dump_c_node (buffer, t, spc);
+      DUMP_NODE (buffer, t, spc);
       
       /* Print the dimensions.  */
       tmp = TREE_TYPE (t);
@@ -1115,11 +1107,11 @@ print_declaration (buffer, t, spc)
   else
     {
       /* Print type declaration.  */
-      dump_c_node (buffer, TREE_TYPE (t), spc);
+      DUMP_NODE (buffer, TREE_TYPE (t), spc);
       
       /* Print variable's name.  */
       output_add_space (buffer);
-      dump_c_node (buffer, t, spc);
+      DUMP_NODE (buffer, t, spc);
     }
   
   /* The initial value of a function serves to determine wether the function 
@@ -1133,7 +1125,7 @@ print_declaration (buffer, t, spc)
 	  output_add_space (buffer);
 	  output_add_character (buffer, '=');
 	  output_add_space (buffer);
-	  dump_c_node (buffer, DECL_INITIAL (t), spc);
+	  DUMP_NODE (buffer, DECL_INITIAL (t), spc);
 	}
     }
   
@@ -1145,23 +1137,31 @@ print_declaration (buffer, t, spc)
 /* Print the declaration of a function given its declaration node.  */
 
 void
-print_function_decl (buffer, node, spc)
+print_function_decl (buffer, node, spc, dump_node_fn, dump_tree_fn)
      output_buffer *buffer;
      tree node;
      HOST_WIDE_INT spc;
+     void *dump_node_fn, *dump_tree_fn;
 {
   if (TREE_CODE_CLASS (TREE_CODE (node)) != 'd')
     NIY;
   
-  INDENT (spc);
+  INDENT (buffer, spc);
 
   /* Print the return type.  */
-  dump_c_node (buffer, TREE_TYPE (TREE_TYPE (node)), 0);
+  DUMP_NODE (buffer, TREE_TYPE (TREE_TYPE (node)), 0);
   output_add_space (buffer);
-  /* Print the namespace.  */
-  dump_c_node (buffer, TREE_TYPE (node), 0);
+
+  if (TREE_TYPE (node))
+    /* Print the namespace.  */
+    {
+      DUMP_NODE (buffer, TREE_TYPE (node), 0);
+      /* Print function name.  */
+      output_add_string (buffer, "::");
+    }
+
   /* Print function name.  */
-  output_printf (buffer, "::%s (", TREE_CODE (node) == NOP_EXPR ?
+  output_printf (buffer, "%s (", TREE_CODE (node) == NOP_EXPR ?
 		 IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (node, 0))) :
 		 IDENTIFIER_POINTER (DECL_NAME (node)));
   
@@ -1170,7 +1170,7 @@ print_function_decl (buffer, node, spc)
     tree tmp = TYPE_ARG_TYPES (TREE_TYPE (node));
     while (tmp && TREE_CHAIN (tmp) && tmp != error_mark_node)
       {
-	dump_c_node (buffer, TREE_VALUE (tmp), 0);
+	DUMP_NODE (buffer, TREE_VALUE (tmp), 0);
 	tmp = TREE_CHAIN (tmp);
 	if (TREE_CHAIN (tmp) && TREE_CODE (TREE_CHAIN (tmp)) == TREE_LIST)
 	  {
@@ -1186,27 +1186,28 @@ print_function_decl (buffer, node, spc)
    FIXME : Not Implemented Yet correctly.  */
 
 void 
-print_struct_decl (buffer, node, spc)
+print_struct_decl (buffer, node, spc, dump_node_fn, dump_tree_fn)
      output_buffer *buffer;
      tree node;
      HOST_WIDE_INT spc;
+     void *dump_node_fn, *dump_tree_fn;
 {
   /* Print the name of the structure.  */
   if (TYPE_NAME (node))
     {
-      INDENT (spc);
+      INDENT (buffer, spc);
       if (TREE_CODE (node) == RECORD_TYPE)
 	output_add_string (buffer, "struct ");
       else if (TREE_CODE (node) == UNION_TYPE)
 	output_add_string (buffer, "union ");
       else
 	NIY;
-      dump_c_node (buffer, TYPE_NAME (node), spc);
+      DUMP_NODE (buffer, TYPE_NAME (node), spc);
     }
 
   /* Print the contents of the structure.  */  
   output_add_newline (buffer);
-  INDENT (spc);
+  INDENT (buffer, spc);
   output_add_character (buffer, '{');
   output_add_newline (buffer);
   
@@ -1224,7 +1225,7 @@ print_struct_decl (buffer, node, spc)
 	if (TREE_TYPE (tmp) != node 
 	    || (TREE_CODE (TREE_TYPE (tmp)) == POINTER_TYPE && 
 		TREE_TYPE (TREE_TYPE (tmp)) != node))
-	  print_declaration (buffer, tmp, spc+2);
+	  print_declaration (buffer, tmp, spc+2, dump_node_fn, dump_tree_fn);
 	else
 	  {
 	    
@@ -1232,7 +1233,7 @@ print_struct_decl (buffer, node, spc)
 	tmp = TREE_CHAIN (tmp);
       }
   }
-  INDENT (spc);
+  INDENT (buffer, spc);
   output_add_character (buffer, '}');
 }
 
@@ -1270,6 +1271,7 @@ op_prio (op)
   switch (TREE_CODE (op))
     {
     case TREE_LIST:
+    case COMPOUND_EXPR:
       return 1;
 
     case MODIFY_EXPR:
@@ -1490,3 +1492,118 @@ op_symbol (op)
     }
 }
 
+
+/* Prints the name of a CALL_EXPR.  */
+
+static void 
+print_call_name (buffer, node)
+     output_buffer *buffer;
+     tree node;
+{
+  tree op0;
+
+  if (TREE_CODE (node) != CALL_EXPR)
+    abort ();
+
+  op0 = TREE_OPERAND (node, 0);
+
+  if (TREE_CODE (op0) == NON_LVALUE_EXPR)
+    op0 = TREE_OPERAND (op0, 0);
+
+
+#define PRINT_FUNCTION_NAME(NODE)  output_printf             \
+  (buffer, "%s", TREE_CODE (NODE) == NOP_EXPR ?              \
+   IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (NODE, 0))) : \
+   IDENTIFIER_POINTER (DECL_NAME (NODE)))
+
+  
+  switch (TREE_CODE (op0))
+    {
+    case VAR_DECL:
+    case PARM_DECL:
+      PRINT_FUNCTION_NAME (op0);
+      break;
+      
+    case ADDR_EXPR:
+    case INDIRECT_REF:
+    case NOP_EXPR:
+      PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
+      break;
+      
+    case COND_EXPR:
+      PRINT_FUNCTION_NAME (TREE_OPERAND (TREE_OPERAND (op0, 0), 1));
+      PRINT_FUNCTION_NAME (TREE_OPERAND (TREE_OPERAND (op0, 0), 2));
+      break;
+      
+    case COMPONENT_REF:
+      /* The function is a pointer contained in a structure.  */
+      if (TREE_CODE (TREE_OPERAND (op0, 0)) == INDIRECT_REF ||
+	  TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
+	PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
+      /* else
+	 We can have several levels of structures and a function 
+	 pointer inside.  This is not implemented yet...  */
+      //		  NIY;
+      break;
+      
+    case ARRAY_REF:
+      if (TREE_CODE (TREE_OPERAND (op0, 0)) == VAR_DECL)
+	PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 0));
+      else
+	PRINT_FUNCTION_NAME (TREE_OPERAND (op0, 1));
+      break;
+      
+    default:
+      NIY;
+    }
+}
+
+/* Parses the string STR and replaces new-lines by '\n', tabs by '\t', ...  */
+
+static void 
+pretty_print_string (buffer, str) 
+     output_buffer *buffer;
+     const char *str;
+{
+  if (str == NULL)
+    return;
+
+  while (*str)
+    {
+      switch (str[0])
+	{
+	case '\b':
+	  output_add_string (buffer, "\\b");
+	  break;
+	  
+	case '\f':
+	  output_add_string (buffer, "\\f");
+	  break;
+	  
+	case '\n':
+	  output_add_string (buffer, "\\n");
+	  break;
+	  
+	case '\r':
+	  output_add_string (buffer, "\\r");
+	  break;
+	  
+	case '\t':
+	  output_add_string (buffer, "\\t");
+	  break;
+	  
+	case '\v':
+	  output_add_string (buffer, "\\v");
+	  break;
+	  
+	case '\\':
+	  output_add_string (buffer, "\\\\");
+	  break;
+	  
+	default:
+	  output_add_character (buffer, str[0]);
+	  break;
+	}
+      str++;
+    }
+}
Index: c-tree.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.64.2.6
diff -d -u -p -r1.64.2.6 c-tree.h
--- c-tree.h	5 Mar 2002 05:27:08 -0000	1.64.2.6
+++ c-tree.h	16 Apr 2002 18:27:31 -0000
@@ -379,16 +379,6 @@ extern tree static_ctors;
 extern tree static_dtors;
 
 /* In c-simplify.c  */
-extern void simplify_stmt PARAMS ((tree, tree));
-
-/* In c-pretty-print.c  */
-extern void print_c_tree  PARAMS ((FILE*, tree));
-extern void print_c_node  PARAMS ((FILE*, tree));
-extern void debug_c_tree  PARAMS ((tree));
-extern void debug_c_node  PARAMS ((tree));
-
-/* In c-call-graph.c  */
-extern void print_call_graph PARAMS ((FILE*, tree));
-extern void debug_call_graph PARAMS ((tree));
+extern void simplify_stmt               PARAMS ((tree, tree));
 
 #endif /* ! GCC_C_TREE_H */
Index: ./cp/Make-lang.in
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.88.2.9
diff -d -u -p -r1.88.2.9 Make-lang.in
--- ./cp/Make-lang.in	18 Mar 2002 23:52:21 -0000	1.88.2.9
+++ ./cp/Make-lang.in	16 Apr 2002 18:27:32 -0000
@@ -105,7 +105,7 @@ CXX_OBJS = cp/call.o cp/decl.o cp/expr.o
  cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parse.o cp/ptree.o cp/rtti.o \
  cp/spew.o cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
  cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o \
- cp/optimize.o cp/mangle.o cp/cp-lang.o
+ cp/optimize.o cp/mangle.o cp/cp-lang.o cp/cp-pretty-print.o
 
 # Use loose warnings for this front end.
 cp-warn =
@@ -255,6 +255,8 @@ cp/lex.o: cp/lex.c $(CXX_TREE_H) cp/pars
   $(TM_P_H)
 cp/cp-lang.o: cp/cp-lang.c $(CXX_TREE_H) toplev.h langhooks.h langhooks-def.h \
   c-common.h
+cp/cp-pretty-print.o: cp/cp-pretty-print.c $(CXX_TREE_H) diagnostic.h \
+  pretty-printers.h
 cp/decl.o: cp/decl.c $(CXX_TREE_H) flags.h cp/lex.h cp/decl.h stack.h \
   output.h $(EXPR_H) except.h toplev.h hash.h $(GGC_H) $(RTL_H) \
   cp/operators.def $(TM_P_H) tree-inline.h diagnostic.h

--- /dev/null	Sat Jan  5 10:09:16 2002
+++ ./pretty-printers.h	Wed Apr 10 22:32:08 2002
@@ -0,0 +1,62 @@
+/* Functions for pretty printing trees.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   Contributed by Sebastian Pop <s.pop@laposte.net>
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+
+#define INDENT(BUFFER, SPACE) do { \
+  int i; for (i = 0; i<SPACE; i++) output_add_space (BUFFER); } while (0)
+
+#define NIY do { \
+  debug_output_buffer (buffer); debug_tree (node); abort (); } while (0)
+
+#define LNIY do {                                                            \
+  fprintf (stderr, "Sorry, not implemented yet on this language.\n");        \
+  abort ();                                                                  \
+} while (0)
+
+/* During development use the name of the function passed in argument for 
+   avoiding to duplicate code and changes in the big switch in dump_c_node.
+   Once finished, we can duplicate the code in the big switch and delete these 
+   function pointers (it's not very clean, but works).  */
+#define DUMP_NODE(BUFF, NODE, SPC) ((int (*) PARAMS ((output_buffer *, tree, HOST_WIDE_INT, void *, void *))) dump_node_fn) (BUFF, NODE, SPC, dump_node_fn, dump_tree_fn)
+#define DUMP_TREE(BUFF, NODE, SPC) ((void (*) PARAMS ((output_buffer *, tree, HOST_WIDE_INT))) dump_tree_fn) (BUFF, NODE, SPC)
+
+/* In c-pretty-print.c  */
+extern void print_c_tree        PARAMS ((FILE*, tree));
+extern void print_c_node        PARAMS ((FILE*, tree));
+extern void debug_c_tree        PARAMS ((tree));
+extern void debug_c_node        PARAMS ((tree));
+extern void dump_c_tree         PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
+extern int  dump_c_node         PARAMS ((output_buffer *, tree, HOST_WIDE_INT, void *, void *));
+extern void print_function_decl PARAMS ((output_buffer *, tree, HOST_WIDE_INT, void *, void *));
+extern void print_struct_decl   PARAMS ((output_buffer *, tree, HOST_WIDE_INT, void *, void *));
+
+/* In cp-pretty-print.c  */
+extern void print_cp_tree       PARAMS ((FILE *, tree));
+extern void print_cp_node       PARAMS ((FILE *, tree));
+extern void debug_cp_tree       PARAMS ((tree));
+extern void debug_cp_node       PARAMS ((tree));
+extern void dump_cp_tree        PARAMS ((output_buffer *, tree, HOST_WIDE_INT));
+extern int  dump_cp_node        PARAMS ((output_buffer *, tree, HOST_WIDE_INT, 
+					 void *, void *));
+
+/* In c-call-graph.c  */
+extern void print_call_graph    PARAMS ((FILE*, tree));
+extern void debug_call_graph    PARAMS ((tree));

--- /dev/null	Sat Jan  5 10:09:16 2002
+++ ./cp/cp-pretty-print.c	Thu Apr 11 00:27:34 2002
@@ -0,0 +1,235 @@
+/* Pretty formatting of a tree in C++ syntax.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   Contributed by Sebastian Pop <s.pop@laposte.net>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+#include "config.h"
+#include "system.h"
+#include "errors.h"
+#include "tree.h"
+#include "cp-tree.h"
+#include "c-common.h"
+#include "diagnostic.h"
+#include "pretty-printers.h"
+
+
+/* Print the tree T in full, on file FILE.  */
+ 
+void 
+print_cp_tree (file, t)
+     FILE *file;
+     tree t;
+{
+  output_buffer buffer_rec;
+  output_buffer *buffer = &buffer_rec;
+  
+  init_output_buffer (buffer, /* prefix */NULL, /* line-width */0);
+  output_clear_message_text (buffer);
+  dump_cp_tree (buffer, t, 0);
+  fprintf (file, "%s", output_finalize_message (buffer));
+}
+
+/* Print the node T on file FILE.  */
+
+void 
+print_cp_node (file, t)
+     FILE *file;
+     tree t;
+{
+  output_buffer buffer_rec;
+  output_buffer *buffer = &buffer_rec;
+
+  init_output_buffer (buffer, /* prefix */NULL, /* line-width */0);
+  output_clear_message_text (buffer);
+  dump_cp_node (buffer, t, 0, (void *) dump_cp_node, (void *) dump_cp_tree);
+  fprintf (file, "%s", output_finalize_message (buffer));
+}
+
+/* Print the tree T in full, on stderr.  */
+
+void 
+debug_cp_tree (t)
+     tree t;
+{
+  print_cp_tree (stderr, t);
+}
+
+/* Print the node T on stderr.  */
+
+void 
+debug_cp_node (t)
+     tree t;
+{
+  print_cp_node (stderr, t);
+}
+
+/* Dump the tree T on the output_buffer BUFFER.  */
+ 
+void
+dump_cp_tree (buffer, t, spc)
+     output_buffer *buffer;
+     tree t;
+     HOST_WIDE_INT spc;
+{
+  tree node = t;
+  while (node && node != error_mark_node)
+    {
+      spc = dump_cp_node (buffer, node, spc, (void *) dump_cp_node, 
+			  (void *) dump_cp_tree);
+      switch (TREE_CODE (node))
+	{
+	case TYPE_DECL:
+	case FIELD_DECL:
+	case VAR_DECL:
+	case PARM_DECL:
+	  /* Some nodes on which we need to stop the recursive printing,
+	     otherwise we print all declared vars in the scope.  */
+	  return;
+	default:
+	  break;
+	}
+      node = TREE_CHAIN (node);
+    }
+}
+
+/* Dump the node NODE on the output_buffer BUFFER, SPC spaces of indent.  
+   In order to avoid maintenance problems, this function implements only 
+   the dump of C++ specific nodes.  The default behaviour is to print the
+   node as a normal C node.  */
+
+int
+dump_cp_node (buffer, node, spc, dump_node_fn, dump_tree_fn)
+     output_buffer *buffer;
+     tree node;
+     HOST_WIDE_INT spc;
+     void *dump_node_fn, *dump_tree_fn;
+{
+  if (node == NULL_TREE)
+    return spc;
+  
+  /* Keep the following switch ordered as in 'cp-tree.def'.  */
+  switch (TREE_CODE (node))
+    {
+    case OFFSET_REF:
+    case PTRMEM_CST:
+    case NEW_EXPR:
+    case VEC_NEW_EXPR:
+    case DELETE_EXPR:
+    case VEC_DELETE_EXPR:
+    case SCOPE_REF:
+    case MEMBER_REF:
+    case TYPE_EXPR:
+    case AGGR_INIT_EXPR:
+    case THROW_EXPR:
+    case EMPTY_CLASS_EXPR:
+    case TEMPLATE_DECL:
+    case TEMPLATE_PARM_INDEX:
+    case TEMPLATE_TYPE_PARM:
+    case TEMPLATE_TEMPLATE_PARM:
+    case BOUND_TEMPLATE_TEMPLATE_PARM:
+    case TYPENAME_TYPE:
+    case UNBOUND_CLASS_TEMPLATE:
+    case TYPEOF_TYPE:
+    case USING_DECL:
+    case USING_STMT:
+    case DEFAULT_ARG:
+    case TEMPLATE_ID_EXPR:
+    case CPLUS_BINDING:
+    case OVERLOAD:
+    case WRAPPER:
+    case LOOKUP_EXPR:
+    case MODOP_EXPR:
+    case CAST_EXPR:
+    case REINTERPRET_CAST_EXPR:
+    case CONST_CAST_EXPR:
+    case STATIC_CAST_EXPR:
+    case DYNAMIC_CAST_EXPR:
+    case DOTSTAR_EXPR:
+    case TYPEID_EXPR:
+    case PSEUDO_DTOR_EXPR:
+    case SUBOBJECT:
+      NIY;
+    case CTOR_STMT:
+    case CLEANUP_STMT:
+      break;
+    case CTOR_INITIALIZER:
+    case RETURN_INIT:
+    case TRY_BLOCK:
+    case EH_SPEC_BLOCK:
+    case HANDLER:
+    case MUST_NOT_THROW_EXPR:
+    case TAG_DEFN:
+    case IDENTITY_CONV:
+    case LVALUE_CONV:
+    case QUAL_CONV:
+    case STD_CONV:
+    case PTR_CONV:
+    case PMEM_CONV:
+    case BASE_CONV:
+    case REF_BIND:
+    case USER_CONV:
+    case AMBIG_CONV:
+    case RVALUE_CONV:
+      NIY;
+
+    case METHOD_TYPE:
+      output_add_string (buffer, IDENTIFIER_POINTER 
+			 (DECL_NAME (TYPE_NAME (TYPE_METHOD_BASETYPE (node)))));
+      output_add_string (buffer, "::");
+      break;
+
+    case REFERENCE_TYPE:
+      DUMP_NODE (buffer, TREE_TYPE (node), spc);
+      output_add_string (buffer, " &");
+      break;
+
+    case RETURN_STMT:
+      INDENT (buffer, spc);
+      output_add_string (buffer, "return");
+      /* if (TREE_CODE (TREE_TYPE (TREE_TYPE (current_function_decl))) != VOID_TYPE)  */
+	{
+	  output_add_space (buffer);
+	  switch (TREE_CODE (RETURN_EXPR (node)))
+	    {
+	    case MODIFY_EXPR:
+	    case INIT_EXPR:
+	      DUMP_NODE (buffer, TREE_OPERAND (RETURN_EXPR (node), 1), spc);
+	      break;
+	    default:
+	      DUMP_NODE (buffer, RETURN_EXPR (node), spc);
+	      break;
+	    }
+	}
+      output_add_character (buffer, ';');
+      output_add_newline (buffer);
+      break;
+
+    case INIT_EXPR:
+      NIY;
+
+    case TARGET_EXPR:
+      NIY;
+
+    default:
+      /* The default behaviour is that of a C node.  */
+      spc = dump_c_node (buffer, node, spc, (void *) dump_cp_node, (void *) dump_cp_tree);
+      break;
+    }
+  return spc;
+}


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