GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
Type.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 */
40
41package com.jogamp.gluegen.cgram.types;
42
43import com.jogamp.common.os.MachineDataInfo;
44import com.jogamp.gluegen.ASTLocusTag.ASTLocusTagProvider;
45import com.jogamp.gluegen.ASTLocusTag;
46import com.jogamp.gluegen.GlueGen;
47import com.jogamp.gluegen.TypeConfig;
48import com.jogamp.gluegen.cgram.types.TypeComparator.SemanticEqualityOp;
49
50/** Models a C type. Primitive types include int, float, and
51 double. All types have an associated name. Structs and unions are
52 modeled as "compound" types -- composed of fields of primitive or
53 other types. */
54public abstract class Type implements SemanticEqualityOp, ASTLocusTagProvider {
55 public final boolean relaxedEqSem;
56 private final int cvAttributes;
57 final ASTLocusTag astLocus;
58 private String name;
59 private SizeThunk size;
60 private int typedefCVAttributes;
61 private boolean isTypedef;
62 private boolean hasCachedHash;
63 private int cachedHash;
64 private boolean hasCachedSemanticHash;
65 private int cachedSemanticHash;
66
67 protected Type(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus) {
68 setName(name); // -> clearCache()
69 this.relaxedEqSem = TypeConfig.relaxedEqualSemanticsTest();
70 this.cvAttributes = cvAttributes;
71 this.astLocus = astLocus;
72 this.size = size;
73 this.typedefCVAttributes = 0;
74 this.isTypedef = false;
75 }
76 Type(final Type o, final int cvAttributes, final ASTLocusTag astLocus) {
77 this.relaxedEqSem = o.relaxedEqSem;
78 this.cvAttributes = cvAttributes;
79 this.astLocus = astLocus;
80 this.name = o.name;
81 this.size = o.size;
82 this.typedefCVAttributes = o.typedefCVAttributes;
83 this.isTypedef = o.isTypedef;
84 clearCache();
85 }
86
87 protected final void clearCache() {
88 hasCachedHash = false;
89 cachedHash = 0;
90 hasCachedSemanticHash = false;
91 cachedSemanticHash = 0;
92 }
93
94 /**
95 * Return a variant of this type matching the given const/volatile
96 * attributes. May return this object if the attributes match.
97 */
98 public final Type newCVVariant(final int cvAttributes) {
99 if (this.cvAttributes == cvAttributes) {
100 return this;
101 } else {
102 return newVariantImpl(true, cvAttributes, astLocus);
103 }
104 }
105
106 /**
107 * Clones this instance using a new {@link ASTLocusTag}.
108 */
109 public Type clone(final ASTLocusTag newLoc) {
110 return newVariantImpl(true, cvAttributes, newLoc);
111 }
112
113 /**
114 * Create a new variant of this type matching the given parameter
115 * <p>
116 * Implementation <i>must</i> use {@link Type}'s copy-ctor: {@link #Type(Type, int, ASTLocusTag)}!
117 * </p>
118 * @param newCVVariant true if new variant is intended to have new <i>cvAttributes</i>
119 * @param cvAttributes the <i>cvAttributes</i> to be used
120 * @param astLocus the {@link ASTLocusTag} to be used
121 */
122 abstract Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus);
123
124 @Override
125 public final ASTLocusTag getASTLocusTag() { return astLocus; }
126
127 public boolean isAnon() { return null == name; }
128
129 /** Returns the name of this type. The returned string is suitable
130 for use as a type specifier for native C. Does not include any const/volatile
131 attributes. */
132 public final String getCName() { return getCName(false); }
133
134 /** Returns the name of this type, optionally including
135 const/volatile attributes. The returned string is suitable for
136 use as a type specifier for native C. */
137 public String getCName(final boolean includeCVAttrs) { return getName(includeCVAttrs); }
138
139 /** Returns the name of this type. The returned string is suitable
140 for use as a type specifier for Java. Does not include any const/volatile
141 attributes. */
142 public final String getName() { return getName(false); }
143
144 /** Returns the name of this type, optionally including
145 const/volatile attributes. The returned string is suitable for
146 use as a type specifier for Java. */
147 public String getName(final boolean includeCVAttrs) {
148 if (!includeCVAttrs) {
149 return name;
150 }
151 return getCVAttributesString() + name;
152 }
153
154 /**
155 * Returns a string representation of this type.
156 * The returned string is suitable for use as a type specifier for native C.
157 * It does contain an expanded description of structs/unions,
158 * hence may not be suitable for type declarations.
159 */
160 @Override
161 public String toString() {
162 return getCName(true);
163 }
164
165
166 private static StringBuilder append(final StringBuilder sb, final String val, final boolean prepComma) {
167 if( prepComma ) {
168 sb.append(", ");
169 }
170 sb.append(val);
171 return sb;
172 }
173 public final StringBuilder getSignature(StringBuilder sb) {
174 if( null == sb ) {
175 sb = new StringBuilder();
176 }
177 boolean prepComma = false;
178 sb.append("(").append(getClass().getSimpleName()).append(") ");
179 if( isTypedef() ) {
180 sb.append("typedef ");
181 }
182 if( null != name ) {
183 sb.append("'").append(name).append("'");
184 } else {
185 sb.append("ANON");
186 }
187 if ( isFunctionPointer() ) {
188 sb.append(" -> ");
189 final FunctionType ft = getTargetFunction();
190 sb.append(ft.toString(null /* functionName */, null /* callingConvention */, false, true));
191 } else {
192 final Type targetType = getTargetType();
193 if( null != targetType && this != targetType ) {
194 sb.append(" -> ");
195 sb.append("(" + targetType.toString() + ") * " + getCVAttributesString());
196 }
197 }
198
199 if( GlueGen.debug() ) {
200 sb.append(", o=0x"+Integer.toHexString(objHash()));
201 }
202 sb.append(", size");
203 prepComma=true;
204 if( null != size ) {
205 final long mdSize;
206 {
207 long _mdSize = -1;
208 try {
210 } catch (final Exception e) {}
211 mdSize = _mdSize;
212 }
213 sb.append("[fixed ").append(size.hasFixedNativeSize()).append(", lnx64 ").append(mdSize).append("]");
214 } else {
215 sb.append(" ZERO");
216 }
217 {
218 append(sb, "const[", prepComma); prepComma=false;
219 {
220 if( isConstTypedef() ) {
221 append(sb, "typedef", prepComma); prepComma=true;
222 }
223 if( isConstRaw() ) {
224 append(sb, "native", prepComma); prepComma=true;
225 }
226 if( isConst() ) {
227 append(sb, "true]", prepComma);
228 } else {
229 append(sb, "false]", prepComma);
230 }
231 prepComma=true;
232 }
233 append(sb, "is[", prepComma); prepComma=false;
234 {
235 if( isVolatile() ) {
236 append(sb, "volatile ", prepComma); prepComma=true;
237 }
238 if( isPrimitive() ) {
239 append(sb, "primitive", prepComma); prepComma=true;
240 }
241 if( isPointer() ) {
242 append(sb, "pointer*"+pointerDepth(), prepComma); prepComma=true;
243 }
244 if( isArray() ) {
245 append(sb, "array*"+arrayDimension(), prepComma); prepComma=true;
246 }
247 if( isBit() ) {
248 append(sb, "bit", prepComma); prepComma=true;
249 }
250 if( isCompound() ) {
251 append(sb, "struct{", prepComma).append(asCompound().getStructName()).append(": ").append(asCompound().getNumFields());
252 append(sb, "}", prepComma); prepComma=true;
253 }
254 if( isDouble() ) {
255 append(sb, "double", prepComma); prepComma=true;
256 }
257 if( isEnum() ) {
258 final EnumType eT = asEnum();
259 append(sb, "enum ", prepComma).append(" [").append(eT.getUnderlyingType()).append("] {").append(eT.getNumEnumerates()).append(": ");
260 eT.appendEnums(sb, false);
261 prepComma=true;
262 }
263 if( isFloat() ) {
264 append(sb, "float", prepComma); prepComma=true;
265 }
266 if( isFunction() ) {
267 append(sb, "function", prepComma); prepComma=true;
268 }
269 if( isFunctionPointer() ) {
270 append(sb, "funcPointer", prepComma); prepComma=true;
271 }
272 if( isInt() ) {
273 append(sb, "int", prepComma); prepComma=true;
274 }
275 if( isVoid() ) {
276 append(sb, "void", prepComma); prepComma=true;
277 }
278 }
279 append(sb, "]", false); prepComma=true;
280 }
281 return sb;
282 }
283
284 // For debugging
285 public final String getDebugString() {
286 final StringBuilder sb = new StringBuilder();
287 sb.append("CType[");
288 getSignature(sb);
289 sb.append("]");
290 return sb.toString();
291 }
292 private final int objHash() { return super.hashCode(); }
293
294
295 /**
296 * Returns {@code true} if given {@code name} is not {@code null}
297 * and has a length &gt; 0. In this case this instance's names will
298 * be set to the internalized version.
299 * <p>
300 * Otherwise method returns {@code false}
301 * and this instance's name will be set to {@code null}.
302 * </p>
303 * <p>
304 * Method issues {@link #clearCache()}, to force re-evaluation
305 * of hashes.
306 * </p>
307 */
308 private final boolean setName(final String name) {
309 clearCache();
310 if( null == name || 0 == name.length() ) {
311 this.name = name;
312 return false;
313 } else {
314 this.name = name.intern();
315 return true;
316 }
317 }
318
319 /**
320 * Set the typedef name of this type and renders this type a typedef,
321 * if given {@code name} has a length.
322 * <p>
323 * Method issues {@link #clearCache()}, to force re-evaluation
324 * of hashes.
325 * </p>
326 */
327 public boolean setTypedefName(final String name) {
328 if( setName(name) ) {
329 // Capture the const/volatile attributes at the time of typedef so
330 // we don't redundantly repeat them in the CV attributes string
331 typedefCVAttributes = cvAttributes;
332 isTypedef = true;
333 return true;
334 } else {
335 return false;
336 }
337 }
338 final void setTypedef(final int typedefedCVAttributes) {
339 this.name = this.name.intern(); // just make sure ..
340 this.typedefCVAttributes = typedefedCVAttributes;
341 this.isTypedef = true;
342 clearCache();
343 }
344 final int getTypedefCVAttributes() {
345 return typedefCVAttributes;
346 }
347
348 /**
349 * Indicates whether this type is a typedef type,
350 * i.e. declared via {@link #setTypedefName(String)}.
351 */
352 public final boolean isTypedef() {
353 return isTypedef;
354 }
355
356 /** Returns true if {@link #getSize()} is not null, otherwise false. */
357 public final boolean hasSize() { return null != size; }
358
359 /** SizeThunk which computes size of this type in bytes. */
360 public final SizeThunk getSize() { return size; }
361 /** Size of this type in bytes according to the given MachineDataInfo. */
362 public final long getSize(final MachineDataInfo machDesc) {
363 final SizeThunk thunk = getSize();
364 if (thunk == null) {
365 throw new RuntimeException("No size set for type \"" + getName() + "\"");
366 }
367 return thunk.computeSize(machDesc);
368 }
369 /** Set the size of this type; only available for CompoundTypes. */
370 final void setSize(final SizeThunk size) {
371 this.size = size;
372 clearCache();
373 }
374
375 /** Casts this to a BitType or returns null if not a BitType. */
376 public BitType asBit() { return null; }
377 /** Casts this to an IntType or returns null if not an IntType. */
378 public IntType asInt() { return null; }
379 /** Casts this to an EnumType or returns null if not an EnumType. */
380 public EnumType asEnum() { return null; }
381 /** Casts this to a FloatType or returns null if not a FloatType. */
382 public FloatType asFloat() { return null; }
383 /** Casts this to a DoubleType or returns null if not a DoubleType. */
384 public DoubleType asDouble() { return null; }
385 /** Casts this to a PointerType or returns null if not a PointerType. */
386 public PointerType asPointer() { return null; }
387 /** Casts this to an ArrayType or returns null if not an ArrayType. */
388 public ArrayType asArray() { return null; }
389 /** Casts this to a CompoundType or returns null if not a CompoundType. */
390 public CompoundType asCompound() { return null; }
391 /** Casts this to a FunctionType or returns null if not a FunctionType. */
392 public FunctionType asFunction() { return null; }
393 /** Casts this to a VoidType or returns null if not a VoidType. */
394 public VoidType asVoid() { return null; }
395
396 /** Indicates whether this is a BitType. */
397 public final boolean isBit() { return (asBit() != null); }
398 /** Indicates whether this is an IntType. */
399 public final boolean isInt() { return (asInt() != null); }
400 /** Indicates whether this is an EnumType. */
401 public final boolean isEnum() { return (asEnum() != null); }
402 /** Indicates whether this is a FloatType. */
403 public final boolean isFloat() { return (asFloat() != null); }
404 /** Indicates whether this is a DoubleType. */
405 public final boolean isDouble() { return (asDouble() != null); }
406 /** Indicates whether this is a PointerType. */
407 public final boolean isPointer() { return (asPointer() != null); }
408 /** Indicates whether this is an ArrayType. */
409 public final boolean isArray() { return (asArray() != null); }
410 /** Indicates whether this is a CompoundType. */
411 public final boolean isCompound() { return (asCompound() != null); }
412 /** Indicates whether this is a FunctionType. */
413 public final boolean isFunction() { return (asFunction() != null); }
414 /** Indicates whether this is a VoidType. */
415 public final boolean isVoid() { return (asVoid() != null); }
416
417 /** Indicates whether this type is volatile. */
418 public final boolean isVolatile() { return 0 != ( ( cvAttributes & ~typedefCVAttributes ) & CVAttributes.VOLATILE ); }
419 /** Indicates whether this type is const. */
420 public final boolean isConst() { return 0 != ( ( cvAttributes & ~typedefCVAttributes ) & CVAttributes.CONST ); }
421
422 private final boolean isConstTypedef() { return 0 != ( typedefCVAttributes & CVAttributes.CONST ); }
423 private final boolean isConstRaw() { return 0 != ( cvAttributes & CVAttributes.CONST ); }
424
425 /** Indicates whether this type is a primitive type. */
426 public boolean isPrimitive(){ return false; }
427
428 /** Convenience routine indicating whether this Type is a pointer to
429 a function. */
430 public boolean isFunctionPointer() {
431 return false;
432 }
433
434 /**
435 * Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.
436 * <p>
437 * Note: Intermediate 'const' qualifier are not considered, e.g. const pointer.
438 * </p>
439 */
440 public final boolean isBaseTypeConst() {
441 return getBaseType().isConst();
442 }
443
444 /** Hashcode for Types. */
445 @Override
446 public final int hashCode() {
447 if( !hasCachedHash ) {
448 // 31 * x == (x << 5) - x
449 int hash = 31 + ( isTypedef ? 1 : 0 );
450 hash = ((hash << 5) - hash) + ( null != size ? size.hashCode() : 0 );
451 hash = ((hash << 5) - hash) + cvAttributes;
452 hash = ((hash << 5) - hash) + typedefCVAttributes;
453 hash = ((hash << 5) - hash) + ( null != name ? name.hashCode() : 0 );
454 if( !isTypedef ) {
455 hash = ((hash << 5) - hash) + hashCodeImpl();
456 }
457 cachedHash = hash;
458 hasCachedHash = true;
459 }
460 return cachedHash;
461 }
462 protected abstract int hashCodeImpl();
463
464 /**
465 * Equality test for Types inclusive its given {@link #getName() name}.
466 */
467 @Override
468 public final boolean equals(final Object arg) {
469 if (arg == this) {
470 return true;
471 } else if ( !getClass().isInstance(arg) ) { // implies null == arg || !(arg instanceof Type)
472 return false;
473 } else {
474 final Type t = (Type)arg;
475 if( isTypedef == t.isTypedef &&
476 ( ( null != size && size.equals(t.size) ) ||
477 ( null == size && null == t.size )
478 ) &&
479 cvAttributes == t.cvAttributes &&
480 typedefCVAttributes == t.typedefCVAttributes &&
481 ( null == name ? null == t.name : name.equals(t.name) )
482 )
483 {
484 if( !isTypedef ) {
485 return equalsImpl(t);
486 } else {
487 return true;
488 }
489 } else {
490 return false;
491 }
492 }
493 }
494 protected abstract boolean equalsImpl(final Type t);
495
496 @Override
497 public final int hashCodeSemantics() {
498 if( !hasCachedSemanticHash ) {
499 // 31 * x == (x << 5) - x
500 int hash = 31 + ( null != size ? size.hashCodeSemantics() : 0 );
501 if( !relaxedEqSem ) {
502 hash = ((hash << 5) - hash) + cvAttributes;
503 hash = ((hash << 5) - hash) + typedefCVAttributes;
504 }
505 hash = ((hash << 5) - hash) + hashCodeSemanticsImpl();
506 cachedSemanticHash = hash;
507 hasCachedSemanticHash = true;
508 }
509 return cachedSemanticHash;
510 }
511 protected abstract int hashCodeSemanticsImpl();
512
513 @Override
514 public final boolean equalSemantics(final SemanticEqualityOp arg) {
515 if (arg == this) {
516 return true;
517 } else if ( !(arg instanceof Type) ||
518 !getClass().isInstance(arg) ) { // implies null == arg
519 return false;
520 } else {
521 final Type t = (Type) arg;
522 if( ( ( null != size && size.equalSemantics(t.size) ) ||
523 ( null == size && null == t.size )
524 ) &&
525 ( relaxedEqSem ||
526 ( cvAttributes == t.cvAttributes &&
527 typedefCVAttributes == t.typedefCVAttributes
528 )
529 )
530 )
531 {
532 return equalSemanticsImpl(t);
533 } else {
534 return false;
535 }
536 }
537 }
538 protected abstract boolean equalSemanticsImpl(final Type t);
539
540 /**
541 * Traverse this {@link Type} and all of its component types; for
542 * example, the return type and argument types of a FunctionType.
543 */
544 public void visit(final TypeVisitor visitor) {
545 visitor.visitType(this);
546 }
547
548 public final int getCVAttributes() {
549 return cvAttributes;
550 }
551
552 /** Returns a string indicating the const/volatile attributes of
553 this type. */
554 public final String getCVAttributesString() {
555 if (isConst() && isVolatile()) return "const volatile ";
556 if (isConst()) return "const ";
557 if (isVolatile()) return "volatile ";
558 return "";
559 }
560
561 /** Helper method for determining how many pointer indirections this
562 type represents (i.e., "void **" returns 2). Returns 0 if this
563 type is not a pointer type. */
564 public int pointerDepth() {
565 return 0;
566 }
567
568 /** Helper method for determining how many array dimentions this
569 type represents (i.e., "char[][]" returns 2). Returns 0 if this
570 type is not an array type. */
571 public int arrayDimension() {
572 return 0;
573 }
574
575 /**
576 * Helper method to returns the bottom-most element type of this type,
577 * i.e. returns `{@code type}` if this-type is `{@code type}*`, `{@code type}**`, `{@code type}[]` or `{@code type}[][]`.
578 * <p>
579 * If this is a multidimensional array or pointer method returns the bottom-most element type,
580 * otherwise this.
581 * </p>
582 * <p>
583 * In case a {@link #isFunctionPointer()} type is reached, traversing ends and the function {@link PointerType} is returned.
584 * </p>
585 * @see #getTargetType()
586 * @see #getTargetFunction()
587 */
588 public Type getBaseType() {
589 return this;
590 }
591
592 /**
593 * Helper method to returns the target type of this type, in case another type is being referenced,
594 * i.e. returns `{@code type}` if this-type is `{@code type}*` or `{@code type}[]`
595 * and returns `{@code type}*` if this-type is `{@code type}**` or `{@code type}[][]`.
596 * <p>
597 * If this is an array or pointer method returns the next target element type, otherwise `this`.
598 * </p>
599 * <p>
600 * In this is a {@link #isFunctionPointer()} type, `this` function {@link PointerType} is returned.
601 * </p>
602 * @see #getBaseType()
603 * @see #getTargetFunction()
604 */
606 return this;
607 }
608
609 /**
610 * Return {@link #getBaseType()} if {@link #isArray()} or returns {@link #getTargetType()} otherwise.
611 */
613 return this;
614 }
615
616 /**
617 * Returns the target {@link FunctionType} if this type is {@link #isFunctionPointer()}.
618 */
619 public FunctionType getTargetFunction() { return null; }
620
621}
Machine data description for alignment and size onle, see com.jogamp.gluegen.
Glue code generator for C functions and data structures.
Definition: GlueGen.java:59
Static Type config helper binding JavaConfiguration#relaxedEqualSemanticsTest() system wide.
Definition: TypeConfig.java:37
Represents a bitfield in a struct.
Definition: BitType.java:47
Models all compound types, i.e., those containing fields: structs and unions.
Represents a double-word floating-point type (C type "double".)
Definition: DoubleType.java:45
Describes enumerated types.
Definition: EnumType.java:54
int getNumEnumerates()
Number of enumerates defined in this enum.
Definition: EnumType.java:189
StringBuilder appendEnums(final StringBuilder sb, final boolean cr)
Definition: EnumType.java:236
Represents a single-word floating-point type (C type "float".)
Definition: FloatType.java:47
Describes a function type, used to model both function declarations and (via PointerType) function po...
String toString()
Returns a string representation of this type.
Provides a level of indirection between the definition of a type's size and the absolute value of thi...
Definition: SizeThunk.java:51
final boolean equals(final Object arg)
Definition: SizeThunk.java:86
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
Definition: SizeThunk.java:105
abstract long computeSize(MachineDataInfo machDesc)
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
Definition: SizeThunk.java:98
final String getCName()
Returns the name of this type.
Definition: Type.java:132
final boolean isArray()
Indicates whether this is an ArrayType.
Definition: Type.java:409
final String getCVAttributesString()
Returns a string indicating the const/volatile attributes of this type.
Definition: Type.java:554
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
Definition: Type.java:497
final boolean isInt()
Indicates whether this is an IntType.
Definition: Type.java:399
IntType asInt()
Casts this to an IntType or returns null if not an IntType.
Definition: Type.java:378
Type(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus)
Definition: Type.java:67
BitType asBit()
Casts this to a BitType or returns null if not a BitType.
Definition: Type.java:376
final StringBuilder getSignature(StringBuilder sb)
Definition: Type.java:173
abstract boolean equalSemanticsImpl(final Type t)
final int hashCode()
Hashcode for Types.
Definition: Type.java:446
final boolean isVoid()
Indicates whether this is a VoidType.
Definition: Type.java:415
Type clone(final ASTLocusTag newLoc)
Clones this instance using a new ASTLocusTag.
Definition: Type.java:109
final boolean isBaseTypeConst()
Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.
Definition: Type.java:440
final ASTLocusTag getASTLocusTag()
Returns this instance's ASTLocusTag, if available, otherwise returns null.
Definition: Type.java:125
abstract boolean equalsImpl(final Type t)
Type getArrayBaseOrPointerTargetType()
Return getBaseType() if isArray() or returns getTargetType() otherwise.
Definition: Type.java:612
final boolean isConst()
Indicates whether this type is const.
Definition: Type.java:420
Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.
Definition: Type.java:588
VoidType asVoid()
Casts this to a VoidType or returns null if not a VoidType.
Definition: Type.java:394
int arrayDimension()
Helper method for determining how many array dimentions this type represents (i.e....
Definition: Type.java:571
DoubleType asDouble()
Casts this to a DoubleType or returns null if not a DoubleType.
Definition: Type.java:384
EnumType asEnum()
Casts this to an EnumType or returns null if not an EnumType.
Definition: Type.java:380
boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
Definition: Type.java:430
final boolean isVolatile()
Indicates whether this type is volatile.
Definition: Type.java:418
String getCName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
Definition: Type.java:137
PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
Definition: Type.java:386
final boolean isFloat()
Indicates whether this is a FloatType.
Definition: Type.java:403
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
Definition: Type.java:514
final String getName()
Returns the name of this type.
Definition: Type.java:142
boolean setTypedefName(final String name)
Set the typedef name of this type and renders this type a typedef, if given name has a length.
Definition: Type.java:327
int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i....
Definition: Type.java:564
String toString()
Returns a string representation of this type.
Definition: Type.java:161
FunctionType getTargetFunction()
Returns the target FunctionType if this type is isFunctionPointer().
Definition: Type.java:619
final boolean isFunction()
Indicates whether this is a FunctionType.
Definition: Type.java:413
Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
Definition: Type.java:605
final boolean hasSize()
Returns true if getSize() is not null, otherwise false.
Definition: Type.java:357
boolean isPrimitive()
Indicates whether this type is a primitive type.
Definition: Type.java:426
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
final boolean equals(final Object arg)
Equality test for Types inclusive its given name.
Definition: Type.java:468
FloatType asFloat()
Casts this to a FloatType or returns null if not a FloatType.
Definition: Type.java:382
final SizeThunk getSize()
SizeThunk which computes size of this type in bytes.
Definition: Type.java:360
final boolean isDouble()
Indicates whether this is a DoubleType.
Definition: Type.java:405
FunctionType asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.
Definition: Type.java:392
final boolean isEnum()
Indicates whether this is an EnumType.
Definition: Type.java:401
final Type newCVVariant(final int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.
Definition: Type.java:98
ArrayType asArray()
Casts this to an ArrayType or returns null if not an ArrayType.
Definition: Type.java:388
final boolean isPointer()
Indicates whether this is a PointerType.
Definition: Type.java:407
String getName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
Definition: Type.java:147
CompoundType asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.
Definition: Type.java:390
final boolean isBit()
Indicates whether this is a BitType.
Definition: Type.java:397
final long getSize(final MachineDataInfo machDesc)
Size of this type in bytes according to the given MachineDataInfo.
Definition: Type.java:362
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
Static enumeration of MachineDataInfo instances used for high performance data size and alignment loo...
Interface tag for ASTLocusTag provider.
Enumeration for const/volatile attributes.
Supports semantic equality and hash functions for types.
A visitor for Type's visitor model.
void visitType(Type t)
Visiting the given Type.