From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12454 invoked by alias); 26 Oct 2005 01:35:43 -0000 Mailing-List: contact java-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-patches-owner@gcc.gnu.org Received: (qmail 12443 invoked by uid 22791); 26 Oct 2005 01:35:40 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 26 Oct 2005 01:35:40 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j9Q1Zcw2004002 for ; Tue, 25 Oct 2005 21:35:38 -0400 Received: from opsy.redhat.com (vpn50-121.rdu.redhat.com [172.16.50.121]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j9Q1ZbV17492; Tue, 25 Oct 2005 21:35:37 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 2B6532DC12A; Tue, 25 Oct 2005 19:29:15 -0600 (MDT) To: Java Patch List Subject: [gcjx] Patch: FYI: conditional expressions -vs- lub From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Wed, 26 Oct 2005 01:35:00 -0000 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2005-q4/txt/msg00135.txt.bz2 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 * 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 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 &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 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 (true_type), + assert_cast (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, "