[gcjx] Patch: FYI: fix import test failure
Tom Tromey
tromey@redhat.com
Fri Oct 28 19:31:00 GMT 2005
I'm checking this in on the gcjx branch.
This fixes a test failure related to 'import'. Now we verify that an
import is canonical.
There are still a few more cases to catch here, I haven't done that
yet. Another nice cleanup would be to rationalize the "get a name for
a class" code.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* model/import.cc (resolve): Error if name is not canonical.
* model/class.cc (get_canonical_name): New method.
* model/class.hh (model_class::get_canonical_name): Declare.
Index: model/class.hh
===================================================================
--- model/class.hh (revision 105944)
+++ model/class.hh (working copy)
@@ -324,11 +324,17 @@
std::string get_output_name () const;
/// Returns this class' name in the form "java.lang.Object".
+ /// Member classes are separated using '$'.
std::string get_fully_qualified_name ();
- /// Returns this class' name in the form "java/lang/Object".
+ /// Like get_fully_qualified_name(), but returns this class' name in
+ /// the form "java/lang/Object".
std::string get_fully_qualified_name_with_slashes ();
+ /// Like get_fully_qualified_name(), but member classes are
+ /// separated using '.'.
+ std::string get_canonical_name ();
+
void implicit_modifier (modifier_t);
// Ambiguity prevention.
Index: model/import.cc
===================================================================
--- model/import.cc (revision 105944)
+++ model/import.cc (working copy)
@@ -50,6 +50,10 @@
if (! resolved_type)
throw error ("%1 does not name a class or interface type") % name;
+ if (resolved_type->get_canonical_name () != join (name, '.'))
+ throw error ("%1 is not the canonical name of class %2")
+ % join (name, '.') % resolved_type;
+
if (scope->warn_java_lang_import ()
&& java_lang_p (resolved_type->get_package ()))
std::cerr << warn (global->get_compiler ()->warn_java_lang_import (),
@@ -77,6 +81,14 @@
if (! resolved_type)
resolved_type = classify_package_or_type_name (scope, this, name);
+ if (! resolved_type->package_p ())
+ {
+ model_class *k = assert_cast<model_class *> (resolved_type);
+ if (k->get_canonical_name () != join (name, '.'))
+ throw error ("%1 is not the canonical name of class %2")
+ % join (name, '.') % k;
+ }
+
if (! implicit
&& scope->warn_java_lang_import ()
&& java_lang_p (resolved_type))
@@ -135,6 +147,10 @@
if (! resolved_type)
throw error ("%1 does not name a class or interface type")
% join (name, '.');
+
+ if (resolved_type->get_canonical_name () != join (name, '.'))
+ throw error ("%1 is not the canonical name of class %2")
+ % join (name, '.') % resolved_type;
}
model_class *
Index: model/class.cc
===================================================================
--- model/class.cc (revision 105944)
+++ model/class.cc (working copy)
@@ -496,6 +496,24 @@
return name;
}
+std::string
+model_class::get_canonical_name ()
+{
+ std::string result;
+ if (declaring_class)
+ result = (declaring_class->get_canonical_name ()
+ + "."
+ + get_assigned_name ());
+ else
+ {
+ result = compilation_unit->get_package ()->get_fully_qualified_name ();
+ if (! result.empty ())
+ result += ".";
+ result += name;
+ }
+ return result;
+}
+
bool
model_class::assignable_from_p (model_type *other)
{
More information about the Java-patches
mailing list