This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

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


-----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-----
Index: ChangeLog
from  Ranjit Mathew  <rmathew@gcc.gnu.org>

	Start implementation of a pretty-printer for AST nodes.
	* dump.hh (dump_tree): New method for printing a node from the AST.
	* dump.cc (dumper::visit_field_ref): Remove const qualifier from
	model_field * parameter
	(dumper::visit_field): New method.
	(dumper::visit_method_invocation): Remove const qualifier for METH.
	(dumper::visit_forwarding_type): Remove const qualifier for
	model_type * parameter.
	(dumper::visit_forwarding_resolved): New method.
	(dumper::visit_forwarding_owned): Likewise.
	(dumper::visit_forwarding_simple): Likewise.
	(dumper::visit_forwarding_array): Likewise.
	(dumper::visit_forwarding_element): Likewise.
	(dumper::visit_forwarding_full): Likewise.
	(dumper::visit_forwarding_inner): Likewise.
	(dumper::visit_forwarding_parameterized): Likewise.
	(pretty_printer): New class for pretty-printing AST nodes.
	(dump_tree): Implement.
	* visitor.hh (visitor::visit_field_ref): Remove const qualifier from
	model_field * parameter
	(visitor::visit_field): New method.
	(visitor::visit_method_invocation): Remove const qualifier for METH.
	(visitor::visit_forwarding_type): Remove const qualifier for
	model_type * parameter.
	(visitor::visit_forwarding_resolved): New method.
	(visitor::visit_forwarding_owned): Likewise.
	(visitor::visit_forwarding_simple): Likewise.
	(visitor::visit_forwarding_array): Likewise.
	(visitor::visit_forwarding_element): Likewise.
	(visitor::visit_forwarding_full): Likewise.
	(visitor::visit_forwarding_inner): Likewise.
	(visitor::visit_forwarding_parameterized): Likewise.
	* model/fwdtype.hh (model_forwarding_resolved::visit): New method.
	(model_forwarding_owned::visit): Likewise.
	(model_forwarding_simple::visit): Likewise.
	(model_forwarding_array::visit): Likewise.
	(model_forwarding_element::visit): Likewise.
	(model_forwarding_full::visit): Likewise.
	(model_forwarding_inner::visit): Likewise.
	(model_forwarding_parameterized::visit): Likewise.
	* model/fwdtype.cc (model_forwarding::resolved::visit): Implement.
	(model_forwarding_owned::visit): Likewise.
	(model_forwarding_simple::visit): Likewise.
	(model_forwarding_array::visit): Likewise.
	(model_forwarding_element::visit): Likewise.
	(model_forwarding_full::visit): Likewise.
	(model_forwarding_inner::visit): Likewise.
	(model_forwarding_parameterized::visit): Likewise.
	* model/field.hh (model_field::visit): New method.
	* model/field.cc (model_field::visit): Implement.
	* fold.cc (fold_visitor): Adjust for visitor changes.
	* defassign.cc (definite_assignment_visitor): Likewise.
	* bytecode/generate.hh (bytecode_generator): Likewise.
	* bytecode/generate.cc (bytecode_generator): Likewise.


Index: dump.hh
===================================================================
--- dump.hh	2005-10-08 15:27:53.000000000 +0530
+++ dump.hh	2005-10-08 16:15:21.000000000 +0530
@@ -1,6 +1,6 @@
 // Print the model for debugging.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -22,6 +22,10 @@
 #ifndef GCJX_DUMP_HH
 #define GCJX_DUMP_HH
 
+/// Print out a human-readable representation of the AST.
+/// @param e a pointer to the node from which to start printing the tree.
+void dump_tree (model_element *e);
+
 void dump_method (model_method *);
 
 #endif // GCJX_DUMP_HH
Index: dump.cc
===================================================================
--- dump.cc	2005-10-08 15:29:49.000000000 +0530
+++ dump.cc	2005-10-08 23:42:57.000000000 +0530
@@ -662,7 +662,7 @@ public:
 
   void visit_field_ref (model_field_ref *,
 			const ref_expression &expr,
-			const model_field *field)
+			model_field *field)
   {
     if (expr)
       {
@@ -687,6 +687,11 @@ public:
     out << ";" << std::endl;
   }
 
+  void visit_field (model_field *)
+  {
+    // Nothing.
+  }
+
   void visit_instanceof (model_instanceof *,
 			 const ref_expression &expr,
 			 const ref_forwarding_type &type)
@@ -783,7 +788,7 @@ public:
   }
 
   void visit_method_invocation (model_method_invocation *,
-				const model_method *meth,
+				model_method *meth,
 				const ref_expression &expr,
 				const std::list<ref_expression> &args)
   {
@@ -800,9 +805,9 @@ public:
 
   void
   visit_type_qualified_invocation (model_type_qualified_invocation *,
-				   const model_method *meth,
-				   const std::list<ref_expression> &args,
-				   bool super)
+                                   const model_method *meth,
+                                   const std::list<ref_expression> &args,
+                                   bool super)
   {
     out << meth->get_declaring_class ()->get_pretty_name () << ".";
     if (super)
@@ -931,7 +936,61 @@ public:
   }
 
   void visit_forwarding_type (model_forwarding_type *,
-                              const model_type *)
+                              model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *,
+                                  model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *,
+                               const ref_type &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *,
+                                const std::list<std::string> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_full (model_forwarding_full *,
+                              const std::string &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &)
   {
     // Nothing.
   }
@@ -992,9 +1051,877 @@ public:
   }
 };
 
+class pretty_printer : public visitor
+{
+protected:
+
+  // The output stream to use.
+  std::ostream &out;
+
+  // The current indentation level.
+  int indentation;
+
+  virtual void begin_element (model_element *e, const std::string &name)
+  {
+    for (int i = 0; i < indentation; i++)
+      out << " ";
+
+    out << "(" << name << " " << e;
+
+    if (e != NULL)
+      {
+        location l = e->get_location ();
+        out << " " << l.get_line () << ":" << l.get_column ();
+      }
+  }
+
+  virtual void end_element ()
+  {
+    out << ")";
+    if (indentation == 0)
+      out << std::endl;
+  }
+
+  virtual void descend (model_element *e)
+  {
+    if (e != NULL)
+      {
+        indentation += 2;
+        out << std::endl;
+        e->visit (this);
+        indentation -= 2;
+      }
+  }
+
+  template<typename T>
+  void descend (const std::list<T> &l)
+  {
+    typename std::list<T>::const_iterator i = l.begin ();
+    if (i != l.end ())
+      {
+        indentation += 2;
+        out << std::endl;
+        if (*i)
+          (*i)->visit (this);
+        indentation -= 2;
+      }
+  }
+
+  virtual void print_multi_name (const std::list<std::string> &name)
+  {
+    std::list<std::string>::const_iterator i = name.begin ();
+
+    if (i != name.end ())
+      out << " ";
+
+    bool first = true;
+    while (i != name.end ())
+      {
+        if (!first)
+          out << ".";
+        else
+          first = false;
+
+        out << (*i);
+        ++i;
+      }
+  }
+
+public:
+
+  pretty_printer (std::ostream &o)
+    : out (o),
+      indentation (0)
+  {
+  }
+
+  void visit_method (model_method *meth,
+                     const std::list<ref_variable_decl> &args,
+                     const ref_block &body)
+  {
+    begin_element (meth, "method");
+
+    out << " " << meth->get_declaring_class ()->get_pretty_name ()
+        << "." << meth->get_name ();
+
+    descend (meth->get_return_type ());
+    descend (args);
+    if (body)
+      descend (body.get ());
+
+    end_element ();
+  }
+
+  void visit_assert (model_assert *, const ref_expression &,
+                     const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_block (model_block *block, const std::list<ref_stmt> &stmts)
+  {
+    begin_element (block, "block");
+    descend (stmts);
+    end_element ();
+  }
+
+  void visit_bytecode_block (model_bytecode_block *,
+                             int, int, int, const uint8 *)
+  {
+    // TODO.
+  }
+
+  void visit_break (model_break *, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_catch (model_catch *, const ref_variable_decl &,
+                    const ref_block &)
+  {
+    // TODO.
+  }
+
+  void visit_continue (model_continue *, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_class_decl_stmt (model_class_decl_stmt *, const ref_class &)
+  {
+    // TODO.
+  }
+
+  void visit_do (model_do *, const ref_expression &, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_empty (model_empty *e)
+  {
+    begin_element (e, "empty");
+    end_element ();
+  }
+
+  void visit_expression_stmt (model_expression_stmt *stmt,
+                              const ref_expression &expr)
+  {
+    begin_element (stmt, "expr_stmt");
+    if (expr)
+      descend (expr.get ());
+    end_element ();
+  }
+
+  void visit_for_enhanced (model_for_enhanced *,
+                           const ref_stmt &, const ref_expression &,
+                           const ref_variable_decl &)
+  {
+    // TODO.
+  }
+
+  void visit_for (model_for *, const ref_stmt &, const ref_expression &,
+                  const ref_stmt &, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_if (model_if *, const ref_expression &, const ref_stmt &,
+                 const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_label (model_label *, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_return (model_return *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_switch (model_switch *, const ref_expression &,
+                     const std::list<ref_switch_block> &)
+  {
+    // TODO.
+  }
+
+  void visit_switch_block (model_switch_block *,
+                           const std::list<ref_stmt> &)
+  {
+    // TODO.
+  }
+
+  void visit_synchronized (model_synchronized *, const ref_expression &,
+                           const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_throw (model_throw *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_try (model_try *, const ref_block &,
+                  const std::list<ref_catch> &, const ref_block &)
+  {
+    // TODO.
+  }
+
+  void visit_variable_stmt (model_variable_stmt *var_stmt,
+                            const std::list<ref_variable_decl> &vars)
+  {
+    begin_element (var_stmt, "var_stmt");
+    descend (vars);
+    end_element ();
+  }
+
+  void visit_while (model_while *, const ref_expression &, const ref_stmt &)
+  {
+    // TODO.
+  }
+
+  void visit_array_initializer (model_array_initializer *,
+                                const ref_forwarding_type &,
+                                const std::list<ref_expression> &)
+  {
+    // TODO.
+  }
+
+  void visit_array_ref (model_array_ref *, const ref_expression &,
+                        const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_assignment (model_assignment *, const ref_expression &,
+                         const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_minus_equal *,
+                            const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_mult_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_div_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_and_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_or_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_plus_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_xor_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_mod_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_ls_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_rs_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_op_assignment (model_urs_equal *,
+                            const ref_expression &,
+                            const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_minus *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_mult *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_div *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_mod *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_and *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_or *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_xor *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_binary (model_plus *,
+                           const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_shift (model_left_shift *,
+                          const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_shift (model_right_shift *,
+                          const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_arith_shift (model_unsigned_right_shift *,
+                          const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_cast (model_cast *, const ref_forwarding_type &,
+                   const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_class_ref (model_class_ref *cref,
+                        const ref_forwarding_type &ctype)
+  {
+    begin_element (cref, "class_ref");
+    if (ctype)
+      descend (ctype.get ());
+    end_element ();
+  }
+
+  void visit_comparison (model_equal *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_comparison (model_notequal *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_comparison (model_lessthan *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_comparison (model_greaterthan *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_comparison (model_lessthanequal *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_comparison (model_greaterthanequal *,
+                         const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_conditional (model_conditional *,
+                          const ref_expression &, const ref_expression &,
+                          const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_field_ref (model_field_ref *f,
+                        const ref_expression &expr,
+                        model_field *field)
+  {
+    begin_element (f, "field_ref");
+
+    if (f->qualified_p ())
+      out << " QUALIFIED";
+
+    descend (f->get_qualifying_class ());
+    if (expr)
+      descend (expr.get ());
+    descend (field);
+     
+    end_element ();
+  }
+
+  void visit_field_initializer (model_field_initializer *, model_field *)
+  {
+    // TODO.
+  }
+
+  void visit_field (model_field *field)
+  {
+    begin_element (field, "field");
+    
+    modifier_t mods = field->get_modifiers ();
+    if ((mods & ACC_PUBLIC) != 0)
+      out << " PUBLIC";
+    else if ((mods & ACC_PROTECTED) != 0)
+      out << " PROTECTED";
+    else if ((mods & ACC_PRIVATE) != 0)
+      out << " PRIVATE";
+    else
+      out << " PKG_PVT";
+
+    if ((mods & ACC_STATIC) != 0)
+      out << " STATIC";
+    if ((mods & ACC_FINAL) != 0)
+      out << " FINAL";
+    if ((mods & ACC_ABSTRACT) != 0)
+      out << " ABSTRACT";
+    if ((mods & ACC_NATIVE) != 0)
+      out << " NATIVE";
+
+    if (field->constant_p ())
+      out << " CONSTANT";
+    if (field->synthetic_p ())
+      out << " SYNTHETIC";
+
+    out << " " << field->get_name ();
+
+    end_element ();
+  }
+
+  void visit_instanceof (model_instanceof *,
+                         const ref_expression &,
+                         const ref_forwarding_type &)
+  {
+    // TODO.
+  }
+
+  void visit_logical_binary (model_lor *,
+                             const ref_expression &, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_logical_binary (model_land *, const ref_expression &,
+                             const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jboolean &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jbyte &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jchar &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jshort &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jint &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jlong &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jfloat &val)
+  {
+    // TODO.
+  }
+
+  void visit_simple_literal (model_literal_base *, const jdouble &val)
+  {
+    // TODO.
+  }
+
+  void visit_string_literal (model_string_literal *s, const std::string &val)
+  {
+    begin_element (s, "string");
+    out << " \"" << val << "\"";
+    end_element ();
+  }
+
+  void visit_method_invocation (model_method_invocation *meth_inv,
+                                model_method *meth,
+                                const ref_expression &expr,
+                                const std::list<ref_expression> &args)
+  {
+    begin_element (meth_inv, "method_invocation");
+    descend (meth);
+    if (expr)
+      descend (expr.get ());
+    descend (args);
+    end_element ();
+  }
+
+  void
+  visit_type_qualified_invocation (model_type_qualified_invocation *,
+				   const model_method *,
+				   const std::list<ref_expression> &,
+				   bool)
+  {
+    // TODO.
+  }
+
+  void visit_super_invocation (model_super_invocation *,
+                               const model_method *,
+                               const std::list<ref_expression> &)
+  {
+    // TODO.
+  }
+
+  void visit_this_invocation (model_this_invocation *,
+                              const model_method *,
+                              const std::list<ref_expression> &)
+  {
+    // TODO.
+  }
+
+  void visit_new (model_new *, const model_method *,
+                  const ref_forwarding_type &,
+                  const std::list<ref_expression> &)
+  {
+    // TODO.
+  }
+
+  void visit_new_array (model_new_array *,
+                        const ref_forwarding_type &,
+                        const std::list<ref_expression> &,
+                        const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_null_literal (model_null_literal *)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_simple (model_prefix_plus *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_simple (model_prefix_minus *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_simple (model_bitwise_not *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_simple (model_logical_not *, const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_side_effect (model_prefix_plusplus *,
+                                 const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_prefix_side_effect (model_prefix_minusminus *,
+                                 const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_postfix_side_effect (model_postfix_plusplus *,
+                                  const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_postfix_side_effect (model_postfix_minusminus *,
+                                  const ref_expression &)
+  {
+    // TODO.
+  }
+
+  void visit_this (model_this *)
+  {
+    // TODO.
+  }
+
+  void visit_simple_variable_ref (model_simple_variable_ref *,
+                                  const model_variable_decl *)
+  {
+    // TODO.
+  }
+
+  void visit_forwarding_type (model_forwarding_type *fwd_type,
+                              model_type *res_type)
+  {
+    begin_element (fwd_type, "fwd_type");
+    descend (res_type);
+    end_element ();
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *fwd_resolved,
+                                  model_type *res_type)
+  {
+    begin_element (fwd_resolved, "fwd_type_resolved");
+    descend (res_type);
+    end_element ();
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *fwd_owned,
+                               const ref_type &own_type)
+  {
+    begin_element (fwd_owned, "fwd_type_owned");
+    if (own_type)
+      descend (own_type.get ());
+    end_element ();
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *fwd_simple,
+                                const std::list<std::string> &name)
+  {
+    begin_element (fwd_simple, "fwd_type_simple");
+    print_multi_name (name);
+    end_element ();
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *fwd_array,
+                          const owner<model_forwarding_type> &t)
+  {
+    begin_element (fwd_array, "fwd_type_array");
+    if (t)
+      descend (t.get ());
+    end_element ();
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *fwd_element,
+                            const owner<model_forwarding_type> &t)
+  {
+    begin_element (fwd_element, "fwd_type_element");
+    if (t)
+      descend (t.get ());
+    end_element ();
+  }
+
+  void visit_forwarding_full (model_forwarding_full *fwd_full,
+                              const std::string &name)
+  {
+    begin_element (fwd_full, "fwd_type_full");
+    out << " " << name;
+    end_element ();
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *fwd_inner,
+                          const std::list<std::string> &name,
+                          const owner<model_forwarding_type> &parent)
+  {
+    begin_element (fwd_inner, "fwd_type_inner");
+    print_multi_name (name);
+    if (parent)
+      descend (parent.get ());
+    end_element ();
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *fwd_param,
+                                  const owner<model_forwarding_type> &base,
+                                  const std::list< owner<model_forwarding_type> > &params)
+  {
+    begin_element (fwd_param, "fwd_type_param");
+    if (base)
+      descend (base.get ());
+    descend (params);
+    end_element ();
+  }
+
+  void visit_variable_decl (model_variable_decl *var,
+                            const std::string &name,
+                            const ref_forwarding_type &decltype,
+                            const ref_expression &initializer,
+                            bool is_final,
+                            bool is_used)
+  {
+    begin_element (var, "var_decl");
+
+    out << " " << name;
+
+    if (is_final)
+      out << " FINAL";
+    if (!is_used)
+      out << " UNUSED";
+
+    if (decltype)
+      descend (decltype.get ());
+    if (initializer)
+      descend (initializer.get ());
+
+    end_element ();
+  }
+
+  void visit_parameter_decl (model_variable_decl *param,
+                             const std::string &name,
+                             const ref_forwarding_type &decltype,
+                             const ref_expression &initializer,
+                             bool is_final,
+                             bool is_used)
+  {
+    begin_element (param, "param_decl");
+
+    out << " " << name;
+
+    if (is_final)
+      out << " FINAL";
+    if (!is_used)
+      out << " UNUSED";
+
+    if (decltype)
+      descend (decltype.get ());
+    if (initializer)
+      descend (initializer.get ());
+
+    end_element ();
+  }
+
+  void visit_catch_decl (model_variable_decl *, const std::string &,
+                         const ref_forwarding_type &, const ref_expression &,
+                         bool, bool)
+  {
+    // TODO.
+  }
+
+  void visit_package (model_package *, const std::list<std::string> &)
+  {
+    // TODO.
+  }
+
+  void visit_primitive (model_primitive_base *prim, const char *name)
+  {
+    begin_element (prim, "primitive");
+    out << " " << name;
+    end_element ();
+  }
+
+  void visit_type (model_type *t, const std::string &descriptor)
+  {
+    begin_element (t, "type");
+    out << " " << descriptor;
+    end_element ();
+  }
+
+  void visit_identifier (model_identifier *i, const std::string &ident)
+  {
+    begin_element (i, "identifier");
+    out << " " << ident;
+    end_element ();
+  }
+
+  void visit_element (model_element *e)
+  {
+    begin_element (e, "element");
+    end_element ();
+  }
+};
+
 void
 dump_method (model_method *m)
 {
   dumper d (std::cout);
   m->visit (&d);
 }
+
+void
+dump_tree (model_element *e)
+{
+  if (e != NULL)
+    {
+      pretty_printer p (std::cout);
+      e->visit (&p);
+    }
+  else
+    std::cout << "NULL" << std::endl;
+}
Index: visitor.hh
===================================================================
--- visitor.hh	2005-10-08 18:30:04.000000000 +0530
+++ visitor.hh	2005-10-08 21:27:49.000000000 +0530
@@ -235,11 +235,13 @@ public:
 
   virtual void visit_field_ref (model_field_ref *,
 				const ref_expression &,
-				const model_field *) = 0;
+				model_field *) = 0;
 
   virtual void visit_field_initializer (model_field_initializer *,
 					model_field *) = 0;
 
+  virtual void visit_field (model_field *) = 0;
+
   virtual void visit_instanceof (model_instanceof *,
 				 const ref_expression &,
 				 const ref_forwarding_type &) = 0;
@@ -280,7 +282,7 @@ public:
 				     const std::string &val) = 0;
 
   virtual void visit_method_invocation (model_method_invocation *,
-					const model_method *,
+					model_method *,
 					const ref_expression &,
 					const std::list<ref_expression> &) = 0;
 
@@ -339,7 +341,37 @@ public:
 					  const model_variable_decl *) = 0;
 
   virtual void visit_forwarding_type (model_forwarding_type *,
-                                      const model_type *) = 0;
+                                      model_type *) = 0;
+
+  virtual void visit_forwarding_resolved (model_forwarding_resolved *,
+                                          model_type *) = 0;
+
+  virtual void visit_forwarding_owned (model_forwarding_owned *,
+                                       const ref_type &) = 0;
+
+  virtual void visit_forwarding_simple (model_forwarding_simple *,
+                                        const std::list<std::string> &) = 0;
+
+  virtual void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &) = 0;
+
+  virtual void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &) = 0;
+
+  virtual void visit_forwarding_full (model_forwarding_full *,
+                                      const std::string &) = 0;
+
+  virtual void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &) = 0;
+
+  virtual void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &) = 0;
 
   virtual void visit_variable_decl (model_variable_decl *,
                                     const std::string &,
Index: model/fwdtype.hh
===================================================================
--- model/fwdtype.hh	2005-10-08 18:48:23.000000000 +0530
+++ model/fwdtype.hh	2005-10-08 18:49:39.000000000 +0530
@@ -95,6 +95,8 @@ public:
   {
     // Nothing to do.
   }
+
+  void visit (visitor *);
 };
 
 /// This is like model_forwarding_resolved, but it owns the resulting
@@ -110,6 +112,8 @@ public:
       ref (t)
   {
   }
+
+  void visit (visitor *);
 };  
 
 class model_forwarding_simple : public model_forwarding_type
@@ -126,6 +130,8 @@ public:
   }
 
   void resolve (resolution_scope *);
+
+  void visit (visitor *);
 };
 
 // This represents an array where the element type is also a
@@ -149,6 +155,8 @@ public:
   {
     return true;
   }
+
+  void visit (visitor *);
 };
 
 // This represents the element type of an array where the array's type
@@ -167,6 +175,8 @@ public:
   }
 
   void resolve (resolution_scope *);
+
+  void visit (visitor *);
 };
 
 /// This is a forwarding type whose argument is always fully-qualified
@@ -198,6 +208,8 @@ public:
   {
     return name;
   }
+
+  void visit (visitor *);
 };
 
 /// This is a forwarding type which finds its argument as a member of
@@ -222,6 +234,8 @@ public:
   }
 
   void resolve (resolution_scope *);
+
+  void visit (visitor *);
 };
 
 /// This is a forwarding type whose argument is an instance of a
@@ -261,6 +275,8 @@ public:
   }
 
   void resolve (resolution_scope *);
+
+  void visit (visitor *);
 };
 
 const format &operator% (const format &, const owner<model_forwarding_type> &);
Index: model/fwdtype.cc
===================================================================
--- model/fwdtype.cc	2005-10-08 18:49:45.000000000 +0530
+++ model/fwdtype.cc	2005-10-08 19:00:55.000000000 +0530
@@ -50,6 +50,22 @@ model_forwarding_type::visit (visitor *v
 
 
 void
+model_forwarding_resolved::visit (visitor *v)
+{
+  v->visit_forwarding_resolved (this, resolved_type);
+}
+
+
+
+void
+model_forwarding_owned::visit (visitor *v)
+{
+  v->visit_forwarding_owned (this, ref);
+}
+
+
+
+void
 model_forwarding_simple::resolve (resolution_scope *scope)
 {
   // We've already been resolved.
@@ -60,6 +76,12 @@ model_forwarding_simple::resolve (resolu
   resolved_type = classify_type_name (scope, this, name);
 }
 
+void
+model_forwarding_simple::visit (visitor *v)
+{
+  v->visit_forwarding_simple (this, name);
+}
+
 
 
 void
@@ -69,6 +91,12 @@ model_forwarding_array::resolve (resolut
   resolved_type = element->type ()->array ();
 }
 
+void
+model_forwarding_array::visit (visitor *v)
+{
+  v->visit_forwarding_array (this, element);
+}
+
 
 
 void
@@ -84,6 +112,12 @@ model_forwarding_element::resolve (resol
   resolved_type = ary->element_type ();
 }
 
+void
+model_forwarding_element::visit (visitor *v)
+{
+  v->visit_forwarding_element (this, array_type);
+}
+
 
 
 void
@@ -98,6 +132,12 @@ model_forwarding_full::resolve (resoluti
     }
 }
 
+void
+model_forwarding_full::visit (visitor *v)
+{
+  v->visit_forwarding_full (this, name);
+}
+
 
 
 void
@@ -122,6 +162,12 @@ model_forwarding_inner::resolve (resolut
   resolved_type = r;
 }
 
+void
+model_forwarding_inner::visit (visitor *v)
+{
+  v->visit_forwarding_inner (this, name, parent);
+}
+
 
 
 void
@@ -155,6 +201,12 @@ model_forwarding_parameterized::resolve 
   resolved_type = k->create_instance (this, rp);
 }
 
+void
+model_forwarding_parameterized::visit (visitor *v)
+{
+  v->visit_forwarding_parameterized (this, base, parameters);
+}
+
 
 
 const format &
Index: model/field.hh
===================================================================
--- model/field.hh	2005-10-08 21:20:04.000000000 +0530
+++ model/field.hh	2005-10-08 21:25:31.000000000 +0530
@@ -1,6 +1,6 @@
 // Represent a field.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -143,6 +143,8 @@ public:
   void check_referenced (resolution_scope *);
 
   model_variable_decl *apply_type_map (const model_type_map &, model_class *);
+
+  void visit (visitor *);
 };
 
 class model_ambiguous_field : public model_field_base
Index: model/field.cc
===================================================================
--- model/field.cc	2005-10-08 21:23:55.000000000 +0530
+++ model/field.cc	2005-10-08 21:27:23.000000000 +0530
@@ -201,3 +201,9 @@ model_field::require_resolution ()
       resolve (&scope);
     }
 }
+
+void
+model_field::visit (visitor *v)
+{
+  v->visit_field (this);
+}
Index: fold.cc
===================================================================
--- fold.cc	2005-10-08 18:34:52.000000000 +0530
+++ fold.cc	2005-10-08 21:28:35.000000000 +0530
@@ -432,7 +432,7 @@ public:
 
   void visit_field_ref (model_field_ref *,
 			const ref_expression &expr,
-			const model_field *)
+			model_field *)
   {
     if (expr)
       expr->visit (this);
@@ -445,6 +445,11 @@ public:
     abort ();
   }
 
+  void visit_field (model_field *)
+  {
+    // Nothing.
+  }
+
   void visit_instanceof (model_instanceof *,
 			 const ref_expression &expr,
 			 const ref_forwarding_type &)
@@ -514,7 +519,7 @@ public:
   }
 
   void visit_method_invocation (model_method_invocation *invocation,
-				const model_method *,
+				model_method *,
 				const ref_expression &expr,
 				const std::list<ref_expression> &arguments)
   {
@@ -626,7 +631,61 @@ public:
   }
 
   void visit_forwarding_type (model_forwarding_type *,
-                              const model_type *)
+                              model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *,
+                                  model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *,
+                               const ref_type &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *,
+                                const std::list<std::string> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_full (model_forwarding_full *,
+                              const std::string &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &)
   {
     // Nothing.
   }
Index: defassign.cc
===================================================================
--- defassign.cc	2005-10-08 18:34:31.000000000 +0530
+++ defassign.cc	2005-10-08 21:29:03.000000000 +0530
@@ -1149,7 +1149,7 @@ public:
 
   void visit_field_ref (model_field_ref *ref,
 			const ref_expression &expr,
-			const model_field *fld)
+			model_field *fld)
   {
     // For first phase of simple assignment, visit the expression.
     // For second phase, do everything else.  For ordinary references,
@@ -1251,6 +1251,11 @@ public:
       }
   }
 
+  void visit_field (model_field *)
+  {
+    // Nothing.
+  }
+
   void visit_instanceof (model_instanceof *,
 			 const ref_expression &expr,
 			 const ref_forwarding_type &)
@@ -1345,7 +1350,7 @@ public:
   }
 
   void visit_method_invocation (model_method_invocation *,
-				const model_method *meth,
+				model_method *meth,
 				const ref_expression &qual,
 				const std::list<ref_expression> &exprs)
   {
@@ -1518,7 +1523,61 @@ public:
       }
   }
 
-  void visit_forwarding_type (model_forwarding_type *, const model_type *)
+  void visit_forwarding_type (model_forwarding_type *, model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *,
+                                  model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *,
+                               const ref_type &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *,
+                                const std::list<std::string> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_full (model_forwarding_full *,
+                              const std::string &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &)
   {
     // Nothing.
   }
Index: bytecode/generate.hh
===================================================================
--- bytecode/generate.hh	2005-10-08 20:18:19.000000000 +0530
+++ bytecode/generate.hh	2005-10-08 21:29:33.000000000 +0530
@@ -485,7 +485,7 @@ public:
 			 const ref_expression &);
 
   void visit_method_invocation (model_method_invocation *,
-				const model_method *,
+				model_method *,
 				const ref_expression &,
 				const std::list<ref_expression> &);
 
@@ -627,11 +627,16 @@ public:
 
   void visit_field_ref (model_field_ref *,
 			const ref_expression &,
-			const model_field *);
+			model_field *);
 
   void visit_field_initializer (model_field_initializer *,
 				model_field *);
 
+  void visit_field (model_field *)
+  {
+    // Nothing.
+  }
+
   void visit_instanceof (model_instanceof *,
 			 const ref_expression &,
 			 const ref_forwarding_type &);
@@ -712,7 +717,61 @@ public:
 				  const model_variable_decl *);
 
   void visit_forwarding_type (model_forwarding_type *,
-                              const model_type *)
+                              model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *,
+                                  model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *,
+                               const ref_type &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *,
+                                const std::list<std::string> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_full (model_forwarding_full *,
+                              const std::string &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &)
   {
     // Nothing.
   }
Index: bytecode/generate.cc
===================================================================
--- bytecode/generate.cc	2005-10-08 20:51:14.000000000 +0530
+++ bytecode/generate.cc	2005-10-08 21:16:34.000000000 +0530
@@ -2704,7 +2704,7 @@ bytecode_generator::visit_conditional (m
 void
 bytecode_generator::visit_field_ref (model_field_ref *ref,
 				     const ref_expression &expr,
-				     const model_field *field)
+				     model_field *field)
 {
   // From the binary compatibility spec, we must inline any 'final'
   // field that has an initializer which is a compile-time constant.
@@ -3193,7 +3193,7 @@ bytecode_generator::handle_invocation (j
 
 void
 bytecode_generator::visit_method_invocation (model_method_invocation *inv,
-					     const model_method *meth,
+					     model_method *meth,
 					     const ref_expression &this_expr,
 					     const std::list<ref_expression> &args)
 {
Index: ChangeLog
from  Ranjit Mathew  <rmathew@gcc.gnu.org>

	* tree.hh (tree_generator): Adjustments for changes in the
	visitor interface.

Index: tree.hh
===================================================================
--- tree.hh	2005-10-08 19:20:45.000000000 +0530
+++ tree.hh	2005-10-08 21:29:52.000000000 +0530
@@ -388,11 +388,16 @@ public:
 
   void visit_field_ref (model_field_ref *,
 			const ref_expression &,
-			const model_field *);
+			model_field *);
 
   void visit_field_initializer (model_field_initializer *,
 				model_field *);
 
+  void visit_field (model_field *)
+  {
+    // Nothing.
+  }
+
   void visit_instanceof (model_instanceof *,
 			 const ref_expression &,
 			 const ref_forwarding_type &);
@@ -433,7 +438,7 @@ public:
 			     const std::string &val);
 
   void visit_method_invocation (model_method_invocation *,
-				const model_method *,
+				model_method *,
 				const ref_expression &,
 				const std::list<ref_expression> &);
 
@@ -491,7 +496,61 @@ public:
 				  const model_variable_decl *);
 
   void visit_forwarding_type (model_forwarding_type *,
-                              const model_type *)
+                              model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_resolved (model_forwarding_resolved *,
+                                  model_type *)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_owned (model_forwarding_owned *,
+                               const ref_type &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_simple (model_forwarding_simple *,
+                                const std::list<std::string> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_array (model_forwarding_array *,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_element (model_forwarding_element *,
+                            const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void visit_forwarding_full (model_forwarding_full *,
+                              const std::string &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_inner (model_forwarding_inner *,
+                          const std::list<std::string> &,
+                          const owner<model_forwarding_type> &)
+  {
+    // Nothing.
+  }
+
+  void
+  visit_forwarding_parameterized (model_forwarding_parameterized *,
+                                  const owner<model_forwarding_type> &,
+                                  const std::list< owner<model_forwarding_type> > &)
   {
     // Nothing.
   }

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