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