• 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 
isEGLHandle()56     public boolean isEGLHandle() {
57         if(baseType.equals("EGLContext")
58            || baseType.equals("EGLConfig")
59            || baseType.equals("EGLSurface")
60            || baseType.equals("EGLDisplay")) {
61                return true;
62         }
63         return false;
64     }
65 
isVoid()66     boolean isVoid() {
67     String baseType = getBaseType();
68     return baseType.equals("GLvoid") ||
69         baseType.equals("void");
70     }
71 
isConstCharPointer()72     public boolean isConstCharPointer() {
73         return isConst && isPointer && baseType.equals("char");
74     }
75 
isTypedPointer()76     public boolean isTypedPointer() {
77     return isPointer() && !isVoid() && !isConstCharPointer();
78     }
79 
setBaseType(String baseType)80     public void setBaseType(String baseType) {
81     this.baseType = baseType;
82     }
83 
getBaseType()84     public String getBaseType() {
85     return baseType;
86     }
87 
88     @Override
toString()89     public String toString() {
90     String s = "";
91     if (isConst()) {
92         s += "const ";
93     }
94     s += baseType;
95     if (isPointer()) {
96         s += "*";
97     }
98 
99     return s;
100     }
101 
102     @Override
hashCode()103     public int hashCode() {
104     return baseType.hashCode() ^ (isPointer ? 2 : 0) ^ (isConst ? 1 : 0);
105     }
106 
107     @Override
equals(Object o)108     public boolean equals(Object o) {
109     if (o != null && o instanceof CType) {
110         CType c = (CType)o;
111         return baseType.equals(c.baseType) &&
112         isPointer() == c.isPointer() &&
113         isConst() == c.isConst();
114     }
115     return false;
116     }
117 }
118