Commit 83c1f628 by Tom Tromey Committed by Tom Tromey

re GNATS gcj/211 (gcjh doesn't handle method names that are reserved C++ keywords)

	PR gcj/211:
	* gjavah.c (utf8_cmp): Changed return value.
	(cxx_keyword_subst): Handle all C++ keywords.  Allocate new return
	result.
	(cxx_keywords): New global.
	(get_field_name): Handle new result of cxx_keyword_subst.
	(print_method_info): Likewise.

From-SVN: r33225
parent 44c01391
2000-04-18 Tom Tromey <tromey@cygnus.com>
PR gcj/211:
* gjavah.c (utf8_cmp): Changed return value.
(cxx_keyword_subst): Handle all C++ keywords. Allocate new return
result.
(cxx_keywords): New global.
(get_field_name): Handle new result of cxx_keyword_subst.
(print_method_info): Likewise.
2000-04-17 Bryce McKinlay <bryce@albatross.co.nz> 2000-04-17 Bryce McKinlay <bryce@albatross.co.nz>
* gjavah.c (print_name_for_stub_or_jni): Don't prefix method names * gjavah.c (print_name_for_stub_or_jni): Don't prefix method names
......
...@@ -131,7 +131,7 @@ static int java_double_finite PARAMS ((jdouble)); ...@@ -131,7 +131,7 @@ static int java_double_finite PARAMS ((jdouble));
static void print_name PARAMS ((FILE *, JCF *, int)); static void print_name PARAMS ((FILE *, JCF *, int));
static void print_base_classname PARAMS ((FILE *, JCF *, int)); static void print_base_classname PARAMS ((FILE *, JCF *, int));
static int utf8_cmp PARAMS ((const unsigned char *, int, const char *)); static int utf8_cmp PARAMS ((const unsigned char *, int, const char *));
static const char *cxx_keyword_subst PARAMS ((const unsigned char *, int)); static char *cxx_keyword_subst PARAMS ((const unsigned char *, int));
static void generate_access PARAMS ((FILE *, JCF_u2)); static void generate_access PARAMS ((FILE *, JCF_u2));
static int name_is_method_p PARAMS ((const unsigned char *, int)); static int name_is_method_p PARAMS ((const unsigned char *, int));
static char *get_field_name PARAMS ((JCF *, int, JCF_u2)); static char *get_field_name PARAMS ((JCF *, int, JCF_u2));
...@@ -336,7 +336,8 @@ print_base_classname (stream, jcf, index) ...@@ -336,7 +336,8 @@ print_base_classname (stream, jcf, index)
} }
} }
/* Return 0 if NAME is equal to STR, nonzero otherwise. */ /* Return 0 if NAME is equal to STR, -1 if STR is "less" than NAME,
and 1 if STR is "greater" than NAME. */
static int static int
utf8_cmp (str, length, name) utf8_cmp (str, length, name)
...@@ -351,26 +352,79 @@ utf8_cmp (str, length, name) ...@@ -351,26 +352,79 @@ utf8_cmp (str, length, name)
{ {
int ch = UTF8_GET (str, limit); int ch = UTF8_GET (str, limit);
if (ch != name[i]) if (ch != name[i])
return 1; return ch - name[i];
} }
return str != limit; return str == limit ? 0 : 1;
} }
/* This is a sorted list of all C++ keywords. */
static const char *cxx_keywords[] =
{
"asm",
"auto",
"bool",
"const_cast",
"delete",
"dynamic_cast",
"enum",
"explicit",
"extern",
"friend",
"inline",
"mutable",
"namespace",
"overload",
"register",
"reinterpret_cast",
"signed",
"sizeof",
"static_cast",
"struct",
"template",
"typedef",
"typeid",
"typename",
"typenameopt",
"union",
"unsigned",
"using",
"virtual",
"volatile",
"wchar_t"
};
/* If NAME is the name of a C++ keyword, then return an override name. /* If NAME is the name of a C++ keyword, then return an override name.
This is a name that can be used in place of the keyword. This is a name that can be used in place of the keyword.
Otherwise, return NULL. FIXME: for now, we only handle those Otherwise, return NULL. The return value is malloc()d. */
keywords we know to be a problem for libgcj. */
static const char * static char *
cxx_keyword_subst (str, length) cxx_keyword_subst (str, length)
const unsigned char *str; const unsigned char *str;
int length; int length;
{ {
if (! utf8_cmp (str, length, "delete")) int last = sizeof (cxx_keywords) / sizeof (const char *);
return "__dummy_delete"; int first = 0;
else if (! utf8_cmp (str, length, "enum")) int mid, r;
return "__dummy_enum";
while (last != first)
{
mid = (last + first) / 2;
r = utf8_cmp (str, length, cxx_keywords[mid]);
if (r == 0)
{
char *str = xmalloc (9 + strlen (cxx_keywords[mid]));
strcpy (str, "__dummy_");
strcat (str, cxx_keywords[mid]);
return str;
}
else if (r < 0)
last = mid;
else
first = mid;
}
return NULL; return NULL;
} }
...@@ -455,7 +509,6 @@ get_field_name (jcf, name_index, flags) ...@@ -455,7 +509,6 @@ get_field_name (jcf, name_index, flags)
unsigned char *name = JPOOL_UTF_DATA (jcf, name_index); unsigned char *name = JPOOL_UTF_DATA (jcf, name_index);
int length = JPOOL_UTF_LENGTH (jcf, name_index); int length = JPOOL_UTF_LENGTH (jcf, name_index);
char *override; char *override;
const char *tmpconstptr;
if (name_is_method_p (name, length)) if (name_is_method_p (name, length))
{ {
...@@ -474,13 +527,8 @@ get_field_name (jcf, name_index, flags) ...@@ -474,13 +527,8 @@ get_field_name (jcf, name_index, flags)
memcpy (override, name, length); memcpy (override, name, length);
strcpy (override + length, "__"); strcpy (override + length, "__");
} }
else if ((tmpconstptr = cxx_keyword_subst (name, length)) != NULL)
{
/* Must malloc OVERRIDE. */
override = xstrdup (tmpconstptr);
}
else else
override = NULL; override = cxx_keyword_subst (name, length);
return override; return override;
} }
...@@ -621,7 +669,7 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags), ...@@ -621,7 +669,7 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags),
{ {
const unsigned char *str; const unsigned char *str;
int length, is_init = 0; int length, is_init = 0;
const char *override = NULL; char *override = NULL;
method_declared = 0; method_declared = 0;
method_access = flags; method_access = flags;
...@@ -687,9 +735,12 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags), ...@@ -687,9 +735,12 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags),
mangling will be wrong. FIXME. */ mangling will be wrong. FIXME. */
if (METHOD_IS_FINAL (jcf->access_flags, flags) if (METHOD_IS_FINAL (jcf->access_flags, flags)
|| (flags & ACC_STATIC)) || (flags & ACC_STATIC))
{
free (override);
return; return;
} }
} }
}
if (! stubs && ! flag_jni) if (! stubs && ! flag_jni)
{ {
...@@ -722,6 +773,9 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags), ...@@ -722,6 +773,9 @@ DEFUN(print_method_info, (stream, jcf, name_index, sig_index, flags),
is_init, override, flags); is_init, override, flags);
} }
} }
if (override)
free (override);
} }
/* Try to decompile a method body. Right now we just try to handle a /* Try to decompile a method body. Right now we just try to handle a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment