summaryrefslogtreecommitdiffstats
path: root/src/java/com/sun
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-06 03:44:12 +0100
committerSven Gothel <[email protected]>2010-11-06 03:44:12 +0100
commit6b6b9b3b81cdc85b7260664ebec547756a6be5d7 (patch)
tree5f2b4e83d4d04117ea27571d278b4074ae9ca038 /src/java/com/sun
parent33ea83cfcad373e477791a0aca49864399357877 (diff)
Fix native type representation; Retain typedef declName in resulting Type for variables; Misc
Fix native type representation ---------------------------------- The following custom types were previously build-in: __int32, __int64 Adding the following native build-in types (necessary): ptrdiff_t, size_t These compiler/platform specific types shall not be typedef'ed via header files. Hence we provide proper typing for such, as the compiler would do. Adding the following native build-in types (convenience): int32_t, uint32_t, int64_t, uint64_t These are provided due to their lack of support on certain platforms, and probable source of bugs, when defined by the user. Retain typedef declName in resulting Type for variables. -------------------------------------------------------- Adding Clonable to all cgram Type derivations. Assume use case: typedef khronos_ssize_t GLsizeiptr typedef size_t khronos_ssize_t The previous code picked a one level depth type in the dictionary if exists. Hence it made khronos_ssize_t visible in the javadoc and native code. It is our believe that the generated native code, as well as the javadoc comments shall reflect the original GlueGen'ed API and it's types. Also, aliasing or reducing native types via GlueGen could result in plattorm dependencies and in worst cases, incompatible native types. This patch clones the 1 level depth Type (typedef), clones it and sets the declName, so it's visible to the GlueGen layers. Misc ------- GlueGen's debug flag is passed to HeaderParser, where it traces misc information.
Diffstat (limited to 'src/java/com/sun')
-rw-r--r--src/java/com/sun/gluegen/GlueGen.java20
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java3
-rw-r--r--src/java/com/sun/gluegen/JavaEmitter.java1
-rw-r--r--src/java/com/sun/gluegen/JavaType.java1
-rw-r--r--src/java/com/sun/gluegen/TypeInfo.java1
-rw-r--r--src/java/com/sun/gluegen/cgram/GnuCParser.g10
-rw-r--r--src/java/com/sun/gluegen/cgram/HeaderParser.g223
-rw-r--r--src/java/com/sun/gluegen/cgram/types/ArrayType.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/BitType.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/CompoundType.java9
-rw-r--r--src/java/com/sun/gluegen/cgram/types/DoubleType.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/EnumType.java16
-rw-r--r--src/java/com/sun/gluegen/cgram/types/FloatType.java4
-rw-r--r--src/java/com/sun/gluegen/cgram/types/FunctionType.java10
-rw-r--r--src/java/com/sun/gluegen/cgram/types/IntType.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/PointerType.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/PrimitiveType.java3
-rwxr-xr-xsrc/java/com/sun/gluegen/cgram/types/SizeThunk.java11
-rw-r--r--src/java/com/sun/gluegen/cgram/types/Type.java11
-rw-r--r--src/java/com/sun/gluegen/cgram/types/VoidType.java3
20 files changed, 237 insertions, 104 deletions
diff --git a/src/java/com/sun/gluegen/GlueGen.java b/src/java/com/sun/gluegen/GlueGen.java
index 866f602..b03109c 100644
--- a/src/java/com/sun/gluegen/GlueGen.java
+++ b/src/java/com/sun/gluegen/GlueGen.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -48,7 +49,23 @@ import com.sun.gluegen.pcpp.*;
import static java.lang.System.*;
-/** Glue code generator for C functions and data structures. */
+/**
+ * Glue code generator for C functions and data structures.<br>
+ * <br>
+ * Gluegen has build-in types (terminal symbols) for:<br>
+ * <br>
+ * <table border="1">
+ * <tr><th>type</th> <th>java</th> <th>native-x32</th><th>native-x64</th><th>type</th> <th>signed</th></tr>
+ * <tr><th>__int32</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed or unsigned</th></tr>
+ * <tr><th>int32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>signed</th></tr>
+ * <tr><th>uint32_t</th> <th>32bit</th><th>32bit</th> <th>32bit</th> <th>integer</th><th>unsigned</th></tr>
+ * <tr><th>__int64</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed or unsigned</th></tr>
+ * <tr><th>int64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>signed</th></tr>
+ * <tr><th>uint64_t</th> <th>64bit</th><th>64bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th></tr>
+ * <tr><th>ptrdiff_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>signed</th></tr>
+ * <tr><th>size_t</th> <th>64bit</th><th>32bit</th> <th>64bit</th> <th>integer</th><th>unsigned</th></tr>
+ * </table>
+ */
public class GlueGen implements GlueEmitterControls {
static{
@@ -127,6 +144,7 @@ public class GlueGen implements GlueEmitterControls {
}
HeaderParser headerParser = new HeaderParser();
+ headerParser.setDebug(debug);
TypeDictionary td = new TypeDictionary();
headerParser.setTypedefDictionary(td);
TypeDictionary sd = new TypeDictionary();
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java
index 7a1e45e..f4cf0bd 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- *
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
diff --git a/src/java/com/sun/gluegen/JavaEmitter.java b/src/java/com/sun/gluegen/JavaEmitter.java
index c7156c3..5fc07b0 100644
--- a/src/java/com/sun/gluegen/JavaEmitter.java
+++ b/src/java/com/sun/gluegen/JavaEmitter.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
diff --git a/src/java/com/sun/gluegen/JavaType.java b/src/java/com/sun/gluegen/JavaType.java
index dbdabe4..a7e9fcf 100644
--- a/src/java/com/sun/gluegen/JavaType.java
+++ b/src/java/com/sun/gluegen/JavaType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
diff --git a/src/java/com/sun/gluegen/TypeInfo.java b/src/java/com/sun/gluegen/TypeInfo.java
index 4a626bc..10df349 100644
--- a/src/java/com/sun/gluegen/TypeInfo.java
+++ b/src/java/com/sun/gluegen/TypeInfo.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
diff --git a/src/java/com/sun/gluegen/cgram/GnuCParser.g b/src/java/com/sun/gluegen/cgram/GnuCParser.g
index 7de057c..7b4c8f8 100644
--- a/src/java/com/sun/gluegen/cgram/GnuCParser.g
+++ b/src/java/com/sun/gluegen/cgram/GnuCParser.g
@@ -308,13 +308,19 @@ typeSpecifier [int specCount] returns [int retSpecCount]
| "char"
| "short"
| "int"
- | "__int32"
- | "__int64"
| "long"
| "float"
| "double"
| "signed"
| "unsigned"
+ | "__int32"
+ | "int32_t"
+ | "uint32_t"
+ | "__int64"
+ | "int64_t"
+ | "uint64_t"
+ | "ptrdiff_t"
+ | "size_t"
| structOrUnionSpecifier ( options{warnWhenFollowAmbig=false;}: attributeDecl )*
| enumSpecifier
| { specCount==0 }? typedefName
diff --git a/src/java/com/sun/gluegen/cgram/HeaderParser.g b/src/java/com/sun/gluegen/cgram/HeaderParser.g
index 7c13968..9040c29 100644
--- a/src/java/com/sun/gluegen/cgram/HeaderParser.g
+++ b/src/java/com/sun/gluegen/cgram/HeaderParser.g
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -56,6 +57,16 @@ options {
/** Name assigned to a anonymous EnumType (e.g., "enum { ... }"). */
public static final String ANONYMOUS_ENUM_NAME = "<anonymous>";
+ boolean debug = false;
+
+ public boolean getDebug() {
+ return debug;
+ }
+
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
/** Set the dictionary mapping typedef names to types for this
HeaderParser. Must be done before parsing. */
public void setTypedefDictionary(TypeDictionary dict) {
@@ -88,13 +99,13 @@ options {
}
/** Pre-define the list of EnumTypes for this HeaderParser. Must be
- done before parsing. */
+ done before parsing. */
public void setEnums(List/*<EnumType>*/ enumTypes) {
// FIXME: Need to take the input set of EnumTypes, extract all
// the enumerates from each EnumType, and fill in the enumHash
// so that each enumerate maps to the enumType to which it
// belongs.
- throw new RuntimeException("setEnums is Unimplemented!");
+ throw new RuntimeException("setEnums is Unimplemented!");
}
/** Returns the EnumTypes this HeaderParser processed. */
@@ -176,24 +187,53 @@ options {
boolean isTypedef() { return isTypedef; }
- // for easier debugging
- public String toString() {
- String tStr = "Type=NULL_REF";
- if (type == origType) {
- tStr = "Type=ORIG_TYPE";
- } else if (type != null) {
- tStr = "Type: name=\"" + type.getCVAttributesString() + " " +
+ // for easier debugging
+ public String toString() {
+ String tStr = "Type=NULL_REF";
+ if (type == origType) {
+ tStr = "Type=ORIG_TYPE";
+ } else if (type != null) {
+ tStr = "Type: name=\"" + type.getCVAttributesString() + " " +
type.getName() + "\"; signature=\"" + type + "\"; class " +
- type.getClass().getName();
- }
- String oStr = "OrigType=NULL_REF";
- if (origType != null) {
- oStr = "OrigType: name=\"" + origType.getCVAttributesString() + " " +
+ type.getClass().getName();
+ }
+ String oStr = "OrigType=NULL_REF";
+ if (origType != null) {
+ oStr = "OrigType: name=\"" + origType.getCVAttributesString() + " " +
origType.getName() + "\"; signature=\"" + origType + "\"; class " +
- origType.getClass().getName();
- }
- return "<["+tStr + "] [" + oStr + "] " + " isTypedef=" + isTypedef+">";
- }
+ origType.getClass().getName();
+ }
+ return "<["+tStr + "] [" + oStr + "] " + " isTypedef=" + isTypedef+">";
+ }
+ }
+
+ private String getTypeString(Type t) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[");
+ sb.append(t);
+ sb.append(", size: ");
+ if(null!=t) {
+ SizeThunk st = t.getSize();
+ if(null!=st) {
+ sb.append(st.getClass().getName());
+ } else {
+ sb.append("undef");
+ }
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ private void debugPrintln(String msg) {
+ if(debug) {
+ System.err.println(msg);
+ }
+ }
+
+ private void debugPrint(String msg) {
+ if(debug) {
+ System.err.print(msg);
+ }
}
private boolean doDeclaration; // Used to only process function typedefs
@@ -231,12 +271,12 @@ options {
private void processDeclaration(Type returnType) {
if (doDeclaration) {
FunctionSymbol sym = new FunctionSymbol(declId, new FunctionType(null, null, returnType, 0));
- if (parameters != null) { // handle funcs w/ empty parameter lists (e.g., "foo()")
+ if (parameters != null) { // handle funcs w/ empty parameter lists (e.g., "foo()")
for (Iterator iter = parameters.iterator(); iter.hasNext(); ) {
ParameterDeclaration pd = (ParameterDeclaration) iter.next();
sym.addArgument(pd.type(), pd.id());
}
- }
+ }
functions.add(sym);
}
}
@@ -276,29 +316,29 @@ options {
}
/** Utility function: creates a new EnumType with the given name, or
- returns an existing one if it has already been created. */
+ returns an existing one if it has already been created. */
private EnumType getEnumType(String enumTypeName) {
- EnumType enumType = null;
- Iterator it = enumHash.values().iterator();
- while (it.hasNext()) {
- EnumType potentialMatch = (EnumType)it.next();
- if (potentialMatch.getName().equals(enumTypeName)) {
- enumType = potentialMatch;
- break;
- }
- }
-
- if (enumType == null) {
+ EnumType enumType = null;
+ Iterator it = enumHash.values().iterator();
+ while (it.hasNext()) {
+ EnumType potentialMatch = (EnumType)it.next();
+ if (potentialMatch.getName().equals(enumTypeName)) {
+ enumType = potentialMatch;
+ break;
+ }
+ }
+
+ if (enumType == null) {
// This isn't quite correct. In theory the enum should expand to
// the size of the largest element, so if there were a long long
// entry the enum should expand to e.g. int64. However, using
// "long" here (which is what used to be the case) was
// definitely incorrect and caused problems.
- enumType = new EnumType(enumTypeName, SizeThunk.INT);
- }
-
- return enumType;
- }
+ enumType = new EnumType(enumTypeName, SizeThunk.INT);
+ }
+
+ return enumType;
+ }
// Map used to canonicalize types. For example, we may typedef
// struct foo { ... } *pfoo; subsequent references to struct foo* should
@@ -343,17 +383,17 @@ declarator[TypeBox tb] returns [String s] {
/* TypeBox becomes function pointer in this case */
FunctionType ft = new FunctionType(null, null, tb.type(), 0);
if (params == null) {
- // If the function pointer has no declared parameters, it's a
- // void function. I'm not sure if the parameter name is
- // ever referenced anywhere when the type is VoidType, so
+ // If the function pointer has no declared parameters, it's a
+ // void function. I'm not sure if the parameter name is
+ // ever referenced anywhere when the type is VoidType, so
// just in case I'll set it to a comment string so it will
- // still compile if written out to code anywhere.
- ft.addArgument(new VoidType(0), "/*unnamed-void*/");
- } else {
- for (Iterator iter = params.iterator(); iter.hasNext(); ) {
+ // still compile if written out to code anywhere.
+ ft.addArgument(new VoidType(0), "/*unnamed-void*/");
+ } else {
+ for (Iterator iter = params.iterator(); iter.hasNext(); ) {
ParameterDeclaration pd = (ParameterDeclaration) iter.next();
ft.addArgument(pd.type(), pd.id());
- }
+ }
}
tb.setType(canonicalize(new PointerType(SizeThunk.POINTER,
ft,
@@ -457,15 +497,21 @@ typeSpecifier[int attributes] returns [Type t] {
int cvAttrs = attrs2CVAttrs(attributes);
boolean unsigned = ((attributes & UNSIGNED) != 0);
}
- : "void" { t = new VoidType(cvAttrs); }
- | "char" { t = new IntType("char" , SizeThunk.CHAR, unsigned, cvAttrs); }
- | "short" { t = new IntType("short", SizeThunk.SHORT, unsigned, cvAttrs); }
- | "int" { t = new IntType("int" , SizeThunk.INT, unsigned, cvAttrs); }
- | "long" { t = new IntType("long" , SizeThunk.LONG, unsigned, cvAttrs); }
- | "__int32" { t = new IntType("__int32", SizeThunk.INT, unsigned, cvAttrs); }
- | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); }
- | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs); }
- | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); }
+ : "void" { t = new VoidType(cvAttrs); }
+ | "char" { t = new IntType("char" , SizeThunk.CHAR, unsigned, cvAttrs); }
+ | "short" { t = new IntType("short", SizeThunk.SHORT, unsigned, cvAttrs); }
+ | "int" { t = new IntType("int" , SizeThunk.INT, unsigned, cvAttrs); }
+ | "long" { t = new IntType("long" , SizeThunk.LONG, unsigned, cvAttrs); }
+ | "float" { t = new FloatType("float", SizeThunk.FLOAT, cvAttrs); }
+ | "double" { t = new DoubleType("double", SizeThunk.DOUBLE, cvAttrs); }
+ | "__int32" { t = new IntType("__int32", SizeThunk.INT, unsigned, cvAttrs); }
+ | "int32_t" { t = new IntType("int32_t", SizeThunk.INT, false, cvAttrs); /* TS: always signed */ }
+ | "uint32_t" { t = new IntType("uint32_t", SizeThunk.INT, true, cvAttrs); /* TS: always unsigned */ }
+ | "__int64" { t = new IntType("__int64", SizeThunk.INT64, unsigned, cvAttrs); }
+ | "int64_t" { t = new IntType("int64_t", SizeThunk.INT64, false, cvAttrs); /* TS: always signed */ }
+ | "uint64_t" { t = new IntType("uint64_t", SizeThunk.INT64, true, cvAttrs); /* TS: always unsigned */ }
+ | "ptrdiff_t" { t = new IntType("ptrdiff_t", SizeThunk.POINTER, false, cvAttrs); /* TS: always signed */ }
+ | "size_t" { t = new IntType("size_t", SizeThunk.POINTER, true, cvAttrs); /* TS: always unsigned */ }
| t = structSpecifier[cvAttrs] ( attributeDecl )*
| t = unionSpecifier [cvAttrs] ( attributeDecl )*
| t = enumSpecifier [cvAttrs]
@@ -481,8 +527,10 @@ typeSpecifier[int attributes] returns [Type t] {
typedefName[int cvAttrs] returns [Type t] { t = null; }
: #(NTypedefName id : ID)
- {
- t = canonicalize(lookupInTypedefDictionary(id.getText()).getCVVariant(cvAttrs));
+ {
+ Type tdict = lookupInTypedefDictionary(id.getText());
+ t = canonicalize(tdict.getCVVariant(cvAttrs));
+ debugPrintln("Adding typedef canon : [" + id.getText() + "] -> [" + tdict + "] -> "+getTypeString(t));
}
;
@@ -575,7 +623,7 @@ structDeclarator[CompoundType containingType, Type t] returns [boolean addedAny]
// I haven't implemented it yet because I'm not sure how to get the
// "enumName" *before* executing the enumList rule.
enumSpecifier [int cvAttrs] returns [Type t] {
- t = null;
+ t = null;
}
: #( "enum"
( ( ID LCURLY )=> i:ID LCURLY enumList[(EnumType)(t = getEnumType(i.getText()))] RCURLY
@@ -586,18 +634,18 @@ enumSpecifier [int cvAttrs] returns [Type t] {
;
enumList[EnumType enumeration] {
- long defaultEnumerantValue = 0;
+ long defaultEnumerantValue = 0;
}
: ( defaultEnumerantValue = enumerator[enumeration, defaultEnumerantValue] )+
;
enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValue] {
- newDefaultValue = defaultValue;
+ newDefaultValue = defaultValue;
}
: eName:ID ( ASSIGN eVal:expr )? {
long value = 0;
if (eVal != null) {
- String vTxt = eVal.getAllChildrenText();
+ String vTxt = eVal.getAllChildrenText();
if (enumHash.containsKey(vTxt)) {
EnumType oldEnumType = (EnumType) enumHash.get(vTxt);
value = oldEnumType.getEnumValue(vTxt);
@@ -605,7 +653,7 @@ enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValu
try {
value = Long.decode(vTxt).longValue();
} catch (NumberFormatException e) {
- System.err.println("NumberFormatException: ID[" + eName.getText() + "], VALUE=[" + vTxt + "]");
+ System.err.println("NumberFormatException: ID[" + eName.getText() + "], VALUE=[" + vTxt + "]");
throw e;
}
}
@@ -613,25 +661,25 @@ enumerator[EnumType enumeration, long defaultValue] returns [long newDefaultValu
value = defaultValue;
}
- newDefaultValue = value+1;
- String eTxt = eName.getText();
- if (enumHash.containsKey(eTxt)) {
- EnumType oldEnumType = (EnumType) enumHash.get(eTxt);
- long oldValue = oldEnumType.getEnumValue(eTxt);
- System.err.println("WARNING: redefinition of enumerated value '" + eTxt + "';" +
- " existing definition is in enumeration '" + oldEnumType.getName() +
- "' with value " + oldValue + " and new definition is in enumeration '" +
- enumeration.getName() + "' with value " + value);
- // remove old definition
- oldEnumType.removeEnumerate(eTxt);
- }
- // insert new definition
- enumeration.addEnum(eTxt, value);
- enumHash.put(eTxt, enumeration);
- //System.err.println("ENUM [" + enumeration.getName() + "]: " + eTxt + " = " + enumeration.getEnumValue(eTxt) +
- // " (new default = " + newDefaultValue + ")");
- }
- ;
+ newDefaultValue = value+1;
+ String eTxt = eName.getText();
+ if (enumHash.containsKey(eTxt)) {
+ EnumType oldEnumType = (EnumType) enumHash.get(eTxt);
+ long oldValue = oldEnumType.getEnumValue(eTxt);
+ System.err.println("WARNING: redefinition of enumerated value '" + eTxt + "';" +
+ " existing definition is in enumeration '" + oldEnumType.getName() +
+ "' with value " + oldValue + " and new definition is in enumeration '" +
+ enumeration.getName() + "' with value " + value);
+ // remove old definition
+ oldEnumType.removeEnumerate(eTxt);
+ }
+ // insert new definition
+ enumeration.addEnum(eTxt, value);
+ enumHash.put(eTxt, enumeration);
+ debugPrintln("ENUM [" + enumeration.getName() + "]: " + eTxt + " = " + enumeration.getEnumValue(eTxt) +
+ " (new default = " + newDefaultValue + ")");
+ }
+ ;
initDeclList[TypeBox tb]
: ( initDecl[tb] )+
@@ -642,8 +690,8 @@ initDecl[TypeBox tb] {
}
: #( NInitDecl
declName = declarator[tb] {
- //System.err.println("GOT declName: " + declName + " TB=" + tb);
- }
+ debugPrintln("GOT declName: " + declName + " TB=" + tb);
+ }
( attributeDecl )*
( ASSIGN initializer
| COLON expr
@@ -652,11 +700,18 @@ initDecl[TypeBox tb] {
{
if ((declName != null) && (tb != null) && tb.isTypedef()) {
Type t = tb.type();
- //System.err.println("Adding typedef mapping: [" + declName + "] -> [" + t + "]");
+ debugPrint("Adding typedef mapping: [" + declName + "] -> "+getTypeString(t));
if (!t.hasTypedefName()) {
t.setName(declName);
+ debugPrint(" - declName -> "+getTypeString(t));
+ } else {
+ // copy type to preserve declName !
+ t = (Type) t.clone();
+ t.setName(declName);
+ debugPrint(" - copy -> "+getTypeString(t));
}
t = canonicalize(t);
+ debugPrintln(" - canon -> "+getTypeString(t));
typedefDictionary.put(declName, t);
// Clear out PointerGroup effects in case another typedef variant follows
tb.reset();
@@ -667,7 +722,7 @@ initDecl[TypeBox tb] {
pointerGroup[TypeBox tb] { int x = 0; int y = 0; }
: #( NPointerGroup ( STAR { x = 0; y = 0; } ( y = typeQualifier { x |= y; } )*
{
- //System.err.println("IN PTR GROUP: TB=" + tb);
+ debugPrintln("IN PTR GROUP: TB=" + tb);
if (tb != null) {
tb.setType(canonicalize(new PointerType(SizeThunk.POINTER,
tb.type(),
diff --git a/src/java/com/sun/gluegen/cgram/types/ArrayType.java b/src/java/com/sun/gluegen/cgram/types/ArrayType.java
index 31ec13c..6ef4682 100644
--- a/src/java/com/sun/gluegen/cgram/types/ArrayType.java
+++ b/src/java/com/sun/gluegen/cgram/types/ArrayType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -44,7 +45,7 @@ package com.sun.gluegen.cgram.types;
not be known; if the length is unknown then a negative number
should be passed in to the constructor. */
-public class ArrayType extends Type {
+public class ArrayType extends Type implements Cloneable {
private Type elementType;
private int length;
private String computedName;
diff --git a/src/java/com/sun/gluegen/cgram/types/BitType.java b/src/java/com/sun/gluegen/cgram/types/BitType.java
index b5a5337..fc6f851 100644
--- a/src/java/com/sun/gluegen/cgram/types/BitType.java
+++ b/src/java/com/sun/gluegen/cgram/types/BitType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -41,7 +42,7 @@ package com.sun.gluegen.cgram.types;
/** Represents a bitfield in a struct. */
-public class BitType extends IntType {
+public class BitType extends IntType implements Cloneable {
private IntType underlyingType;
private int sizeInBits;
private int offset;
diff --git a/src/java/com/sun/gluegen/cgram/types/CompoundType.java b/src/java/com/sun/gluegen/cgram/types/CompoundType.java
index 9b982fd..51efad5 100644
--- a/src/java/com/sun/gluegen/cgram/types/CompoundType.java
+++ b/src/java/com/sun/gluegen/cgram/types/CompoundType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -45,7 +46,7 @@ import java.util.*;
and unions. The boolean type accessors indicate how the type is
really defined. */
-public class CompoundType extends Type {
+public class CompoundType extends Type implements Cloneable {
private CompoundTypeKind kind;
// The name "foo" in the construct "struct foo { ... }";
private String structName;
@@ -66,6 +67,12 @@ public class CompoundType extends Type {
this.structName = structName;
}
+ public Object clone() {
+ CompoundType n = (CompoundType) super.clone();
+ n.fields = (ArrayList) this.fields.clone();
+ return n;
+ }
+
@Override
public int hashCode() {
if (computedHashcode) {
diff --git a/src/java/com/sun/gluegen/cgram/types/DoubleType.java b/src/java/com/sun/gluegen/cgram/types/DoubleType.java
index 7e295cd..cc4ffba 100644
--- a/src/java/com/sun/gluegen/cgram/types/DoubleType.java
+++ b/src/java/com/sun/gluegen/cgram/types/DoubleType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -39,7 +40,7 @@
package com.sun.gluegen.cgram.types;
/** Represents a double-word floating-point type (C type "double".) */
-public class DoubleType extends PrimitiveType {
+public class DoubleType extends PrimitiveType implements Cloneable {
public DoubleType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
diff --git a/src/java/com/sun/gluegen/cgram/types/EnumType.java b/src/java/com/sun/gluegen/cgram/types/EnumType.java
index b06ed9a..c6f8541 100644
--- a/src/java/com/sun/gluegen/cgram/types/EnumType.java
+++ b/src/java/com/sun/gluegen/cgram/types/EnumType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,11 +39,13 @@
*/
package com.sun.gluegen.cgram.types;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.NoSuchElementException;
+
/** Describes enumerated types. Enumerations are like ints except that
they have a set of named values. */
-public class EnumType extends IntType {
+public class EnumType extends IntType implements Cloneable {
private IntType underlyingType;
@@ -65,7 +68,7 @@ public class EnumType extends IntType {
}
}
- private List<Enum> enums;
+ private ArrayList<Enum> enums;
public EnumType(String name) {
super(name, SizeThunk.LONG, false, CVAttributes.CONST);
@@ -82,6 +85,13 @@ public class EnumType extends IntType {
this.underlyingType = underlyingType;
}
+ public Object clone() {
+ EnumType n = (EnumType) super.clone();
+ n.underlyingType = (IntType) this.underlyingType.clone();
+ n.enums = (ArrayList) this.enums.clone();
+ return n;
+ }
+
@Override
public boolean equals(Object arg) {
if (arg == this) {
diff --git a/src/java/com/sun/gluegen/cgram/types/FloatType.java b/src/java/com/sun/gluegen/cgram/types/FloatType.java
index 91b45b4..2e80be9 100644
--- a/src/java/com/sun/gluegen/cgram/types/FloatType.java
+++ b/src/java/com/sun/gluegen/cgram/types/FloatType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -41,12 +42,11 @@ package com.sun.gluegen.cgram.types;
/** Represents a single-word floating-point type (C type "float".) */
-public class FloatType extends PrimitiveType {
+public class FloatType extends PrimitiveType implements Cloneable {
public FloatType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
}
-
@Override
public boolean equals(Object arg) {
if (arg == this) {
diff --git a/src/java/com/sun/gluegen/cgram/types/FunctionType.java b/src/java/com/sun/gluegen/cgram/types/FunctionType.java
index d36f839..35b62b7 100644
--- a/src/java/com/sun/gluegen/cgram/types/FunctionType.java
+++ b/src/java/com/sun/gluegen/cgram/types/FunctionType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -42,7 +43,7 @@ import java.util.*;
/** Describes a function type, used to model both function
declarations and (via PointerType) function pointers. */
-public class FunctionType extends Type {
+public class FunctionType extends Type implements Cloneable {
private Type returnType;
private ArrayList<Type> argumentTypes;
@@ -53,6 +54,13 @@ public class FunctionType extends Type {
this.returnType = returnType;
}
+ public Object clone() {
+ FunctionType n = (FunctionType) super.clone();
+ n.argumentTypes = (ArrayList) this.argumentTypes.clone();
+ n.argumentNames = (ArrayList) this.argumentNames.clone();
+ return n;
+ }
+
@Override
public boolean equals(Object arg) {
if (arg == this) {
diff --git a/src/java/com/sun/gluegen/cgram/types/IntType.java b/src/java/com/sun/gluegen/cgram/types/IntType.java
index b94e7bb..fbbd939 100644
--- a/src/java/com/sun/gluegen/cgram/types/IntType.java
+++ b/src/java/com/sun/gluegen/cgram/types/IntType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,7 +39,7 @@
*/
package com.sun.gluegen.cgram.types;
-public class IntType extends PrimitiveType {
+public class IntType extends PrimitiveType implements Cloneable {
private boolean unsigned;
private boolean typedefedUnsigned;
diff --git a/src/java/com/sun/gluegen/cgram/types/PointerType.java b/src/java/com/sun/gluegen/cgram/types/PointerType.java
index 712c4ee..cfd54c5 100644
--- a/src/java/com/sun/gluegen/cgram/types/PointerType.java
+++ b/src/java/com/sun/gluegen/cgram/types/PointerType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,7 +39,7 @@
*/
package com.sun.gluegen.cgram.types;
-public class PointerType extends Type {
+public class PointerType extends Type implements Cloneable {
private Type targetType;
private String computedName;
diff --git a/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java b/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java
index 8b6e096..27cd3dd 100644
--- a/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java
+++ b/src/java/com/sun/gluegen/cgram/types/PrimitiveType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,7 +39,7 @@
*/
package com.sun.gluegen.cgram.types;
-public abstract class PrimitiveType extends Type {
+public abstract class PrimitiveType extends Type implements Cloneable {
protected PrimitiveType(String name, SizeThunk size, int cvAttributes) {
super(name, size, cvAttributes);
diff --git a/src/java/com/sun/gluegen/cgram/types/SizeThunk.java b/src/java/com/sun/gluegen/cgram/types/SizeThunk.java
index 74feef9..fcc96be 100755
--- a/src/java/com/sun/gluegen/cgram/types/SizeThunk.java
+++ b/src/java/com/sun/gluegen/cgram/types/SizeThunk.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -45,10 +46,18 @@ package com.sun.gluegen.cgram.types;
32-bit and 64-bit) from the same internal representation of the
various types involved. */
-public abstract class SizeThunk {
+public abstract class SizeThunk implements Cloneable {
// Private constructor because there are only a few of these
private SizeThunk() {}
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
public abstract long compute(MachineDescription machDesc);
public static final SizeThunk CHAR = new SizeThunk() {
diff --git a/src/java/com/sun/gluegen/cgram/types/Type.java b/src/java/com/sun/gluegen/cgram/types/Type.java
index 4df034b..e43acb2 100644
--- a/src/java/com/sun/gluegen/cgram/types/Type.java
+++ b/src/java/com/sun/gluegen/cgram/types/Type.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -45,7 +46,7 @@ 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 {
+public abstract class Type implements Cloneable {
private String name;
private SizeThunk size;
@@ -60,6 +61,14 @@ public abstract class Type {
hasTypedefName = false;
}
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
/** Returns the name of this type. The returned string is suitable
for use as a type specifier. Does not include any const/volatile
attributes. */
diff --git a/src/java/com/sun/gluegen/cgram/types/VoidType.java b/src/java/com/sun/gluegen/cgram/types/VoidType.java
index 779a661..4c3c077 100644
--- a/src/java/com/sun/gluegen/cgram/types/VoidType.java
+++ b/src/java/com/sun/gluegen/cgram/types/VoidType.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2010 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -38,7 +39,7 @@
*/
package com.sun.gluegen.cgram.types;
-public class VoidType extends Type {
+public class VoidType extends Type implements Cloneable {
public VoidType(int cvAttributes) {
this("void", cvAttributes);