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

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

IntType.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright (c) 2010 JogAmp Community. 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 IntType extends PrimitiveType implements Cloneable {
45
46 private final boolean unsigned;
47 private boolean typedefUnsigned;
48
49 public IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes) {
50 this(name, size, unsigned, cvAttributes, null);
51 }
52
53 public IntType(final String name, final SizeThunk size,
54 final boolean unsigned, final int cvAttributes,
55 final ASTLocusTag astLocus) {
56 super(name, size, cvAttributes, astLocus);
57 this.unsigned = unsigned;
58 this.typedefUnsigned = false;
59 }
60
61 /**
62 * Only for HeaderParser!
63 *
64 * @param name the name
65 * @param size the size
66 * @param unsigned true if this instance is unsigned, not the <i>typedef</i>!
67 * @param cvAttributes the cvAttributes for this instance, not for the <i>typedef</i>!
68 * @param isTypedef true if this instance is a <i>typedef</i> variant
69 * @param typedefUnsigned true if the <i>typedef</i> itself is unsigned
70 * @param astLocus the location in source code
71 */
72 public IntType(final String name, final SizeThunk size,
73 final boolean unsigned, final int cvAttributes,
74 final boolean isTypedef, final boolean typedefUnsigned,
75 final ASTLocusTag astLocus) {
76 super(name, size, cvAttributes, astLocus);
77 this.unsigned = unsigned;
78 if( isTypedef ) {
79 // the 'cvAttributes' are intended for this instance, not the 'typedef cvAttributes'!
80 setTypedef(0);
81 this.typedefUnsigned = typedefUnsigned;
82 } else {
83 this.typedefUnsigned = false;
84 }
85 }
86
87 IntType(final IntType o, final int cvAttributes, final ASTLocusTag astLocus) {
88 super(o, cvAttributes, astLocus);
89 this.unsigned = o.unsigned;
90 this.typedefUnsigned = o.typedefUnsigned;
91 }
92
93 @Override
94 Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
95 return new IntType(this, cvAttributes, astLocus);
96 }
97
98 @Override
99 protected int hashCodeImpl() {
100 // 31 * x == (x << 5) - x
101 int hash = 1;
102 hash = ((hash << 5) - hash) + ( unsigned ? 1 : 0 );
103 return ((hash << 5) - hash) + ( typedefUnsigned ? 1 : 0 );
104 }
105
106 @Override
107 protected boolean equalsImpl(final Type arg) {
108 final IntType t = (IntType) arg;
109 return unsigned == t.unsigned &&
110 typedefUnsigned == t.typedefUnsigned;
111 }
112
113 @Override
114 protected int hashCodeSemanticsImpl() {
115 // 31 * x == (x << 5) - x
116 int hash = 1;
117 if( !relaxedEqSem ) {
118 hash = ((hash << 5) - hash) + ( unsigned ? 1 : 0 );
119 hash = ((hash << 5) - hash) + ( typedefUnsigned ? 1 : 0 );
120 }
121 return hash;
122 }
123
124 @Override
125 protected boolean equalSemanticsImpl(final Type arg) {
126 final IntType t = (IntType) arg;
127 return relaxedEqSem ||
128 ( unsigned == t.unsigned &&
129 typedefUnsigned == t.typedefUnsigned
130 );
131 }
132
133 @Override
134 public IntType asInt() {
135 return this;
136 }
137
138 /** Indicates whether this type is unsigned */
139 public boolean isUnsigned() {
140 return unsigned;
141 }
142
143 @Override
144 public String getCName(final boolean includeCVAttrs) {
145 if ( !unsigned || typedefUnsigned ) {
146 return super.getCName(includeCVAttrs);
147 } else {
148 return "unsigned "+super.getCName(includeCVAttrs);
149 }
150 }
151
152 @Override
153 public String toString() {
154 return getCVAttributesString() + ( unsigned && !typedefUnsigned ? "unsigned " : "") + getCName();
155 }
156
157 @Override
158 public boolean setTypedefName(final String name) {
159 if( super.setTypedefName(name) ) {
160 typedefUnsigned = unsigned;
161 return true;
162 } else {
163 return false;
164 }
165 }
166}
com.jogamp.gluegen.ASTLocusTag
An AST location tag.
Definition: ASTLocusTag.java:33
com.jogamp.gluegen.cgram.types.IntType
Definition: IntType.java:44
com.jogamp.gluegen.cgram.types.IntType.IntType
IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes)
Definition: IntType.java:49
com.jogamp.gluegen.cgram.types.IntType.asInt
IntType asInt()
Casts this to an IntType or returns null if not an IntType.
Definition: IntType.java:134
com.jogamp.gluegen.cgram.types.IntType.toString
String toString()
Returns a string representation of this type.
Definition: IntType.java:153
com.jogamp.gluegen.cgram.types.IntType.hashCodeImpl
int hashCodeImpl()
Definition: IntType.java:99
com.jogamp.gluegen.cgram.types.IntType.equalSemanticsImpl
boolean equalSemanticsImpl(final Type arg)
Definition: IntType.java:125
com.jogamp.gluegen.cgram.types.IntType.setTypedefName
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: IntType.java:158
com.jogamp.gluegen.cgram.types.IntType.equalsImpl
boolean equalsImpl(final Type arg)
Definition: IntType.java:107
com.jogamp.gluegen.cgram.types.IntType.getCName
String getCName(final boolean includeCVAttrs)
Returns the name of this type, optionally including const/volatile attributes.
Definition: IntType.java:144
com.jogamp.gluegen.cgram.types.IntType.IntType
IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes, final boolean isTypedef, final boolean typedefUnsigned, final ASTLocusTag astLocus)
Only for HeaderParser!
Definition: IntType.java:72
com.jogamp.gluegen.cgram.types.IntType.IntType
IntType(final String name, final SizeThunk size, final boolean unsigned, final int cvAttributes, final ASTLocusTag astLocus)
Definition: IntType.java:53
com.jogamp.gluegen.cgram.types.IntType.isUnsigned
boolean isUnsigned()
Indicates whether this type is unsigned.
Definition: IntType.java:139
com.jogamp.gluegen.cgram.types.IntType.hashCodeSemanticsImpl
int hashCodeSemanticsImpl()
Definition: IntType.java:114
com.jogamp.gluegen.cgram.types.PrimitiveType
Definition: PrimitiveType.java:44
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.relaxedEqSem
final boolean relaxedEqSem
Definition: Type.java:55
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