summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-12-01 23:24:30 +0100
committerMichael Bien <[email protected]>2009-12-01 23:24:30 +0100
commitb0758ce498793c5e130493d9a03d7632de152855 (patch)
tree2597fa7f1e10dea4ffebff383ec830988460361d
parent0a5bc7f5a379b52cf5fe6bb9ea22f59fdec1fff0 (diff)
Code cleanup. Ported package com.sun.gluegen to java 5 language level.
-rw-r--r--src/java/com/sun/gluegen/ArrayTypes.java32
-rw-r--r--src/java/com/sun/gluegen/CMethodBindingEmitter.java98
-rw-r--r--src/java/com/sun/gluegen/CodeGenUtils.java31
-rw-r--r--src/java/com/sun/gluegen/CommentEmitter.java3
-rw-r--r--src/java/com/sun/gluegen/ConstantDefinition.java14
-rw-r--r--src/java/com/sun/gluegen/DebugEmitter.java24
-rw-r--r--src/java/com/sun/gluegen/FunctionEmitter.java66
-rw-r--r--src/java/com/sun/gluegen/GlueEmitter.java6
-rw-r--r--src/java/com/sun/gluegen/GlueGen.java54
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java472
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java186
-rw-r--r--src/java/com/sun/gluegen/JavaMethodBindingEmitter.java57
-rw-r--r--src/java/com/sun/gluegen/JavaType.java24
-rw-r--r--src/java/com/sun/gluegen/MethodBinding.java143
-rw-r--r--src/java/com/sun/gluegen/ReferencedStructs.java5
-rw-r--r--src/java/com/sun/gluegen/SymbolFilter.java8
-rw-r--r--src/java/com/sun/gluegen/TypeInfo.java1
-rw-r--r--src/java/com/sun/gluegen/cgram/types/TypeDictionary.java44
18 files changed, 624 insertions, 644 deletions
diff --git a/src/java/com/sun/gluegen/ArrayTypes.java b/src/java/com/sun/gluegen/ArrayTypes.java
index 7e5dd95..d943a8a 100644
--- a/src/java/com/sun/gluegen/ArrayTypes.java
+++ b/src/java/com/sun/gluegen/ArrayTypes.java
@@ -48,23 +48,23 @@ import java.nio.*;
*/
public class ArrayTypes {
/** Class for Java type boolean[] */
- public static final Class booleanArrayClass;
+ public static final Class<?> booleanArrayClass;
/** Class for Java type byte[] */
- public static final Class byteArrayClass;
+ public static final Class<?> byteArrayClass;
/** Class for Java type char[] */
- public static final Class charArrayClass;
+ public static final Class<?> charArrayClass;
/** Class for Java type short[] */
- public static final Class shortArrayClass;
+ public static final Class<?> shortArrayClass;
/** Class for Java type int[] */
- public static final Class intArrayClass;
+ public static final Class<?> intArrayClass;
/** Class for Java type long[] */
- public static final Class longArrayClass;
+ public static final Class<?> longArrayClass;
/** Class for Java type float[] */
- public static final Class floatArrayClass;
+ public static final Class<?> floatArrayClass;
/** Class for Java type double[] */
- public static final Class doubleArrayClass;
+ public static final Class<?> doubleArrayClass;
/** Class for Java type String[] */
- public static final Class stringArrayClass;
+ public static final Class<?> stringArrayClass;
// Classes for two-dimensional arrays.
//
@@ -89,19 +89,19 @@ public class ArrayTypes {
// certain OpenGL operations.
/** Class for Java type Buffer[] */
- public static final Class bufferArrayClass;
+ public static final Class<?> bufferArrayClass;
/** Class for Java type ByteBuffer[] */
- public static final Class byteBufferArrayClass;
+ public static final Class<?> byteBufferArrayClass;
/** Class for Java type ShortBuffer[] */
- public static final Class shortBufferArrayClass;
+ public static final Class<?> shortBufferArrayClass;
/** Class for Java type IntBuffer[] */
- public static final Class intBufferArrayClass;
+ public static final Class<?> intBufferArrayClass;
/** Class for Java type LongBuffer[] */
- public static final Class longBufferArrayClass;
+ public static final Class<?> longBufferArrayClass;
/** Class for Java type FloatBuffer[] */
- public static final Class floatBufferArrayClass;
+ public static final Class<?> floatBufferArrayClass;
/** Class for Java type DoubleBuffer[] */
- public static final Class doubleBufferArrayClass;
+ public static final Class<?> doubleBufferArrayClass;
static {
booleanArrayClass = new boolean[0].getClass();
diff --git a/src/java/com/sun/gluegen/CMethodBindingEmitter.java b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
index af632c3..784b2f9 100644
--- a/src/java/com/sun/gluegen/CMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/CMethodBindingEmitter.java
@@ -82,13 +82,13 @@ public class CMethodBindingEmitter extends FunctionEmitter
/**
* Optional List of Strings containing temporary C variables to declare.
*/
- private List/*<String>*/ temporaryCVariableDeclarations;
+ private List<String> temporaryCVariableDeclarations;
/**
* Optional List of Strings containing assignments to temporary C variables
* to make after the call is completed.
*/
- private List/*<String>*/ temporaryCVariableAssignments;
+ private List<String> temporaryCVariableAssignments;
/**
* Capacity of the return value in the event that it is encapsulated in a
@@ -161,8 +161,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
/**
* Get the expression for the capacity of the returned java.nio.Buffer.
*/
- public final MessageFormat getReturnValueCapacityExpression()
- {
+ public final MessageFormat getReturnValueCapacityExpression() {
return returnValueCapacityExpression;
}
@@ -183,13 +182,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
* binding.getJavaReturnType().isCompoundTypeWrapper() == false
* </code>
*/
- public final void setReturnValueCapacityExpression(MessageFormat expression)
- {
+ public final void setReturnValueCapacityExpression(MessageFormat expression) {
returnValueCapacityExpression = expression;
if (!binding.getJavaReturnType().isNIOBuffer() &&
- !binding.getJavaReturnType().isCompoundTypeWrapper())
- {
+ !binding.getJavaReturnType().isCompoundTypeWrapper()) {
throw new IllegalArgumentException(
"Cannot specify return value capacity for a method that does not " +
"return java.nio.Buffer or a compound type wrapper: \"" + binding + "\"");
@@ -199,8 +196,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
/**
* Get the expression for the length of the returned array
*/
- public final MessageFormat getReturnValueLengthExpression()
- {
+ public final MessageFormat getReturnValueLengthExpression() {
return returnValueLengthExpression;
}
@@ -219,13 +215,11 @@ public class CMethodBindingEmitter extends FunctionEmitter
* binding.getJavaReturnType().isNIOBuffer() == false
* </code>
*/
- public final void setReturnValueLengthExpression(MessageFormat expression)
- {
+ public final void setReturnValueLengthExpression(MessageFormat expression) {
returnValueLengthExpression = expression;
if (!binding.getJavaReturnType().isArray() &&
- !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers())
- {
+ !binding.getJavaReturnType().isArrayOfCompoundTypeWrappers()) {
throw new IllegalArgumentException(
"Cannot specify return value length for a method that does not " +
"return an array: \"" + binding + "\"");
@@ -236,7 +230,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
* Returns the List of Strings containing declarations for temporary
* C variables to be assigned to after the underlying function call.
*/
- public final List/*<String>*/ getTemporaryCVariableDeclarations() {
+ public final List<String> getTemporaryCVariableDeclarations() {
return temporaryCVariableDeclarations;
}
@@ -245,7 +239,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
* variables to be assigned to after the underlying function call. A
* null argument indicates that no manual declarations are to be made.
*/
- public final void setTemporaryCVariableDeclarations(List/*<String>*/ arg) {
+ public final void setTemporaryCVariableDeclarations(List<String> arg) {
temporaryCVariableDeclarations = arg;
}
@@ -255,7 +249,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
* null argument indicates that no manual assignments are to be
* made.
*/
- public final List/*<String>*/ getTemporaryCVariableAssignments() {
+ public final List<String> getTemporaryCVariableAssignments() {
return temporaryCVariableAssignments;
}
@@ -264,7 +258,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
* variables which are made after the underlying function call. A
* null argument indicates that no manual assignments are to be made.
*/
- public final void setTemporaryCVariableAssignments(List/*<String>*/ arg) {
+ public final void setTemporaryCVariableAssignments(List<String> arg) {
temporaryCVariableAssignments = arg;
}
@@ -304,29 +298,24 @@ public class CMethodBindingEmitter extends FunctionEmitter
public final MachineDescription getMachineDescription() { return machDesc; }
- protected void emitReturnType(PrintWriter writer)
- {
+ protected void emitReturnType(PrintWriter writer) {
writer.print("JNIEXPORT ");
writer.print(binding.getJavaReturnType().jniTypeName());
writer.print(" JNICALL");
}
- protected void emitName(PrintWriter writer)
- {
+ protected void emitName(PrintWriter writer) {
writer.println(); // start name on new line
writer.print("Java_");
writer.print(jniMangle(getJavaPackageName()));
writer.print("_");
writer.print(jniMangle(getJavaClassName()));
writer.print("_");
- if (isOverloadedBinding)
- {
+ if (isOverloadedBinding) {
writer.print(jniMangle(binding));
//System.err.println("OVERLOADED MANGLING FOR " + getName() +
// " = " + jniMangle(binding));
- }
- else
- {
+ } else {
writer.print(jniMangle(getName()));
//System.err.println(" NORMAL MANGLING FOR " + binding.getName() +
// " = " + jniMangle(getName()));
@@ -344,23 +333,18 @@ public class CMethodBindingEmitter extends FunctionEmitter
return "";
}
- protected int emitArguments(PrintWriter writer)
- {
+ protected int emitArguments(PrintWriter writer) {
writer.print("JNIEnv *env, ");
int numEmitted = 1; // initially just the JNIEnv
- if (isJavaMethodStatic && !binding.hasContainingType())
- {
+ if (isJavaMethodStatic && !binding.hasContainingType()) {
writer.print("jclass");
- }
- else
- {
+ } else {
writer.print("jobject");
}
writer.print(" _unused");
++numEmitted;
- if (binding.hasContainingType())
- {
+ if (binding.hasContainingType()) {
// "this" argument always comes down in argument 0 as direct buffer
writer.print(", jobject " + JavaMethodBindingEmitter.javaThisArgumentName());
}
@@ -394,8 +378,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
- protected void emitBody(PrintWriter writer)
- {
+ protected void emitBody(PrintWriter writer) {
writer.println(" {");
emitBodyVariableDeclarations(writer);
emitBodyUserVariableDeclarations(writer);
@@ -410,8 +393,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
writer.println();
}
- protected void emitBodyVariableDeclarations(PrintWriter writer)
- {
+ protected void emitBodyVariableDeclarations(PrintWriter writer) {
// Emit declarations for all pointer and String conversion variables
if (binding.hasContainingType()) {
emitPointerDeclaration(writer,
@@ -489,7 +471,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
writer.print(arrayResLength);
writer.println(";");
- Class componentType = javaReturnType.getJavaClass().getComponentType();
+ Class<?> componentType = javaReturnType.getJavaClass().getComponentType();
if (componentType.isArray()) {
throw new RuntimeException("Multi-dimensional arrays not supported yet");
}
@@ -511,8 +493,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
TemporaryCVariableDeclarations directive in the .cfg file. */
protected void emitBodyUserVariableDeclarations(PrintWriter writer) {
if (temporaryCVariableDeclarations != null) {
- for (Iterator iter = temporaryCVariableDeclarations.iterator(); iter.hasNext(); ) {
- String val = (String) iter.next();
+ for (String val : temporaryCVariableDeclarations) {
writer.print(" ");
writer.println(val);
}
@@ -566,9 +547,8 @@ public class CMethodBindingEmitter extends FunctionEmitter
* emitBodyVariableDeclarations(), PRIOR TO calling the actual C
* function.
*/
- protected void emitBodyVariablePreCallSetup(PrintWriter writer,
- boolean emittingPrimitiveArrayCritical)
- {
+ protected void emitBodyVariablePreCallSetup(PrintWriter writer, boolean emittingPrimitiveArrayCritical) {
+
if (!emittingPrimitiveArrayCritical) {
// Convert all Buffers to pointers first so we don't have to
// call ReleasePrimitiveArrayCritical for any arrays if any
@@ -1033,8 +1013,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
TemporaryCVariableAssignments directive in the .cfg file. */
protected void emitBodyUserVariableAssignments(PrintWriter writer) {
if (temporaryCVariableAssignments != null) {
- for (Iterator iter = temporaryCVariableAssignments.iterator(); iter.hasNext(); ) {
- String val = (String) iter.next();
+ for (String val : temporaryCVariableAssignments) {
writer.print(" ");
writer.println(val);
}
@@ -1178,7 +1157,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
throw new RuntimeException("Saw illegal \"void\" argument while emitting \"" + getName() + "\"");
}
} else {
- Class c = type.getJavaClass();
+ Class<?> c = type.getJavaClass();
if (c != null) {
jniMangle(c, buf, false);
// If Buffer offset arguments were added, we need to mangle the JNI for the
@@ -1212,7 +1191,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
return buf.toString();
}
- protected void jniMangle(Class c, StringBuffer res, boolean syntheticArgument) {
+ protected void jniMangle(Class<?> c, StringBuffer res, boolean syntheticArgument) {
if (c.isPrimitive()) {
if (c == Boolean.TYPE) res.append("Z");
else if (c == Byte.TYPE) res.append("B");
@@ -1233,7 +1212,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
if (syntheticArgument) {
if (c.isArray()) {
res.append("_3");
- Class componentType = c.getComponentType();
+ Class<?> componentType = c.getComponentType();
// Handle arrays of compound type wrappers differently for
// convenience of the Java-level glue code generation
jniMangle(componentType, res,
@@ -1260,9 +1239,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
}
}
- private void emitOutOfMemoryCheck(PrintWriter writer, String varName,
- String errorMessage)
- {
+ private void emitOutOfMemoryCheck(PrintWriter writer, String varName, String errorMessage) {
writer.print(" if (");
writer.print(varName);
writer.println(" == NULL) {");
@@ -1284,8 +1261,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
String elementTypeString,
boolean elementTypeIsConst,
String numElementsExpression,
- String mallocFailureErrorString)
- {
+ String mallocFailureErrorString) {
writer.print(" ");
writer.print(targetVarName);
writer.print(" = (");
@@ -1310,8 +1286,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
String targetVarName,
String elementTypeString,
String numElementsExpression,
- String mallocFailureErrorString)
- {
+ String mallocFailureErrorString) {
writer.print(" ");
writer.print(targetVarName);
writer.print(" = (");
@@ -1333,8 +1308,7 @@ public class CMethodBindingEmitter extends FunctionEmitter
String sourceVarName,
String receivingVarName,
boolean isUTF8,
- boolean emitElseClause)
- {
+ boolean emitElseClause) {
if (EMIT_NULL_CHECKS) {
writer.print(" if (");
writer.print(sourceVarName);
@@ -1443,9 +1417,9 @@ public class CMethodBindingEmitter extends FunctionEmitter
javaType.isArrayOfCompoundTypeWrappers()) {
ptrTypeString = cType.getName();
} else if (!javaType.isStringArray()) {
- Class elementType = javaType.getJavaClass().getComponentType();
+ Class<?> elementType = javaType.getJavaClass().getComponentType();
if (elementType.isArray()) {
- Class subElementType = elementType.getComponentType();
+ Class<?> subElementType = elementType.getComponentType();
if (subElementType.isPrimitive()) {
// type is pointer to pointer to primitive
ptrTypeString = cType.getName();
diff --git a/src/java/com/sun/gluegen/CodeGenUtils.java b/src/java/com/sun/gluegen/CodeGenUtils.java
index ab81bec..a558c66 100644
--- a/src/java/com/sun/gluegen/CodeGenUtils.java
+++ b/src/java/com/sun/gluegen/CodeGenUtils.java
@@ -42,8 +42,7 @@ package com.sun.gluegen;
import java.io.*;
import java.util.*;
-public class CodeGenUtils
-{
+public class CodeGenUtils {
/**
* Given a java package name (e.g., "java.lang"), return the package as a
* directory path (i.e., "java/lang").
@@ -60,8 +59,7 @@ public class CodeGenUtils
*/
public static void emitAutogeneratedWarning(PrintWriter w, Object generator) {
w.print("/* !---- DO NOT EDIT: This file autogenerated ");
- if (generator != null)
- {
+ if (generator != null) {
w.print("by ");
w.print(packageAsPath(generator.getClass().getName()));
w.print(".java ");
@@ -75,18 +73,16 @@ public class CodeGenUtils
/**
* Emit the opening headers for one java class/interface file.
*/
- public static void emitJavaHeaders(
- PrintWriter w,
- String packageName,
- String className,
- String gluegenRuntimePackage,
- boolean isClassNotInterface,
- String[] imports,
- String[] accessModifiers,
- String[] interfaces,
- String classExtended,
- EmissionCallback classDocComment) throws IOException
- {
+ public static void emitJavaHeaders( PrintWriter w,
+ String packageName,
+ String className,
+ String gluegenRuntimePackage,
+ boolean isClassNotInterface,
+ String[] imports,
+ String[] accessModifiers,
+ String[] interfaces,
+ String classExtended,
+ EmissionCallback classDocComment) throws IOException {
w.println("package " + packageName + ";");
w.println();
@@ -142,8 +138,7 @@ public class CodeGenUtils
//-----------------------------------------
/** A class that emits source code of some time when activated. */
- public interface EmissionCallback
- {
+ public interface EmissionCallback {
/** Emit appropriate source code through the given writer. */
public void emit(PrintWriter output);
}
diff --git a/src/java/com/sun/gluegen/CommentEmitter.java b/src/java/com/sun/gluegen/CommentEmitter.java
index 30004f8..e5fdc6f 100644
--- a/src/java/com/sun/gluegen/CommentEmitter.java
+++ b/src/java/com/sun/gluegen/CommentEmitter.java
@@ -41,8 +41,7 @@ package com.sun.gluegen;
import java.io.*;
-public interface CommentEmitter
-{
+public interface CommentEmitter {
/**
* Emit the body of a comment for the specified function; do NOT emit the
* open (e.g., comment "/*") or close (e.g., "*\/") characters.
diff --git a/src/java/com/sun/gluegen/ConstantDefinition.java b/src/java/com/sun/gluegen/ConstantDefinition.java
index 44ce8e0..e4cb3f5 100644
--- a/src/java/com/sun/gluegen/ConstantDefinition.java
+++ b/src/java/com/sun/gluegen/ConstantDefinition.java
@@ -38,13 +38,14 @@ import java.util.*;
/** Represents the definition of a constant which was provided either
via a #define statement or through an enum definition. */
public class ConstantDefinition {
+
private String origName;
- private HashSet aliasedNames;
+ private HashSet<String> aliasedNames;
private String name;
private String value;
private boolean isEnum;
private String enumName;
- private Set/*<String>*/ aliases;
+ private Set<String> aliases;
public ConstantDefinition(String name,
String value,
@@ -55,7 +56,7 @@ public class ConstantDefinition {
this.value = value;
this.isEnum = isEnum;
this.enumName = enumName;
- this.aliasedNames=new HashSet();
+ this.aliasedNames=new HashSet<String>();
}
public boolean equals(ConstantDefinition other) {
@@ -75,6 +76,7 @@ public class ConstantDefinition {
return s1.equals(s2);
}
+ @Override
public int hashCode() {
return name.hashCode();
}
@@ -90,7 +92,7 @@ public class ConstantDefinition {
public void addAliasedName(String name) {
aliasedNames.add(name);
}
- public Collection getAliasedNames() {
+ public Collection<String> getAliasedNames() {
return aliasedNames;
}
@@ -109,13 +111,13 @@ public class ConstantDefinition {
public boolean isEnum() { return isEnum; }
- public Set/*<String>*/ getAliases() {
+ public Set<String> getAliases() {
return aliases;
}
public void addAlias(String alias) {
if (aliases == null) {
- aliases = new LinkedHashSet/*<String>*/();
+ aliases = new LinkedHashSet<String>();
}
aliases.add(alias);
}
diff --git a/src/java/com/sun/gluegen/DebugEmitter.java b/src/java/com/sun/gluegen/DebugEmitter.java
index 34586a1..06fba30 100644
--- a/src/java/com/sun/gluegen/DebugEmitter.java
+++ b/src/java/com/sun/gluegen/DebugEmitter.java
@@ -46,6 +46,7 @@ import com.sun.gluegen.cgram.types.*;
/** Debug emitter which prints the parsing results to standard output. */
public class DebugEmitter implements GlueEmitter {
+
public void readConfigurationFile(String filename) {}
public void setMachineDescription(MachineDescription md32,
@@ -54,10 +55,13 @@ public class DebugEmitter implements GlueEmitter {
public void beginEmission(GlueEmitterControls controls) {
System.out.println("----- BEGIN EMISSION OF GLUE CODE -----");
}
+
public void endEmission() {
System.out.println("----- END EMISSION OF GLUE CODE -----");
}
+
public void beginDefines() {}
+
public void emitDefine(ConstantDefinition def, String optionalComment) {
String name = def.getName();
String value = def.getValue();
@@ -68,18 +72,16 @@ public class DebugEmitter implements GlueEmitter {
public void beginFunctions(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
- Map canonMap) {
- Set keys = typedefDictionary.keySet();
- for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
- String key = (String) iter.next();
+ Map<Type, Type> canonMap) {
+ Set<String> keys = typedefDictionary.keySet();
+ for (String key: keys) {
Type value = typedefDictionary.get(key);
System.out.println("typedef " + value + " " + key + ";");
}
}
- public Iterator emitFunctions(List/*<FunctionSymbol>*/ originalCFunctions)
- throws Exception {
- for (Iterator iter = originalCFunctions.iterator(); iter.hasNext(); ) {
- FunctionSymbol sym = (FunctionSymbol) iter.next();
+
+ public Iterator<FunctionSymbol> emitFunctions(List<FunctionSymbol> originalCFunctions) throws Exception {
+ for (FunctionSymbol sym : originalCFunctions) {
emitSingleFunction(sym);
}
return originalCFunctions.iterator();
@@ -94,10 +96,9 @@ public class DebugEmitter implements GlueEmitter {
public void layoutStruct(CompoundType t) throws Exception {}
public void endStructLayout() throws Exception {}
- public void beginStructs(TypeDictionary typedefDictionary,
- TypeDictionary structDictionary,
- Map canonMap) {
+ public void beginStructs(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) {
}
+
public void emitStruct(CompoundType t, String alternateName) {
String name = t.getName();
if (name == null && alternateName != null) {
@@ -106,5 +107,6 @@ public class DebugEmitter implements GlueEmitter {
System.out.println("Referenced type \"" + name + "\"");
}
+
public void endStructs() {}
}
diff --git a/src/java/com/sun/gluegen/FunctionEmitter.java b/src/java/com/sun/gluegen/FunctionEmitter.java
index 32ac071..a9bfc5a 100644
--- a/src/java/com/sun/gluegen/FunctionEmitter.java
+++ b/src/java/com/sun/gluegen/FunctionEmitter.java
@@ -41,22 +41,20 @@ package com.sun.gluegen;
import java.util.*;
import java.io.*;
-import com.sun.gluegen.cgram.types.MachineDescription;
-public abstract class FunctionEmitter
-{
+public abstract class FunctionEmitter {
+
public static final EmissionModifier STATIC = new EmissionModifier("static");
private boolean isInterfaceVal;
- private ArrayList modifiers = new ArrayList();
+ private ArrayList<EmissionModifier> modifiers = new ArrayList<EmissionModifier>();
private CommentEmitter commentEmitter = null;
private PrintWriter defaultOutput;
/**
* Constructs the FunctionEmitter with a CommentEmitter that emits nothing.
*/
- public FunctionEmitter(PrintWriter defaultOutput, boolean isInterface)
- {
+ public FunctionEmitter(PrintWriter defaultOutput, boolean isInterface) {
assert(defaultOutput != null);
this.defaultOutput = defaultOutput;
this.isInterfaceVal = isInterface;
@@ -65,8 +63,9 @@ public abstract class FunctionEmitter
/**
* Makes this FunctionEmitter a copy of the passed one.
*/
+ @SuppressWarnings("unchecked")
public FunctionEmitter(FunctionEmitter arg) {
- modifiers = (ArrayList) arg.modifiers.clone();
+ modifiers = (ArrayList<EmissionModifier>)arg.modifiers.clone();
commentEmitter = arg.commentEmitter;
defaultOutput = arg.defaultOutput;
isInterfaceVal = arg.isInterfaceVal;
@@ -76,11 +75,9 @@ public abstract class FunctionEmitter
public PrintWriter getDefaultOutput() { return defaultOutput; }
- public void addModifiers(Iterator/*<EmissionModifier>*/ mi)
- {
- while (mi.hasNext())
- {
- modifiers.add((EmissionModifier) mi.next());
+ public void addModifiers(Iterator<EmissionModifier> mi) {
+ while (mi.hasNext()) {
+ modifiers.add(mi.next());
}
}
public void addModifier(EmissionModifier m) { modifiers.add(m); }
@@ -91,7 +88,7 @@ public abstract class FunctionEmitter
public boolean hasModifier(EmissionModifier m) { return modifiers.contains(m); }
- public Iterator getModifiers() { return modifiers.iterator(); }
+ public Iterator<EmissionModifier> getModifiers() { return modifiers.iterator(); }
public abstract String getName();
@@ -99,8 +96,7 @@ public abstract class FunctionEmitter
* Emit the function to the specified output (instead of the default
* output).
*/
- public void emit(PrintWriter output)
- {
+ public void emit(PrintWriter output) {
emitDocComment(output);
//output.println(" // Emitter: " + getClass().getName());
emitSignature(output);
@@ -111,14 +107,13 @@ public abstract class FunctionEmitter
* Emit the function to the default output (the output that was passed to
* the constructor)
*/
- public final void emit()
- {
+ public final void emit() {
emit(getDefaultOutput());
}
/** Returns, as a String, whatever {@link #emit} would output. */
- public String toString()
- {
+ @Override
+ public String toString() {
StringWriter sw = new StringWriter(500);
PrintWriter w = new PrintWriter(sw);
emit(w);
@@ -129,8 +124,7 @@ public abstract class FunctionEmitter
* Set the object that will emit the comment for this function. If the
* parameter is null, no comment will be emitted.
*/
- public void setCommentEmitter(CommentEmitter cEmitter)
- {
+ public void setCommentEmitter(CommentEmitter cEmitter) {
commentEmitter = cEmitter;
}
@@ -140,10 +134,9 @@ public abstract class FunctionEmitter
*/
public CommentEmitter getCommentEmitter() { return commentEmitter; }
- protected void emitDocComment(PrintWriter writer)
- {
- if (commentEmitter != null)
- {
+ protected void emitDocComment(PrintWriter writer) {
+
+ if (commentEmitter != null) {
writer.print(getBaseIndentString()); //indent
writer.print(getCommentStartString());
@@ -156,13 +149,12 @@ public abstract class FunctionEmitter
}
}
- protected void emitSignature(PrintWriter writer)
- {
+ protected void emitSignature(PrintWriter writer) {
+
writer.print(getBaseIndentString()); // indent method
int numEmitted = emitModifiers(writer);
- if (numEmitted > 0)
- {
+ if (numEmitted > 0) {
writer.print(" ");
}
@@ -176,16 +168,13 @@ public abstract class FunctionEmitter
writer.print(")");
}
- protected int emitModifiers(PrintWriter writer)
- {
+ protected int emitModifiers(PrintWriter writer) {
PrintWriter w = getDefaultOutput();
int numEmitted = 0;
- for (Iterator it = getModifiers(); it.hasNext(); )
- {
+ for (Iterator<EmissionModifier> it = getModifiers(); it.hasNext(); ) {
writer.print(it.next());
++numEmitted;
- if (it.hasNext())
- {
+ if (it.hasNext()) {
writer.print(" ");
}
}
@@ -203,16 +192,19 @@ public abstract class FunctionEmitter
protected abstract int emitArguments(PrintWriter writer);
protected abstract void emitBody(PrintWriter writer);
- public static class EmissionModifier
- {
+ public static class EmissionModifier {
+
+ @Override
public final String toString() { return emittedForm; }
private String emittedForm;
+ @Override
public int hashCode() {
return emittedForm.hashCode();
}
+ @Override
public boolean equals(Object arg) {
if (arg == null || (!(arg instanceof EmissionModifier))) {
return false;
diff --git a/src/java/com/sun/gluegen/GlueEmitter.java b/src/java/com/sun/gluegen/GlueEmitter.java
index 2738411..94d8981 100644
--- a/src/java/com/sun/gluegen/GlueEmitter.java
+++ b/src/java/com/sun/gluegen/GlueEmitter.java
@@ -93,10 +93,10 @@ public interface GlueEmitter {
public void beginFunctions(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
- Map canonMap) throws Exception;
+ Map<Type, Type> canonMap) throws Exception;
/** Emit glue code for the list of FunctionSymbols. */
- public Iterator emitFunctions(java.util.List/*<FunctionSymbol>*/ cFunctions) throws Exception;
+ public Iterator<FunctionSymbol> emitFunctions(List<FunctionSymbol> cFunctions) throws Exception;
public void endFunctions() throws Exception;
/** Begins the process of computing field offsets and type sizes for
@@ -109,7 +109,7 @@ public interface GlueEmitter {
public void beginStructs(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
- Map canonMap) throws Exception;
+ Map<Type, Type> canonMap) throws Exception;
/** Emit glue code for the given CompoundType. alternateName is
provided when the CompoundType (e.g. "struct foo_t") has not
been typedefed to anything but the type of "pointer to struct
diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java
index 3804795..e046850 100644
--- a/src/java/com/sun/gluegen/GlueGen.java
+++ b/src/java/com/sun/gluegen/GlueGen.java
@@ -43,7 +43,6 @@ import java.io.*;
import java.util.*;
import antlr.*;
-import antlr.collections.*;
import com.sun.gluegen.cgram.*;
import com.sun.gluegen.cgram.types.*;
import com.sun.gluegen.pcpp.*;
@@ -51,12 +50,13 @@ import com.sun.gluegen.pcpp.*;
/** Glue code generator for C functions and data structures. */
public class GlueGen implements GlueEmitterControls {
- private java.util.List forcedStructNames = new ArrayList();
+
+ private List<String> forcedStructNames = new ArrayList<String>();
private PCPP preprocessor;
// State for SymbolFilters
- private java.util.List/*<ConstantDefinition>*/ constants;
- private java.util.List/*<FunctionSymbol>*/ functions;
+ private List<ConstantDefinition> constants;
+ private List<FunctionSymbol> functions;
public void forceStructEmission(String typedefName) {
forcedStructNames.add(typedefName);
@@ -68,8 +68,8 @@ public class GlueGen implements GlueEmitterControls {
public void runSymbolFilter(SymbolFilter filter) {
filter.filterSymbols(constants, functions);
- java.util.List/*<ConstantDefinition>*/ newConstants = filter.getConstants();
- java.util.List/*<FunctionSymbol>*/ newFunctions = filter.getFunctions();
+ List<ConstantDefinition> newConstants = filter.getConstants();
+ List<FunctionSymbol> newFunctions = filter.getFunctions();
if (newConstants != null) {
constants = newConstants;
}
@@ -84,13 +84,13 @@ public class GlueGen implements GlueEmitterControls {
String filename = null;
String emitterClass = null;
String outputRootDir = null;
- java.util.List cfgFiles = new ArrayList();
+ List<String> cfgFiles = new ArrayList<String>();
if (args.length == 0) {
usage();
}
- java.util.List includePaths = new ArrayList();
+ List<String> includePaths = new ArrayList<String>();
for (int i = 0; i < args.length; i++) {
if (i < args.length - 1) {
String arg = args[i];
@@ -195,8 +195,8 @@ public class GlueGen implements GlueEmitterControls {
}
}
- for (Iterator iter = cfgFiles.iterator(); iter.hasNext(); ) {
- emit.readConfigurationFile((String) iter.next());
+ for (String cfgFile: cfgFiles) {
+ emit.readConfigurationFile(cfgFile);
}
if(null!=outputRootDir && outputRootDir.trim().length()>0) {
@@ -216,9 +216,9 @@ public class GlueGen implements GlueEmitterControls {
// Repackage the enum and #define statements from the parser into a common format
// so that SymbolFilters can operate upon both identically
- constants = new ArrayList/*<ConstantDefinition>*/();
- for (Iterator iter = headerParser.getEnums().iterator(); iter.hasNext(); ) {
- EnumType enumeration = (EnumType)iter.next();
+ constants = new ArrayList<ConstantDefinition>();
+ for (Object elem: headerParser.getEnums()) {
+ EnumType enumeration = (EnumType)elem;
String enumName = enumeration.getName();
if (enumName.equals("<anonymous>")) {
enumName = null;
@@ -230,8 +230,8 @@ public class GlueGen implements GlueEmitterControls {
constants.add(new ConstantDefinition(enumElementName, value, true, enumName));
}
}
- for (Iterator iter = lexer.getDefines().iterator(); iter.hasNext(); ) {
- Define def = (Define) iter.next();
+ for (Object elem : lexer.getDefines()) {
+ Define def = (Define)elem;
constants.add(new ConstantDefinition(def.getName(), def.getValue(), false, null));
}
@@ -241,18 +241,16 @@ public class GlueGen implements GlueEmitterControls {
emit.beginEmission(this);
emit.beginDefines();
- Set emittedDefines = new HashSet(100);
+ Set<String> emittedDefines = new HashSet<String>(100);
// emit java equivalent of enum { ... } statements
- for (Iterator iter = constants.iterator(); iter.hasNext(); ) {
- ConstantDefinition def = (ConstantDefinition) iter.next();
+ for (ConstantDefinition def : constants) {
if (!emittedDefines.contains(def.getName())) {
emittedDefines.add(def.getName());
String comment = null;
- Set/*<String>*/ aliases = def.getAliases();
+ Set<String> aliases = def.getAliases();
if (aliases != null) {
comment = "Alias for: <code>";
- for (Iterator i2 = aliases.iterator(); i2.hasNext(); ) {
- String alias = (String) i2.next();
+ for (String alias : aliases) {
comment += " " + alias;
}
comment += "</code>";
@@ -274,8 +272,7 @@ public class GlueGen implements GlueEmitterControls {
// Iterate through the functions finding structs that are referenced in
// the function signatures; these will be remembered for later emission
ReferencedStructs referencedStructs = new ReferencedStructs();
- for (Iterator iter = functions.iterator(); iter.hasNext(); ) {
- FunctionSymbol sym = (FunctionSymbol) iter.next();
+ for (FunctionSymbol sym : functions) {
// FIXME: this doesn't take into account the possibility that some of
// the functions we send to emitMethodBindings() might not actually be
// emitted (e.g., if an Ignore directive in the JavaEmitter causes it
@@ -286,8 +283,7 @@ public class GlueGen implements GlueEmitterControls {
// Normally only referenced types will be emitted. The user can force a
// type to be emitted via a .cfg file directive. Those directives are
// processed here.
- for (Iterator iter = forcedStructNames.iterator(); iter.hasNext(); ) {
- String name = (String) iter.next();
+ for (String name: forcedStructNames) {
Type type = td.get(name);
if (type == null) {
System.err.println("WARNING: during forced struct emission: struct \"" + name + "\" not found");
@@ -300,8 +296,8 @@ public class GlueGen implements GlueEmitterControls {
// Lay out structs
emit.beginStructLayout();
- for (Iterator iter = referencedStructs.results(); iter.hasNext(); ) {
- Type t = (Type) iter.next();
+ for (Iterator<Type> iter = referencedStructs.results(); iter.hasNext(); ) {
+ Type t = iter.next();
if (t.isCompound()) {
emit.layoutStruct(t.asCompound());
} else if (t.isPointer()) {
@@ -314,8 +310,8 @@ public class GlueGen implements GlueEmitterControls {
// Emit structs
emit.beginStructs(td, sd, headerParser.getCanonMap());
- for (Iterator iter = referencedStructs.results(); iter.hasNext(); ) {
- Type t = (Type) iter.next();
+ for (Iterator<Type> iter = referencedStructs.results(); iter.hasNext(); ) {
+ Type t = iter.next();
if (t.isCompound()) {
emit.emitStruct(t.asCompound(), null);
} else if (t.isPointer()) {
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java
index 636cef8..0d7b3cc 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -42,6 +42,7 @@ package com.sun.gluegen;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
+import java.util.Map.Entry;
import java.util.regex.*;
import com.sun.gluegen.jgram.*;
@@ -52,99 +53,106 @@ import com.sun.gluegen.cgram.types.*;
public class JavaConfiguration {
- private int nestedReads;
- private String packageName;
- private String implPackageName;
- private String className;
- private String implClassName;
- /**
- * Root directory for the hierarchy of generated java classes. Default is
- * working directory.
- */
- private String javaOutputDir = ".";
-
- /**
- * Top output root directory for all generated files. Default is null, ie not to use it.
- */
- private String outputRootDir = null;
-
- /**
- * Directory into which generated native JNI code will be written. Default
- * is current working directory.
- */
- private String nativeOutputDir = ".";
- /**
- * If true, then each native *.c and *.h file will be generated in the
- * directory nativeOutputDir/packageAsPath(packageName). Default is false.
- */
- private boolean nativeOutputUsesJavaHierarchy;
- /**
- * If true, then the comment of a native method binding will include a @native tag
- * to allow taglets to augment the javadoc with additional information regarding
- * the mapped C function. Defaults to false.
- */
- private boolean tagNativeBinding;
- /**
- * Style of code emission. Can emit everything into one class
- * (AllStatic), separate interface and implementing classes
- * (InterfaceAndImpl), only the interface (InterfaceOnly), or only
- * the implementation (ImplOnly).
- */
- private int emissionStyle = JavaEmitter.ALL_STATIC;
- /**
- * List of imports to emit at the head of the output files.
- */
- private List/*<String>*/ imports = new ArrayList();
- /**
- * The package in which the generated glue code expects to find its
- * run-time helper classes (BufferFactory, CPU,
- * StructAccessor). Defaults to "com.sun.gluegen.runtime".
- */
- private String gluegenRuntimePackage = "com.sun.gluegen.runtime";
-
- /**
- * The kind of exception raised by the generated code if run-time
- * checks fail. Defaults to RuntimeException.
- */
- private String runtimeExceptionType = "RuntimeException";
- private String unsupportedExceptionType = "UnsupportedOperationException";
- private Map/*<String,Integer>*/ accessControl = new HashMap();
- private Map/*<String,TypeInfo>*/ typeInfoMap = new HashMap();
- private Set/*<String>*/ returnsString = new HashSet();
- private Map/*<String, String>*/ returnedArrayLengths = new HashMap();
- /**
- * Key is function that has some byte[] or short[] arguments that should be
- * converted to String args; value is List of Integer argument indices
- */
- private Map/*<String,List<Integer>>*/ argumentsAreString = new HashMap();
- private Set/*<String>*/ extendedIntfSymbolsIgnore = new HashSet();
- private Set/*<String>*/ extendedIntfSymbolsOnly = new HashSet();
- private Set/*<Pattern>*/ ignores = new HashSet();
- private Map/*<String,Pattern>*/ ignoreMap = new HashMap();
- private Set/*<Pattern>*/ ignoreNots = new HashSet();
- private Set/*<Pattern>*/ unignores = new HashSet();
- private Set/*<Pattern>*/ unimplemented = new HashSet();
- private boolean forceNioOnly4All=false;
- private Set/*<String>*/ nioOnly = new HashSet();
- private boolean forceNioDirectOnly4All=false;
- private Set/*<String>*/ nioDirectOnly = new HashSet();
- private Set/*<String>*/ manuallyImplement = new HashSet();
- private Map/*<String,List<String>>*/ customJavaCode = new HashMap();
- private Map/*<String,List<String>>*/ classJavadoc = new HashMap();
- private Map/*<String,String>*/ structPackages = new HashMap();
- private List/*<String>*/ customCCode = new ArrayList();
- private List/*<String>*/ forcedStructs = new ArrayList();
- private Map/*<String, String>*/ returnValueCapacities = new HashMap();
- private Map/*<String, String>*/ returnValueLengths = new HashMap();
- private Map/*<String, List<String>>*/ temporaryCVariableDeclarations = new HashMap();
- private Map/*<String, List<String>>*/ temporaryCVariableAssignments = new HashMap();
- private Map/*<String,List<String>>*/ extendedInterfaces = new HashMap();
- private Map/*<String,List<String>>*/ implementedInterfaces = new HashMap();
- private Map/*<String,String>*/ parentClass = new HashMap();
- private Map/*<String,String>*/ javaTypeRenames = new HashMap();
- private Map/*<String,String>*/ javaSymbolRenames = new HashMap();
- private Map/*<String,List<String>>*/ javaPrologues = new HashMap();
- private Map/*<String,List<String>>*/ javaEpilogues = new HashMap();
+ private int nestedReads;
+ private String packageName;
+ private String implPackageName;
+ private String className;
+ private String implClassName;
+
+ /**
+ * Root directory for the hierarchy of generated java classes. Default is
+ * working directory.
+ */
+ private String javaOutputDir = ".";
+
+ /**
+ * Top output root directory for all generated files. Default is null, ie not to use it.
+ */
+ private String outputRootDir = null;
+
+ /**
+ * Directory into which generated native JNI code will be written. Default
+ * is current working directory.
+ */
+ private String nativeOutputDir = ".";
+
+ /**
+ * If true, then each native *.c and *.h file will be generated in the
+ * directory nativeOutputDir/packageAsPath(packageName). Default is false.
+ */
+ private boolean nativeOutputUsesJavaHierarchy;
+
+ /**
+ * If true, then the comment of a native method binding will include a @native tag
+ * to allow taglets to augment the javadoc with additional information regarding
+ * the mapped C function. Defaults to false.
+ */
+ private boolean tagNativeBinding;
+
+ /**
+ * Style of code emission. Can emit everything into one class
+ * (AllStatic), separate interface and implementing classes
+ * (InterfaceAndImpl), only the interface (InterfaceOnly), or only
+ * the implementation (ImplOnly).
+ */
+ private int emissionStyle = JavaEmitter.ALL_STATIC;
+
+ /**
+ * List of imports to emit at the head of the output files.
+ */
+ private List<String> imports = new ArrayList<String>();
+
+ /**
+ * The package in which the generated glue code expects to find its
+ * run-time helper classes (BufferFactory, CPU,
+ * StructAccessor). Defaults to "com.sun.gluegen.runtime".
+ */
+ private String gluegenRuntimePackage = "com.sun.gluegen.runtime";
+
+ /**
+ * The kind of exception raised by the generated code if run-time
+ * checks fail. Defaults to RuntimeException.
+ */
+ private String runtimeExceptionType = "RuntimeException";
+ private String unsupportedExceptionType = "UnsupportedOperationException";
+ private Map<String, Integer> accessControl = new HashMap<String, Integer>();
+ private Map<String, TypeInfo> typeInfoMap = new HashMap<String, TypeInfo>();
+ private Set<String> returnsString = new HashSet<String>();
+ private Map<String, String> returnedArrayLengths = new HashMap<String, String>();
+
+ /**
+ * Key is function that has some byte[] or short[] arguments that should be
+ * converted to String args; value is List of Integer argument indices
+ */
+ private Map<String, List<Integer>> argumentsAreString = new HashMap<String, List<Integer>>();
+ private Set<String> extendedIntfSymbolsIgnore = new HashSet<String>();
+ private Set<String> extendedIntfSymbolsOnly = new HashSet<String>();
+ private Set<Pattern> ignores = new HashSet<Pattern>();
+ private Map<String, Pattern> ignoreMap = new HashMap<String, Pattern>();
+ private Set<Pattern> ignoreNots = new HashSet<Pattern>();
+ private Set<Pattern> unignores = new HashSet<Pattern>();
+ private Set<Pattern> unimplemented = new HashSet<Pattern>();
+ private boolean forceNioOnly4All = false;
+ private Set<String> nioOnly = new HashSet<String>();
+ private boolean forceNioDirectOnly4All = false;
+ private Set<String> nioDirectOnly = new HashSet<String>();
+ private Set<String> manuallyImplement = new HashSet<String>();
+ private Map<String, List<String>> customJavaCode = new HashMap<String, List<String>>();
+ private Map<String, List<String>> classJavadoc = new HashMap<String, List<String>>();
+ private Map<String, String> structPackages = new HashMap<String, String>();
+ private List<String> customCCode = new ArrayList<String>();
+ private List<String> forcedStructs = new ArrayList<String>();
+ private Map<String, String> returnValueCapacities = new HashMap<String, String>();
+ private Map<String, String> returnValueLengths = new HashMap<String, String>();
+ private Map<String, List<String>> temporaryCVariableDeclarations = new HashMap<String, List<String>>();
+ private Map<String, List<String>> temporaryCVariableAssignments = new HashMap<String, List<String>>();
+ private Map<String, List<String>> extendedInterfaces = new HashMap<String, List<String>>();
+ private Map<String, List<String>> implementedInterfaces = new HashMap<String, List<String>>();
+ private Map<String, String> parentClass = new HashMap<String, String>();
+ private Map<String, String> javaTypeRenames = new HashMap<String, String>();
+ private Map<String, String> javaSymbolRenames = new HashMap<String, String>();
+ private Map<String, List<String>> javaPrologues = new HashMap<String, List<String>>();
+ private Map<String, List<String>> javaEpilogues = new HashMap<String, List<String>>();
/** Reads the configuration file.
@param filename path to file that should be read
@@ -175,20 +183,17 @@ public class JavaConfiguration {
++nestedReads;
while ((line = reader.readLine()) != null) {
++lineNo;
- if (hasPrefix)
- {
+ if (hasPrefix) {
line = linePrefix + " " + line;
}
- if (line.trim().startsWith("#"))
- {
+ if (line.trim().startsWith("#")) {
// comment line
continue;
}
StringTokenizer tok = new StringTokenizer(line);
- if (tok.hasMoreTokens())
- {
+ if (tok.hasMoreTokens()) {
// always reset delimiters in case of CustomJavaCode, etc.
String cmd = tok.nextToken(" \t\n\r\f");
@@ -243,44 +248,82 @@ public class JavaConfiguration {
public void setOutputRootDir(String s) { outputRootDir=s; }
- /** Returns the package name parsed from the configuration file. */
- public String packageName() { return packageName; }
- /** Returns the implementation package name parsed from the configuration file. */
- public String implPackageName() { return implPackageName; }
- /** Returns the class name parsed from the configuration file. */
- public String className() { return className; }
- /** Returns the implementation class name parsed from the configuration file. */
- public String implClassName() { return implClassName; }
- /** Returns the Java code output directory parsed from the configuration file. */
- public String javaOutputDir() { return (null!=outputRootDir)?(outputRootDir + "/" + javaOutputDir):javaOutputDir; }
- /** Returns the native code output directory parsed from the configuration file. */
- public String nativeOutputDir() { return (null!=outputRootDir)?(outputRootDir + "/" + nativeOutputDir):nativeOutputDir; }
- /** Returns whether the native code directory structure mirrors the Java hierarchy. */
- public boolean nativeOutputUsesJavaHierarchy() { return nativeOutputUsesJavaHierarchy; }
- /** Returns whether the comment of a native method binding should include a @native tag. */
- public boolean tagNativeBinding() { return tagNativeBinding; }
- /** Returns the code emission style (constants in JavaEmitter) parsed from the configuration file. */
- public int emissionStyle() { return emissionStyle; }
- /** Returns the access control for the emitted Java method. Returns one of JavaEmitter.ACC_PUBLIC, JavaEmitter.ACC_PROTECTED, JavaEmitter.ACC_PRIVATE, or JavaEmitter.ACC_PACKAGE_PRIVATE. */
- public int accessControl(String methodName) {
- Integer ret = (Integer) accessControl.get(methodName);
- if (ret != null) {
- return ret.intValue();
- }
- // Default access control is public
- return JavaEmitter.ACC_PUBLIC;
- }
-
- /** Returns the package in which the generated glue code expects to
- find its run-time helper classes (BufferFactory, CPU,
- StructAccessor). Defaults to "com.sun.gluegen.runtime". */
- public String gluegenRuntimePackage() { return gluegenRuntimePackage; }
- /** Returns the kind of exception to raise if run-time checks fail in the generated code. */
- public String runtimeExceptionType() { return runtimeExceptionType; }
- /** Returns the kind of exception to raise if run-time checks fail in the generated code. */
- public String unsupportedExceptionType() { return unsupportedExceptionType; }
- /** Returns the list of imports that should be emitted at the top of each .java file. */
- public List/*<String>*/ imports() { return imports; }
+ /** Returns the package name parsed from the configuration file. */
+ public String packageName() {
+ return packageName;
+ }
+
+ /** Returns the implementation package name parsed from the configuration file. */
+ public String implPackageName() {
+ return implPackageName;
+ }
+
+ /** Returns the class name parsed from the configuration file. */
+ public String className() {
+ return className;
+ }
+
+ /** Returns the implementation class name parsed from the configuration file. */
+ public String implClassName() {
+ return implClassName;
+ }
+
+ /** Returns the Java code output directory parsed from the configuration file. */
+ public String javaOutputDir() {
+ return (null != outputRootDir) ? (outputRootDir + "/" + javaOutputDir) : javaOutputDir;
+ }
+
+ /** Returns the native code output directory parsed from the configuration file. */
+ public String nativeOutputDir() {
+ return (null != outputRootDir) ? (outputRootDir + "/" + nativeOutputDir) : nativeOutputDir;
+ }
+
+ /** Returns whether the native code directory structure mirrors the Java hierarchy. */
+ public boolean nativeOutputUsesJavaHierarchy() {
+ return nativeOutputUsesJavaHierarchy;
+ }
+
+ /** Returns whether the comment of a native method binding should include a @native tag. */
+ public boolean tagNativeBinding() {
+ return tagNativeBinding;
+ }
+
+ /** Returns the code emission style (constants in JavaEmitter) parsed from the configuration file. */
+ public int emissionStyle() {
+ return emissionStyle;
+ }
+
+ /** Returns the access control for the emitted Java method. Returns one of JavaEmitter.ACC_PUBLIC, JavaEmitter.ACC_PROTECTED, JavaEmitter.ACC_PRIVATE, or JavaEmitter.ACC_PACKAGE_PRIVATE. */
+ public int accessControl(String methodName) {
+ Integer ret = accessControl.get(methodName);
+ if (ret != null) {
+ return ret.intValue();
+ }
+ // Default access control is public
+ return JavaEmitter.ACC_PUBLIC;
+ }
+
+ /** Returns the package in which the generated glue code expects to
+ find its run-time helper classes (BufferFactory, CPU,
+ StructAccessor). Defaults to "com.sun.gluegen.runtime". */
+ public String gluegenRuntimePackage() {
+ return gluegenRuntimePackage;
+ }
+
+ /** Returns the kind of exception to raise if run-time checks fail in the generated code. */
+ public String runtimeExceptionType() {
+ return runtimeExceptionType;
+ }
+
+ /** Returns the kind of exception to raise if run-time checks fail in the generated code. */
+ public String unsupportedExceptionType() {
+ return unsupportedExceptionType;
+ }
+
+ /** Returns the list of imports that should be emitted at the top of each .java file. */
+ public List<String> imports() {
+ return imports;
+ }
private static final boolean DEBUG_TYPE_INFO = false;
/** If this type should be considered opaque, returns the TypeInfo
@@ -328,12 +371,11 @@ public class JavaConfiguration {
}
// Try all typedef names that map to this type
- Set entrySet = typedefDictionary.entrySet();
- for (Iterator iter = entrySet.iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
+ Set<Entry<String, Type>> entrySet = typedefDictionary.entrySet();
+ for (Map.Entry<String, Type> entry : entrySet) {
// "eq" equality is OK to use here since all types have been canonicalized
if (entry.getValue() == type) {
- name = (String) entry.getKey();
+ name = entry.getKey();
if (DEBUG_TYPE_INFO) {
System.err.println("Looking under typedef name " + name);
}
@@ -359,14 +401,12 @@ public class JavaConfiguration {
// Helper functions for above
private TypeInfo closestTypeInfo(String name, int pointerDepth) {
- TypeInfo info = (TypeInfo) typeInfoMap.get(name);
+ TypeInfo info = typeInfoMap.get(name);
TypeInfo closest = null;
while (info != null) {
if (DEBUG_TYPE_INFO)
System.err.println(" Checking TypeInfo for " + name + " at pointerDepth " + pointerDepth);
- if (info.pointerDepth() <= pointerDepth &&
- (closest == null ||
- info.pointerDepth() > closest.pointerDepth())) {
+ if (info.pointerDepth() <= pointerDepth && (closest == null || info.pointerDepth() > closest.pointerDepth())) {
if (DEBUG_TYPE_INFO)
System.err.println(" Accepted");
closest = info;
@@ -389,7 +429,7 @@ public class JavaConfiguration {
numPointersStripped);
}
- Class c = info.javaType().getJavaClass();
+ Class<?> c = info.javaType().getJavaClass();
int pd = info.pointerDepth();
// Handle single-pointer stripping for types compatible with C
@@ -432,15 +472,15 @@ public class JavaConfiguration {
pointer to a CompoundType, is actually an array of the
CompoundType rather than a pointer to a single object. */
public String returnedArrayLength(String functionName) {
- return (String) returnedArrayLengths.get(functionName);
+ return returnedArrayLengths.get(functionName);
}
/** Returns a list of <code>Integer</code>s which are the indices of <code>const char*</code>
arguments that should be converted to <code>String</code>s. Returns null if there are no
such hints for the given function name. */
- public List/*<Integer>*/ stringArguments(String functionName) {
- return (List) argumentsAreString.get(functionName);
+ public List<Integer> stringArguments(String functionName) {
+ return argumentsAreString.get(functionName);
}
public boolean isForceNioOnly4All() { return forceNioOnly4All; }
@@ -474,10 +514,10 @@ public class JavaConfiguration {
the given Java type name (not fully-qualified, only the class
name); returns either null or an empty list if there is no
custom code for the class. */
- public List customJavaCodeForClass(String className) {
- List res = (List) customJavaCode.get(className);
+ public List<String> customJavaCodeForClass(String className) {
+ List<String> res = customJavaCode.get(className);
if (res == null) {
- res = new ArrayList();
+ res = new ArrayList<String>();
customJavaCode.put(className, res);
}
return res;
@@ -487,10 +527,10 @@ public class JavaConfiguration {
the given Java type name (not fully-qualified, only the class
name); returns either null or an empty list if there is no
Javadoc documentation for the class. */
- public List javadocForClass(String className) {
- List res = (List) classJavadoc.get(className);
+ public List<String> javadocForClass(String className) {
+ List<String> res = classJavadoc.get(className);
if (res == null) {
- res = new ArrayList();
+ res = new ArrayList<String>();
classJavadoc.put(className, res);
}
return res;
@@ -500,7 +540,7 @@ public class JavaConfiguration {
accessing the specified struct. Defaults to emitting into the
regular package (i.e., the result of {@link #packageName}). */
public String packageForStruct(String structName) {
- String res = (String) structPackages.get(structName);
+ String res = structPackages.get(structName);
if (res == null) {
res = packageName;
}
@@ -509,13 +549,13 @@ public class JavaConfiguration {
/** Returns, as a List of Strings, the custom C code to be emitted
along with the glue code for the main class. */
- public List/*<String>*/ customCCode() {
+ public List<String> customCCode() {
return customCCode;
}
/** Returns, as a List of Strings, the structs for which glue code
emission should be forced. */
- public List/*<String>*/ forcedStructs() {
+ public List<String> forcedStructs() {
return forcedStructs;
}
@@ -523,36 +563,36 @@ public class JavaConfiguration {
the capacity of the java.nio.ByteBuffer being returned from a
native method, or null if no expression has been specified. */
public String returnValueCapacity(String functionName) {
- return (String) returnValueCapacities.get(functionName);
+ return returnValueCapacities.get(functionName);
}
/** Returns a MessageFormat string of the C expression calculating
the length of the array being returned from a native method, or
null if no expression has been specified. */
public String returnValueLength(String functionName) {
- return (String) returnValueLengths.get(functionName);
+ return returnValueLengths.get(functionName);
}
/** Returns a List of Strings of expressions declaring temporary C
variables in the glue code for the specified function. */
- public List/*<String>*/ temporaryCVariableDeclarations(String functionName) {
- return (List) temporaryCVariableDeclarations.get(functionName);
+ public List<String> temporaryCVariableDeclarations(String functionName) {
+ return temporaryCVariableDeclarations.get(functionName);
}
/** Returns a List of Strings of expressions containing assignments
to temporary C variables in the glue code for the specified
function. */
- public List/*<String>*/ temporaryCVariableAssignments(String functionName) {
- return (List) temporaryCVariableAssignments.get(functionName);
+ public List<String> temporaryCVariableAssignments(String functionName) {
+ return temporaryCVariableAssignments.get(functionName);
}
/** Returns a List of Strings indicating the interfaces the passed
interface should declare it extends. May return null or a list
of zero length if there are none. */
- public List/*<String>*/ extendedInterfaces(String interfaceName) {
- List res = (List) extendedInterfaces.get(interfaceName);
+ public List<String> extendedInterfaces(String interfaceName) {
+ List<String> res = extendedInterfaces.get(interfaceName);
if (res == null) {
- res = new ArrayList();
+ res = new ArrayList<String>();
extendedInterfaces.put(interfaceName, res);
}
return res;
@@ -561,10 +601,10 @@ public class JavaConfiguration {
/** Returns a List of Strings indicating the interfaces the passed
class should declare it implements. May return null or a list
of zero length if there are none. */
- public List/*<String>*/ implementedInterfaces(String className) {
- List res = (List) implementedInterfaces.get(className);
+ public List<String> implementedInterfaces(String className) {
+ List<String> res = implementedInterfaces.get(className);
if (res == null) {
- res = new ArrayList();
+ res = new ArrayList<String>();
implementedInterfaces.put(className, res);
}
return res;
@@ -574,7 +614,7 @@ public class JavaConfiguration {
class should declare it implements. May return null or a list
of zero length if there are none. */
public String extendedParentClass(String className) {
- return (String) parentClass.get(className);
+ return parentClass.get(className);
}
public static final boolean DEBUG_IGNORES = false;
@@ -589,19 +629,18 @@ public class JavaConfiguration {
public void dumpIgnores() {
System.err.println("Extended Intf: ");
- for (Iterator iter = extendedIntfSymbolsIgnore.iterator(); iter.hasNext(); ) {
- System.err.println("\t"+(String)iter.next());
+ for (String str : extendedIntfSymbolsIgnore) {
+ System.err.println("\t"+str);
}
System.err.println("Ignores (All): ");
- for (Iterator iter = ignores.iterator(); iter.hasNext(); ) {
- System.err.println("\t"+iter.next());
+ for (Pattern pattern : ignores) {
+ System.err.println("\t"+pattern);
}
}
public void dumpRenames() {
System.err.println("Symbol Renames: ");
- for (Iterator iter = javaSymbolRenames.keySet().iterator(); iter.hasNext(); ) {
- String key = (String)iter.next();
+ for (String key : javaSymbolRenames.keySet()) {
System.err.println("\t"+key+" -> "+javaSymbolRenames.get(key));
}
}
@@ -653,8 +692,7 @@ public class JavaConfiguration {
// Ok, the slow case. We need to check the entire table, in case the table
// contains an regular expression that matches the symbol.
- for (Iterator iter = ignores.iterator(); iter.hasNext(); ) {
- Pattern regexp = (Pattern)iter.next();
+ for (Pattern regexp : ignores) {
Matcher matcher = regexp.matcher(symbol);
if (matcher.matches()) {
if(DEBUG_IGNORES) {
@@ -668,8 +706,7 @@ public class JavaConfiguration {
if (ignoreNots.size() > 0) {
// Ok, the slow case. We need to check the entire table, in case the table
// contains an regular expression that matches the symbol.
- for (Iterator iter = ignoreNots.iterator(); iter.hasNext(); ) {
- Pattern regexp = (Pattern)iter.next();
+ for (Pattern regexp : ignoreNots) {
Matcher matcher = regexp.matcher(symbol);
if (!matcher.matches()) {
// Special case as this is most often likely to be the case.
@@ -682,8 +719,7 @@ public class JavaConfiguration {
}
boolean unignoreFound = false;
- for (Iterator iter2 = unignores.iterator(); iter2.hasNext(); ) {
- Pattern unignoreRegexp = (Pattern)iter2.next();
+ for (Pattern unignoreRegexp : unignores) {
Matcher unignoreMatcher = unignoreRegexp.matcher(symbol);
if (unignoreMatcher.matches()) {
unignoreFound = true;
@@ -715,8 +751,7 @@ public class JavaConfiguration {
// Ok, the slow case. We need to check the entire table, in case the table
// contains an regular expression that matches the symbol.
- for (Iterator iter = unimplemented.iterator(); iter.hasNext(); ) {
- Pattern regexp = (Pattern)iter.next();
+ for (Pattern regexp : unimplemented) {
Matcher matcher = regexp.matcher(symbol);
if (matcher.matches()) {
return true;
@@ -731,7 +766,7 @@ public class JavaConfiguration {
unchanged if no RenameJavaType directive was specified for this
type. */
public String renameJavaType(String javaTypeName) {
- String rename = (String) javaTypeRenames.get(javaTypeName);
+ String rename = javaTypeRenames.get(javaTypeName);
if (rename != null) {
return rename;
}
@@ -744,7 +779,7 @@ public class JavaConfiguration {
function under the hood. Returns null if this symbol has not
been explicitly renamed. */
public String getJavaSymbolRename(String symbolName) {
- return (String) javaSymbolRenames.get(symbolName);
+ return javaSymbolRenames.get(symbolName);
}
/** Programmatically adds a rename directive for the given symbol. */
@@ -773,15 +808,13 @@ public class JavaConfiguration {
/** Returns a list of Strings which should be emitted as a prologue
to the body for the Java-side glue code for the given method.
Returns null if no prologue was specified. */
- public List/*<String>*/ javaPrologueForMethod(MethodBinding binding,
+ public List<String> javaPrologueForMethod(MethodBinding binding,
boolean forImplementingMethodCall,
boolean eraseBufferAndArrayTypes) {
- List/*<String>*/ res = (List/*<String>*/) javaPrologues.get(binding.getName());
+ List<String> res = javaPrologues.get(binding.getName());
if (res == null) {
// Try again with method name and descriptor
- res = (List/*<String>*/) javaPrologues.get(binding.getName() +
- binding.getDescriptor(forImplementingMethodCall,
- eraseBufferAndArrayTypes));
+ res = javaPrologues.get(binding.getName() + binding.getDescriptor(forImplementingMethodCall, eraseBufferAndArrayTypes));
}
return res;
}
@@ -789,15 +822,13 @@ public class JavaConfiguration {
/** Returns a list of Strings which should be emitted as an epilogue
to the body for the Java-side glue code for the given method.
Returns null if no epilogue was specified. */
- public List/*<String>*/ javaEpilogueForMethod(MethodBinding binding,
+ public List<String> javaEpilogueForMethod(MethodBinding binding,
boolean forImplementingMethodCall,
boolean eraseBufferAndArrayTypes) {
- List/*<String>*/ res = (List/*<String>*/) javaEpilogues.get(binding.getName());
+ List<String> res = javaEpilogues.get(binding.getName());
if (res == null) {
// Try again with method name and descriptor
- res = (List/*<String>*/) javaEpilogues.get(binding.getName() +
- binding.getDescriptor(forImplementingMethodCall,
- eraseBufferAndArrayTypes));
+ res = javaEpilogues.get(binding.getName() + binding.getDescriptor(forImplementingMethodCall, eraseBufferAndArrayTypes));
}
return res;
}
@@ -978,7 +1009,7 @@ public class JavaConfiguration {
}
}
- protected Class stringToPrimitiveType(String type) throws ClassNotFoundException {
+ protected Class<?> stringToPrimitiveType(String type) throws ClassNotFoundException {
if (type.equals("boolean")) return Boolean.TYPE;
if (type.equals("byte")) return Byte.TYPE;
if (type.equals("char")) return Character.TYPE;
@@ -1061,6 +1092,7 @@ public class JavaConfiguration {
}
}
+ @SuppressWarnings("unchecked")
protected void readExtendedInterfaceSymbols(StringTokenizer tok, String filename, int lineNo, boolean onlyList) {
File javaFile;
BufferedReader javaReader;
@@ -1110,7 +1142,7 @@ public class JavaConfiguration {
protected void readUnignore(StringTokenizer tok, String filename, int lineNo) {
try {
String regex = tok.nextToken();
- Pattern pattern = (Pattern) ignoreMap.get(regex);
+ Pattern pattern = ignoreMap.get(regex);
ignoreMap.remove(regex);
ignores.remove(pattern);
@@ -1171,12 +1203,12 @@ public class JavaConfiguration {
protected void readCustomJavaCode(StringTokenizer tok, String filename, int lineNo) {
try {
- String className = tok.nextToken();
+ String tokenClassName = tok.nextToken();
try {
String restOfLine = tok.nextToken("\n\r\f");
- addCustomJavaCode(className, restOfLine);
+ addCustomJavaCode(tokenClassName, restOfLine);
} catch (NoSuchElementException e) {
- addCustomJavaCode(className, "");
+ addCustomJavaCode(tokenClassName, "");
}
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"CustomJavaCode\" command at line " + lineNo +
@@ -1185,7 +1217,7 @@ public class JavaConfiguration {
}
protected void addCustomJavaCode(String className, String code) {
- List codeList = customJavaCodeForClass(className);
+ List<String> codeList = customJavaCodeForClass(className);
codeList.add(code);
}
@@ -1200,9 +1232,9 @@ public class JavaConfiguration {
protected void readClassJavadoc(StringTokenizer tok, String filename, int lineNo) {
try {
- String className = tok.nextToken();
+ String tokenClassName = tok.nextToken();
String restOfLine = tok.nextToken("\n\r\f");
- addClassJavadoc(className, restOfLine);
+ addClassJavadoc(tokenClassName, restOfLine);
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"ClassJavadoc\" command at line " + lineNo +
" in file \"" + filename + "\"", e);
@@ -1210,7 +1242,7 @@ public class JavaConfiguration {
}
protected void addClassJavadoc(String className, String code) {
- List codeList = javadocForClass(className);
+ List<String> codeList = javadocForClass(className);
codeList.add(code);
}
@@ -1246,7 +1278,7 @@ public class JavaConfiguration {
protected void readArgumentIsString(StringTokenizer tok, String filename, int lineNo) {
try {
String methodName = tok.nextToken();
- ArrayList argIndices = new ArrayList(2);
+ ArrayList<Integer> argIndices = new ArrayList<Integer>(2);
while (tok.hasMoreTokens()) {
Integer idx = Integer.valueOf(tok.nextToken());
argIndices.add(idx);
@@ -1305,9 +1337,9 @@ public class JavaConfiguration {
String functionName = tok.nextToken();
String restOfLine = tok.nextToken("\n\r\f");
restOfLine = restOfLine.trim();
- List list = (List) temporaryCVariableDeclarations.get(functionName);
+ List<String> list = temporaryCVariableDeclarations.get(functionName);
if (list == null) {
- list = new ArrayList/*<String>*/();
+ list = new ArrayList<String>();
temporaryCVariableDeclarations.put(functionName, list);
}
list.add(restOfLine);
@@ -1322,9 +1354,9 @@ public class JavaConfiguration {
String functionName = tok.nextToken();
String restOfLine = tok.nextToken("\n\r\f");
restOfLine = restOfLine.trim();
- List list = (List) temporaryCVariableAssignments.get(functionName);
+ List<String> list = temporaryCVariableAssignments.get(functionName);
if (list == null) {
- list = new ArrayList/*<String>*/();
+ list = new ArrayList<String>();
temporaryCVariableAssignments.put(functionName, list);
}
list.add(restOfLine);
@@ -1372,7 +1404,7 @@ public class JavaConfiguration {
protected void readExtend(StringTokenizer tok, String filename, int lineNo) {
try {
String interfaceName = tok.nextToken();
- List intfs = extendedInterfaces(interfaceName);
+ List<String> intfs = extendedInterfaces(interfaceName);
intfs.add(tok.nextToken());
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"Extends\" command at line " + lineNo +
@@ -1382,8 +1414,8 @@ public class JavaConfiguration {
protected void readImplements(StringTokenizer tok, String filename, int lineNo) {
try {
- String className = tok.nextToken();
- List intfs = implementedInterfaces(className);
+ String tokenClassName = tok.nextToken();
+ List<String> intfs = implementedInterfaces(tokenClassName);
intfs.add(tok.nextToken());
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"Implements\" command at line " + lineNo +
@@ -1393,8 +1425,8 @@ public class JavaConfiguration {
protected void readParentClass(StringTokenizer tok, String filename, int lineNo) {
try {
- String className = tok.nextToken();
- parentClass.put(className, tok.nextToken());
+ String tokenClassName = tok.nextToken();
+ parentClass.put(tokenClassName, tok.nextToken());
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"ParentClass\" command at line " + lineNo +
" in file \"" + filename + "\": missing expected parameter", e);
@@ -1447,10 +1479,10 @@ public class JavaConfiguration {
}
protected void addJavaPrologueOrEpilogue(String methodName, String code, boolean prologue) {
- Map codes = (prologue ? javaPrologues : javaEpilogues);
- List/*<String>*/ data = (List/*<String>*/) codes.get(methodName);
+ Map<String, List<String>> codes = (prologue ? javaPrologues : javaEpilogues);
+ List<String> data = codes.get(methodName);
if (data == null) {
- data = new ArrayList/*<String>*/();
+ data = new ArrayList<String>();
codes.put(methodName, data);
}
data.add(code);
@@ -1495,7 +1527,7 @@ public class JavaConfiguration {
}
protected void addTypeInfo(TypeInfo info) {
- TypeInfo tmp = (TypeInfo) typeInfoMap.get(info.name());
+ TypeInfo tmp = typeInfoMap.get(info.name());
if (tmp == null) {
typeInfoMap.put(info.name(), info);
return;
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index 5a64ef6..0d118cf 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -56,10 +56,11 @@ import com.sun.gluegen.cgram.types.*;
public class JavaEmitter implements GlueEmitter {
+
private StructLayout layout;
private TypeDictionary typedefDictionary;
private TypeDictionary structDictionary;
- private Map canonMap;
+ private Map<Type, Type> canonMap;
protected JavaConfiguration cfg;
/**
@@ -93,8 +94,8 @@ public class JavaEmitter implements GlueEmitter {
cfg.read(filename);
}
- public void setMachineDescription(MachineDescription md32,
- MachineDescription md64) {
+ public void setMachineDescription(MachineDescription md32, MachineDescription md64) {
+
if ((md32 == null) && (md64 == null)) {
throw new RuntimeException("Must specify at least one MachineDescription");
}
@@ -104,28 +105,26 @@ public class JavaEmitter implements GlueEmitter {
}
class ConstantRenamer implements SymbolFilter {
- private List/*<ConstantDefinition>*/ constants;
- public void filterSymbols(List/*<ConstantDefinition>*/ constants,
- List/*<FunctionSymbol>*/ functions) {
+ private List<ConstantDefinition> constants;
+
+ public void filterSymbols(List<ConstantDefinition> constants, List<FunctionSymbol> functions) {
this.constants = constants;
doWork();
}
- public List/*<ConstantDefinition>*/ getConstants() {
+ public List<ConstantDefinition> getConstants() {
return constants;
}
- public List/*<FunctionSymbol>*/ getFunctions() {
+ public List<FunctionSymbol> getFunctions() {
return null;
}
private void doWork() {
- List/*<ConstantDefinition>*/ newConstants = new ArrayList/*<ConstantDefinition>*/();
+ List<ConstantDefinition> newConstants = new ArrayList<ConstantDefinition>();
JavaConfiguration cfg = getConfig();
- for (Iterator iter = constants.iterator(); iter.hasNext(); ) {
- ConstantDefinition def = (ConstantDefinition) iter.next();
- String rename = cfg.getJavaSymbolRename(def.getName());
+ for (ConstantDefinition def : constants) {
def.rename(cfg.getJavaSymbolRename(def.getName()));
newConstants.add(def);
}
@@ -137,15 +136,14 @@ public class JavaEmitter implements GlueEmitter {
try {
openWriters();
} catch (Exception e) {
- throw new RuntimeException(
- "Unable to open files for writing", e);
+ throw new RuntimeException("Unable to open files for writing", e);
}
emitAllFileHeaders();
// Request emission of any structs requested
- for (Iterator iter = cfg.forcedStructs().iterator(); iter.hasNext(); ) {
- controls.forceStructEmission((String) iter.next());
+ for (String structs : cfg.forcedStructs()) {
+ controls.forceStructEmission(structs);
}
// Handle renaming of constants
@@ -158,8 +156,7 @@ public class JavaEmitter implements GlueEmitter {
try {
closeWriters();
} catch (Exception e) {
- throw new RuntimeException(
- "Unable to close open files", e);
+ throw new RuntimeException("Unable to close open files", e);
}
}
@@ -275,13 +272,11 @@ public class JavaEmitter implements GlueEmitter {
if (value.startsWith("0x") || value.startsWith("0X")) {
radix = 16;
parseValue = value.substring(2);
- }
- else if (value.startsWith("0") && value.length() > 1) {
+ } else if (value.startsWith("0") && value.length() > 1) {
// TODO: is "0" the prefix in C to indicate octal???
radix = 8;
parseValue = value.substring(1);
- }
- else {
+ } else {
radix = 10;
parseValue = value;
}
@@ -289,9 +284,9 @@ public class JavaEmitter implements GlueEmitter {
long longVal = Long.parseLong(parseValue, radix);
// if constant is small enough, store it as an int instead of a long
if (longVal > Integer.MIN_VALUE && longVal < Integer.MAX_VALUE) {
- return new Integer((int)longVal);
+ return (int)longVal;
}
- return new Long(longVal);
+ return longVal;
} catch (NumberFormatException e) {
try {
@@ -366,7 +361,7 @@ public class JavaEmitter implements GlueEmitter {
public void beginFunctions(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
- Map canonMap) throws Exception {
+ Map<Type, Type> canonMap) throws Exception {
this.typedefDictionary = typedefDictionary;
this.structDictionary = structDictionary;
this.canonMap = canonMap;
@@ -375,8 +370,8 @@ public class JavaEmitter implements GlueEmitter {
}
}
- public Iterator emitFunctions(List/*<FunctionSymbol>*/ originalCFunctions)
- throws Exception {
+ public Iterator<FunctionSymbol> emitFunctions(List<FunctionSymbol> originalCFunctions) throws Exception {
+
// Sometimes headers will have the same function prototype twice, once
// with the argument names and once without. We'll remember the signatures
// we've already processed we don't generate duplicate bindings.
@@ -384,9 +379,8 @@ public class JavaEmitter implements GlueEmitter {
// Note: this code assumes that on the equals() method in FunctionSymbol
// only considers function name and argument types (i.e., it does not
// consider argument *names*) when comparing FunctionSymbols for equality
- Set funcsToBindSet = new HashSet(100);
- for (Iterator cIter = originalCFunctions.iterator(); cIter.hasNext(); ) {
- FunctionSymbol cFunc = (FunctionSymbol) cIter.next();
+ Set<FunctionSymbol> funcsToBindSet = new HashSet<FunctionSymbol>(100);
+ for (FunctionSymbol cFunc : originalCFunctions) {
if (!funcsToBindSet.contains(cFunc)) {
funcsToBindSet.add(cFunc);
}
@@ -394,38 +388,36 @@ public class JavaEmitter implements GlueEmitter {
// validateFunctionsToBind(funcsToBindSet);
- ArrayList funcsToBind = new ArrayList(funcsToBindSet.size());
+ ArrayList<FunctionSymbol> funcsToBind = new ArrayList<FunctionSymbol>(funcsToBindSet.size());
funcsToBind.addAll(funcsToBindSet);
// sort functions to make them easier to find in native code
Collections.sort(
funcsToBind,
- new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((FunctionSymbol)o1).getName().compareTo(
- ((FunctionSymbol)o2).getName());
+ new Comparator<FunctionSymbol>() {
+ public int compare(FunctionSymbol o1, FunctionSymbol o2) {
+ return o1.getName().compareTo(o2.getName());
}
+ @Override
public boolean equals(Object obj) {
return obj.getClass() == this.getClass();
}
});
// Bind all the C funcs to Java methods
- HashSet/*<MethodBinding>*/ methodBindingSet = new HashSet();
- ArrayList/*<FunctionEmitter>*/ methodBindingEmitters = new ArrayList(2*funcsToBind.size());
- for (Iterator iter = funcsToBind.iterator(); iter.hasNext(); ) {
- FunctionSymbol cFunc = (FunctionSymbol) iter.next();
+ HashSet<MethodBinding> methodBindingSet = new HashSet<MethodBinding>();
+ ArrayList<FunctionEmitter> methodBindingEmitters = new ArrayList<FunctionEmitter>(2*funcsToBind.size());
+ for (FunctionSymbol cFunc : funcsToBind) {
// Check to see whether this function should be ignored
if (cfg.shouldIgnoreInImpl(cFunc.getName())) {
continue; // don't generate bindings for this symbol
}
- List allBindings = generateMethodBindingEmitters(methodBindingSet, cFunc);
- methodBindingEmitters.addAll(allBindings);
+ methodBindingEmitters.addAll(generateMethodBindingEmitters(methodBindingSet, cFunc));
}
// Emit all the methods
for (int i = 0; i < methodBindingEmitters.size(); ++i) {
- FunctionEmitter emitter = (FunctionEmitter)methodBindingEmitters.get(i);
+ FunctionEmitter emitter = methodBindingEmitters.get(i);
try {
if (!emitter.isInterface() || !cfg.shouldIgnoreInInterface(emitter.getName())) {
emitter.emit();
@@ -465,7 +457,7 @@ public class JavaEmitter implements GlueEmitter {
* outgoing arguments).
*/
protected void generatePublicEmitters(MethodBinding binding,
- List allEmitters,
+ List<FunctionEmitter> allEmitters,
boolean signatureOnly) {
PrintWriter writer = ((signatureOnly || cfg.allStatic()) ? javaWriter() : javaImplWriter());
@@ -485,8 +477,8 @@ public class JavaEmitter implements GlueEmitter {
// set to false; for example, if the routine doesn't take any
// arrays or buffers as arguments
boolean isUnimplemented = cfg.isUnimplemented(binding.getName());
- List/*<String>*/ prologue = cfg.javaPrologueForMethod(binding, false, false);
- List/*<String>*/ epilogue = cfg.javaEpilogueForMethod(binding, false, false);
+ List<String> prologue = cfg.javaPrologueForMethod(binding, false, false);
+ List<String> epilogue = cfg.javaEpilogueForMethod(binding, false, false);
boolean needsBody = (isUnimplemented ||
(binding.needsNIOWrappingOrUnwrapping() ||
binding.signatureUsesJavaPrimitiveArrays()) ||
@@ -536,7 +528,7 @@ public class JavaEmitter implements GlueEmitter {
* creating duplicated methods / functions.
*/
protected void generatePrivateEmitters(MethodBinding binding,
- List allEmitters) {
+ List<FunctionEmitter> allEmitters) {
if (cfg.manuallyImplement(binding.getName())) {
// Don't produce emitters for the implementation class
return;
@@ -703,9 +695,9 @@ public class JavaEmitter implements GlueEmitter {
* Generate all appropriate Java bindings for the specified C function
* symbols.
*/
- protected List generateMethodBindingEmitters(HashSet/*<MethodBinding>*/ methodBindingSet, FunctionSymbol sym) throws Exception {
+ protected List<FunctionEmitter> generateMethodBindingEmitters(HashSet<MethodBinding> methodBindingSet, FunctionSymbol sym) throws Exception {
- ArrayList/*<FunctionEmitter>*/ allEmitters = new ArrayList();
+ ArrayList<FunctionEmitter> allEmitters = new ArrayList<FunctionEmitter>();
try {
// Get Java binding for the function
@@ -713,10 +705,9 @@ public class JavaEmitter implements GlueEmitter {
// JavaTypes representing C pointers in the initial
// MethodBinding have not been lowered yet to concrete types
- List bindings = expandMethodBinding(mb);
+ List<MethodBinding> bindings = expandMethodBinding(mb);
- for (Iterator iter = bindings.iterator(); iter.hasNext(); ) {
- MethodBinding binding = (MethodBinding) iter.next();
+ for (MethodBinding binding : bindings) {
if(!methodBindingSet.add(binding)) {
// skip .. already exisiting binding ..
@@ -783,8 +774,7 @@ public class JavaEmitter implements GlueEmitter {
}
} // end iteration over expanded bindings
} catch (Exception e) {
- throw new RuntimeException(
- "Error while generating bindings for \"" + sym + "\"", e);
+ throw new RuntimeException("Error while generating bindings for \"" + sym + "\"", e);
}
return allEmitters;
@@ -809,7 +799,7 @@ public class JavaEmitter implements GlueEmitter {
public void beginStructs(TypeDictionary typedefDictionary,
TypeDictionary structDictionary,
- Map canonMap) throws Exception {
+ Map<Type, Type> canonMap) throws Exception {
this.typedefDictionary = typedefDictionary;
this.structDictionary = structDictionary;
this.canonMap = canonMap;
@@ -900,8 +890,7 @@ public class JavaEmitter implements GlueEmitter {
String structClassPkg = cfg.packageForStruct(name);
PrintWriter writer = null;
PrintWriter cWriter = null;
- try
- {
+ try {
writer = openFile(
cfg.javaOutputDir() + File.separator +
CodeGenUtils.packageAsPath(structClassPkg) +
@@ -910,19 +899,14 @@ public class JavaEmitter implements GlueEmitter {
if (needsNativeCode) {
String nRoot = cfg.nativeOutputDir();
if (cfg.nativeOutputUsesJavaHierarchy()) {
- nRoot +=
- File.separator +
- CodeGenUtils.packageAsPath(cfg.packageName());
+ nRoot += File.separator + CodeGenUtils.packageAsPath(cfg.packageName());
}
cWriter = openFile(nRoot + File.separator + containingTypeName + "_JNI.c");
CodeGenUtils.emitAutogeneratedWarning(cWriter, this);
emitCHeader(cWriter, containingTypeName);
}
- }
- catch(Exception e)
- {
- throw new RuntimeException(
- "Unable to open files for emission of struct class", e);
+ } catch(Exception e) {
+ throw new RuntimeException("Unable to open files for emission of struct class", e);
}
writer.println();
@@ -932,29 +916,29 @@ public class JavaEmitter implements GlueEmitter {
writer.println();
writer.println("import " + cfg.gluegenRuntimePackage() + ".*;");
writer.println();
- List/*<String>*/ imports = cfg.imports();
- for (Iterator iter = imports.iterator(); iter.hasNext(); ) {
+ List<String> imports = cfg.imports();
+ for (String str : imports) {
writer.print("import ");
- writer.print(iter.next());
+ writer.print(str);
writer.println(";");
}
writer.println();
- List/*<String>*/ javadoc = cfg.javadocForClass(containingTypeName);
- for (Iterator iter = javadoc.iterator(); iter.hasNext(); ) {
- writer.println((String) iter.next());
+ List<String> javadoc = cfg.javadocForClass(containingTypeName);
+ for (String doc : javadoc) {
+ writer.println(doc);
}
writer.print((doBaseClass ? "public " : "") + (doBaseClass ? "abstract " : "") + "class " + containingTypeName + suffix + " ");
if (!doBaseClass) {
writer.print("extends " + containingTypeName + " ");
}
boolean firstIteration = true;
- List/*<String>*/ userSpecifiedInterfaces = cfg.implementedInterfaces(containingTypeName);
- for (Iterator iter = userSpecifiedInterfaces.iterator(); iter.hasNext(); ) {
+ List<String> userSpecifiedInterfaces = cfg.implementedInterfaces(containingTypeName);
+ for (String userInterface : userSpecifiedInterfaces) {
if (firstIteration) {
writer.print("implements ");
}
firstIteration = false;
- writer.print(iter.next());
+ writer.print(userInterface);
writer.print(" ");
}
writer.println("{");
@@ -1193,11 +1177,11 @@ public class JavaEmitter implements GlueEmitter {
}
public void endStructs() throws Exception {}
- public static int addStrings2Buffer(StringBuffer buf, String sep, String first, Collection col) {
+ public static int addStrings2Buffer(StringBuffer buf, String sep, String first, Collection<String> col) {
int num = 0;
- if(null==buf) buf=new StringBuffer();
+ if(null==buf) buf = new StringBuffer();
- Iterator iter=col.iterator();
+ Iterator<String> iter = col.iterator();
if(null!=first) {
buf.append(first);
if( iter.hasNext() ) {
@@ -1206,7 +1190,7 @@ public class JavaEmitter implements GlueEmitter {
num++;
}
while( iter.hasNext() ) {
- buf.append((String)iter.next());
+ buf.append(iter.next());
if( iter.hasNext() ) {
buf.append(sep);
}
@@ -1368,7 +1352,7 @@ public class JavaEmitter implements GlueEmitter {
}
}
- private static boolean isIntegerType(Class c) {
+ private static boolean isIntegerType(Class<?> c) {
return ((c == Byte.TYPE) ||
(c == Short.TYPE) ||
(c == Character.TYPE) ||
@@ -1422,7 +1406,7 @@ public class JavaEmitter implements GlueEmitter {
private String compatiblePrimitiveJavaTypeName(Type fieldType,
JavaType javaType,
MachineDescription curMachDesc) {
- Class c = javaType.getJavaClass();
+ Class<?> c = javaType.getJavaClass();
if (!isIntegerType(c)) {
// FIXME
throw new RuntimeException("Can't yet handle opaque definitions of structs' fields to non-integer types (byte, short, int, long, etc.)");
@@ -1545,16 +1529,15 @@ public class JavaEmitter implements GlueEmitter {
* Emit all the strings specified in the "CustomJavaCode" parameters of
* the configuration file.
*/
- protected void emitCustomJavaCode(PrintWriter writer, String className) throws Exception
- {
- List code = cfg.customJavaCodeForClass(className);
+ protected void emitCustomJavaCode(PrintWriter writer, String className) throws Exception {
+ List<String> code = cfg.customJavaCodeForClass(className);
if (code.size() == 0)
return;
writer.println();
writer.println(" // --- Begin CustomJavaCode .cfg declarations");
- for (Iterator iter = code.iterator(); iter.hasNext(); ) {
- writer.println((String) iter.next());
+ for (String line : code) {
+ writer.println(line);
}
writer.println(" // ---- End CustomJavaCode .cfg declarations");
}
@@ -1567,7 +1550,7 @@ public class JavaEmitter implements GlueEmitter {
try {
if (cfg.allStatic() || cfg.emitInterface()) {
String[] interfaces;
- List userSpecifiedInterfaces = null;
+ List<String> userSpecifiedInterfaces = null;
if (cfg.emitInterface()) {
userSpecifiedInterfaces = cfg.extendedInterfaces(cfg.className());
} else {
@@ -1576,7 +1559,7 @@ public class JavaEmitter implements GlueEmitter {
interfaces = new String[userSpecifiedInterfaces.size()];
userSpecifiedInterfaces.toArray(interfaces);
- final List/*<String>*/ intfDocs = cfg.javadocForClass(cfg.className());
+ final List<String> intfDocs = cfg.javadocForClass(cfg.className());
CodeGenUtils.EmissionCallback docEmitter =
new CodeGenUtils.EmissionCallback() {
public void emit(PrintWriter w) {
@@ -1598,8 +1581,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.packageName(),
cfg.className(),
cfg.gluegenRuntimePackage(),
- cfg.allStatic() ? true : false,
- (String[]) cfg.imports().toArray(new String[] {}),
+ cfg.allStatic() ? true : false, cfg.imports().toArray(new String[] {}),
accessModifiers,
interfaces,
cfg.extendedParentClass(cfg.className()),
@@ -1607,7 +1589,7 @@ public class JavaEmitter implements GlueEmitter {
}
if (!cfg.allStatic() && cfg.emitImpl()) {
- final List/*<String>*/ implDocs = cfg.javadocForClass(cfg.implClassName());
+ final List<String> implDocs = cfg.javadocForClass(cfg.implClassName());
CodeGenUtils.EmissionCallback docEmitter =
new CodeGenUtils.EmissionCallback() {
public void emit(PrintWriter w) {
@@ -1618,7 +1600,7 @@ public class JavaEmitter implements GlueEmitter {
};
String[] interfaces;
- List userSpecifiedInterfaces = null;
+ List<String> userSpecifiedInterfaces = null;
userSpecifiedInterfaces = cfg.implementedInterfaces(cfg.implClassName());
int additionalNum = 0;
if (cfg.className() != null) {
@@ -1643,7 +1625,7 @@ public class JavaEmitter implements GlueEmitter {
cfg.implClassName(),
cfg.gluegenRuntimePackage(),
true,
- (String[]) cfg.imports().toArray(new String[] {}),
+ cfg.imports().toArray(new String[] {}),
accessModifiers,
interfaces,
cfg.extendedParentClass(cfg.implClassName()),
@@ -1651,8 +1633,7 @@ public class JavaEmitter implements GlueEmitter {
}
if (cfg.emitImpl()) {
- PrintWriter cWriter = cWriter();
- emitCHeader(cWriter, cfg.implClassName());
+ emitCHeader(cWriter(), cfg.implClassName());
}
} catch (Exception e) {
throw new RuntimeException(
@@ -1673,8 +1654,8 @@ public class JavaEmitter implements GlueEmitter {
cWriter.println();
}
- for (Iterator iter = cfg.customCCode().iterator(); iter.hasNext(); ) {
- cWriter.println((String) iter.next());
+ for (String code : cfg.customCCode()) {
+ cWriter.println(code);
}
cWriter.println();
}
@@ -1688,14 +1669,13 @@ public class JavaEmitter implements GlueEmitter {
javaWriter().println();
javaWriter().println("} // end of class " + cfg.className());
}
- if (!cfg.allStatic() && cfg.emitImpl())
- {
+ if (!cfg.allStatic() && cfg.emitImpl()) {
javaImplWriter().println();
javaImplWriter().println("} // end of class " + cfg.implClassName());
}
}
- private JavaType javaType(Class c) {
+ private JavaType javaType(Class<?> c) {
return JavaType.createForClass(c);
}
@@ -1730,7 +1710,7 @@ public class JavaEmitter implements GlueEmitter {
// List of the indices of the arguments in this function that should be
// converted from byte[] or short[] to String
- List stringArgIndices = cfg.stringArguments(binding.getName());
+ List<Integer> stringArgIndices = cfg.stringArguments(binding.getName());
for (int i = 0; i < sym.getNumArguments(); i++) {
Type cArgType = sym.getArgumentType(i);
@@ -1739,7 +1719,7 @@ public class JavaEmitter implements GlueEmitter {
//System.out.println(" Java -> \"" + mappedType + "\"" );
// Take into account any ArgumentIsString configuration directives that apply
- if (stringArgIndices != null && stringArgIndices.contains(new Integer(i))) {
+ if (stringArgIndices != null && stringArgIndices.contains(i)) {
//System.out.println("Forcing conversion of " + binding.getName() + " arg #" + i + " from byte[] to String ");
if (mappedType.isCVoidPointerType() ||
mappedType.isCCharPointerType() ||
@@ -1864,8 +1844,8 @@ public class JavaEmitter implements GlueEmitter {
// Expands a MethodBinding containing C primitive pointer types into
// multiple variants taking Java primitive arrays and NIO buffers, subject
// to the per-function "NIO only" rule in the configuration file
- protected List/*<MethodBinding>*/ expandMethodBinding(MethodBinding binding) {
- List result = new ArrayList();
+ protected List<MethodBinding> expandMethodBinding(MethodBinding binding) {
+ List<MethodBinding> result = new ArrayList<MethodBinding>();
// Indicates whether it is possible to produce an array variant
// Prevents e.g. char* -> String conversions from emitting two entry points
boolean[] canProduceArrayVariant = new boolean[1];
@@ -1895,7 +1875,7 @@ public class JavaEmitter implements GlueEmitter {
}
private Type canonicalize(Type t) {
- Type res = (Type) canonMap.get(t);
+ Type res = canonMap.get(t);
if (res != null) {
return res;
}
diff --git a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
index 558c184..bf9d3ae 100644
--- a/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/JavaMethodBindingEmitter.java
@@ -60,8 +60,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
public static final EmissionModifier SYNCHRONIZED = new EmissionModifier("synchronized");
protected final CommentEmitter defaultJavaCommentEmitter = new DefaultCommentEmitter();
- protected final CommentEmitter defaultInterfaceCommentEmitter =
- new InterfaceCommentEmitter();
+ protected final CommentEmitter defaultInterfaceCommentEmitter = new InterfaceCommentEmitter();
// Exception type raised in the generated code if runtime checks fail
private String runtimeExceptionType;
@@ -79,8 +78,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
protected MethodBinding binding;
// Manually-specified prologue and epilogue code
- protected List/*<String>*/ prologue;
- protected List/*<String>*/ epilogue;
+ protected List<String> prologue;
+ protected List<String> epilogue;
// A non-null value indicates that rather than returning a compound
// type accessor we are returning an array of such accessors; this
@@ -109,8 +108,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
boolean forIndirectBufferAndArrayImplementation,
boolean isUnimplemented,
boolean isInterface,
- JavaConfiguration configuration)
- {
+ JavaConfiguration configuration) {
super(output, isInterface);
this.binding = binding;
this.runtimeExceptionType = runtimeExceptionType;
@@ -187,12 +185,12 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
/** Sets the manually-generated prologue code for this emitter. */
- public void setPrologue(List/*<String>*/ prologue) {
+ public void setPrologue(List<String> prologue) {
this.prologue = prologue;
}
/** Sets the manually-generated epilogue code for this emitter. */
- public void setEpilogue(List/*<String>*/ epilogue) {
+ public void setEpilogue(List<String> epilogue) {
this.epilogue = epilogue;
}
@@ -228,8 +226,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
this.forIndirectBufferAndArrayImplementation = indirect;
}
- protected void emitReturnType(PrintWriter writer)
- {
+ protected void emitReturnType(PrintWriter writer) {
writer.print(getReturnTypeString(false));
}
@@ -294,8 +291,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return erasedTypeString(binding.getJavaReturnType(), true) + "[]";
}
- protected void emitName(PrintWriter writer)
- {
+ protected void emitName(PrintWriter writer) {
if (forImplementingMethodCall) {
if (forIndirectBufferAndArrayImplementation) {
writer.print(getImplMethodName(false));
@@ -307,8 +303,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
}
- protected int emitArguments(PrintWriter writer)
- {
+ protected int emitArguments(PrintWriter writer) {
boolean needComma = false;
int numEmitted = 0;
@@ -392,31 +387,29 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return getArgumentName(i) + "_offset";
}
- protected void emitBody(PrintWriter writer)
- {
+ protected void emitBody(PrintWriter writer) {
if (!emitBody) {
writer.println(';');
} else {
- MethodBinding binding = getBinding();
+ MethodBinding mBinding = getBinding();
writer.println();
writer.println(" {");
if (isUnimplemented) {
writer.println(" throw new " + getUnsupportedExceptionType() + "(\"Unimplemented\");");
} else {
emitPrologueOrEpilogue(prologue, writer);
- emitPreCallSetup(binding, writer);
+ emitPreCallSetup(mBinding, writer);
//emitReturnVariableSetup(binding, writer);
- emitReturnVariableSetupAndCall(binding, writer);
+ emitReturnVariableSetupAndCall(mBinding, writer);
}
writer.println(" }");
}
}
- protected void emitPrologueOrEpilogue(List/*<String>*/ code, PrintWriter writer) {
+ protected void emitPrologueOrEpilogue(List<String> code, PrintWriter writer) {
if (code != null) {
String[] argumentNames = argumentNameArray();
- for (Iterator iter = code.iterator(); iter.hasNext(); ) {
- String str = (String) iter.next();
+ for (String str : code) {
try {
MessageFormat fmt = new MessageFormat(str);
writer.println(" " + fmt.format(argumentNames));
@@ -434,7 +427,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
protected void emitArrayLengthAndNIOBufferChecks(MethodBinding binding, PrintWriter writer) {
- int numBufferOffsetArrayArgs = 0;
+
boolean firstBuffer = true;
// Check lengths of any incoming arrays if necessary
for (int i = 0; i < binding.getNumArguments(); i++) {
@@ -799,8 +792,10 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
return "jthis0";
}
+ @Override
protected String getCommentStartString() { return "/** "; }
+ @Override
protected String getBaseIndentString() { return " "; }
protected String getReturnedArrayLengthExpression() {
@@ -838,7 +833,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
// don't emit param comments for anonymous enums, since we can't
// distinguish between the values found within multiple anonymous
// enums in the same C translation unit.
- if (type.isEnum() && type.getName() != HeaderParser.ANONYMOUS_ENUM_NAME) {
+ if (type.isEnum() && !HeaderParser.ANONYMOUS_ENUM_NAME.equals(type.getName())) {
EnumType enumType = (EnumType)type;
writer.println();
writer.print(emitter.getBaseIndentString());
@@ -863,13 +858,13 @@ public class JavaMethodBindingEmitter extends FunctionEmitter
}
}
- protected class InterfaceCommentEmitter
- extends JavaMethodBindingEmitter.DefaultCommentEmitter
- {
- protected void emitBeginning(FunctionEmitter emitter,
- PrintWriter writer) {
- writer.print("Interface to C language function: <br> ");
+ protected class InterfaceCommentEmitter extends JavaMethodBindingEmitter.DefaultCommentEmitter {
+
+ @Override
+ protected void emitBeginning(FunctionEmitter emitter,
+ PrintWriter writer) {
+ writer.print("Interface to C language function: <br> ");
+ }
}
- }
}
diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java
index 3e9a399..30f30a2 100644
--- a/src/java/com/sun/gluegen/JavaType.java
+++ b/src/java/com/sun/gluegen/JavaType.java
@@ -57,7 +57,7 @@ public class JavaType {
private static final int PTR_C_FLOAT = 6;
private static final int PTR_C_DOUBLE = 7;
- private Class clazz; // Primitive types and other types representable as Class objects
+ private Class<?> clazz; // Primitive types and other types representable as Class objects
private String name; // Types we're generating glue code for (i.e., C structs)
private Type elementType; // Element type if this JavaType represents a C array
private int primitivePointerType; // Represents C arrays that
@@ -75,6 +75,7 @@ public class JavaType {
private static JavaType nioDoubleBufferType;
private static JavaType nioByteBufferArrayType;
+ @Override
public boolean equals(Object arg) {
if ((arg == null) || (!(arg instanceof JavaType))) {
return false;
@@ -82,13 +83,14 @@ public class JavaType {
JavaType t = (JavaType) arg;
return (this == t ||
(t.clazz == clazz &&
- ((name == t.name) ||
+ ((name == null ? t.name == null : name.equals(t.name)) ||
((name != null) && (t.name != null) && (name.equals(t.name)))) &&
((elementType == t.elementType) ||
(elementType != null) && (t.elementType != null) && (elementType.equals(t.elementType))) &&
(primitivePointerType == t.primitivePointerType)));
}
+ @Override
public int hashCode() {
if (clazz == null) {
if (name == null) {
@@ -107,7 +109,7 @@ public class JavaType {
can be used to represent arrays of primitive values or Strings;
the emitters understand how to perform proper conversion from
the corresponding C type. */
- public static JavaType createForClass(Class clazz) {
+ public static JavaType createForClass(Class<?> clazz) {
return new JavaType(clazz);
}
@@ -225,7 +227,7 @@ public class JavaType {
* Returns the Java Class corresponding to this type. Returns null if this
* object corresponds to a C primitive array type.
*/
- public Class getJavaClass() {
+ public Class<?> getJavaClass() {
return clazz;
}
@@ -301,7 +303,7 @@ public class JavaType {
return "jobjectArray /*elements are String*/";
}
- Class elementType = clazz.getComponentType();
+ Class<?> elementType = clazz.getComponentType();
if (isNIOBufferArray()) {
return "jobjectArray /*elements are " + elementType.getName() + "*/";
@@ -471,9 +473,10 @@ public class JavaType {
}
public boolean isJNIEnv() {
- return clazz == null && name == "JNIEnv";
+ return clazz == null && "JNIEnv".equals(name);
}
+ @Override
public Object clone() {
JavaType clone = new JavaType(primitivePointerType);
@@ -484,6 +487,7 @@ public class JavaType {
return clone;
}
+ @Override
public String toString() {
return getName();
}
@@ -504,7 +508,7 @@ public class JavaType {
* Constructs a representation for a type corresponding to the given Class
* argument.
*/
- private JavaType(Class clazz) {
+ private JavaType(Class<?> clazz) {
this.clazz = clazz;
}
@@ -524,7 +528,7 @@ public class JavaType {
this.primitivePointerType = primitivePointerType;
}
- private String arrayName(Class clazz) {
+ private String arrayName(Class<?> clazz) {
StringBuffer buf = new StringBuffer();
int arrayCount = 0;
while (clazz.isArray()) {
@@ -538,7 +542,7 @@ public class JavaType {
return buf.toString();
}
- private String arrayDescriptor(Class clazz) {
+ private String arrayDescriptor(Class<?> clazz) {
StringBuffer buf = new StringBuffer();
int arrayCount = 0;
while (clazz.isArray()) {
@@ -549,7 +553,7 @@ public class JavaType {
return buf.toString();
}
- private String descriptor(Class clazz) {
+ private String descriptor(Class<?> clazz) {
if (clazz.isPrimitive()) {
if (clazz == Boolean.TYPE) return "Z";
if (clazz == Byte.TYPE) return "B";
diff --git a/src/java/com/sun/gluegen/MethodBinding.java b/src/java/com/sun/gluegen/MethodBinding.java
index 228f581..dae381b 100644
--- a/src/java/com/sun/gluegen/MethodBinding.java
+++ b/src/java/com/sun/gluegen/MethodBinding.java
@@ -51,9 +51,9 @@ public class MethodBinding {
private FunctionSymbol sym;
private String renamedMethodName;
- private HashSet aliasedNames;
+ private HashSet<String> aliasedNames;
private JavaType javaReturnType;
- private List javaArgumentTypes;
+ private List<JavaType> javaArgumentTypes;
private boolean computedSignatureProperties;
private boolean argumentsUseNIO;
private boolean signatureUsesNIO;
@@ -77,12 +77,11 @@ public class MethodBinding {
this.sym = bindingToCopy.sym;
this.renamedMethodName = bindingToCopy.renamedMethodName;
- this.aliasedNames=new HashSet();
- this.aliasedNames.addAll(bindingToCopy.aliasedNames);
+ this.aliasedNames = new HashSet<String>(bindingToCopy.aliasedNames);
this.containingType = bindingToCopy.containingType;
this.containingCType = bindingToCopy.containingCType;
this.javaReturnType = bindingToCopy.javaReturnType;
- this.javaArgumentTypes = (List)((ArrayList)bindingToCopy.javaArgumentTypes).clone();
+ this.javaArgumentTypes = new ArrayList<JavaType>(bindingToCopy.javaArgumentTypes);
this.computedSignatureProperties = bindingToCopy.computedSignatureProperties;
this.argumentsUseNIO = bindingToCopy.argumentsUseNIO;
this.signatureUsesNIO = bindingToCopy.signatureUsesNIO;
@@ -99,7 +98,7 @@ public class MethodBinding {
/** Constructor for calling a C function. */
public MethodBinding(FunctionSymbol sym) {
this.sym = sym;
- this.aliasedNames=new HashSet();
+ this.aliasedNames = new HashSet<String>();
}
/** Constructor for calling a function pointer contained in a
@@ -108,92 +107,92 @@ public class MethodBinding {
this.sym = sym;
this.containingType = containingType;
this.containingCType = containingCType;
- this.aliasedNames=new HashSet();
+ this.aliasedNames = new HashSet<String>();
}
- public void setJavaReturnType(JavaType type) {
- javaReturnType = type;
- computedSignatureProperties = false;
- }
+ public void setJavaReturnType(JavaType type) {
+ javaReturnType = type;
+ computedSignatureProperties = false;
+ }
- public void addJavaArgumentType(JavaType type) {
- if (javaArgumentTypes == null) {
- javaArgumentTypes = new ArrayList();
+ public void addJavaArgumentType(JavaType type) {
+ if (javaArgumentTypes == null) {
+ javaArgumentTypes = new ArrayList<JavaType>();
+ }
+ javaArgumentTypes.add(type);
+ computedSignatureProperties = false;
}
- javaArgumentTypes.add(type);
- computedSignatureProperties = false;
- }
- public JavaType getJavaReturnType() {
- return javaReturnType;
- }
+ public JavaType getJavaReturnType() {
+ return javaReturnType;
+ }
- public int getNumArguments() {
- return sym.getNumArguments();
- }
+ public int getNumArguments() {
+ return sym.getNumArguments();
+ }
- public JavaType getJavaArgumentType(int i) {
- return (JavaType) javaArgumentTypes.get(i);
- }
+ public JavaType getJavaArgumentType(int i) {
+ return javaArgumentTypes.get(i);
+ }
- public Type getCReturnType() {
- return sym.getReturnType();
- }
+ public Type getCReturnType() {
+ return sym.getReturnType();
+ }
- public Type getCArgumentType(int i) {
- return sym.getArgumentType(i);
- }
+ public Type getCArgumentType(int i) {
+ return sym.getArgumentType(i);
+ }
- public FunctionSymbol getCSymbol() {
- return sym;
- }
+ public FunctionSymbol getCSymbol() {
+ return sym;
+ }
- /** Returns either the argument name specified by the underlying
- FunctionSymbol or a fabricated argument name based on the
- position. Note that it is currently not guaranteed that there
- are no namespace clashes with these fabricated argument
- names. */
- public String getArgumentName(int i) {
- String ret = sym.getArgumentName(i);
- if (ret != null) {
- return ret;
- }
- return "arg" + i;
- }
+ /** Returns either the argument name specified by the underlying
+ FunctionSymbol or a fabricated argument name based on the
+ position. Note that it is currently not guaranteed that there
+ are no namespace clashes with these fabricated argument
+ names. */
+ public String getArgumentName(int i) {
+ String ret = sym.getArgumentName(i);
+ if (ret != null) {
+ return ret;
+ }
+ return "arg" + i;
+ }
- public String getOrigName() {
- return sym.getName();
- }
+ public String getOrigName() {
+ return sym.getName();
+ }
- public String getName() {
- // Defaults to same as C symbol unless renamed
- if (renamedMethodName != null) {
- return renamedMethodName;
+ public String getName() {
+ // Defaults to same as C symbol unless renamed
+ if (renamedMethodName != null) {
+ return renamedMethodName;
+ }
+ return sym.getName();
}
- return sym.getName();
- }
- /** Supports renaming C function in Java binding. */
- public void renameMethodName(String name) {
- if(null!=name) {
- renamedMethodName = name;
- aliasedNames.add(sym.getName());
+ /** Supports renaming C function in Java binding. */
+ public void renameMethodName(String name) {
+ if (null != name) {
+ renamedMethodName = name;
+ aliasedNames.add(sym.getName());
+ }
}
- }
- public void addAliasedName(String name) {
- aliasedNames.add(name);
- }
+ public void addAliasedName(String name) {
+ aliasedNames.add(name);
+ }
- public Collection getAliasedNames() {
- return aliasedNames;
- }
+ public Collection<String> getAliasedNames() {
+ return aliasedNames;
+ }
/** Creates a new MethodBinding replacing the specified Java
argument type with a new argument type. If argumentNumber is
less than 0 then replaces the return type. */
- public MethodBinding replaceJavaArgumentType(int argumentNumber,
- JavaType newArgType) {
+ public MethodBinding replaceJavaArgumentType(int argumentNumber, JavaType newArgType) {
+
MethodBinding binding = (MethodBinding) clone();
binding.javaArgumentTypes = null;
if (argumentNumber < 0) {
@@ -457,6 +456,7 @@ public class MethodBinding {
public boolean isArgumentThisPointer(int i) {
return (thisPointerIndex == i);
}
+ @Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
@@ -490,6 +490,7 @@ public class MethodBinding {
return true;
}
+ @Override
public int hashCode() {
StringBuffer buf = new StringBuffer(200);
buf.append(getName());
@@ -514,6 +515,7 @@ public class MethodBinding {
}
/** Returns the signature of this binding. */
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer(200);
buf.append(getJavaReturnType().getName());
@@ -547,6 +549,7 @@ public class MethodBinding {
return buf.toString();
}
+ @Override
public final Object clone() {
return new MethodBinding(this);
}
diff --git a/src/java/com/sun/gluegen/ReferencedStructs.java b/src/java/com/sun/gluegen/ReferencedStructs.java
index 6c0dfb4..21d1142 100644
--- a/src/java/com/sun/gluegen/ReferencedStructs.java
+++ b/src/java/com/sun/gluegen/ReferencedStructs.java
@@ -43,13 +43,14 @@ import java.util.*;
import com.sun.gluegen.cgram.types.*;
public class ReferencedStructs implements TypeVisitor {
- private Set results = new HashSet();
+
+ private final Set<Type> results = new HashSet<Type>();
public void clear() {
results.clear();
}
- public Iterator results() {
+ public Iterator<Type> results() {
return results.iterator();
}
diff --git a/src/java/com/sun/gluegen/SymbolFilter.java b/src/java/com/sun/gluegen/SymbolFilter.java
index 1cc31aa..dcac628 100644
--- a/src/java/com/sun/gluegen/SymbolFilter.java
+++ b/src/java/com/sun/gluegen/SymbolFilter.java
@@ -33,6 +33,7 @@
package com.sun.gluegen;
+import com.sun.gluegen.cgram.types.FunctionSymbol;
import java.util.List;
/** Provides a mechanism by which the GlueEmitter can look at all of
@@ -49,16 +50,15 @@ public interface SymbolFilter {
* @param defines a list of {@link com.sun.gluegen.cgram.Define Define} objects
* @param functions a list of {@link com.sun.gluegen.cgram.types.FunctionSymbol FunctionSymbol} objects
*/
- public void filterSymbols(List/*<ConstantDefinition>*/ constants,
- List/*<FunctionSymbol>*/ functions);
+ public void filterSymbols(List<ConstantDefinition> constants, List<FunctionSymbol> functions);
/** Returns the filtered list of constants. This method may return
a new list, the original list, or null, in which case the
original list will be used. */
- public List/*<ConstantDefinition>*/ getConstants();
+ public List<ConstantDefinition> getConstants();
/** Returns the filtered list of function symbols. This method may
return a new list, the original list, or null, in which case
the original list will be used. */
- public List/*<FunctionSymbol>*/ getFunctions();
+ public List<FunctionSymbol> getFunctions();
}
diff --git a/src/java/com/sun/gluegen/TypeInfo.java b/src/java/com/sun/gluegen/TypeInfo.java
index 8f21c9f..4a626bc 100644
--- a/src/java/com/sun/gluegen/TypeInfo.java
+++ b/src/java/com/sun/gluegen/TypeInfo.java
@@ -59,6 +59,7 @@ public class TypeInfo {
public void setNext(TypeInfo info) { this.next = info; }
public TypeInfo next() { return next; }
+ @Override
public String toString() {
StringBuffer buf = new StringBuffer("TypeInfo: ");
buf.append(name);
diff --git a/src/java/com/sun/gluegen/cgram/types/TypeDictionary.java b/src/java/com/sun/gluegen/cgram/types/TypeDictionary.java
index 5c74455..256b5ce 100644
--- a/src/java/com/sun/gluegen/cgram/types/TypeDictionary.java
+++ b/src/java/com/sun/gluegen/cgram/types/TypeDictionary.java
@@ -45,10 +45,10 @@ import java.util.*;
public class TypeDictionary {
/** Mapping from type name to type.*/
- private HashMap/*<String, Type>*/ map = new HashMap/*<String, Type>*/();
+ private HashMap<String, Type> map = new HashMap<String, Type>();
/** Reverse mapping; created lazily from the regular map */
- private HashMap/*<Set<Type>, String>*/ reverseMap = new HashMap/*<Set<Type>, String>*/();
+ private HashMap<Set<Type>, String> reverseMap = new HashMap<Set<Type>, String>();
/** Has a type been added/removed since the last time the reverse map was
* calculated? */
@@ -61,43 +61,44 @@ public class TypeDictionary {
*/
public Type put(String name, Type type) {
reverseMapOutOfDate = true;
- return (Type) map.put(name, type);
+ return map.put(name, type);
}
/** Get the type corresponding to the given name. Returns null if no type
* was found corresponding to the given name. */
public Type get(String name) {
- return (Type) map.get(name);
+ return map.get(name);
}
+ //this method is broken
/**
* Get the names that correspond to the given type. There will be more than
* one name in the returned list if the type has been defined to multiple
* names. Returns null if no names were found for given type.
*/
- public Set/*<String>*/ get(Type type) {
- if (reverseMapOutOfDate) {
- rebuildReverseMap();
- reverseMapOutOfDate = false;
- }
- // Don't let callers muck with the set.
- return Collections.unmodifiableSet((Set)reverseMap.get(type));
- }
+// public Set/*<String>*/ get(Type type) {
+// if (reverseMapOutOfDate) {
+// rebuildReverseMap();
+// reverseMapOutOfDate = false;
+// }
+// // Don't let callers muck with the set.
+// return Collections.unmodifiableSet((Set)reverseMap.get(type));
+// }
/** Remove the mapping from the specified name to its associated type.*/
public Type remove(String name) {
reverseMapOutOfDate = true;
- return (Type) map.remove(name);
+ return map.remove(name);
}
/** Get all the names that map to Types.
* @return a Set of Strings that are the typedef names that map to Types in the dictionary.
*/
- public Set keySet() {
+ public Set<String> keySet() {
return map.keySet();
}
- public Set entrySet() {
+ public Set<Map.Entry<String, Type>> entrySet() {
return map.entrySet();
}
@@ -114,16 +115,17 @@ public class TypeDictionary {
}
/** Returns a collection of all the Types in the dictionary that are mapped via typedefs names. */
- public Collection values() {
+ public Collection<Type> values() {
return map.values();
}
/** Build the mapping of from each Type to all the names by which is may be
* referenced. Warning: this is a slow operation!
- */
+ */
+ /*
private void rebuildReverseMap() {
reverseMap.clear();
- for (Iterator/*<String>*/ it = map.keySet().iterator(); it.hasNext(); ) {
+ for (Iterator<String> it = map.keySet().iterator(); it.hasNext(); ) {
String name = (String)it.next();
Type type = (Type)map.get(name);
if (type == null) {
@@ -131,17 +133,18 @@ public class TypeDictionary {
}
HashSet allNamesForType = (HashSet)reverseMap.get(type);
if (allNamesForType == null) {
- allNamesForType = new HashSet/*<String>*/();
+ allNamesForType = new HashSet<String>();
reverseMap.put(type, allNamesForType);
}
allNamesForType.add(name);
}
}
-
+*/
/**
* Dumps the dictionary contents to the specified output stream, annotated
* with the specified description. Useful for debugging.
*/
+ /*
public void dumpDictionary(java.io.PrintStream out, String description) {
out.println("------------------------------------------------------------------------------");
out.println("TypeDictionary: " + (description == null ? "" : description));
@@ -166,4 +169,5 @@ public class TypeDictionary {
}
out.println("------------------------------------------------------------------------------");
}
+ */
}