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