GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
ReferencedStructs.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 * You acknowledge that this software is not designed or intended for use
33 * in the design, construction, operation or maintenance of any nuclear
34 * facility.
35 *
36 * Sun gratefully acknowledges that this software was originally authored
37 * and developed by Kenneth Bradley Russell and Christopher John Kline.
38 */
39
40package com.jogamp.gluegen;
41
42import java.util.*;
43import com.jogamp.gluegen.cgram.types.*;
44
45public class ReferencedStructs implements TypeVisitor {
46
47 private final Map<String, Type> resultMap = new HashMap<String, Type>();
48 private final Set<CompoundType> layoutSet = new HashSet<CompoundType>();
49 private final Set<Type> skip = new HashSet<Type>();
50
51 public void clear() {
52 resultMap.clear();
53 }
54
55 public Iterator<Type> results() {
56 return resultMap.values().iterator();
57 }
58 public Iterator<CompoundType> layouts() {
59 return layoutSet.iterator();
60 }
61
62 @Override
63 public void visitType(final Type t) {
64 if( skip.contains(t) ) {
65 return;
66 }
67 if ( t.isPointer() ) {
68 final PointerType p = t.asPointer();
70 if( p.isTypedef() && null != c ) {
71 // If containing pointer is typedef, use it (preferred)
72 skip.add(c); // earmark to skip the compound!
73 resultMap.put(c.getName(), p);
74 layoutSet.add(c);
75 } else {
76 // .. otherwise skip pointer and use followup compound
77 }
78 } else if( t.isCompound() ) {
79 // Use compound if not yet mapped, e.g. by typedef'ed (preferred)
80 if( !resultMap.containsKey(t.getName()) ) {
81 resultMap.put(t.getName(), t);
82 }
83 layoutSet.add(t.asCompound()); // always: could be const/volatile variants ..
84 }
85 }
86}
void visitType(final Type t)
Visiting the given Type.
Iterator< CompoundType > layouts()
Models all compound types, i.e., those containing fields: structs and unions.
final Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
Definition: Type.java:386
final String getName()
Returns the name of this type.
Definition: Type.java:142
final boolean isPointer()
Indicates whether this is a PointerType.
Definition: Type.java:407
CompoundType asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.
Definition: Type.java:390
final boolean isTypedef()
Indicates whether this type is a typedef type, i.e.
Definition: Type.java:352
final boolean isCompound()
Indicates whether this is a CompoundType.
Definition: Type.java:411
String getName()
Return the current-name, which is the last renamed-name if issued, or the original-name.
A visitor for Type's visitor model.