[gcjx] Patch: FYI: start writing out method structs

Tom Tromey tromey@redhat.com
Sun Feb 13 04:19:00 GMT 2005


I'm checking this in on the gcjx branch.

This is the first step toward writing out reflection information
describing methods.

Tom

# 
# patch "gcc/gcc/java/ChangeLog"
#  from [5ef8565b3f02d225c2864e00df356ab8201bd9ec]
#    to [8ebb8343e656970715e655d3652a0a57e501ec67]
# 
# patch "gcc/gcc/java/classobj.cc"
#  from [d1cfc1d394422d9232ea6d1e5eef62ca52acff66]
#    to [0c61a248624f126f8ce0b00be8399b9e8cd0e9ae]
# 
# patch "gcc/gcc/java/classobj.hh"
#  from [a193f433c6ff4a84f649b0da7a50ab81adc15094]
#    to [cc84758f40dd38890c228ff24d179f077866b293]
# 
# patch "gcc/gcc/java/decl.cc"
#  from [f0ac0df73f09521bf65f1b96e196d62f6e546bde]
#    to [38f321a6937eb5e84e73033677b7e0982b7645fd]
# 
# patch "gcc/gcc/java/hooks.hh"
#  from [8e335fd6277f3dddb97f83c2a97740644c219d13]
#    to [cc4ab8ee4035b2ef31b70f5c91ca1ac8461b5287]
# 
--- gcc/gcc/java/ChangeLog
+++ gcc/gcc/java/ChangeLog
@@ -1,3 +1,14 @@
+2005-02-10  Tom Tromey  <tromey@redhat.com>
+
+	* classobj.hh (class_object_creator::create_one_field_record):
+	Declare.
+	* classobj.cc (create_method_array): Wrote.
+	(create_one_method_record): New method.
+	* hooks.hh (type_method_array): Declare.
+	* decl.cc (type_method_array): New global.
+	(start_type_initialization): Initialize it.
+	(build_method_type): Lay out new type.
+
 2005-02-09  Tom Tromey  <tromey@redhat.com>
 
 	* abi.cc (build_class_reference): New methods.
--- gcc/gcc/java/classobj.cc
+++ gcc/gcc/java/classobj.cc
@@ -104,6 +104,7 @@
   tree fdecl = builtins->map_field (field);
 
   inst.set_field ("name", builtins->map_utf8const (field->get_name ()));
+  // FIXME: ABI difference here.
   inst.set_field ("type", builtins->map_type (field->type ()));
   inst.set_field ("accflags", build_int_cst (type_jint,
 					     field->get_modifiers ()));
@@ -141,7 +142,8 @@
        ++i)
     {
       tree elt = create_one_field_record ((*i).get ());
-      field_array = tree_cons (NULL_TREE, elt, field_array);
+      field_array = tree_cons (NULL_TREE, // FIXME
+			       elt, field_array);
       if ((*i)->static_p ())
 	++num_static_fields;
       else
@@ -156,11 +158,50 @@
 }
 
 tree
-class_object_creator::create_method_array (model_class *real_class, int &)
+class_object_creator::create_one_method_record (model_method *method)
 {
-  return null_pointer_node;	// FIXME
+  record_creator inst (type_method);
+  tree mdecl = builtins->map_method (method);
+  inst.set_field ("name", builtins->map_utf8const (method->get_name()));
+  inst.set_field ("signature",
+		  builtins->map_utf8const (method->get_descriptor ()));
+  inst.set_field ("accflags",
+		  build_int_cst (type_jushort, method->get_modifiers ()));
+  inst.set_field ("index", integer_zero_node); // FIXME
+  inst.set_field ("ncode", null_pointer_node); // FIXME
+  inst.set_field ("throws", null_pointer_node);	// FIXME
+  return inst.finish_record ();
 }
 
+tree
+class_object_creator::create_method_array (model_class *real_class,
+					   int &num_methods)
+{
+  std::list<ref_method> methods = real_class->get_methods ();
+  num_methods = methods.size ();
+  if (num_methods == 0)
+    return null_pointer_node;
+
+  tree method_array = NULL_TREE;
+  int index = 0;
+  for (std::list<ref_method>::const_iterator i = methods.begin ();
+       i != methods.end ();
+       ++i, ++index)
+    {
+      tree elt = create_one_method_record ((*i).get ());
+      method_array = tree_cons (build_int_cst (type_jint, index),
+				elt, method_array);
+    }
+
+  method_array = nreverse (method_array);
+
+  tree ma_type
+    = build_array_type (type_method,
+			build_index_type (build_int_cst (type_jint,
+							 num_methods - 1)));
+  return make_decl (ma_type, build_constructor (ma_type, method_array));
+}
+
 void
 class_object_creator::create_index_table (const std::vector<model_element *> &table,
 					  tree &result_table,
--- gcc/gcc/java/classobj.hh
+++ gcc/gcc/java/classobj.hh
@@ -66,6 +66,7 @@
   tree make_decl (tree, tree);
   tree create_one_field_record (model_field *);
   tree create_field_array (model_class *, int &, int &);
+  tree create_one_method_record (model_method *);
   tree create_method_array (model_class *, int &);
   void handle_interfaces (model_class *, tree &, tree &);
   void create_index_table (const std::vector<model_element *> &,
--- gcc/gcc/java/decl.cc
+++ gcc/gcc/java/decl.cc
@@ -46,6 +46,9 @@
 tree type_method;
 tree type_method_ptr;
 
+// Array of _Jv_Method objects.
+tree type_method_array;
+
 // Type of a _Jv_Field and a pointer to it.
 tree type_field;
 tree type_field_ptr;
@@ -194,6 +197,7 @@
   type_class_ptr = build_pointer_type (type_class);
   type_method = make_node (RECORD_TYPE);
   type_method_ptr = build_pointer_type (type_method);
+  type_method_array = build_array_type (type_method, type_jint);
   type_field = make_node (RECORD_TYPE);
   type_field_ptr = build_pointer_type (type_field);
 }
--- gcc/gcc/java/hooks.hh
+++ gcc/gcc/java/hooks.hh
@@ -32,6 +32,7 @@
 extern GTY (()) tree type_method_symbol_array;
 extern GTY (()) tree type_method;
 extern GTY (()) tree type_method_ptr;
+extern GTY (()) tree type_method_array;
 extern GTY (()) tree type_field;
 extern GTY (()) tree type_field_ptr;
 extern GTY (()) tree type_field_info_union;



More information about the Java-patches mailing list