* [gcjx] Patch: FYI: method overloading fix
@ 2005-10-25 21:01 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2005-10-25 21:01 UTC (permalink / raw)
To: Java Patch List
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 <tromey@redhat.com>
* 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<ref_variable_decl>::const_iterator this_it
= parameters.begin ();
std::list<ref_variable_decl>::const_iterator other_it
@@ -402,13 +405,16 @@
model_class *this_class = assert_cast<model_class *> (this_type);
model_class *other_class = assert_cast<model_class *> (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<model_method *> (this),
+ type_map);
+ other_type
+ = other_class->apply_type_map (const_cast<model_method *> (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<model_method> 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<model_type *> &,
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)
{
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-25 21:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-25 21:01 [gcjx] Patch: FYI: method overloading fix Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).