From: Tom Tromey <tromey@redhat.com>
To: Java Patch List <java-patches@gcc.gnu.org>
Subject: [gcjx] Patch: FYI: conditional expressions -vs- lub
Date: Wed, 26 Oct 2005 01:35:00 -0000 [thread overview]
Message-ID: <m3oe5dxdzp.fsf@localhost.localdomain> (raw)
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, "
reply other threads:[~2005-10-26 1:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3oe5dxdzp.fsf@localhost.localdomain \
--to=tromey@redhat.com \
--cc=java-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).