1 #ifndef _RSGVARIABLETYPE_HPP
2 #define _RSGVARIABLETYPE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Random Shader Generator
5 * ----------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Variable Type class.
24 *//*--------------------------------------------------------------------*/
26 #include "rsgDefs.hpp"
72 Member (const VariableType& type, const char* name)
73 : m_type(new VariableType(type))
83 Member (const Member& other)
85 , m_name(other.m_name)
88 m_type = new VariableType(*other.m_type);
91 Member& operator= (const Member& other)
99 m_name = other.m_name;
102 m_type = new VariableType(*other.m_type);
107 bool operator!= (const Member& other) const
109 if (m_name != other.m_name)
111 if (!!m_type != !!other.m_type)
113 if (m_type && *m_type != *other.m_type)
118 bool operator== (const Member& other) const
120 return !(*this != other);
123 const VariableType& getType (void) const { return *m_type; }
124 const char* getName (void) const { return m_name.c_str(); }
127 VariableType* m_type;
132 VariableType (Type baseType, int numElements = 0);
133 VariableType (Type baseType, const VariableType& elementType, int numElements);
134 VariableType (Type baseType, const char* typeName);
135 ~VariableType (void);
137 Type getBaseType (void) const { return m_baseType; }
138 Precision getPrecision (void) const { return m_precision; }
139 const char* getTypeName (void) const { return m_typeName.c_str(); }
140 int getNumElements (void) const { return m_numElements; }
141 const VariableType& getElementType (void) const;
143 const std::vector<Member>& getMembers (void) const { return m_members; }
144 std::vector<Member>& getMembers (void) { return m_members; }
146 int getScalarSize (void) const;
147 int getElementScalarOffset (int elementNdx) const;
148 int getMemberScalarOffset (int memberNdx) const;
150 bool operator!= (const VariableType& other) const;
151 bool operator== (const VariableType& other) const;
153 VariableType& operator= (const VariableType& other);
154 VariableType (const VariableType& other);
156 void tokenizeShortType (TokenStream& str) const;
158 bool isStruct (void) const { return m_baseType == TYPE_STRUCT; }
159 bool isArray (void) const { return m_baseType == TYPE_ARRAY; }
160 bool isFloatOrVec (void) const { return m_baseType == TYPE_FLOAT; }
161 bool isIntOrVec (void) const { return m_baseType == TYPE_INT; }
162 bool isBoolOrVec (void) const { return m_baseType == TYPE_BOOL; }
163 bool isSampler (void) const { return m_baseType == TYPE_SAMPLER_2D || m_baseType == TYPE_SAMPLER_CUBE; }
164 bool isVoid (void) const { return m_baseType == TYPE_VOID; }
166 static const VariableType& getScalarType (Type baseType);
170 Precision m_precision;
171 std::string m_typeName;
173 VariableType* m_elementType;
174 std::vector<Member> m_members;
177 inline VariableType::VariableType (void)
178 : m_baseType (TYPE_VOID)
179 , m_precision (PRECISION_NONE)
182 , m_elementType (DE_NULL)
186 inline VariableType::VariableType (Type baseType, int numElements)
187 : m_baseType (baseType)
188 , m_precision (PRECISION_NONE)
190 , m_numElements (numElements)
191 , m_elementType (DE_NULL)
193 DE_ASSERT(baseType != TYPE_ARRAY && baseType != TYPE_STRUCT);
196 inline VariableType::VariableType (Type baseType, const VariableType& elementType, int numElements)
197 : m_baseType (baseType)
198 , m_precision (PRECISION_NONE)
200 , m_numElements (numElements)
201 , m_elementType (new VariableType(elementType))
203 DE_ASSERT(baseType == TYPE_ARRAY);
206 inline VariableType::VariableType (Type baseType, const char* typeName)
207 : m_baseType (baseType)
208 , m_precision (PRECISION_NONE)
209 , m_typeName (typeName)
211 , m_elementType (DE_NULL)
213 DE_ASSERT(baseType == TYPE_STRUCT);
216 inline VariableType::~VariableType (void)
218 delete m_elementType;
223 #endif // _RSGVARIABLETYPE_HPP