summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/ConstantDefinition.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-03-05 07:14:04 +0100
committerSven Gothel <[email protected]>2015-03-05 07:14:04 +0100
commit72d3635279ffc8ad88e47dff9bbe95d211226d11 (patch)
tree62b3735680dfc5980a94afa14c56045bd082af24 /src/java/com/jogamp/gluegen/ConstantDefinition.java
parentdd2440cbadc642a561d8f92c502fe822b2f11762 (diff)
Bug 1134 - Enhance GlueGen Compiler: Minimal GL Header Changes _and_ Typesafety
- We shall be able to import 'most' vanilla GL header, i.e. only change the typedef part using our GlueGen types - Type Safety: - GlueGen now detects '#define' and 'enum' redefines and throw an exception in this case. This helps detecting wrongly renamed GL extensions into core! - GlueGen now detects function redefines (overloading) and throw an exception in this case. Hence the semantics of duplicate functions has to be equal! This helps detecting wrongly renamed GL extensions into core! - Semantic equality for all types is provided via interface TypeComparator.SemanticEqualityOp, i.e. 'boolean equalSemantics(..)' implemented by com.jogamp.gluegen.cgram.types.Type. Semantic equality can be relaxed via config "RelaxedEqualSemanticsTest true", i.e. ignoring integer size, and const / volatile qualifiers. - All equality/hash methods of 'com.jogamp.gluegen.cgram.types.*' are restructured. - Track and simplify renamed 'symbol', i.e. use a common sub-interface for all renamed symbols (ConstantDefinition, FunctionSymbol, ..) - This is provided in a unified manner via interface com.jogamp.gluegen.cgram.types.AliasedSymbol and its common implementation AliasedSymbolImpl - All JavaConfiguration.shouldIgnore* methods operate w/ 'AliasedSymbol' trying to match all aliases. - Support 'struct NAME [ { ... } ]' w/o typedef's - New GL / CL headers do not use typedef's for anonymous opaque types - Opaque Type handling - JavaConfiguration.typeInfo(..), identifying opaque types, no more back references from target-type -> typedef. Hence the following is possible now: typedef void * Opaque01; // Opaque typedef void * APointerBuffer; // A Buffer - All Logger instances are no more static and derive their warning level from the package's root Logger via Logging.getLogger(..).
Diffstat (limited to 'src/java/com/jogamp/gluegen/ConstantDefinition.java')
-rw-r--r--src/java/com/jogamp/gluegen/ConstantDefinition.java153
1 files changed, 92 insertions, 61 deletions
diff --git a/src/java/com/jogamp/gluegen/ConstantDefinition.java b/src/java/com/jogamp/gluegen/ConstantDefinition.java
index ca67001..78d2e43 100644
--- a/src/java/com/jogamp/gluegen/ConstantDefinition.java
+++ b/src/java/com/jogamp/gluegen/ConstantDefinition.java
@@ -33,100 +33,131 @@
package com.jogamp.gluegen;
-import java.util.*;
+import com.jogamp.gluegen.cgram.types.AliasedSymbol.AliasedSymbolImpl;
+import com.jogamp.gluegen.cgram.types.TypeComparator.AliasedSemanticSymbol;
+import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp;
/** Represents the definition of a constant which was provided either
via a #define statement or through an enum definition. */
-public class ConstantDefinition {
-
- private final String origName;
- private final HashSet<String> aliasedNames;
- private String name;
- private final String value;
+public class ConstantDefinition extends AliasedSymbolImpl implements AliasedSemanticSymbol {
+ private final boolean relaxedEqSem;
+ private final String sValue;
+ private final long iValue;
+ private final boolean hasIntValue;
private final boolean isEnum;
private final String enumName;
- private Set<String> aliases;
+ /** Covering enums */
public ConstantDefinition(final String name,
- final String value,
- final boolean isEnum,
+ final long value,
final String enumName) {
- this.origName = name;
- this.name = name;
- this.value = value;
- this.isEnum = isEnum;
+ super(name);
+ this.relaxedEqSem = TypeConfig.relaxedEqualSemanticsTest();
+ this.sValue = String.valueOf(value);
+ this.iValue = value;
+ this.hasIntValue = true;
+ this.isEnum = true;
this.enumName = enumName;
- this.aliasedNames=new HashSet<String>();
- }
-
- public boolean equals(final ConstantDefinition other) {
- return (equals(name, other.name) &&
- equals(value, other.value) &&
- equals(enumName, other.enumName));
}
- private boolean equals(final String s1, final String s2) {
- if (s1 == null || s2 == null) {
- if (s1 == null && s2 == null) {
- return true;
+ /** Covering defines */
+ public ConstantDefinition(final String name,
+ final String value) {
+ super(name);
+ this.relaxedEqSem = TypeConfig.relaxedEqualSemanticsTest();
+ this.sValue = value;
+ {
+ // Attempt to parse define string as number
+ long v;
+ boolean b;
+ try {
+ v = Long.decode(value).longValue();
+ b = true;
+ } catch (final NumberFormatException e) {
+ v = 0;
+ b = false;
}
- return false;
+ this.iValue = v;
+ this.hasIntValue = b;
}
-
- return s1.equals(s2);
+ this.isEnum = false;
+ this.enumName = null;
}
+ /**
+ * Hash by its given {@link #getName() name}.
+ */
@Override
- public int hashCode() {
- return name.hashCode();
- }
-
- /** Supports renaming in Java binding. */
- public void rename(final String name) {
- if(null!=name) {
- this.name = name;
- aliasedNames.add(origName);
- }
+ public final int hashCode() {
+ return getName().hashCode();
}
- public void addAliasedName(final String name) {
- aliasedNames.add(name);
- }
- public Collection<String> getAliasedNames() {
- return aliasedNames;
+ /**
+ * Equality test by its given {@link #getName() name}.
+ */
+ @Override
+ public final boolean equals(final Object arg) {
+ if (arg == this) {
+ return true;
+ } else if ( !(arg instanceof ConstantDefinition) ) {
+ return false;
+ } else {
+ final ConstantDefinition t = (ConstantDefinition)arg;
+ return equals(getName(), t.getName());
+ }
}
- public String getOrigName() {
- return origName;
+ @Override
+ public final int hashCodeSemantics() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + ( null != getName() ? getName().hashCode() : 0 );
+ hash = ((hash << 5) - hash) + ( null != sValue ? sValue.hashCode() : 0 );
+ return ((hash << 5) - hash) + ( null != enumName ? enumName.hashCode() : 0 );
}
- public String getName() {
- return name;
+ @Override
+ public final boolean equalSemantics(final SemanticEqualityOp arg) {
+ if (arg == this) {
+ return true;
+ } else if ( !(arg instanceof ConstantDefinition) ) {
+ return false;
+ } else {
+ final ConstantDefinition t = (ConstantDefinition) arg;
+ if( !equals(getName(), t.getName()) ||
+ !equals(enumName, t.enumName) ) {
+ return false;
+ }
+ if( hasIntValue ) {
+ return iValue == t.iValue;
+ } else {
+ // define's string value may be semantical equal .. but formatted differently!
+ return relaxedEqSem || equals(sValue, t.sValue);
+ }
+ }
}
- public String getValue() { return value; }
+ public String getValue() { return sValue; }
/** Returns null if this definition was not part of an
enumeration, or if the enum was anonymous. */
public String getEnumName() { return enumName; }
public boolean isEnum() { return isEnum; }
- public Set<String> getAliases() {
- return aliases;
+ @Override
+ public String toString() {
+ return "ConstantDefinition [name " + getName()
+ + ", value " + sValue + " (isInt " + hasIntValue
+ + "), enumName " + enumName + ", isEnum " + isEnum + "]";
}
- public void addAlias(final String alias) {
- if (aliases == null) {
- aliases = new LinkedHashSet<String>();
+ private static boolean equals(final String s1, final String s2) {
+ if (s1 == null || s2 == null) {
+ if (s1 == null && s2 == null) {
+ return true;
+ }
+ return false;
}
- aliases.add(alias);
- }
- @Override
- public String toString() {
- return "ConstantDefinition [name " + name + " origName " + origName + " value " + value
- + " aliasedNames " + aliasedNames + " aliases " + aliases
- + " enumName " + enumName + " isEnum " + isEnum + "]";
+ return s1.equals(s2);
}
-
}