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