[ast-optimizer-branch] langhooks for pretty printer

Gabriel Dos Reis gdr@codesourcery.com
Sun Jun 9 11:45:00 GMT 2002


Sebastian Pop <m1sp@csc.liv.ac.uk> writes:

| [1  <text/plain; us-ascii (7bit)>]
| Hi, 
| 
| The following patch adds langhooks for the pretty-printer.
| The C pretty printer is used as a default behaviour for the ObjC and C++ 
| front ends.  Since the ObjC is translated into plain C, there is nothing to 
| be done.  I think that there's no use to pretty print back to the ObjC syntax 
| since the aim of the pretty printer is for the moment for debugging purposes 
| only.  

Hi Sebastian,

   I would like we don't tangle each other on this issue.  Did you
read Jason's message?  I think we should coordinate efforts here as
this project intersect some of mines.

I have several comments.

First, we should work to incorporate recent changes from mainline.
Second, we should use a single code to hanlde the intersection of C
and C++ pretty-printing.  For C++, there are some additional
information about context and scope that we need to handle.

cp/error.c uses flags to tell which piece of information is relevant.
Currently the set of flags is too coarse -- sometimes we don't want to
print default arguments (either for ordinary paranmeters or
template-parameters), we don't want to repeat scopes (that tends to be
noisy); Nathan Myers outlined some of the desiderata years ago on the
libstdc++ list (I'll have to find the exact reference)


[...]

| 2002-06-09  Sebastian Pop  <s.pop@laposte.net>
| 
| 	Added langhooks for pretty printing.
| 	Use output_indent for indenting.
| 
| 	* pretty-print.h: New file.
| 
| 	* pretty-print.c: New file.

I think, there should be c-pretty-print.[ch]

| Index: langhooks-def.h
| ===================================================================
| RCS file: /cvsroot/gcc/gcc/gcc/langhooks-def.h,v
| retrieving revision 1.8.2.6
| diff -d -u -p -r1.8.2.6 langhooks-def.h
| --- langhooks-def.h	6 Jun 2002 03:52:19 -0000	1.8.2.6
| +++ langhooks-def.h	9 Jun 2002 17:08:00 -0000
| @@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA.  */
|  #include "hooks.h"
|  
|  struct diagnostic_context;
| +struct output_buffer;
|  
|  /* Provide a hook routine for alias sets that always returns 1.  This is
|     used by languages that haven't deal with alias sets yet.  */
| @@ -186,6 +187,39 @@ int lhd_tree_dump_type_quals			PARAMS ((
|    LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN \
|  }
|  
| +/* Pretty printing hooks.  */
| +extern void lhd_pretty_print_print_chain        PARAMS ((struct output_buffer *,
| +							 tree));
| +extern void lhd_pretty_print_print_node         PARAMS ((struct output_buffer *,
| +							 tree));
| +extern void lhd_pretty_print_print_declaration  PARAMS ((struct output_buffer *,
| +							 tree));
| +extern void lhd_pretty_print_print_function_decl PARAMS ((struct output_buffer*,
| +							  tree));
| +extern void lhd_pretty_print_print_struct_decl  PARAMS ((struct output_buffer *,
| +							 tree));
| +extern int  lhd_pretty_print_op_prio            PARAMS ((tree));

There ought to be a way to tell these functions how the
declaration/expression have to formated, i.e. what is interesting
about them.

[...]

| Index: langhooks.h
| ===================================================================
| RCS file: /cvsroot/gcc/gcc/gcc/langhooks.h,v
| retrieving revision 1.15.2.7
| diff -d -u -p -r1.15.2.7 langhooks.h
| --- langhooks.h	6 Jun 2002 03:52:19 -0000	1.15.2.7
| +++ langhooks.h	9 Jun 2002 17:08:00 -0000
| @@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA.  */
|  /* This file should be #include-d after tree.h.  */
|  
|  struct diagnostic_context;
| +struct output_buffer;

I would prefer #include "diagnostic.h" here.

[...]

| +  /* Function for pretty print a declaration node.  */
| +  void (*print_declaration) PARAMS ((struct output_buffer *, tree));
| +  
| +  /* Function for pretty print a function declaration node.  */
| +  void (*print_function_decl) PARAMS ((struct output_buffer *, tree));

Since a function declaration is a declaration, I'm not convinced that
we want to bring in that oddity from cp/error.c.  I would rather see
hooks for pretty-printing

   * declarations
   * definitions
   * expressions
   * statements (if they are relevant)


-- Gaby



More information about the Gcc-patches mailing list