GlueGen v2.6.0-rc-20250712
GlueGen, Native Binding Generator for Java™ (public API).
BitType.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 */
40
41package com.jogamp.gluegen.cgram.types;
42
43import com.jogamp.gluegen.ASTLocusTag;
44
45/** Represents a bitfield in a struct. */
46
47public class BitType extends IntType implements Cloneable {
48 private final IntType underlyingType;
49 private final int sizeInBits;
50 private final int offset;
51
52 public BitType(final IntType underlyingType, final int sizeInBits, final int lsbOffset,
53 final int cvAttributes, final ASTLocusTag astLocus) {
54 super(underlyingType.getName(), underlyingType.getSize(), underlyingType.isUnsigned(), cvAttributes, astLocus);
55 this.underlyingType = underlyingType;
56 this.sizeInBits = sizeInBits;
57 this.offset = lsbOffset;
58 }
59
60 private BitType(final BitType o, final int cvAttributes, final ASTLocusTag astLocus) {
61 super(o, cvAttributes, astLocus);
62 underlyingType = o.underlyingType;
63 sizeInBits = o.sizeInBits;
64 offset = o.offset;
65 }
66
67 @Override
68 Type newVariantImpl(final boolean newCVVariant, final int cvAttributes, final ASTLocusTag astLocus) {
69 return new BitType(this, cvAttributes, astLocus);
70 }
71
72 @Override
73 protected int hashCodeImpl() {
74 // 31 * x == (x << 5) - x
75 int hash = super.hashCodeImpl();
76 hash = ((hash << 5) - hash) + underlyingType.hashCode();
77 hash = ((hash << 5) - hash) + sizeInBits;
78 return ((hash << 5) - hash) + offset;
79 }
80
81 @Override
82 protected boolean equalsImpl(final Type arg) {
83 final BitType t = (BitType) arg;
84 return super.equalsImpl(arg) &&
85 underlyingType.equals(t.underlyingType) &&
86 sizeInBits == t.sizeInBits &&
87 offset == t.offset;
88 }
89
90 @Override
91 protected int hashCodeSemanticsImpl() {
92 // 31 * x == (x << 5) - x
93 int hash = super.hashCodeSemanticsImpl();
94 hash = ((hash << 5) - hash) + underlyingType.hashCodeSemantics();
95 hash = ((hash << 5) - hash) + sizeInBits;
96 return ((hash << 5) - hash) + offset;
97 }
98
99 @Override
100 protected boolean equalSemanticsImpl(final Type arg) {
101 final BitType t = (BitType) arg;
102 return super.equalSemanticsImpl(arg) &&
103 underlyingType.equalSemantics(t.underlyingType) &&
104 sizeInBits == t.sizeInBits &&
105 offset == t.offset;
106 }
107
108 @Override
109 public BitType asBit() { return this; }
110
111 /** Size in bits of this type. */
112 public int getSizeInBits() {
113 return sizeInBits;
114 }
115
116 /** Offset from the least-significant bit (LSB) of the LSB of this
117 type */
118 public int getOffset() {
119 return offset;
120 }
121
122 @Override
123 public void visit(final TypeVisitor arg) {
124 super.visit(arg);
125 underlyingType.visit(arg);
126 }
127}
Represents a bitfield in a struct.
Definition: BitType.java:47
boolean equalSemanticsImpl(final Type arg)
Definition: BitType.java:100
BitType asBit()
Casts this to a BitType or returns null if not a BitType.
Definition: BitType.java:109
boolean equalsImpl(final Type arg)
Definition: BitType.java:82
BitType(final IntType underlyingType, final int sizeInBits, final int lsbOffset, final int cvAttributes, final ASTLocusTag astLocus)
Definition: BitType.java:52
int getSizeInBits()
Size in bits of this type.
Definition: BitType.java:112
int getOffset()
Offset from the least-significant bit (LSB) of the LSB of this type.
Definition: BitType.java:118
void visit(final TypeVisitor arg)
Traverse this Type and all of its component types; for example, the return type and argument types of...
Definition: BitType.java:123
boolean isUnsigned()
Indicates whether this type is unsigned.
Definition: IntType.java:139
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
Definition: Type.java:497
abstract boolean equalSemanticsImpl(final Type t)
final int hashCode()
Hashcode for Types.
Definition: Type.java:446
abstract boolean equalsImpl(final Type t)
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
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
final SizeThunk getSize()
SizeThunk which computes size of this type in bytes.
Definition: Type.java:360
final Type newCVVariant(final int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.
Definition: Type.java:98
A visitor for Type's visitor model.