From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22283 invoked by alias); 10 Oct 2005 21:41:42 -0000 Mailing-List: contact java-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-patches-owner@gcc.gnu.org Received: (qmail 22241 invoked by uid 22791); 10 Oct 2005 21:41:40 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 10 Oct 2005 21:41:40 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j9ALfcjk016366 for ; Mon, 10 Oct 2005 17:41:38 -0400 Received: from opsy.redhat.com (vpn50-2.rdu.redhat.com [172.16.50.2]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j9ALfbV18864; Mon, 10 Oct 2005 17:41:37 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 191252DC0FB; Mon, 10 Oct 2005 15:35:18 -0600 (MDT) To: Java Patch List Subject: [gcjx] Patch: FYI: mangling fix From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Mon, 10 Oct 2005 21:41:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2005-q4/txt/msg00053.txt.bz2 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 * 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 + + +// 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])) + + + std::list drop_last_element (const std::list &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 -// 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 &,