[gcjx] RFC/RFA: A Simple Pretty-Printer for the AST (WIP)

Ranjit Mathew rmathew@gmail.com
Sat Oct 8 18:45:00 GMT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

  I am attaching a work-in-progress implementation of a simple
pretty-printer for the AST. It is not finished yet, but I wanted
to post it so that the patch doesn't become too unwieldy and to
find out if I'm doing something ghastly. Comments on the output
format are also welcome.

This patch puts in the basic infrastructure and allows me to see
the AST for the "main" method in a "Hello World" program:
- ----------------------------- 8< -----------------------------
public class Hello
{
  public static void main( String[] args)
  {
    System.out.println( "Hello World!");
  }
}
- ----------------------------- 8< -----------------------------

- ----------------------------- 8< -----------------------------
(method 0x80d8cc8 3:26 Hello.main
  (type 0x80587f8 -1:-1 V)
  (param_decl 0x80d8db0 3:36 args UNUSED
    (fwd_type_array 0x80d8d90 -1:-1
      (fwd_type_simple 0x80d8d60 3:27 String)))
  (block 0x80d8e08 4:2
    (expr_stmt 0x80d8e48 5:4
      (method_invocation 0x8115160 5:4
        (method 0x8106ac8 -1:-1 java.io.PrintStream.println
          (type 0x80587f8 -1:-1 V)
          (var_decl 0x8106a38 -1:-1 arg0 UNUSED
            (fwd_type_full 0x81069c8 -1:-1 java/lang/String))
          (block 0x8106a00 -1:-1))
        (field_ref 0x8115058 5:4
          (type 0x80fc5e8 -1:-1 )
          (field 0x80fca0c -1:-1 PUBLIC STATIC FINAL out))
        (string 0x80d84f0 5:25 "Hello World!")))))
- ----------------------------- 8< -----------------------------

For every node, I print its type, address, location and basic
information for the node. I have not tried to detect cycles
or compress the output. I chose to implement a new dump_tree()
and a new pretty_printer class rather than change the existing
dump_method() method and dumper class since I didn't want this
patch to be unnecessarily obtrusive.

As can be seen, I do not yet print everything for a node. I
hope to get around to doing it eventually.

I had to add a few more visitor methods and make corresponding
changes in the affected classes.

Comments? OK to apply?

Thanks,
Ranjit.

- --
Ranjit Mathew       Email: rmathew AT gmail DOT com

Bangalore, INDIA.     Web: http://ranjitmathew.hostingzero.com/




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDSBOcYb1hx2wRS48RAnLcAJ0QZ/n2o8jF4DFdvZCSKINW5RdEtQCeMXAM
VKE5Udu6PccQjWij2E9cSDA=
=BP/v
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: p1.txt
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20051008/641663e4/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: p2.txt
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20051008/641663e4/attachment-0001.txt>


More information about the Java-patches mailing list