[gcjx] Patch: FYI:
Tom Tromey
tromey@redhat.com
Fri Oct 21 21:45:00 GMT 2005
I'm checking this in on the gcjx branch.
This fixes some small bugs in the type inference code.
It also fixes a problem when apply a type map to an array type.
With these changes we can compile this program:
public class vt
{
public static <T> void m(T... args)
{
System.out.println(args.getClass());
}
public static void main(String[] args)
{
m("hi", "bob");
}
}
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* unify.cc (resolve_constraints): Add '==' mappings to resulting
type map.
(compute_ec): Set 'ec' the first time through.
(compute_inv): Put non-generic types into the map.
* model/arraytype.cc (apply_type_map): New method.
* model/arraytype.hh (model_array_type::apply_type_map): Declare.
Index: unify.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/unify.cc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 unify.cc
--- unify.cc 18 Oct 2005 22:16:55 -0000 1.1.2.1
+++ unify.cc 21 Oct 2005 21:42:15 -0000
@@ -109,12 +109,14 @@
++i)
{
std::set<model_class *> inter, newset;
- compute_supertype_sets (*i, st, inter);
+ compute_supertype_sets (*i, st, first ? ec : inter);
if (! first)
- std::set_intersection (ec.begin (), ec.end (),
- inter.begin (), inter.end (),
- std::inserter (newset, newset.begin ()));
- ec = newset;
+ {
+ std::set_intersection (ec.begin (), ec.end (),
+ inter.begin (), inter.end (),
+ std::inserter (newset, newset.begin ()));
+ ec = newset;
+ }
first = false;
}
}
@@ -158,18 +160,23 @@
i != mec.end ();
++i)
{
- if ((*i)->get_type_parameters ().empty ())
- continue;
-
std::set<model_class_instance *> one_inv;
- for (std::set<model_class *>::const_iterator j = st.begin ();
- j != st.end ();
- ++j)
- {
- model_class_instance *ci
- = dynamic_cast<model_class_instance *> (*j);
- if (ci != NULL && ci->get_parent () == *i)
- one_inv.insert (ci);
+
+ // Note that if the type is not generic, then it will simply
+ // map to an empty set. This is ok -- see the definition of
+ // the Candidate() function in the JLS. This situation is
+ // recognized in compute_lub.
+ if (! (*i)->get_type_parameters ().empty ())
+ {
+ for (std::set<model_class *>::const_iterator j = st.begin ();
+ j != st.end ();
+ ++j)
+ {
+ model_class_instance *ci
+ = dynamic_cast<model_class_instance *> (*j);
+ if (ci != NULL && ci->get_parent () == *i)
+ one_inv.insert (ci);
+ }
}
invocation_map[*i] = one_inv;
@@ -505,16 +512,20 @@
i != formal_type_params.end ();
++i)
{
- if (mapping.find (*i) == mapping.end ())
+ std::map<model_class *, model_class *>::const_iterator mp
+ = mapping.find (*i);
+ if (mp != mapping.end ())
{
// FIXME: should we check the other constraints too?
- continue;
+ result.add (*i, (*mp).second);
+ }
+ else
+ {
+ std::set<model_class *> constraints;
+ update_constraint_set (LESS_THAN, *i, constraints);
+ update_constraint_set (GREATER_THAN, *i, constraints);
+ result.add (*i, compute_lub (constraints));
}
-
- std::set<model_class *> constraints;
- update_constraint_set (LESS_THAN, *i, constraints);
- update_constraint_set (GREATER_THAN, *i, constraints);
- result.add (*i, compute_lub (constraints));
}
}
Index: model/arraytype.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/arraytype.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 arraytype.cc
--- model/arraytype.cc 12 Oct 2005 19:07:42 -0000 1.1.2.2
+++ model/arraytype.cc 21 Oct 2005 21:42:15 -0000
@@ -74,6 +74,16 @@
return element->erasure ()->array ();
}
+model_class *
+model_array_type::apply_type_map (model_element *request,
+ const model_type_map &type_map)
+{
+ if (! element->reference_p ())
+ return this;
+ model_class *eltc = assert_cast<model_class *> (element);
+ return eltc->apply_type_map (request, type_map)->array ();
+}
+
void
model_array_type::visit (visitor *v)
{
Index: model/arraytype.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/arraytype.hh,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 arraytype.hh
--- model/arraytype.hh 12 Oct 2005 19:07:42 -0000 1.1.2.2
+++ model/arraytype.hh 21 Oct 2005 21:42:15 -0000
@@ -57,6 +57,8 @@
abort ();
}
+ model_class *apply_type_map (model_element *, const model_type_map &);
+
void visit (visitor *);
};
More information about the Java-patches
mailing list