• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 public class CType {
18 
19     String baseType;
20     boolean isConst;
21     boolean isPointer;
22 
CType()23     public CType() {
24     }
25 
CType(String baseType)26     public CType(String baseType) {
27     setBaseType(baseType);
28     }
29 
CType(String baseType, boolean isConst, boolean isPointer)30     public CType(String baseType, boolean isConst, boolean isPointer) {
31     setBaseType(baseType);
32     setIsConst(isConst);
33     setIsPointer(isPointer);
34     }
35 
getDeclaration()36     public String getDeclaration() {
37     return baseType + (isPointer ? " *" : "");
38     }
39 
setIsConst(boolean isConst)40     public void setIsConst(boolean isConst) {
41     this.isConst = isConst;
42     }
43 
isConst()44     public boolean isConst() {
45     return isConst;
46     }
47 
setIsPointer(boolean isPointer)48     public void setIsPointer(boolean isPointer) {
49     this.isPointer = isPointer;
50     }
51 
isPointer()52     public boolean isPointer() {
53     return isPointer;
54     }
55 
isVoid()56     boolean isVoid() {
57     String baseType = getBaseType();
58     return baseType.equals("GLvoid") ||
59         baseType.equals("void");
60     }
61 
isConstCharPointer()62     public boolean isConstCharPointer() {
63         return isConst && isPointer && baseType.equals("char");
64     }
65 
isTypedPointer()66     public boolean isTypedPointer() {
67     return isPointer() && !isVoid() && !isConstCharPointer();
68     }
69 
setBaseType(String baseType)70     public void setBaseType(String baseType) {
71     this.baseType = baseType;
72     }
73 
getBaseType()74     public String getBaseType() {
75     return baseType;
76     }
77 
78     @Override
toString()79     public String toString() {
80     String s = "";
81     if (isConst()) {
82         s += "const ";
83     }
84     s += baseType;
85     if (isPointer()) {
86         s += "*";
87     }
88 
89     return s;
90     }
91 
92     @Override
hashCode()93     public int hashCode() {
94     return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0);
95     }
96 
97     @Override
equals(Object o)98     public boolean equals(Object o) {
99     if (o != null && o instanceof CType) {
100         CType c = (CType)o;
101         return baseType.equals(c.baseType) &&
102         isPointer() == c.isPointer() &&
103         isConst() == c.isConst();
104     }
105     return false;
106     }
107 }
108