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: conditional expressions -vs- lub


I'm checking this in on the gcjx branch.

When the generics feature is enabled, the type of a conditional
expression is based on lub() of the argument types.  This required
exposing a bit of the type inference code to the conditional
expression code.

Really we should also do capture conversion here, but I haven't
written that yet.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* model/cond.cc (resolve): Use compute_lub.
	* unify.hh (compute_lub): Declare.
	* unify.cc (unifier::compute_lub): Now public.
	(unifier::unifier): New constructor.
	(unify): Updated.
	(compute_lub): New method.

Index: unify.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/unify.cc,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 unify.cc
--- unify.cc 25 Oct 2005 00:43:31 -0000 1.1.2.3
+++ unify.cc 26 Oct 2005 01:33:26 -0000
@@ -306,14 +306,6 @@
     return result;
   }
 
-  model_class *compute_lub (model_class *one, model_class *two)
-  {
-    std::set<model_class *> constraints;
-    constraints.insert (one);
-    constraints.insert (two);
-    return compute_lub (constraints);
-  }
-
   model_class *conforming_array_type (model_class *actual)
   {
     if (actual->array_p ())
@@ -553,6 +545,11 @@
 
 public:
 
+  unifier (const location &w)
+    : where (w)
+  {
+  }
+
   void unify (const std::list<model_type *> &actual, model_method *method,
 	      model_type_map &result)
   {
@@ -596,6 +593,14 @@
 
     resolve_constraints (result);
   }
+
+  model_class *compute_lub (model_class *one, model_class *two)
+  {
+    std::set<model_class *> constraints;
+    constraints.insert (one);
+    constraints.insert (two);
+    return compute_lub (constraints);
+  }
 };
 
 void
@@ -604,6 +609,14 @@
        model_class *assignment_type,
        model_type_map &result)
 {
-  unifier u;
+  // FIXME: correct location.
+  unifier u (method->get_location ());
   u.unify (actual, method, result);
 }
+
+model_class *
+compute_lub (model_element *request, model_class *one, model_class *two)
+{
+  unifier u (request->get_location ());
+  return u.compute_lub (one, two);
+}
Index: unify.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/unify.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 unify.hh
--- unify.hh 18 Oct 2005 22:16:55 -0000 1.1.2.1
+++ unify.hh 26 Oct 2005 01:33:26 -0000
@@ -36,4 +36,8 @@
        model_class *assignment_type,
        model_type_map &result);
 
+/// Compute the LUB of two classes.
+model_class *compute_lub (model_element *request, model_class *,
+			  model_class *);
+
 #endif // GCJX_UNIFY_HH
Index: model/cond.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/cond.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 cond.cc
--- model/cond.cc 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ model/cond.cc 26 Oct 2005 01:33:26 -0000
@@ -1,6 +1,6 @@
 // Conditional expression.
 
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
 //
 // This file is part of GCC.
 //
@@ -20,6 +20,7 @@
 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 #include "typedefs.hh"
+#include "unify.hh"
 
 void
 model_conditional::resolve (resolution_scope *scope)
@@ -121,11 +122,21 @@
   else
     {
       // Reference types.
-      // FIXME: we don't have capture conversion yet.
       // Also, this will fail if a primitive type makes it here...
-      model_type *merge = assignment_conversion (true_type, false_type);
-      if (merge == NULL)
-	merge = assignment_conversion (false_type, true_type);
+      model_type *merge;
+      if (global->get_compiler ()->feature_generics ())
+	{
+	  // FIXME: we don't have capture conversion yet, but should
+	  // run it on the result here.
+	  merge = compute_lub (this, assert_cast<model_class *> (true_type),
+			       assert_cast<model_class *> (false_type));
+	}
+      else
+	{
+	  merge = assignment_conversion (true_type, false_type);
+	  if (merge == NULL)
+	    merge = assignment_conversion (false_type, true_type);
+	}
       if (merge == NULL)
 	// fixme bad message
 	throw error ("operands of condition have types %1 and %2, "


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