diff options
Diffstat (limited to 'src/java/com/sun/gluegen/cgram')
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/ArrayType.java | 5 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/BitType.java | 4 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/CompoundType.java | 22 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/DoubleType.java | 35 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/EnumType.java | 212 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/Field.java | 3 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/FloatType.java | 3 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/FunctionSymbol.java | 150 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/FunctionType.java | 259 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/IntType.java | 72 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/PointerType.java | 188 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/PrimitiveType.java | 15 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/Type.java | 16 | ||||
-rw-r--r-- | src/java/com/sun/gluegen/cgram/types/VoidType.java | 25 |
14 files changed, 555 insertions, 454 deletions
diff --git a/src/java/com/sun/gluegen/cgram/types/ArrayType.java b/src/java/com/sun/gluegen/cgram/types/ArrayType.java index 0e23d35..31ec13c 100644 --- a/src/java/com/sun/gluegen/cgram/types/ArrayType.java +++ b/src/java/com/sun/gluegen/cgram/types/ArrayType.java @@ -55,6 +55,7 @@ public class ArrayType extends Type { this.length = length; } + @Override public boolean equals(Object arg) { if (arg == this) return true; if (arg == null || (!(arg instanceof ArrayType))) { @@ -64,6 +65,7 @@ public class ArrayType extends Type { return (super.equals(arg) && elementType.equals(t.elementType) && (length == t.length)); } + @Override public String getName(boolean includeCVAttrs) { // Lazy computation of name due to lazy setting of compound type // names during parsing @@ -75,6 +77,7 @@ public class ArrayType extends Type { return computedName; } + @Override public ArrayType asArray() { return this; } public Type getElementType() { return elementType; } @@ -103,6 +106,7 @@ public class ArrayType extends Type { super.setSize(SizeThunk.mul(SizeThunk.constant(getLength()), elementType.getSize())); } + @Override public String toString() { return toString(null); } @@ -120,6 +124,7 @@ public class ArrayType extends Type { return buf.toString(); } + @Override public void visit(TypeVisitor arg) { super.visit(arg); elementType.visit(arg); diff --git a/src/java/com/sun/gluegen/cgram/types/BitType.java b/src/java/com/sun/gluegen/cgram/types/BitType.java index 293eb39..b5a5337 100644 --- a/src/java/com/sun/gluegen/cgram/types/BitType.java +++ b/src/java/com/sun/gluegen/cgram/types/BitType.java @@ -53,6 +53,7 @@ public class BitType extends IntType { this.offset = lsbOffset; } + @Override public boolean equals(Object arg) { if (arg == this) return true; if (arg == null || (!(arg instanceof BitType))) { @@ -63,6 +64,7 @@ public class BitType extends IntType { (sizeInBits == t.sizeInBits) && (offset == t.offset)); } + @Override public BitType asBit() { return this; } /** Size in bits of this type. */ @@ -76,11 +78,13 @@ public class BitType extends IntType { return offset; } + @Override public void visit(TypeVisitor arg) { super.visit(arg); underlyingType.visit(arg); } + @Override Type newCVVariant(int cvAttributes) { return new BitType(underlyingType, sizeInBits, offset, cvAttributes); } diff --git a/src/java/com/sun/gluegen/cgram/types/CompoundType.java b/src/java/com/sun/gluegen/cgram/types/CompoundType.java index 28d7b76..9b982fd 100644 --- a/src/java/com/sun/gluegen/cgram/types/CompoundType.java +++ b/src/java/com/sun/gluegen/cgram/types/CompoundType.java @@ -49,7 +49,7 @@ public class CompoundType extends Type { private CompoundTypeKind kind; // The name "foo" in the construct "struct foo { ... }"; private String structName; - private ArrayList fields; + private ArrayList<Field> fields; private boolean visiting; private boolean bodyParsed; private boolean computedHashcode; @@ -66,6 +66,7 @@ public class CompoundType extends Type { this.structName = structName; } + @Override public int hashCode() { if (computedHashcode) { return hashcode; @@ -83,16 +84,17 @@ public class CompoundType extends Type { return hashcode; } + @Override public boolean equals(Object arg) { if (arg == this) return true; - if (arg == null || (!(arg instanceof CompoundType))) { + if (arg == null || !(arg instanceof CompoundType)) { return false; } CompoundType t = (CompoundType) arg; - return (super.equals(arg) && - (structName == t.structName || (structName != null && structName.equals(t.structName))) && - kind == t.kind && - listsEqual(fields, t.fields)); + return super.equals(arg) && + ((structName == null ? t.structName == null : structName.equals(t.structName)) || + (structName != null && structName.equals(t.structName))) && + kind == t.kind && listsEqual(fields, t.fields); } /** Returns the struct name of this CompoundType, i.e. the "foo" in @@ -107,10 +109,12 @@ public class CompoundType extends Type { this.structName = structName; } + @Override public void setSize(SizeThunk size) { super.setSize(size); } + @Override public CompoundType asCompound() { return this; } /** Returns the number of fields in this type. */ @@ -120,7 +124,7 @@ public class CompoundType extends Type { /** Returns the <i>i</i>th field of this type. */ public Field getField(int i) { - return (Field) fields.get(i); + return fields.get(i); } /** Adds a field to this type. */ @@ -129,7 +133,7 @@ public class CompoundType extends Type { throw new RuntimeException("Body of this CompoundType has already been parsed; should not be adding more fields"); } if (fields == null) { - fields = new ArrayList(); + fields = new ArrayList<Field>(); } fields.add(f); } @@ -145,6 +149,7 @@ public class CompoundType extends Type { /** Indicates whether this type was declared as a union. */ public boolean isUnion() { return (kind == CompoundTypeKind.UNION); } + @Override public String toString() { String cvAttributesString = getCVAttributesString(); if (getName() != null) { @@ -156,6 +161,7 @@ public class CompoundType extends Type { } } + @Override public void visit(TypeVisitor arg) { if (visiting) { return; diff --git a/src/java/com/sun/gluegen/cgram/types/DoubleType.java b/src/java/com/sun/gluegen/cgram/types/DoubleType.java index 6d6e62c..7e295cd 100644 --- a/src/java/com/sun/gluegen/cgram/types/DoubleType.java +++ b/src/java/com/sun/gluegen/cgram/types/DoubleType.java @@ -36,29 +36,32 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; /** Represents a double-word floating-point type (C type "double".) */ - public class DoubleType extends PrimitiveType { - public DoubleType(String name, SizeThunk size, int cvAttributes) { - super(name, size, cvAttributes); - } - public boolean equals(Object arg) { - if (arg == this) { - return true; + public DoubleType(String name, SizeThunk size, int cvAttributes) { + super(name, size, cvAttributes); } - if (arg == null || (!(arg instanceof DoubleType))) { - return false; + + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + if (arg == null || (!(arg instanceof DoubleType))) { + return false; + } + return super.equals(arg); } - return super.equals(arg); - } - public DoubleType asDouble() { return this; } + @Override + public DoubleType asDouble() { + return this; + } - Type newCVVariant(int cvAttributes) { - return new DoubleType(getName(), getSize(), cvAttributes); - } + Type newCVVariant(int cvAttributes) { + return new DoubleType(getName(), getSize(), cvAttributes); + } } diff --git a/src/java/com/sun/gluegen/cgram/types/EnumType.java b/src/java/com/sun/gluegen/cgram/types/EnumType.java index 717d389..b06ed9a 100644 --- a/src/java/com/sun/gluegen/cgram/types/EnumType.java +++ b/src/java/com/sun/gluegen/cgram/types/EnumType.java @@ -36,110 +36,140 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; import java.util.*; /** Describes enumerated types. Enumerations are like ints except that - they have a set of named values. */ - +they have a set of named values. */ public class EnumType extends IntType { - private IntType underlyingType; - - private static class Enum { - String name; - long value; - Enum(String name, long value) { - this.name = name; - this.value = value; + + private IntType underlyingType; + + private static class Enum { + + String name; + long value; + + Enum(String name, long value) { + this.name = name; + this.value = value; + } + + String getName() { + return name; + } + + long getValue() { + return value; + } } - String getName() { return name; } - long getValue() { return value; } - } - private List/*<Enum>*/ enums; - - public EnumType(String name) { - super(name, SizeThunk.LONG, false, CVAttributes.CONST ); - this.underlyingType = new IntType(name, SizeThunk.LONG, false, CVAttributes.CONST); - } - - public EnumType(String name, SizeThunk enumSizeInBytes) { - super(name, enumSizeInBytes, false, CVAttributes.CONST ); - this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST); - } - - protected EnumType(String name, IntType underlyingType, int cvAttributes) { - super(name, underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes); - this.underlyingType = underlyingType; - } - - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof EnumType))) { - return false; + private List<Enum> enums; + + public EnumType(String name) { + super(name, SizeThunk.LONG, false, CVAttributes.CONST); + this.underlyingType = new IntType(name, SizeThunk.LONG, false, CVAttributes.CONST); } - EnumType t = (EnumType) arg; - return (super.equals(arg) && - underlyingType.equals(t.underlyingType) && - listsEqual(enums, t.enums)); - } - public EnumType asEnum() { return this; } + public EnumType(String name, SizeThunk enumSizeInBytes) { + super(name, enumSizeInBytes, false, CVAttributes.CONST); + this.underlyingType = new IntType(name, enumSizeInBytes, false, CVAttributes.CONST); + } - public void addEnum(String name, long val) { - if (enums == null) { - enums = new ArrayList(); + protected EnumType(String name, IntType underlyingType, int cvAttributes) { + super(name, underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes); + this.underlyingType = underlyingType; } - enums.add(new Enum(name, val)); - } - - /** Number of enumerates defined in this enum. */ - public int getNumEnumerates() { return enums.size(); } - /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) name */ - public String getEnumName(int i) { return ((Enum) enums.get(i)).getName(); } - /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) value */ - public long getEnumValue(int i) { return ((Enum) enums.get(i)).getValue(); } - /** Fetch the value of the enumerate with the given name. */ - public long getEnumValue(String name) { - for (int i = 0; i < enums.size(); ++i) { - Enum n = ((Enum)enums.get(i)); - if (n.getName().equals(name)) { return n.getValue(); } + + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + if (arg == null || (!(arg instanceof EnumType))) { + return false; + } + EnumType t = (EnumType) arg; + return (super.equals(arg) + && underlyingType.equals(t.underlyingType) + && listsEqual(enums, t.enums)); } - throw new NoSuchElementException( - "No enumerate named \"" + name + "\" in EnumType \"" + - getName() + "\""); - } - /** Does this enum type contain an enumerate with the given name? */ - public boolean containsEnumerate(String name) { - for (int i = 0; i < enums.size(); ++i) { - if (((Enum)enums.get(i)).getName().equals(name)) { return true; } + + @Override + public EnumType asEnum() { + return this; } - return false; - } - /** Remove the enumerate with the given name. Returns true if it was found - * and removed; false if it was not found. - */ - public boolean removeEnumerate(String name) { - for (int i = 0; i < enums.size(); ++i) { - Enum e = (Enum)enums.get(i); - if (e.getName().equals(name)) { - enums.remove(e); - return true; - } + + public void addEnum(String name, long val) { + if (enums == null) { + enums = new ArrayList<Enum>(); + } + enums.add(new Enum(name, val)); + } + + /** Number of enumerates defined in this enum. */ + public int getNumEnumerates() { + return enums.size(); + } + + /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) name */ + public String getEnumName(int i) { + return (enums.get(i)).getName(); + } + + /** Fetch <i>i</i>th (0..getNumEnumerates() - 1) value */ + public long getEnumValue(int i) { + return (enums.get(i)).getValue(); + } + + /** Fetch the value of the enumerate with the given name. */ + public long getEnumValue(String name) { + for (int i = 0; i < enums.size(); ++i) { + Enum n = (enums.get(i)); + if (n.getName().equals(name)) { + return n.getValue(); + } + } + throw new NoSuchElementException( + "No enumerate named \"" + name + "\" in EnumType \"" + + getName() + "\""); + } + + /** Does this enum type contain an enumerate with the given name? */ + public boolean containsEnumerate(String name) { + for (int i = 0; i < enums.size(); ++i) { + if ((enums.get(i)).getName().equals(name)) { + return true; + } + } + return false; + } + + /** Remove the enumerate with the given name. Returns true if it was found + * and removed; false if it was not found. + */ + public boolean removeEnumerate(String name) { + for (int i = 0; i < enums.size(); ++i) { + Enum e = enums.get(i); + if (e.getName().equals(name)) { + enums.remove(e); + return true; + } + } + return false; + } + + @Override + public void visit(TypeVisitor arg) { + super.visit(arg); + underlyingType.visit(arg); + } + + @Override + Type newCVVariant(int cvAttributes) { + EnumType t = new EnumType(getName(), underlyingType, cvAttributes); + t.enums = enums; + return t; } - return false; - } - - public void visit(TypeVisitor arg) { - super.visit(arg); - underlyingType.visit(arg); - } - - Type newCVVariant(int cvAttributes) { - EnumType t = new EnumType(getName(), underlyingType, cvAttributes); - t.enums = enums; - return t; - } } diff --git a/src/java/com/sun/gluegen/cgram/types/Field.java b/src/java/com/sun/gluegen/cgram/types/Field.java index e6ec18d..dd7ecff 100644 --- a/src/java/com/sun/gluegen/cgram/types/Field.java +++ b/src/java/com/sun/gluegen/cgram/types/Field.java @@ -52,10 +52,12 @@ public class Field { this.offset = offset; } + @Override public int hashCode() { return name.hashCode(); } + @Override public boolean equals(Object arg) { if (arg == null || (!(arg instanceof Field))) { return false; @@ -85,6 +87,7 @@ public class Field { /** Sets the offset of this field in the containing data structure. */ public void setOffset(SizeThunk offset) { this.offset = offset; } + @Override public String toString() { if (!getType().isFunctionPointer()) { if (getName() == null && diff --git a/src/java/com/sun/gluegen/cgram/types/FloatType.java b/src/java/com/sun/gluegen/cgram/types/FloatType.java index 7a6fa4d..91b45b4 100644 --- a/src/java/com/sun/gluegen/cgram/types/FloatType.java +++ b/src/java/com/sun/gluegen/cgram/types/FloatType.java @@ -46,6 +46,8 @@ public class FloatType extends PrimitiveType { super(name, size, cvAttributes); } + + @Override public boolean equals(Object arg) { if (arg == this) { return true; @@ -56,6 +58,7 @@ public class FloatType extends PrimitiveType { return super.equals(arg); } + @Override public FloatType asFloat() { return this; } Type newCVVariant(int cvAttributes) { diff --git a/src/java/com/sun/gluegen/cgram/types/FunctionSymbol.java b/src/java/com/sun/gluegen/cgram/types/FunctionSymbol.java index 65e172f..730674a 100644 --- a/src/java/com/sun/gluegen/cgram/types/FunctionSymbol.java +++ b/src/java/com/sun/gluegen/cgram/types/FunctionSymbol.java @@ -36,87 +36,93 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; -import java.util.*; - /** Describes a function symbol, which includes the name and - type. Since we are currently only concerned with processing - functions this is the only symbol type, though plausibly more - types should be added and a true symbol table constructed during - parsing. */ - +type. Since we are currently only concerned with processing +functions this is the only symbol type, though plausibly more +types should be added and a true symbol table constructed during +parsing. */ public class FunctionSymbol { - private String name; - private FunctionType type; - - public FunctionSymbol(String name, FunctionType type) { - this.name = name; - this.type = type; - } - - public String getName() { return name; } - - /** Returns the type of this function. Do not add arguments to it - directly; use addArgument instead. */ - public FunctionType getType() { return type; } - - /** Returns the return type of this function. */ - public Type getReturnType() { return type.getReturnType(); } - - public int getNumArguments() { return type.getNumArguments(); } - - /** Returns the name of the <i>i</i>th argument. May return null if - no argument names were available during parsing. */ - public String getArgumentName(int i) { - return type.getArgumentName(i); - } - - /** Returns the type of the <i>i</i>th argument. */ - public Type getArgumentType(int i) { - return type.getArgumentType(i); - } - - /** Add an argument's name and type. Use null for unknown argument - names. */ - public void addArgument(Type argumentType, String argumentName) { - type.addArgument(argumentType, argumentName); - } - - public String toString() { - return getType().toString(getName()); - } - - /** Helper routine for emitting native javadoc tags */ - public String toString(boolean emitNativeTag) { - return getType().toString(getName(), emitNativeTag); - } - - public int hashCode() { - if (name == null) { - return 0; + + private String name; + private FunctionType type; + + public FunctionSymbol(String name, FunctionType type) { + this.name = name; + this.type = type; } - return name.hashCode(); - } - public boolean equals(Object arg) { - if (arg == this) { - return true; + public String getName() { + return name; } - - if (arg == null || (!(arg instanceof FunctionSymbol))) { - return false; + + /** Returns the type of this function. Do not add arguments to it + directly; use addArgument instead. */ + public FunctionType getType() { + return type; } - - FunctionSymbol other = (FunctionSymbol) arg; - if(getName()==null && other.getName()!=null) { - return false; + /** Returns the return type of this function. */ + public Type getReturnType() { + return type.getReturnType(); } - return ( - (getName() == other.getName() || getName().equals(other.getName())) - && type.equals(other.type)); - } + public int getNumArguments() { + return type.getNumArguments(); + } + + /** Returns the name of the <i>i</i>th argument. May return null if + no argument names were available during parsing. */ + public String getArgumentName(int i) { + return type.getArgumentName(i); + } + + /** Returns the type of the <i>i</i>th argument. */ + public Type getArgumentType(int i) { + return type.getArgumentType(i); + } + + /** Add an argument's name and type. Use null for unknown argument + names. */ + public void addArgument(Type argumentType, String argumentName) { + type.addArgument(argumentType, argumentName); + } + + @Override + public String toString() { + return getType().toString(getName()); + } + + /** Helper routine for emitting native javadoc tags */ + public String toString(boolean emitNativeTag) { + return getType().toString(getName(), emitNativeTag); + } + + @Override + public int hashCode() { + if (name == null) { + return 0; + } + return name.hashCode(); + } + + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + + if (arg == null || (!(arg instanceof FunctionSymbol))) { + return false; + } + + FunctionSymbol other = (FunctionSymbol) arg; + + if (getName() == null && other.getName() != null) { + return false; + } + + return (getName().equals(other.getName()) || getName().equals(other.getName())) && type.equals(other.type); + } } diff --git a/src/java/com/sun/gluegen/cgram/types/FunctionType.java b/src/java/com/sun/gluegen/cgram/types/FunctionType.java index 7a9c2b5..d36f839 100644 --- a/src/java/com/sun/gluegen/cgram/types/FunctionType.java +++ b/src/java/com/sun/gluegen/cgram/types/FunctionType.java @@ -36,144 +36,155 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; import java.util.*; /** Describes a function type, used to model both function - declarations and (via PointerType) function pointers. */ - +declarations and (via PointerType) function pointers. */ public class FunctionType extends Type { - private Type returnType; - private ArrayList argumentTypes; - private ArrayList argumentNames; - - public FunctionType(String name, SizeThunk size, Type returnType, int cvAttributes) { - super(name, size, cvAttributes); - this.returnType = returnType; - } - - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof FunctionType))) { - return false; + + private Type returnType; + private ArrayList<Type> argumentTypes; + private ArrayList<String> argumentNames; + + public FunctionType(String name, SizeThunk size, Type returnType, int cvAttributes) { + super(name, size, cvAttributes); + this.returnType = returnType; + } + + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + if (arg == null || (!(arg instanceof FunctionType))) { + return false; + } + FunctionType t = (FunctionType) arg; + return (super.equals(arg) + && returnType.equals(t.returnType) + && listsEqual(argumentTypes, t.argumentTypes)); } - FunctionType t = (FunctionType) arg; - return (super.equals(arg) && - returnType.equals(t.returnType) && - listsEqual(argumentTypes, t.argumentTypes)); - } - - public FunctionType asFunction() { return this; } - - /** Returns the return type of this function. */ - public Type getReturnType() { return returnType; } - - public int getNumArguments() { return ((argumentTypes == null) ? 0 : argumentTypes.size()); } - - /** Returns the name of the <i>i</i>th argument. May return null if - no argument names were available during parsing. */ - public String getArgumentName(int i) { - return (String) argumentNames.get(i); - } - - /** Returns the type of the <i>i</i>th argument. */ - public Type getArgumentType(int i) { - return (Type) argumentTypes.get(i); - } - - /** Add an argument's name and type. Use null for unknown argument - names. */ - public void addArgument(Type argumentType, String argumentName) { - if (argumentTypes == null) { - argumentTypes = new ArrayList(); - argumentNames = new ArrayList(); + + @Override + public FunctionType asFunction() { + return this; + } + + /** Returns the return type of this function. */ + public Type getReturnType() { + return returnType; } - argumentTypes.add(argumentType); - argumentNames.add(argumentName); - } - - public void setArgumentName(int i, String name) - { - argumentNames.set(i,name); - } - - public String toString() { - return toString(null); - } - - public String toString(String functionName) { - return toString(functionName, false); - } - - public String toString(String functionName, boolean emitNativeTag) { - return toString(functionName, null, emitNativeTag, false); - } - - String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) { - StringBuffer res = new StringBuffer(); - res.append(getReturnType()); - res.append(" "); - if (isPointer) { - res.append("("); - if (callingConvention != null) { - res.append(callingConvention); - } - res.append("*"); + + public int getNumArguments() { + return ((argumentTypes == null) ? 0 : argumentTypes.size()); } - if (functionName != null) { - if (emitNativeTag) { - // Emit @native tag for javadoc purposes - res.append("{@native "); - } - res.append(functionName); - if (emitNativeTag) { - res.append("}"); - } + + /** Returns the name of the <i>i</i>th argument. May return null if + no argument names were available during parsing. */ + public String getArgumentName(int i) { + return argumentNames.get(i); } - if (isPointer) { - res.append(")"); + + /** Returns the type of the <i>i</i>th argument. */ + public Type getArgumentType(int i) { + return argumentTypes.get(i); } - res.append("("); - int n = getNumArguments(); - for (int i = 0; i < n; i++) { - Type t = getArgumentType(i); - if (t.isFunctionPointer()) { - FunctionType ft = t.asPointer().getTargetType().asFunction(); - res.append(ft.toString(getArgumentName(i), callingConvention, false, true)); - } else if (t.isArray()) { - res.append(t.asArray().toString(getArgumentName(i))); - } else { - res.append(t); - String argumentName = getArgumentName(i); - if (argumentName != null) { - res.append(" "); - res.append(argumentName); + + /** + * Add an argument's name and type. Use null for unknown argument names. + */ + public void addArgument(Type argumentType, String argumentName) { + if (argumentTypes == null) { + argumentTypes = new ArrayList<Type>(); + argumentNames = new ArrayList<String>(); } - } - if (i < n - 1) { - res.append(", "); - } + argumentTypes.add(argumentType); + argumentNames.add(argumentName); + } + + public void setArgumentName(int i, String name) { + argumentNames.set(i, name); + } + + @Override + public String toString() { + return toString(null); + } + + public String toString(String functionName) { + return toString(functionName, false); + } + + public String toString(String functionName, boolean emitNativeTag) { + return toString(functionName, null, emitNativeTag, false); } - res.append(")"); - if (!isPointer) { - res.append(";"); + + String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) { + StringBuffer res = new StringBuffer(); + res.append(getReturnType()); + res.append(" "); + if (isPointer) { + res.append("("); + if (callingConvention != null) { + res.append(callingConvention); + } + res.append("*"); + } + if (functionName != null) { + if (emitNativeTag) { + // Emit @native tag for javadoc purposes + res.append("{@native "); + } + res.append(functionName); + if (emitNativeTag) { + res.append("}"); + } + } + if (isPointer) { + res.append(")"); + } + res.append("("); + int n = getNumArguments(); + for (int i = 0; i < n; i++) { + Type t = getArgumentType(i); + if (t.isFunctionPointer()) { + FunctionType ft = t.asPointer().getTargetType().asFunction(); + res.append(ft.toString(getArgumentName(i), callingConvention, false, true)); + } else if (t.isArray()) { + res.append(t.asArray().toString(getArgumentName(i))); + } else { + res.append(t); + String argumentName = getArgumentName(i); + if (argumentName != null) { + res.append(" "); + res.append(argumentName); + } + } + if (i < n - 1) { + res.append(", "); + } + } + res.append(")"); + if (!isPointer) { + res.append(";"); + } + return res.toString(); } - return res.toString(); - } - - public void visit(TypeVisitor arg) { - super.visit(arg); - returnType.visit(arg); - int n = getNumArguments(); - for (int i = 0; i < n; i++) { - getArgumentType(i).visit(arg); + + @Override + public void visit(TypeVisitor arg) { + super.visit(arg); + returnType.visit(arg); + int n = getNumArguments(); + for (int i = 0; i < n; i++) { + getArgumentType(i).visit(arg); + } } - } - Type newCVVariant(int cvAttributes) { - // Functions don't have const/volatile attributes - return this; - } + Type newCVVariant(int cvAttributes) { + // Functions don't have const/volatile attributes + return this; + } } diff --git a/src/java/com/sun/gluegen/cgram/types/IntType.java b/src/java/com/sun/gluegen/cgram/types/IntType.java index acd6a3d..b94e7bb 100644 --- a/src/java/com/sun/gluegen/cgram/types/IntType.java +++ b/src/java/com/sun/gluegen/cgram/types/IntType.java @@ -36,47 +36,57 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; public class IntType extends PrimitiveType { - private boolean unsigned; - private boolean typedefedUnsigned; - public IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes) { - this(name, size, unsigned, cvAttributes, false); - } + private boolean unsigned; + private boolean typedefedUnsigned; - private IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes, boolean typedefedUnsigned) { - super(name, size, cvAttributes); - this.unsigned = unsigned; - this.typedefedUnsigned = typedefedUnsigned; - } + public IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes) { + this(name, size, unsigned, cvAttributes, false); + } - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof IntType))) { - return false; + private IntType(String name, SizeThunk size, boolean unsigned, int cvAttributes, boolean typedefedUnsigned) { + super(name, size, cvAttributes); + this.unsigned = unsigned; + this.typedefedUnsigned = typedefedUnsigned; } - IntType t = (IntType) arg; - return (super.equals(arg) && (unsigned == t.unsigned)); - } - public void setName(String name) { - super.setName(name); - typedefedUnsigned = unsigned; - } + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + if (arg == null || (!(arg instanceof IntType))) { + return false; + } + IntType t = (IntType) arg; + return (super.equals(arg) && (unsigned == t.unsigned)); + } - public IntType asInt() { return this; } + @Override + public void setName(String name) { + super.setName(name); + typedefedUnsigned = unsigned; + } - /** Indicates whether this type is unsigned */ - public boolean isUnsigned() { return unsigned; } + @Override + public IntType asInt() { + return this; + } - public String toString() { - return getCVAttributesString() + ((isUnsigned() & (!typedefedUnsigned)) ? "unsigned " : "") + getName(); - } + /** Indicates whether this type is unsigned */ + public boolean isUnsigned() { + return unsigned; + } + + @Override + public String toString() { + return getCVAttributesString() + ((isUnsigned() & (!typedefedUnsigned)) ? "unsigned " : "") + getName(); + } - Type newCVVariant(int cvAttributes) { - return new IntType(getName(), getSize(), isUnsigned(), cvAttributes, typedefedUnsigned); - } + Type newCVVariant(int cvAttributes) { + return new IntType(getName(), getSize(), isUnsigned(), cvAttributes, typedefedUnsigned); + } } diff --git a/src/java/com/sun/gluegen/cgram/types/PointerType.java b/src/java/com/sun/gluegen/cgram/types/PointerType.java index f95066a..712c4ee 100644 --- a/src/java/com/sun/gluegen/cgram/types/PointerType.java +++ b/src/java/com/sun/gluegen/cgram/types/PointerType.java @@ -36,107 +36,123 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; public class PointerType extends Type { - private Type targetType; - private String computedName; - private boolean hasTypedefedName; - - public PointerType(SizeThunk size, Type targetType, int cvAttributes) { - // can pass null for the final name parameter because the PointerType's getName() - // completely replaces superclass behavior - this(size, targetType, cvAttributes, false, null); - } - - private PointerType(SizeThunk size, Type targetType, int cvAttributes, boolean hasTypedefedName, String typedefedName) { - super(targetType.getName() + " *", size, cvAttributes); - this.hasTypedefedName = false; - this.targetType = targetType; - if (hasTypedefedName) { - setName(typedefedName); + + private Type targetType; + private String computedName; + private boolean hasTypedefedName; + + public PointerType(SizeThunk size, Type targetType, int cvAttributes) { + // can pass null for the final name parameter because the PointerType's getName() + // completely replaces superclass behavior + this(size, targetType, cvAttributes, false, null); + } + + private PointerType(SizeThunk size, Type targetType, int cvAttributes, boolean hasTypedefedName, String typedefedName) { + super(targetType.getName() + " *", size, cvAttributes); + this.hasTypedefedName = false; + this.targetType = targetType; + if (hasTypedefedName) { + setName(typedefedName); + } + } + + @Override + public int hashCode() { + return targetType.hashCode(); } - } - public int hashCode() { - return targetType.hashCode(); - } + @Override + public boolean equals(Object arg) { + if (arg == this) { + return true; + } + if (arg == null || (!(arg instanceof PointerType))) { + return false; + } + PointerType t = (PointerType) arg; + // Note we ignore the name of this type (which might be a typedef + // name) for comparison purposes because this is what allows + // e.g. a newly-fabricated type "PIXELFORMATDESCRIPTOR *" to be + // canonicalized to e.g. "LPPIXELFORMATDESCRIPTOR" + return ((getSize() == t.getSize()) + && (getCVAttributes() == t.getCVAttributes()) + && targetType.equals(t.targetType)); + } - public boolean equals(Object arg) { - if (arg == this) return true; - if (arg == null || (!(arg instanceof PointerType))) { - return false; + @Override + public void setName(String name) { + super.setName(name); + hasTypedefedName = true; } - PointerType t = (PointerType) arg; - // Note we ignore the name of this type (which might be a typedef - // name) for comparison purposes because this is what allows - // e.g. a newly-fabricated type "PIXELFORMATDESCRIPTOR *" to be - // canonicalized to e.g. "LPPIXELFORMATDESCRIPTOR" - return ((getSize() == t.getSize()) && - (getCVAttributes() == t.getCVAttributes()) && - targetType.equals(t.targetType)); - } - - public void setName(String name) { - super.setName(name); - hasTypedefedName = true; - } - - public String getName(boolean includeCVAttrs) { - if (hasTypedefedName) { - return super.getName(includeCVAttrs); - } else { - // Lazy computation of name due to lazy setting of compound type - // names during parsing - if (computedName == null) { - computedName = targetType.getName(includeCVAttrs) + " *"; - computedName = computedName.intern(); - } - if (!includeCVAttrs) { - return computedName; - } - return targetType.getName(includeCVAttrs) + " * " + getCVAttributesString(); + + @Override + public String getName(boolean includeCVAttrs) { + if (hasTypedefedName) { + return super.getName(includeCVAttrs); + } else { + // Lazy computation of name due to lazy setting of compound type + // names during parsing + if (computedName == null) { + computedName = targetType.getName(includeCVAttrs) + " *"; + computedName = computedName.intern(); + } + if (!includeCVAttrs) { + return computedName; + } + return targetType.getName(includeCVAttrs) + " * " + getCVAttributesString(); + } } - } - public boolean hasTypedefedName() { - return hasTypedefedName; - } + public boolean hasTypedefedName() { + return hasTypedefedName; + } - public PointerType asPointer() { return this; } + @Override + public PointerType asPointer() { + return this; + } - public Type getTargetType() { return targetType; } + public Type getTargetType() { + return targetType; + } - public boolean isFunctionPointer() { return targetType.isFunction(); } + @Override + public boolean isFunctionPointer() { + return targetType.isFunction(); + } - public String toString() { - if (hasTypedefedName) { - return super.getName(true); - } else { - if (!targetType.isFunction()) { - return targetType.toString() + " * " + getCVAttributesString(); - } - return toString(null, null); // this is a pointer to an unnamed function + @Override + public String toString() { + if (hasTypedefedName) { + return super.getName(true); + } else { + if (!targetType.isFunction()) { + return targetType.toString() + " * " + getCVAttributesString(); + } + return toString(null, null); // this is a pointer to an unnamed function + } } - } - - /** For use only when printing function pointers. Calling convention - string (i.e., "__stdcall") is optional and is generally only - needed on Windows. */ - public String toString(String functionName, String callingConvention) { - if (!targetType.isFunction()) { - throw new RuntimeException("<Internal error or misuse> This method is only for use when printing function pointers"); + + /** For use only when printing function pointers. Calling convention + string (i.e., "__stdcall") is optional and is generally only + needed on Windows. */ + public String toString(String functionName, String callingConvention) { + if (!targetType.isFunction()) { + throw new RuntimeException("<Internal error or misuse> This method is only for use when printing function pointers"); + } + return ((FunctionType) targetType).toString(functionName, callingConvention, false, true); } - return ((FunctionType) targetType).toString(functionName, callingConvention, false, true); - } - public void visit(TypeVisitor arg) { - super.visit(arg); - targetType.visit(arg); - } + @Override + public void visit(TypeVisitor arg) { + super.visit(arg); + targetType.visit(arg); + } - Type newCVVariant(int cvAttributes) { - return new PointerType(getSize(), targetType, cvAttributes, hasTypedefedName, (hasTypedefedName ? getName() : null)); - } + Type newCVVariant(int cvAttributes) { + return new PointerType(getSize(), targetType, cvAttributes, hasTypedefedName, (hasTypedefedName ? getName() : null)); + } } diff --git a/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java b/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java index 80dab9a..8b6e096 100644 --- a/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java +++ b/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java @@ -36,15 +36,16 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; public abstract class PrimitiveType extends Type { - protected PrimitiveType(String name, SizeThunk size, int cvAttributes) { - super(name, size, cvAttributes); - } - public boolean isPrimitive() { - return true; - } + protected PrimitiveType(String name, SizeThunk size, int cvAttributes) { + super(name, size, cvAttributes); + } + + @Override + public boolean isPrimitive() { + return true; + } } diff --git a/src/java/com/sun/gluegen/cgram/types/Type.java b/src/java/com/sun/gluegen/cgram/types/Type.java index 0dcaabc..4df034b 100644 --- a/src/java/com/sun/gluegen/cgram/types/Type.java +++ b/src/java/com/sun/gluegen/cgram/types/Type.java @@ -45,8 +45,8 @@ import java.util.List; double. All types have an associated name. Structs and unions are modeled as "compound" types -- composed of fields of primitive or other types. */ - public abstract class Type { + private String name; private SizeThunk size; private int cvAttributes; @@ -158,13 +158,13 @@ public abstract class Type { } /** Hashcode for Types. */ + @Override public int hashCode() { if (name == null) { return 0; } - if (cvAttributes != 0) - { + if (cvAttributes != 0) { String nameWithAttribs = name + cvAttributes; return nameWithAttribs.hashCode(); } @@ -174,6 +174,7 @@ public abstract class Type { /** * Equality test for Types. */ + @Override public boolean equals(Object arg) { if (arg == this) { return true; @@ -182,14 +183,14 @@ public abstract class Type { return false; } Type t = (Type) arg; - return ((name == t.name || (name != null && name.equals(name))) && - (size == t.size) && - (cvAttributes == t.cvAttributes)); + return (((name == null ? t.name == null : name.equals(t.name)) || (name != null && name.equals(name))) && + (size == t.size) && (cvAttributes == t.cvAttributes)); } /** Returns a string representation of this type. This string is not necessarily suitable for use as a type specifier; for example, it will contain an expanded description of structs/unions. */ + @Override public String toString() { return getName(true); } @@ -256,7 +257,6 @@ public abstract class Type { /** Helper routine for list equality comparison */ static boolean listsEqual(List a, List b) { - return ((a == null && b == null) || - (a != null && b != null && a.equals(b))); + return ((a == null && b == null) || (a != null && b != null && a.equals(b))); } } diff --git a/src/java/com/sun/gluegen/cgram/types/VoidType.java b/src/java/com/sun/gluegen/cgram/types/VoidType.java index 3a2f1b9..779a661 100644 --- a/src/java/com/sun/gluegen/cgram/types/VoidType.java +++ b/src/java/com/sun/gluegen/cgram/types/VoidType.java @@ -36,21 +36,24 @@ * Sun gratefully acknowledges that this software was originally authored * and developed by Kenneth Bradley Russell and Christopher John Kline. */ - package com.sun.gluegen.cgram.types; public class VoidType extends Type { - public VoidType(int cvAttributes) { - this("void", cvAttributes); - } - private VoidType(String name, int cvAttributes) { - super(name, null, cvAttributes); - } + public VoidType(int cvAttributes) { + this("void", cvAttributes); + } + + private VoidType(String name, int cvAttributes) { + super(name, null, cvAttributes); + } - public VoidType asVoid() { return this; } + @Override + public VoidType asVoid() { + return this; + } - Type newCVVariant(int cvAttributes) { - return new VoidType(getName(), cvAttributes); - } + Type newCVVariant(int cvAttributes) { + return new VoidType(getName(), cvAttributes); + } } |