CType.java revision e09fd9e819c23dc90bca68375645e15544861330
1
2public class CType {
3
4    String baseType;
5    boolean isConst;
6    boolean isPointer;
7
8    public CType() {
9    }
10
11    public CType(String baseType) {
12	setBaseType(baseType);
13    }
14
15    public CType(String baseType, boolean isConst, boolean isPointer) {
16	setBaseType(baseType);
17	setIsConst(isConst);
18	setIsPointer(isPointer);
19    }
20
21    public String getDeclaration() {
22	return baseType + (isPointer ? " *" : "");
23    }
24
25    public void setIsConst(boolean isConst) {
26	this.isConst = isConst;
27    }
28
29    public boolean isConst() {
30	return isConst;
31    }
32
33    public void setIsPointer(boolean isPointer) {
34	this.isPointer = isPointer;
35    }
36
37    public boolean isPointer() {
38	return isPointer;
39    }
40
41    boolean isVoid() {
42	String baseType = getBaseType();
43	return baseType.equals("GLvoid") ||
44	    baseType.equals("void");
45    }
46
47    public boolean isTypedPointer() {
48	return isPointer() && !isVoid();
49    }
50
51    public void setBaseType(String baseType) {
52	this.baseType = baseType;
53    }
54
55    public String getBaseType() {
56	return baseType;
57    }
58
59    public String toString() {
60	String s = "";
61	if (isConst()) {
62	    s += "const ";
63	}
64	s += baseType;
65	if (isPointer()) {
66	    s += "*";
67	}
68
69	return s;
70    }
71
72    public int hashCode() {
73	return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0);
74    }
75
76    public boolean equals(Object o) {
77	if (o != null && o instanceof CType) {
78	    CType c = (CType)o;
79	    return baseType.equals(c.baseType) &&
80		isPointer() == c.isPointer() &&
81		isConst() == c.isConst();
82	}
83	return false;
84    }
85}
86