diff options
author | Sven Gothel <[email protected]> | 2015-03-09 03:09:18 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-03-09 03:09:18 +0100 |
commit | 9eb9403d774db0c55ea3cb2fc5bd04114b8b5feb (patch) | |
tree | 266780ea786df13e582d4ecdd0b05ef9c46bccfb /src/java/com/jogamp/gluegen/ReferencedStructs.java | |
parent | cf9f28cf249393f42d7d2835775521dfadee6b92 (diff) |
Bug 1134 - Fix aliased typedef struct emission
- Code regarding 'aliased typedef struct' is tagged in JavaEmitter and HeaderParser:
'NOTE: Struct Name Resolution (JavaEmitter, HeaderParser)'
Prefers containing cstruct typedef pointer
if available _and_ if cstruct is _not_ a typedef!
- Removed: 'HeaderParser.resolveAnonCompound(..)' no more required,
since CompoundType always sets its name!
Commit cf9f28cf249393f42d7d2835775521dfadee6b92
- JavaEmitter.emitStruct:
- Regard above 'aliased typedef struct' NOTE
- JavaEmitter.typeToJavaType:
- Regard above 'aliased typedef struct' NOTE
- ReferencedStructs
- Drop duplicate CompoundType instances of same name.
This can happen due to const/volatile and ASTLocusTag variants.
Diffstat (limited to 'src/java/com/jogamp/gluegen/ReferencedStructs.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/ReferencedStructs.java | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/src/java/com/jogamp/gluegen/ReferencedStructs.java b/src/java/com/jogamp/gluegen/ReferencedStructs.java index 46a2a7e..26deb3a 100644 --- a/src/java/com/jogamp/gluegen/ReferencedStructs.java +++ b/src/java/com/jogamp/gluegen/ReferencedStructs.java @@ -44,31 +44,43 @@ import com.jogamp.gluegen.cgram.types.*; public class ReferencedStructs implements TypeVisitor { - private final Set<Type> results = new HashSet<Type>(); + private final Map<String, Type> resultMap = new HashMap<String, Type>(); + private final Set<CompoundType> layoutSet = new HashSet<CompoundType>(); + private final Set<Type> skip = new HashSet<Type>(); - public void clear() { - results.clear(); - } + public void clear() { + resultMap.clear(); + } - public Iterator<Type> results() { - return results.iterator(); - } + public Iterator<Type> results() { + return resultMap.values().iterator(); + } + public Iterator<CompoundType> layouts() { + return layoutSet.iterator(); + } - @Override - public void visitType(final Type t) { - if (t.isPointer()) { - final PointerType p = t.asPointer(); - if (p.isTypedef()) { - final CompoundType c = p.getTargetType().asCompound(); - if (c != null && c.getName() == null) { - // This otherwise-unnamed CompoundType is referred to by a - // PointerType that has a typedef name. Assume that it is - // referred to in the glue code and emit it. - results.add(p); + @Override + public void visitType(final Type t) { + if( skip.contains(t) ) { + return; + } + if ( t.isPointer() ) { + final PointerType p = t.asPointer(); + final CompoundType c = p.getTargetType().asCompound(); + if( p.isTypedef() && null != c ) { + // If containing pointer is typedef, use it (preferred) + skip.add(c); // earmark to skip the compound! + resultMap.put(c.getName(), p); + layoutSet.add(c); + } else { + // .. otherwise skip pointer and use followup compound + } + } else if( t.isCompound() ) { + // Use compound if not yet mapped, e.g. by typedef'ed (preferred) + if( !resultMap.containsKey(t.getName()) ) { + resultMap.put(t.getName(), t); + } + layoutSet.add(t.asCompound()); // always: could be const/volatile variants .. } - } - } else if (t.isCompound()) { - results.add(t); } - } } |