GlueGen: src/java/com/jogamp/gluegen/cgram/types/PointerType.java Source File

GlueGen v2.6.0 GlueGen, Native Binding Generator for Java™ (public API).

PointerType.java
Go to the documentation of this file.
1/**
2 * Copyright (c) 2010-2023 JogAmp Community. All rights reserved.
3 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * - Redistribution of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistribution in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any kind. ALL
21 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
22 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
24 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
25 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
27 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
28 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
29 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
30 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
31 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that this software is not designed or intended for use
34 * in the design, construction, operation or maintenance of any nuclear
35 * facility.
36 *
37 * Sun gratefully acknowledges that this software was originally authored
38 * and developed by Kenneth Bradley Russell and Christopher John Kline.
39 */
40package com.jogamp.gluegen.cgram.types;
41
42import com.jogamp.gluegen.ASTLocusTag;
43
44 public class PointerType extends Type implements Cloneable {
45
46 private final Type targetType;
47
48 public PointerType(final SizeThunk size, final Type targetType, final int cvAttributes) {
49 this(size, targetType, cvAttributes, null);
50 }
51 public PointerType(final SizeThunk size, final Type targetType, final int cvAttributes, final ASTLocusTag astLocus) {
52 // can pass null for the final name parameter because the PointerType's getName()
53 // completely replaces superclass behavior
54 super(targetType.getName() + " *", size, cvAttributes, astLocus);
55 this.targetType = targetType;
56 }
57
58 private PointerType(final PointerType o, final int cvAttributes, final ASTLocusTag astLocus) {
59 super(o, cvAttributes, astLocus);
60 targetType = o.targetType;
61 }
62
63 @Override
64 Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
65 return new PointerType(this, cvAttributes, astLocus);
66 }
67
68 @Override
69 protected int hashCodeImpl() {
70 return targetType.hashCode();
71 }
72
73 @Override
74 protected boolean equalsImpl(final Type arg) {
75 final PointerType t = (PointerType) arg;
76 return targetType.equals(t.targetType);
77 }
78
79 @Override
80 protected int hashCodeSemanticsImpl() {
81 return targetType.hashCodeSemantics();
82 }
83
84 @Override
85 protected boolean equalSemanticsImpl(final Type arg) {
86 final PointerType pt = (PointerType) arg;
87 return targetType.equalSemantics(pt.targetType);
88 }
89
90 @Override
91 public boolean isAnon() {
92 if ( isTypedef() ) {
93 return super.isAnon();
94 } else {
95 return targetType.isAnon();
96 }
97 }
98
99 @Override
100 public String getName(final boolean includeCVAttrs) {
101 if ( isTypedef() ) {
102 return super.getName(includeCVAttrs);
103 } else if (!includeCVAttrs) {
104 return targetType.getName(includeCVAttrs) + " *";
105 } else {
106 return targetType.getName(includeCVAttrs) + " * " + getCVAttributesString();
107 }
108 }
109
110 @Override
111 public String getCName(final boolean includeCVAttrs) {
112 if ( isTypedef() ) {
113 return super.getCName(includeCVAttrs);
114 } else if (!includeCVAttrs) {
115 return targetType.getCName(includeCVAttrs) + " *";
116 } else {
117 return targetType.getCName(includeCVAttrs) + " * " + getCVAttributesString();
118 }
119 }
120
121 @Override
122 public final PointerType asPointer() {
123 return this;
124 }
125
126 @Override
127 public final Type getTargetType() {
128 if( isFunctionPointer() ) {
129 return this;
130 } else {
131 return targetType;
132 }
133 }
134
135 @Override
136 public final Type getBaseType() {
137 if( isFunctionPointer() ) {
138 return this;
139 } else {
140 return targetType.getBaseType();
141 }
142 }
143
144 @Override
145 public Type getArrayBaseOrPointerTargetType() {
146 return getTargetType();
147 }
148
149 @Override
150 public FunctionType getTargetFunction() {
151 if( isFunctionPointer() ) {
152 return targetType.asFunction();
153 } else {
154 return null;
155 }
156 }
157 @Override
158 public final boolean isFunctionPointer() {
159 return targetType.isFunction();
160 }
161
162 @Override
163 public final int pointerDepth() {
164 return 1 + targetType.pointerDepth();
165 }
166
167 @Override
168 public String toString() {
169 if ( isTypedef() ) {
170 return super.getCName(true);
171 } else {
172 return toStringInt();
173 }
174 }
175 private String toStringInt() {
176 if (!isFunctionPointer()) {
177 return targetType.getCName(true) + " * " + getCVAttributesString();
178 } else {
179 // return toString(null, null); // this is a pointer to an unnamed function
180 return ((FunctionType) targetType).toString(null /* functionName */, null /* callingConvention */, false, true);
181 }
182 }
183
184 /** For use only when printing function pointers. Calling convention
185 string (i.e., "__stdcall") is optional and is generally only
186 needed on Windows. */
187 public String toString(final String functionName, final String callingConvention) {
188 if (!isFunctionPointer()) {
189 throw new RuntimeException("<Internal error or misuse> This method is only for use when printing function pointers");
190 }
191 return ((FunctionType) targetType).toString(functionName, callingConvention, false, true);
192 }
193
194 @Override
195 public void visit(final TypeVisitor arg) {
196 super.visit(arg);
197 targetType.visit(arg);
198 }
199}
com.jogamp.gluegen.ASTLocusTag
An AST location tag.
Definition: ASTLocusTag.java:33
com.jogamp.gluegen.cgram.types.FunctionType
Describes a function type, used to model both function declarations and (via PointerType) function po...
Definition: FunctionType.java:48
com.jogamp.gluegen.cgram.types.PointerType
Definition: PointerType.java:44
com.jogamp.gluegen.cgram.types.PointerType.visit
void visit(final TypeVisitor arg)
Traverse this Type and all of its component types; for example, the return type and argument types of...
Definition: PointerType.java:195
com.jogamp.gluegen.cgram.types.PointerType.getTargetType
final Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
Definition: PointerType.java:127
com.jogamp.gluegen.cgram.types.PointerType.getTargetFunction
FunctionType getTargetFunction()
Returns the target FunctionType if this type is isFunctionPointer().
Definition: PointerType.java:150
com.jogamp.gluegen.cgram.types.PointerType.hashCodeSemanticsImpl
int hashCodeSemanticsImpl()
Definition: PointerType.java:80
com.jogamp.gluegen.cgram.types.PointerType.toString
String toString()
Returns a string representation of this type.
Definition: PointerType.java:168
com.jogamp.gluegen.cgram.types.PointerType.getCName
String getCName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
Definition: PointerType.java:111
com.jogamp.gluegen.cgram.types.PointerType.getBaseType
final Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.
Definition: PointerType.java:136
com.jogamp.gluegen.cgram.types.PointerType.asPointer
final PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
Definition: PointerType.java:122
com.jogamp.gluegen.cgram.types.PointerType.getArrayBaseOrPointerTargetType
Type getArrayBaseOrPointerTargetType()
Return getBaseType() if isArray() or returns getTargetType() otherwise.
Definition: PointerType.java:145
com.jogamp.gluegen.cgram.types.PointerType.hashCodeImpl
int hashCodeImpl()
Definition: PointerType.java:69
com.jogamp.gluegen.cgram.types.PointerType.PointerType
PointerType(final SizeThunk size, final Type targetType, final int cvAttributes)
Definition: PointerType.java:48
com.jogamp.gluegen.cgram.types.PointerType.toString
String toString(final String functionName, final String callingConvention)
For use only when printing function pointers.
Definition: PointerType.java:187
com.jogamp.gluegen.cgram.types.PointerType.equalSemanticsImpl
boolean equalSemanticsImpl(final Type arg)
Definition: PointerType.java:85
com.jogamp.gluegen.cgram.types.PointerType.getName
String getName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
Definition: PointerType.java:100
com.jogamp.gluegen.cgram.types.PointerType.pointerDepth
final int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i....
Definition: PointerType.java:163
com.jogamp.gluegen.cgram.types.PointerType.PointerType
PointerType(final SizeThunk size, final Type targetType, final int cvAttributes, final ASTLocusTag astLocus)
Definition: PointerType.java:51
com.jogamp.gluegen.cgram.types.PointerType.equalsImpl
boolean equalsImpl(final Type arg)
Definition: PointerType.java:74
com.jogamp.gluegen.cgram.types.PointerType.isFunctionPointer
final boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
Definition: PointerType.java:158
com.jogamp.gluegen.cgram.types.PointerType.isAnon
boolean isAnon()
Definition: PointerType.java:91
com.jogamp.gluegen.cgram.types.SizeThunk
Provides a level of indirection between the definition of a type's size and the absolute value of thi...
Definition: SizeThunk.java:51
com.jogamp.gluegen.cgram.types.Type
Models a C type.
Definition: Type.java:54
com.jogamp.gluegen.cgram.types.Type.getCName
final String getCName()
Returns the name of this type.
Definition: Type.java:132
com.jogamp.gluegen.cgram.types.Type.getCVAttributesString
final String getCVAttributesString()
Returns a string indicating the const/volatile attributes of this type.
Definition: Type.java:554
com.jogamp.gluegen.cgram.types.Type.hashCodeSemantics
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
Definition: Type.java:497
com.jogamp.gluegen.cgram.types.Type.hashCode
final int hashCode()
Hashcode for Types.
Definition: Type.java:446
com.jogamp.gluegen.cgram.types.Type.getBaseType
Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.
Definition: Type.java:588
com.jogamp.gluegen.cgram.types.Type.equalSemantics
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
Definition: Type.java:514
com.jogamp.gluegen.cgram.types.Type.getName
final String getName()
Returns the name of this type.
Definition: Type.java:142
com.jogamp.gluegen.cgram.types.Type.pointerDepth
int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i....
Definition: Type.java:564
com.jogamp.gluegen.cgram.types.Type.isFunction
final boolean isFunction()
Indicates whether this is a FunctionType.
Definition: Type.java:413
com.jogamp.gluegen.cgram.types.Type.visit
void visit(final TypeVisitor visitor)
Traverse this Type and all of its component types; for example, the return type and argument types of...
Definition: Type.java:544
com.jogamp.gluegen.cgram.types.Type.equals
final boolean equals(final Object arg)
Equality test for Types inclusive its given name.
Definition: Type.java:468
com.jogamp.gluegen.cgram.types.Type.asFunction
FunctionType asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.
Definition: Type.java:392
com.jogamp.gluegen.cgram.types.Type.newCVVariant
final Type newCVVariant(final int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.
Definition: Type.java:98
com.jogamp.gluegen.cgram.types.Type.isAnon
boolean isAnon()
Definition: Type.java:127
com.jogamp.gluegen.cgram.types.Type.isTypedef
final boolean isTypedef()
Indicates whether this type is a typedef type, i.e.
Definition: Type.java:352
com.jogamp.gluegen.cgram.types.TypeVisitor
A visitor for Type's visitor model.
Definition: TypeVisitor.java:45