[gcjx] Patch: FYI: minor invocation cleanup
Tom Tromey
tromey@redhat.com
Fri Oct 14 22:04:00 GMT 2005
I'm checking this in on the gcjx branch.
This changes invocation and method applicability to match the JLS 3 a
little more closely. This also enables the possibility of rejecting
certain inappropriate generic method invocations.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* model/invoke.cc (potentially_applicable_p): New methods.
* model/invoke.hh (model_invocation_base::potentially_applicable_p):
Declare.
(model_generic_invocation::potentially_applicable_p): Likewise.
* model/parameters.hh (model_parameters::size): New method.
* model/method.hh (model_method::potentially_applicable_p):
Declare.
* model/method.cc (method_conversion_p): Removed early
applicability test.
(potentially_applicable_p): New methods.
Index: model/invoke.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/invoke.cc,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 invoke.cc
--- model/invoke.cc 14 Oct 2005 19:07:34 -0000 1.1.2.7
+++ model/invoke.cc 14 Oct 2005 22:02:34 -0000
@@ -21,6 +21,13 @@
#include "typedefs.hh"
+bool
+model_invocation_base::potentially_applicable_p (model_method *meth,
+ const std::list<model_type *> &actual_types)
+{
+ return meth->potentially_applicable_p (actual_types);
+}
+
void
model_invocation_base::try_method_conversion
(const std::set<model_method *> &accessible,
@@ -51,7 +58,8 @@
i != accessible.end ();
++i)
{
- if ((*i)->method_conversion_p (actual_types, phase))
+ if (potentially_applicable_p (*i, actual_types)
+ && (*i)->method_conversion_p (actual_types, phase))
applicable.insert (*i);
}
if (! should_loop)
@@ -615,6 +623,14 @@
{
}
+template<typename T>
+bool
+model_generic_invocation<T>::potentially_applicable_p (model_method *meth,
+ const std::list<model_type *> &actual_types)
+{
+ return meth->potentially_applicable_p (actual_types, actual_type_params);
+}
+
// Instantiations.
Index: model/invoke.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/invoke.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 invoke.hh
--- model/invoke.hh 13 Oct 2005 06:28:55 -0000 1.1.2.3
+++ model/invoke.hh 14 Oct 2005 22:02:34 -0000
@@ -58,6 +58,9 @@
const std::list<model_type *> &,
std::set<model_method *> &);
+ virtual bool potentially_applicable_p (model_method *,
+ const std::list<model_type *> &);
+
// This returns the class or interface we must search to find the
// method named NAME, as well as the qualifying class or interface.
virtual void determine_search_class (resolution_scope *,
@@ -274,6 +277,9 @@
/// The actual type parameters.
std::list<ref_forwarding_type> actual_type_params;
+ bool potentially_applicable_p (model_method *,
+ const std::list<model_type *> &);
+
public:
model_generic_invocation (const location &,
Index: model/method.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.cc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 method.cc
--- model/method.cc 12 Oct 2005 19:07:42 -0000 1.1.2.6
+++ model/method.cc 14 Oct 2005 22:02:34 -0000
@@ -151,12 +151,29 @@
}
bool
-model_method::method_conversion_p (const std::list<model_type *> &args,
- method_phase phase)
+model_method::potentially_applicable_p (const std::list<model_type *> &args)
{
- if (! varargs && args.size () != parameters.size ())
+ int args_size = args.size ();
+ int params_size = parameters.size ();
+ if ((! varargs && args_size != params_size)
+ || (varargs && args_size < params_size - 1))
return false;
+ return true;
+}
+bool
+model_method::potentially_applicable_p (const std::list<model_type *> &args,
+ const std::list<ref_forwarding_type> &type_args)
+{
+ if (type_parameters.size () != type_args.size ())
+ return false;
+ return potentially_applicable_p (args);
+}
+
+bool
+model_method::method_conversion_p (const std::list<model_type *> &args,
+ method_phase phase)
+{
std::list<ref_variable_decl>::const_iterator this_it
= parameters.begin ();
std::list<model_type *>::const_iterator args_it = args.begin ();
@@ -170,8 +187,8 @@
// varargs methods.
++this_it;
- // We're handling varargs if we're in phase 3, this is the last
- // argument of a varargs method, and if the feature is enabled.
+ // We're handling varargs if: we're in phase 3, this is the last
+ // argument of a varargs method, and the feature is enabled.
if (phase == PHASE_3
&& this_it == parameters.end ()
&& varargs
Index: model/method.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/method.hh,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 method.hh
--- model/method.hh 12 Oct 2005 19:07:42 -0000 1.1.2.5
+++ model/method.hh 14 Oct 2005 22:02:34 -0000
@@ -274,6 +274,14 @@
/// method is applicable and we can apply all necessary conversions.
void method_conversion (std::list<ref_expression> &);
+ /// Check for potential applicability.
+ bool potentially_applicable_p (const std::list<model_type *> &);
+
+ /// Check for potential applicability, where explicit type
+ /// parameters are given.
+ bool potentially_applicable_p (const std::list<model_type *> &,
+ const std::list<ref_forwarding_type> &);
+
/// Add an argument to a constructor. This is only used for new
/// hidden parameters, like captured 'final' local variables.
virtual void add_parameter (const ref_variable_decl &)
Index: model/parameters.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/model/Attic/parameters.hh,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 parameters.hh
--- model/parameters.hh 13 Jan 2005 03:18:36 -0000 1.1.2.1
+++ model/parameters.hh 14 Oct 2005 22:02:34 -0000
@@ -1,6 +1,6 @@
// Parameters for a generic method or class.
-// Copyright (C) 2004 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
@@ -50,6 +50,11 @@
return type_parameters.empty ();
}
+ unsigned int size () const
+ {
+ return type_parameters.size ();
+ }
+
/// Create a type map that maps our type variables onto the other
/// type variables. Returns true if this was successful, false
/// otherwise.
More information about the Java-patches
mailing list