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] Patch: FYI: special-case Character for unboxing


I'm checking this in on the gcjx branch.

The bytecode generator assumed that all the *Value() methods from
Number could be used.  However, this is not true when unboxing
Character.  (Or Boolean, but that doesn't matter as there are no
conversions to non-boolean types.)

This patch changes the code to call charValue and then apply the
appropriate cast.

A similar change is needed for the tree back end, but I haven't
written that yet.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* bytecode/generate.cc (visit_cast): Handle Character specially.

Index: bytecode/generate.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/bytecode/Attic/generate.cc,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 generate.cc
--- bytecode/generate.cc 11 Jul 2005 16:52:27 -0000 1.1.2.16
+++ bytecode/generate.cc 11 Jul 2005 16:52:52 -0000
@@ -2234,15 +2234,29 @@
 	{
 	  // Unboxing conversion.  Call <type>Value() on the wrapper
 	  // object, e.g. for Integer we call intValue().  Using
-	  // get_pretty_name here is a bit of an abuse.
-	  std::string method_name = dest_type->get_pretty_name () + "Value";
+	  // get_pretty_name here is a bit of an abuse.  Note that
+	  // Character doesn't have all the methods from Number, so we
+	  // need a special case here.
+	  std::string method_name;
+	  bool is_char = false;
+	  model_type *tmp_dest_type = dest_type;
+	  if (expr->type () == global->get_compiler ()->java_lang_Character ())
+	    {
+	      is_char = true;
+	      method_name = "charValue";
+	      tmp_dest_type = primitive_char_type;
+	    }
+	  else
+	    method_name = dest_type->get_pretty_name () + "Value";
 	  model_method *call
 	    = find_method (method_name.c_str (),
 			   assert_cast<model_class *> (expr->type ()),
-			   NULL, dest_type, cast_expr);
+			   NULL, tmp_dest_type, cast_expr);
 	  std::list<ref_expression> args;
 	  handle_invocation (op_invokevirtual, call->get_declaring_class (),
 			     call, args);
+	  if (is_char)
+	    emit_cast (primitive_char_type, dest_type);
 	}
       else
 	{


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