* [gcjx] Patch: FYI: mangling fix
@ 2005-10-10 21:41 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2005-10-10 21:41 UTC (permalink / raw)
To: Java Patch List
I'm checking this in on the gcjx branch.
This fixes a small name mangling bug. We need to add a "$" in some
cases.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* aot/mangle.cc (update_cxx): New method.
* aot/mangle.hh (mangler::update_cxx): Declare.
* header/cni.hh (cni_code_generator::keyword_p): Removed.
* header/cni.cc (keywords): Moved to util.cc.
(NUM_KEYWORDS): Likewise.
(keyword_p): Likewise.
(write_method): Updated.
(write_field): Likewise.
* util.cc (keywords): New global.
(NUM_KEYWORDS): New macro.
* util.hh (cxx_keyword_p): Declare.
Index: util.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/util.cc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 util.cc
--- util.cc 13 Feb 2005 03:39:44 -0000 1.1.2.2
+++ util.cc 10 Oct 2005 21:41:02 -0000
@@ -23,6 +23,94 @@
#include <fstream>
+\f
+
+// Sorted list of C++ keywords.
+// FIXME: doesn't include some things that G++ might consider as
+// keywords.
+static const char *const keywords[] =
+{
+ "and",
+ "and_eq",
+ "asm",
+ "auto",
+ "bitand",
+ "bitor",
+ "bool",
+ "break",
+ "case",
+ "catch",
+ "char",
+ "class",
+ "compl",
+ "const",
+ "const_cast",
+ "continue",
+ "default",
+ "delete",
+ "do",
+ "double",
+ "dynamic_cast",
+ "else",
+ "enum",
+ "explicit",
+ "export",
+ "extern",
+ "false",
+ "float",
+ "for",
+ "friend",
+ "goto",
+ "if",
+ "inline",
+ "int",
+ "long",
+ "mutable",
+ "namespace",
+ "new",
+ "not",
+ "not_eq",
+ "operator",
+ "or",
+ "or_eq",
+ "private",
+ "protected",
+ "public",
+ "register",
+ "reinterpret_cast",
+ "return",
+ "short",
+ "signed",
+ "sizeof",
+ "static",
+ "static_cast",
+ "struct",
+ "switch",
+ "template",
+ "this",
+ "throw",
+ "true",
+ "try",
+ "typedef",
+ "typeid",
+ "typename",
+ "typeof",
+ "union",
+ "unsigned",
+ "using",
+ "virtual",
+ "void",
+ "volatile",
+ "wchar_t",
+ "while",
+ "xor",
+ "xor_eq"
+};
+
+#define NUM_KEYWORDS (sizeof (keywords) / sizeof (keywords[0]))
+
+\f
+
std::list<std::string>
drop_last_element (const std::list<std::string> &in)
{
@@ -211,3 +299,34 @@
// 2. Ensure that name actually represents an existing file6
return name_len > 5 && name.compare (name_len - 5, 5, ".java") == 0;
}
+
+bool
+cxx_keyword_p (const std::string &name)
+{
+ // Strip '$'s off the end.
+ int i;
+ for (i = name.length () - 1; i >= 0 && name[i] == '$'; --i)
+ ;
+ std::string newname = name.substr (0, i + 1);
+
+ int low = 0;
+ int high = NUM_KEYWORDS;
+ int last = -1;
+
+ while (true)
+ {
+ int current = (low + high) / 2;
+ if (current == last)
+ break;
+ int cmp = newname.compare (keywords[current]);
+ if (cmp == 0)
+ return true;
+ else if (cmp > 0)
+ low = current;
+ else
+ high = current;
+ last = current;
+ }
+
+ return false;
+}
Index: util.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/Attic/util.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 util.hh
--- util.hh 11 Sep 2005 01:00:34 -0000 1.1.2.3
+++ util.hh 10 Oct 2005 21:41:02 -0000
@@ -137,4 +137,7 @@
/// Return true if the string names a java source file.
bool java_file_p (const std::string &);
+/// Return true if the string is a C++ keyword.
+bool cxx_keyword_p (const std::string &);
+
#endif // GCJX_UTIL_HH
Index: aot/mangle.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/aot/Attic/mangle.cc,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 mangle.cc
--- aot/mangle.cc 27 Apr 2005 17:43:08 -0000 1.1.2.8
+++ aot/mangle.cc 10 Oct 2005 21:41:02 -0000
@@ -212,6 +212,18 @@
}
void
+mangler::update_cxx (const std::string &name)
+{
+ update (name);
+ // If we have a member whose name is a C++ keyword, we append '$'.
+ // Note that, strangely, we do this after encoding the length of the
+ // member name. E.g., we end up with things like "6delete$" rather
+ // than "7delete$".
+ if (cxx_keyword_p (name))
+ result = result + "$";
+}
+
+void
mangler::update (model_package *p)
{
int n = find_compression (p, false);
@@ -332,7 +344,7 @@
if (m->constructor_p ())
result += "C1";
else
- update (m->get_name ());
+ update_cxx (m->get_name ());
result += "E";
@@ -354,7 +366,7 @@
: result ("_Z")
{
update (f->get_declaring_class (), false);
- update (f->get_name ());
+ update_cxx (f->get_name ());
result += "E";
}
Index: aot/mangle.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/aot/Attic/mangle.hh,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 mangle.hh
--- aot/mangle.hh 8 Mar 2005 00:22:43 -0000 1.1.2.3
+++ aot/mangle.hh 10 Oct 2005 21:41:02 -0000
@@ -44,6 +44,7 @@
void update (model_package *);
void update_array (model_array_type *);
void update (model_type *, bool);
+ void update_cxx (const std::string &);
public:
Index: header/cni.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/header/Attic/cni.cc,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 cni.cc
--- header/cni.cc 29 Apr 2005 02:57:40 -0000 1.1.2.9
+++ header/cni.cc 10 Oct 2005 21:41:02 -0000
@@ -25,90 +25,6 @@
#include <fstream>
-// Sorted list of C++ keywords.
-// FIXME: doesn't include some things that G++ might consider as
-// keywords.
-static const char *const keywords[] =
-{
- "and",
- "and_eq",
- "asm",
- "auto",
- "bitand",
- "bitor",
- "bool",
- "break",
- "case",
- "catch",
- "char",
- "class",
- "compl",
- "const",
- "const_cast",
- "continue",
- "default",
- "delete",
- "do",
- "double",
- "dynamic_cast",
- "else",
- "enum",
- "explicit",
- "export",
- "extern",
- "false",
- "float",
- "for",
- "friend",
- "goto",
- "if",
- "inline",
- "int",
- "long",
- "mutable",
- "namespace",
- "new",
- "not",
- "not_eq",
- "operator",
- "or",
- "or_eq",
- "private",
- "protected",
- "public",
- "register",
- "reinterpret_cast",
- "return",
- "short",
- "signed",
- "sizeof",
- "static",
- "static_cast",
- "struct",
- "switch",
- "template",
- "this",
- "throw",
- "true",
- "try",
- "typedef",
- "typeid",
- "typename",
- "typeof",
- "union",
- "unsigned",
- "using",
- "virtual",
- "void",
- "volatile",
- "wchar_t",
- "while",
- "xor",
- "xor_eq"
-};
-
-#define NUM_KEYWORDS (sizeof (keywords) / sizeof (keywords[0]))
-
cni_code_generator::cni_code_generator (compiler *c, directory_cache &dirs)
: code_generator (dirs),
comp (c),
@@ -116,37 +32,6 @@
{
}
-bool
-cni_code_generator::keyword_p (const std::string &name)
-{
- // Strip '$'s off the end.
- int i;
- for (i = name.length () - 1; i >= 0 && name[i] == '$'; --i)
- ;
- std::string newname = name.substr (0, i + 1);
-
- int low = 0;
- int high = NUM_KEYWORDS;
- int last = -1;
-
- while (true)
- {
- int current = (low + high) / 2;
- if (current == last)
- break;
- int cmp = newname.compare (keywords[current]);
- if (cmp == 0)
- return true;
- else if (cmp > 0)
- low = current;
- else
- high = current;
- last = current;
- }
-
- return false;
-}
-
void
cni_code_generator::emit_actions (std::ostream &out,
cni_code_generator::action what,
@@ -504,7 +389,7 @@
if (! meth->get_return_type ()->reference_p ())
out << " ";
out << meth->get_name ();
- if (keyword_p (meth->get_name ()))
+ if (cxx_keyword_p (meth->get_name ()))
out << "$";
}
out << " (";
@@ -560,7 +445,7 @@
out << field->get_name ();
if (method_names.find (field->get_name ()) != method_names.end ())
out << "__";
- else if (keyword_p (field->get_name ()))
+ else if (cxx_keyword_p (field->get_name ()))
out << "$";
if (field->static_p () && field->constant_p () && ftype->integral_p ())
Index: header/cni.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcjx/header/Attic/cni.hh,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 cni.hh
--- header/cni.hh 29 Apr 2005 02:57:40 -0000 1.1.2.7
+++ header/cni.hh 10 Oct 2005 21:41:03 -0000
@@ -62,7 +62,6 @@
aot_class_factory factory;
- bool keyword_p (const std::string &);
std::string cxxname (model_type *, bool = true);
void update_modifiers (std::ostream &, modifier_t, modifier_t &);
void add (model_type *, std::set<model_class *> &,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-10 21:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-10 21:41 [gcjx] Patch: FYI: mangling 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).