summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Haley <aph@redhat.com>2009-06-30 15:52:12 +0000
committerAndrew Haley <aph@redhat.com>2009-06-30 15:52:12 +0000
commitc00bb49ca6d9e3d9d33ab3f115a26c6ad2750886 (patch)
tree57ab910cf29220321e643023e345fc39920eb6f3
parent67ad404efce9aeb60fa253c680e9c2815f6a13fc (diff)
downloadclasspath-c00bb49ca6d9e3d9d33ab3f115a26c6ad2750886.tar.gz
2009-06-29 Andrew Haley <aph@redhat.com>
PR java/40590 * tools/gnu/classpath/tools/javah/FieldHelper.java (print): Use printName(). * tools/gnu/classpath/tools/javah/MethodHelper.java (print): Use printName(). * tools/gnu/classpath/tools/javah/CniStubPrinter.java (printDecl): Use printName(). * tools/gnu/classpath/tools/javah/Keywords.java (words): Replace with keywords list from gcc/java/mangle.c. * tools/gnu/classpath/tools/javah/ClassWrapper.java (printMethods): Don't pre-convert a C++ keyword. (print(CniPrintStream)): Call CniPrintStream.printName(). (printContents): Likewise. * tools/gnu/classpath/tools/javah/CniPrintStream.java (getClassName): Don't call replaceAll("/", "::"). (print(Type)): Add ""::" befor name, " *" after. Use printName(), not print. (printName(PrintStream, String), printName(String), printlnName): New methods. (moveToPackage): Use printName().
-rw-r--r--ChangeLog23
-rw-r--r--tools/gnu/classpath/tools/javah/ClassWrapper.java7
-rw-r--r--tools/gnu/classpath/tools/javah/CniPrintStream.java39
-rw-r--r--tools/gnu/classpath/tools/javah/CniStubPrinter.java4
-rw-r--r--tools/gnu/classpath/tools/javah/FieldHelper.java2
-rw-r--r--tools/gnu/classpath/tools/javah/Keywords.java131
-rw-r--r--tools/gnu/classpath/tools/javah/MethodHelper.java4
7 files changed, 176 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index d4d8e3e03..81d0d1674 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2009-06-29 Andrew Haley <aph@redhat.com>
+
+ PR java/40590
+ * tools/gnu/classpath/tools/javah/FieldHelper.java (print):
+ Use printName().
+ * tools/gnu/classpath/tools/javah/MethodHelper.java (print):
+ Use printName().
+ * tools/gnu/classpath/tools/javah/CniStubPrinter.java (printDecl):
+ Use printName().
+ * tools/gnu/classpath/tools/javah/Keywords.java (words): Replace
+ with keywords list from gcc/java/mangle.c.
+ * tools/gnu/classpath/tools/javah/ClassWrapper.java (printMethods):
+ Don't pre-convert a C++ keyword.
+ (print(CniPrintStream)): Call CniPrintStream.printName().
+ (printContents): Likewise.
+ * tools/gnu/classpath/tools/javah/CniPrintStream.java
+ (getClassName): Don't call replaceAll("/", "::").
+ (print(Type)): Add ""::" befor name, " *" after. Use printName(), not
+ print.
+ (printName(PrintStream, String), printName(String), printlnName):
+ New methods.
+ (moveToPackage): Use printName().
+
2009-03-29 Mark Wielaard <mark@klomp.org>
* doc/www.gnu.org/faq/faq.wml: Fix link to cp-hacking.html.
diff --git a/tools/gnu/classpath/tools/javah/ClassWrapper.java b/tools/gnu/classpath/tools/javah/ClassWrapper.java
index 1f4d26a23..4b4d25046 100644
--- a/tools/gnu/classpath/tools/javah/ClassWrapper.java
+++ b/tools/gnu/classpath/tools/javah/ClassWrapper.java
@@ -260,7 +260,7 @@ public class ClassWrapper
if (bridgeTargets.contains(sum))
nameToUse = (String) methodNameMap.get(sum);
else
- nameToUse = Keywords.getCxxName(m.name);
+ nameToUse = m.name;
methodNameMap.put(sum, nameToUse);
MethodHelper.print(out, m, this, nameToUse);
}
@@ -291,7 +291,8 @@ public class ClassWrapper
public void print(CniPrintStream out)
{
- out.print("::" + name.replaceAll("/", "::"));
+ out.print("::");
+ out.printName(name);
}
// This prints the body of a class to a CxxPrintStream.
@@ -303,7 +304,7 @@ public class ClassWrapper
out.print("class ");
// Don't use our print() -- we don't want the leading "::".
- out.print(name.replaceAll("/", "::"));
+ out.printName(name);
if (superClass != null)
{
out.print(" : public ");
diff --git a/tools/gnu/classpath/tools/javah/CniPrintStream.java b/tools/gnu/classpath/tools/javah/CniPrintStream.java
index 33fd58b1e..52e6e539d 100644
--- a/tools/gnu/classpath/tools/javah/CniPrintStream.java
+++ b/tools/gnu/classpath/tools/javah/CniPrintStream.java
@@ -125,9 +125,10 @@ public class CniPrintStream
// Add the plain class name; we'll handle it when
// we process namespaces.
allClasses.add(name);
- return "::" + name.replaceAll("/", "::") + " *";
+ return name;
}
+ // Print the C++ form of TYPE, mangling C++ keywords.
public void print(Type type)
{
int arrayCount = 0;
@@ -141,7 +142,9 @@ public class CniPrintStream
}
if (type.getSort() == Type.OBJECT)
{
- print(getClassName(type));
+ print("::");
+ printName(getClassName(type));
+ print(" *");
}
else
{
@@ -156,6 +159,34 @@ public class CniPrintStream
}
}
+ // Print NAME, converting into C++ syntax and mangling C++ keywords
+ // as we go.
+ public final static void printName(PrintStream out, String name)
+ {
+ String[] parts = name.split("::|/");
+ for (int i = 0; i < parts.length; i++)
+ {
+ if (i != 0)
+ out.print("::");
+ out.print(Keywords.getCxxName(parts[i]));
+ }
+ }
+
+ // Println NAME, converting into C++ syntax and mangling C++
+ // keywords as we go.
+ public final static void printlnName(PrintStream out, String name)
+ {
+ printName(out, name);
+ out.println();
+ }
+
+ // Print NAME, converting into C++ syntax and mangling C++ keywords
+ // as we go.
+ final void printName(String name)
+ {
+ printName(this, name);
+ }
+
private void indent(PrintStream out, int n)
{
for (int i = 0; i < n; ++i)
@@ -186,7 +217,7 @@ public class CniPrintStream
{
indent(out, j + 1);
out.print("namespace ");
- out.println(pkgParts[j]);
+ printlnName(out, pkgParts[j]);
indent(out, j + 1);
out.println("{");
}
@@ -202,7 +233,7 @@ public class CniPrintStream
moveToPackage(out, pkgParts);
indent(out, pkgParts.length + 2);
out.print("class ");
- out.print(className);
+ printName(out, className);
out.println(";");
}
diff --git a/tools/gnu/classpath/tools/javah/CniStubPrinter.java b/tools/gnu/classpath/tools/javah/CniStubPrinter.java
index f96091ea1..9b5dc2c36 100644
--- a/tools/gnu/classpath/tools/javah/CniStubPrinter.java
+++ b/tools/gnu/classpath/tools/javah/CniStubPrinter.java
@@ -59,9 +59,9 @@ public class CniStubPrinter
private void printDecl(CniPrintStream out, String className, MethodNode method)
{
- out.print(className);
+ out.printName(className);
out.print("::");
- out.print(method.name);
+ out.printName(method.name);
out.print("(");
Type[] argTypes = Type.getArgumentTypes(method.desc);
for (int j = 0; j < argTypes.length; ++j)
diff --git a/tools/gnu/classpath/tools/javah/FieldHelper.java b/tools/gnu/classpath/tools/javah/FieldHelper.java
index f1c369af2..84b1fce8b 100644
--- a/tools/gnu/classpath/tools/javah/FieldHelper.java
+++ b/tools/gnu/classpath/tools/javah/FieldHelper.java
@@ -66,7 +66,7 @@ public class FieldHelper
out.print(")))) ");
result = true;
}
- out.print(Keywords.getCxxName(field.name));
+ out.printName(field.name);
if (hasMethodName)
out.print("__");
if (Modifier.isStatic(field.access))
diff --git a/tools/gnu/classpath/tools/javah/Keywords.java b/tools/gnu/classpath/tools/javah/Keywords.java
index 9cab62283..73e2c627c 100644
--- a/tools/gnu/classpath/tools/javah/Keywords.java
+++ b/tools/gnu/classpath/tools/javah/Keywords.java
@@ -42,28 +42,115 @@ import java.util.HashSet;
public class Keywords
{
- private static final String[] words = { "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" };
+/* A sorted list of all C++ keywords. This is identical to the list
+ in gcc/java/mangle.c. */
+ private static final String[] words =
+ {
+ "_Complex",
+ "__alignof",
+ "__alignof__",
+ "__asm",
+ "__asm__",
+ "__attribute",
+ "__attribute__",
+ "__builtin_va_arg",
+ "__complex",
+ "__complex__",
+ "__const",
+ "__const__",
+ "__extension__",
+ "__imag",
+ "__imag__",
+ "__inline",
+ "__inline__",
+ "__label__",
+ "__null",
+ "__real",
+ "__real__",
+ "__restrict",
+ "__restrict__",
+ "__signed",
+ "__signed__",
+ "__typeof",
+ "__typeof__",
+ "__volatile",
+ "__volatile__",
+ "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"
+ };
private static final HashSet<String> keywords;
static
diff --git a/tools/gnu/classpath/tools/javah/MethodHelper.java b/tools/gnu/classpath/tools/javah/MethodHelper.java
index 3efd05019..8743f9a84 100644
--- a/tools/gnu/classpath/tools/javah/MethodHelper.java
+++ b/tools/gnu/classpath/tools/javah/MethodHelper.java
@@ -97,14 +97,14 @@ public class MethodHelper
{
out.print(Type.getReturnType(meth.desc));
out.print(" ");
- out.print(realMethodName);
+ out.printName(realMethodName);
}
else
{
String name = declarer.name;
int index = name.lastIndexOf('/');
name = name.substring(index + 1);
- out.print(name);
+ out.printName(name);
}
out.print("(");
Type[] argTypes = Type.getArgumentTypes(meth.desc);