From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32332 invoked by alias); 25 Oct 2005 21:01:16 -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 32280 invoked by uid 22791); 25 Oct 2005 21:01:05 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 25 Oct 2005 21:01:05 +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 j9PL1307030484 for ; Tue, 25 Oct 2005 17:01:03 -0400 Received: from opsy.redhat.com (vpn50-21.rdu.redhat.com [172.16.50.21]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j9PL12V21980; Tue, 25 Oct 2005 17:01:02 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 642AA2DC12A; Tue, 25 Oct 2005 14:54:40 -0600 (MDT) To: Java Patch List Subject: [gcjx] Patch: FYI: method overloading fix From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Tue, 25 Oct 2005 21:01: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/msg00131.txt.bz2 I'm checking this in on the gcjx branch. This fixes the implementation of return type substitutability to be correct. This lets us get a little farther when compiling the Classpath generics branch. Tom Index: ChangeLog from Tom Tromey * model/method.hh (model_method::same_arguments_p): Added argument. * model/method.cc (same_arguments_p): Use const_cast. Added argument. (return_type_substitutable_p): Added 'exact' argument. (hides_or_overrides_p): Updated. Index: model/method.cc =================================================================== RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.cc,v retrieving revision 1.1.2.10 diff -u -r1.1.2.10 method.cc --- model/method.cc 21 Oct 2005 21:47:59 -0000 1.1.2.10 +++ model/method.cc 25 Oct 2005 20:58:05 -0000 @@ -369,7 +369,7 @@ } bool -model_method::same_arguments_p (model_method *other) const +model_method::same_arguments_p (model_method *other, bool *exact_p) const { // Map our type variables to OTHER's. model_type_map type_map; @@ -381,6 +381,9 @@ maybe_same = type_parameters.create_type_map (type_map, other->type_parameters); + if (exact_p) + *exact_p = true; + std::list::const_iterator this_it = parameters.begin (); std::list::const_iterator other_it @@ -402,13 +405,16 @@ model_class *this_class = assert_cast (this_type); model_class *other_class = assert_cast (other_type); - // FIXME: using the wrong kinds of cast here. - this_class = this_class->apply_type_map ((model_element *) this, - type_map); - other_class = other_class->apply_type_map ((model_element *) this, - type_map); + this_type + = this_class->apply_type_map (const_cast (this), + type_map); + other_type + = other_class->apply_type_map (const_cast (this), + type_map); } + if (this_type != other_type && exact_p) + *exact_p = false; if (this_type->erasure () != other_type->erasure ()) return false; ++this_it; @@ -424,21 +430,34 @@ bool model_method::return_type_substitutable_p (model_type *base, - model_type *derived) const + model_type *derived, + bool exact) const { if (base == primitive_void_type || base->primitive_p ()) return base == derived; - // FIXME: if methods have same signature, see if base==derived - // or if we can use unchecked conversion. Otherwise fall back to - // what we have now. - return widening_reference_conversion (base, derived); - // return base->erasure ()->assignable_from_p (derived->erasure ()); + + // If the signatures exactly match, see if derived's type is a + // subtype of base's type, or if derived's type can converted to a + // subtype of base's by unchecked conversion. + if (exact) + { + if (base->assignable_from_p (derived)) + return true; + // Unchecked conversion here means that the erasure of derived + // is a subtype of base. + // FIXME: must emit unchecked warning. + return base->assignable_from_p (derived->erasure ()); + } + + // Otherwise, derived must be a subtype of the erasure of base. + return base->erasure ()->assignable_from_p (derived); } bool model_method::hides_or_overrides_p (model_method *other, model_class *asker) { - if (! same_arguments_p (other)) + bool exact; + if (! same_arguments_p (other, &exact)) return false; if (static_p () && ! other->static_p ()) @@ -451,7 +470,7 @@ if (global->get_compiler ()->feature_generics ()) { if (! return_type_substitutable_p (other->return_type->type (), - return_type->type ())) + return_type->type (), exact)) throw error ("method's return type is not convertible" " from the return type of %1") % other; Index: model/method.hh =================================================================== RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.hh,v retrieving revision 1.1.2.7 diff -u -r1.1.2.7 method.hh --- model/method.hh 18 Oct 2005 22:16:55 -0000 1.1.2.7 +++ model/method.hh 25 Oct 2005 20:58:05 -0000 @@ -88,7 +88,7 @@ model_instance_cache instance_cache; void massage_modifiers (const ref_modifier_list &); - bool return_type_substitutable_p (model_type *, model_type *) const; + bool return_type_substitutable_p (model_type *, model_type *, bool) const; model_method *do_method_conversion_p (const std::list &, method_phase); model_method *do_method_conversion_p (const model_type_map &, @@ -155,9 +155,10 @@ /// declared or inherited. bool hides_or_overrides_p (model_method *, model_class *); - /// Return true if this method has the same argument types as the - /// other method. - bool same_arguments_p (model_method *) const; + /// Return true if this method's signature is a subsignature of + /// other method's signature. The second argument, if not NULL, is + /// set to true if the signatures are identical. + bool same_arguments_p (model_method *, bool * = NULL) const; void set_name (const std::string &n) {