diff options
-rw-r--r-- | src/java/com/jogamp/gluegen/CMethodBindingEmitter.java | 17 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/cgram/types/IntType.java | 58 | ||||
-rw-r--r-- | src/java/com/jogamp/gluegen/cgram/types/Type.java | 24 |
3 files changed, 55 insertions, 44 deletions
diff --git a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java index 85c6d7e..10a9648 100644 --- a/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/CMethodBindingEmitter.java @@ -928,20 +928,9 @@ public class CMethodBindingEmitter extends FunctionEmitter { javaArgType.isArray() || javaArgType.isArrayOfCompoundTypeWrappers() || ( javaArgType.isNIOBuffer() && forIndirectBufferAndArrayImplementation ) ); - if (isBaseTypeConst(cArgType)) { - writer.print("const "); - } - - // if this is a pointer to an unsigned type, add unsigned to the name to avoid compiler warnings - if(cArgType.isPointer()) { - final Type baseType = cArgType.getBaseElementType(); - if(baseType.isInt() && (((IntType)baseType).isPrimitiveUnsigned())) { - writer.print("unsigned "); - } - } - - writer.print(cArgType.getCName()); + writer.print(cArgType.getCName(true)); writer.print(") "); + if (cArgType.isPointer() && javaArgType.isPrimitive()) { writer.print("(intptr_t) "); } @@ -1105,7 +1094,7 @@ public class CMethodBindingEmitter extends FunctionEmitter { } } else if (javaReturnType.isString()) { writer.println(" if (NULL == _res) return NULL;"); - writer.println(" return (*env)->NewStringUTF(env, _res);"); + writer.println(" return (*env)->NewStringUTF(env, (const char *)_res);"); } else if (javaReturnType.isArrayOfCompoundTypeWrappers() || (javaReturnType.isArray() && javaReturnType.isNIOByteBufferArray())) { writer.println(" if (NULL == _res) return NULL;"); diff --git a/src/java/com/jogamp/gluegen/cgram/types/IntType.java b/src/java/com/jogamp/gluegen/cgram/types/IntType.java index 502fe2a..fd2509e 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/IntType.java +++ b/src/java/com/jogamp/gluegen/cgram/types/IntType.java @@ -39,33 +39,45 @@ */ package com.jogamp.gluegen.cgram.types; +import com.jogamp.gluegen.ASTLocusTag; + public class IntType extends PrimitiveType implements Cloneable { private final boolean unsigned; - private boolean typedefedUnsigned; public IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes) { - this(name, size, unsigned, cvAttributes, false); + this(name, size, unsigned, cvAttributes, null); + } + + public IntType(final String name, final SizeThunk size, + final boolean unsigned, final int cvAttributes, + final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); + this.unsigned = unsigned; } - public IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes, final boolean typedefedUnsigned) { - super(name, size, cvAttributes); + /** Only for HeaderParser */ + public IntType(final String name, final SizeThunk size, + final boolean unsigned, final int cvAttributes, + final boolean isTypedef, + final ASTLocusTag astLocus) { + super(name, size, cvAttributes, astLocus); this.unsigned = unsigned; - this.typedefedUnsigned = typedefedUnsigned; + if( isTypedef ) { + setTypedef(cvAttributes); + } } @Override protected int hashCodeImpl() { // 31 * x == (x << 5) - x - final int hash = 31 + ( unsigned ? 1 : 0 ); - return ((hash << 5) - hash) + ( typedefedUnsigned ? 1 : 0 ); + return 31 + ( unsigned ? 1 : 0 ); } @Override protected boolean equalsImpl(final Type arg) { final IntType t = (IntType) arg; - return unsigned == t.unsigned && - typedefedUnsigned == t.typedefedUnsigned; + return unsigned == t.unsigned; } @Override @@ -77,15 +89,7 @@ public class IntType extends PrimitiveType implements Cloneable { protected boolean equalSemanticsImpl(final Type arg) { final IntType t = (IntType) arg; return relaxedEqSem || - ( unsigned == t.unsigned && - typedefedUnsigned == t.typedefedUnsigned - ); - } - - @Override - public void setTypedefName(final String name) { - super.setTypedefName(name); - typedefedUnsigned = unsigned; + unsigned == t.unsigned; } @Override @@ -98,18 +102,26 @@ public class IntType extends PrimitiveType implements Cloneable { return unsigned; } - /** Indicates whether this type is an unsigned primitive type, as opposed to a typedef type that's unsigned. */ - public boolean isPrimitiveUnsigned() { - return unsigned && !typedefedUnsigned; + @Override + public String getCName(final boolean includeCVAttrs) { + if ( isTypedef() || !isUnsigned() ) { + return super.getCName(includeCVAttrs); + } else { + return "unsigned "+super.getCName(includeCVAttrs); + } } @Override public String toString() { - return getCVAttributesString() + ((isUnsigned() & (!typedefedUnsigned)) ? "unsigned " : "") + getCName(); + return getCVAttributesString() + ( isUnsigned() && !isTypedef() ? "unsigned " : "") + getCName(); } @Override Type newCVVariant(final int cvAttributes) { - return new IntType(getName(), getSize(), isUnsigned(), cvAttributes, typedefedUnsigned); + final Type t = new IntType(getName(), getSize(), isUnsigned(), cvAttributes, astLocus); + if( isTypedef() ) { + t.setTypedef(getTypedefCVAttributes()); + } + return t; } } diff --git a/src/java/com/jogamp/gluegen/cgram/types/Type.java b/src/java/com/jogamp/gluegen/cgram/types/Type.java index 9fd51fe..ee1aff1 100644 --- a/src/java/com/jogamp/gluegen/cgram/types/Type.java +++ b/src/java/com/jogamp/gluegen/cgram/types/Type.java @@ -162,13 +162,12 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag if( null != targetType && this != targetType ) { sb.append(" -> "); if (!targetType.isFunction()) { - sb.append(targetType.toString() + " * " + getCVAttributesString()); + sb.append("(" + targetType.toString() + ") * " + getCVAttributesString()); } else { sb.append(((FunctionType) targetType).toString(null /* functionName */, null /* callingConvention */, false, true)); } } if( GlueGen.debug() ) { - // sb.append(", o=0x"+Integer.toHexString(objHash())+" h=0x"+Integer.toHexString(hashCode())); sb.append(", o=0x"+Integer.toHexString(objHash())); } sb.append(", size "); @@ -187,11 +186,20 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag sb.append(" ZERO"); } append(sb, "[", prepComma); prepComma=false; + append(sb, "const[", prepComma); prepComma=false; + if( isConstTypedef() ) { + append(sb, "type ", prepComma); prepComma=true; + } + if( isConstRaw() ) { + append(sb, "inst -> ", prepComma); prepComma=false; + } if( isConst() ) { - append(sb, "const ", false); + append(sb, "true]", prepComma); prepComma=true; + } else { + append(sb, "false]", prepComma); prepComma=true; } if( isVolatile() ) { - append(sb, "volatile ", false); + append(sb, "volatile ", prepComma); prepComma=true; } if( isPointer() ) { append(sb, "pointer*"+pointerDepth(), prepComma); prepComma=true; @@ -369,10 +377,12 @@ public abstract class Type implements Cloneable, SemanticEqualityOp, ASTLocusTag /** Indicates whether this is a VoidType. */ public boolean isVoid() { return (asVoid() != null); } - /** Indicates whether this type is const. */ - public boolean isConst() { return (((cvAttributes & ~typedefCVAttributes) & CVAttributes.CONST) != 0); } /** Indicates whether this type is volatile. */ - public boolean isVolatile() { return (((cvAttributes & ~typedefCVAttributes) & CVAttributes.VOLATILE) != 0); } + public boolean isVolatile() { return 0 != ( ( cvAttributes & ~typedefCVAttributes ) & CVAttributes.VOLATILE ); } + /** Indicates whether this type is const. */ + public boolean isConst() { return 0 != ( ( cvAttributes & ~typedefCVAttributes ) & CVAttributes.CONST ); } + private boolean isConstTypedef() { return 0 != ( typedefCVAttributes & CVAttributes.CONST ); } + private boolean isConstRaw() { return 0 != ( cvAttributes & CVAttributes.CONST ); } /** Indicates whether this type is a primitive type. */ public boolean isPrimitive(){ return false; } |