* tools/gnu/classpath/tools/javah/JniStubPrinter.java

(printClass): Added filename argument.
	* tools/gnu/classpath/tools/javah/JniIncludePrinter.java
	(printClass): Added filename argument.
	* tools/gnu/classpath/tools/javah/CniIncludePrinter.java
	(printClass): Use user's file name.
	* tools/gnu/classpath/tools/javah/CniStubPrinter.java
	(printClass): Use user's file name.
	* tools/gnu/classpath/tools/javah/Printer.java (printClass): Added
	filename argument.
	* tools/gnu/classpath/tools/javah/Main.java (getParser): Fix '-v'
	argument order.
	(writeHeaders): Use a HashMap.
	(run): Put class name into HashMap for writeHeaders.

From-SVN: r123000
This commit is contained in:
Tom Tromey 2007-03-16 22:48:27 +00:00 committed by Tom Tromey
parent 3422222a02
commit 90f89aa496
23 changed files with 50 additions and 21 deletions

View File

@ -1,3 +1,20 @@
2007-03-16 Tom Tromey <tromey@redhat.com>
* tools/gnu/classpath/tools/javah/JniStubPrinter.java
(printClass): Added filename argument.
* tools/gnu/classpath/tools/javah/JniIncludePrinter.java
(printClass): Added filename argument.
* tools/gnu/classpath/tools/javah/CniIncludePrinter.java
(printClass): Use user's file name.
* tools/gnu/classpath/tools/javah/CniStubPrinter.java
(printClass): Use user's file name.
* tools/gnu/classpath/tools/javah/Printer.java (printClass): Added
filename argument.
* tools/gnu/classpath/tools/javah/Main.java (getParser): Fix '-v'
argument order.
(writeHeaders): Use a HashMap.
(run): Put class name into HashMap for writeHeaders.
2007-03-02 Mario Torre <neugens@limasoftware.net>
PR classpath/31017:

View File

@ -1,5 +1,5 @@
/* CniIncludePrinter.java - generate CNI header files
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -63,14 +63,14 @@ public class CniIncludePrinter
return new PrintStream(fos);
}
public void printClass(ClassWrapper klass) throws IOException
public void printClass(File filename, ClassWrapper klass) throws IOException
{
// Never write Object or Class. This is a hack, maybe
// the user would like to see what they look like...
if (klass.name.equals("java/lang/Object")
|| klass.name.equals("java/lang/Class"))
return;
PrintStream ps = getPrintStream(klass.name + ".h", klass);
PrintStream ps = getPrintStream(filename + ".h", klass);
if (ps == null)
return;
ps.println();

View File

@ -1,5 +1,5 @@
/* CniStubPrinter.java - Generate a CNI stub file
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -90,12 +90,12 @@ public class CniStubPrinter
return new CniPrintStream(fos);
}
public void printClass(ClassWrapper klass) throws IOException
public void printClass(File filename, ClassWrapper klass) throws IOException
{
if (! klass.hasNativeMethod())
return;
String className = klass.name.replaceAll("/", "::");
CniPrintStream out = (CniPrintStream) getPrintStream(klass.name + ".cc",
CniPrintStream out = (CniPrintStream) getPrintStream(filename + ".cc",
klass);
if (out == null)
return;

View File

@ -107,8 +107,9 @@ public class JniIncludePrinter
return new JniPrintStream(classpath, fos, klass);
}
public void printClass(ClassWrapper klass) throws IOException
public void printClass(File filename, ClassWrapper klass) throws IOException
{
// Note that we ignore the filename here.
String xname = JniHelper.mangle(klass.name);
JniPrintStream out
= (JniPrintStream) getPrintStream(klass.name.replace('/', '_') + ".h",

View File

@ -1,5 +1,5 @@
/* JniStubPrinter.java - Generate JNI stub files
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -71,8 +71,9 @@ public class JniStubPrinter
return new JniPrintStream(classpath, fos, klass);
}
public void printClass(ClassWrapper klass) throws IOException
public void printClass(File filename, ClassWrapper klass) throws IOException
{
// Note that we ignore the filename here.
if (! klass.hasNativeMethod())
return;
String xname = JniHelper.mangle(klass.name);

View File

@ -58,6 +58,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import org.objectweb.asm.ClassReader;
@ -254,7 +255,7 @@ public class Main
cni = true;
}
});
result.add(new Option('v', "verbose", "Set verbose mode")
result.add(new Option("verbose", 'v', "Set verbose mode")
{
public void parsed(String arg0) throws OptionException
{
@ -309,16 +310,18 @@ public class Main
return result;
}
private void writeHeaders(ArrayList klasses, Printer printer)
private void writeHeaders(HashMap klasses, Printer printer)
throws IOException
{
Iterator i = klasses.iterator();
Iterator i = klasses.entrySet().iterator();
while (i.hasNext())
{
ClassWrapper klass = (ClassWrapper) i.next();
Map.Entry e = (Map.Entry) i.next();
File filename = (File) e.getKey();
ClassWrapper klass = (ClassWrapper) e.getValue();
if (verbose)
System.err.println("[writing " + klass + "]");
printer.printClass(klass);
System.err.println("[writing " + klass + " as " + filename + "]");
printer.printClass(filename, klass);
}
}
@ -376,19 +379,21 @@ public class Main
}
Iterator i = klasses.iterator();
ArrayList results = new ArrayList();
HashMap results = new HashMap();
while (i.hasNext())
{
// Let user specify either kind of class name or a
// file name.
Object item = i.next();
ClassWrapper klass;
File filename;
if (item instanceof File)
{
// Load class from file.
if (verbose)
System.err.println("[reading file " + item + "]");
klass = getClass((File) item);
filename = (File) item;
klass = getClass(filename);
}
else
{
@ -396,9 +401,12 @@ public class Main
String className = ((String) item).replace('.', '/');
if (verbose)
System.err.println("[reading class " + className + "]");
// Use the name the user specified, even if it is
// different from the ultimate class name.
filename = new File(className);
klass = getClass(className);
}
results.add(klass);
results.put(filename, klass);
}
writeHeaders(results, printer);
@ -436,7 +444,8 @@ public class Main
String resource = name.replace('.', '/') + ".class";
URL url = loader.findResource(resource);
if (url == null)
throw new IOException("can't find class file " + resource);
throw new IOException("can't find class file " + resource
+ " in " + loader);
InputStream is = url.openStream();
ClassWrapper result = readClass(is);
classMap.put(name, result);

View File

@ -1,5 +1,5 @@
/* Print.java - abstract base class for printing classes
Copyright (C) 2006 Free Software Foundation, Inc.
Copyright (C) 2006, 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -95,7 +95,8 @@ public abstract class Printer
this.force = force;
}
public abstract void printClass(ClassWrapper klass) throws IOException;
public abstract void printClass(File filename, ClassWrapper klass)
throws IOException;
protected abstract void writePreambleImpl(PrintStream ps);