blob: 8c56559af0cd8e8257cc59a39a992dde2b104d68 [file] [log] [blame]
zonr6315f762010-10-05 15:35:14 +08001#ifndef _SLANG_COMPILER_RS_EXPORT_TYPE_H
2#define _SLANG_COMPILER_RS_EXPORT_TYPE_H
Shih-wei Liao462aefd2010-06-04 15:32:04 -07003
Shih-wei Liao9ef2f782010-10-01 12:31:37 -07004#include <set>
5#include <list>
6#include <string>
7
zonr6315f762010-10-05 15:35:14 +08008#include "llvm/ADT/StringRef.h"
9#include "llvm/ADT/StringMap.h"
10#include "llvm/ADT/SmallPtrSet.h"
11
12#include "clang/AST/Type.h"
13#include "clang/AST/Decl.h"
14
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070015#define GET_CANONICAL_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080016 (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr())
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070017#define UNSAFE_CAST_TYPE(TT, T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080018 static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr())
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070019#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080020 (((T) == NULL) ? NULL : \
21 GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070022#define GET_POINTEE_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080023 (((T) == NULL) ? NULL : \
24 GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr()))
25#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T) \
26 (((T) == NULL) ? NULL : \
27 GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
Zonr Chang0da0a7d2010-10-05 21:26:37 +080028#define DUMMY_RS_TYPE_NAME_PREFIX "<"
29#define DUMMY_RS_TYPE_NAME_POSTFIX ">"
Zonr Chang2e1dba62010-10-05 22:20:11 +080030#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE \
31 DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX
Shih-wei Liao462aefd2010-06-04 15:32:04 -070032
33namespace llvm {
zonr6315f762010-10-05 15:35:14 +080034 class Type;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070035} // namespace llvm
Shih-wei Liao462aefd2010-06-04 15:32:04 -070036
37namespace slang {
38
zonr6315f762010-10-05 15:35:14 +080039 class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070040
Shih-wei Liao462aefd2010-06-04 15:32:04 -070041class RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070042 friend class RSExportElement;
43 public:
44 typedef enum {
45 ExportClassPrimitive,
46 ExportClassPointer,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070047 ExportClassVector,
Zonr Chang92b344a2010-10-05 20:39:03 +080048 ExportClassMatrix,
Zonr Chang2e1dba62010-10-05 22:20:11 +080049 ExportClassConstantArray,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070050 ExportClassRecord
51 } ExportClass;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070052
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070053 private:
54 RSContext *mContext;
Zonr Chang6b6320a2010-10-05 22:42:01 +080055 ExportClass mClass;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070056 std::string mName;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070057
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070058 // Cache the result after calling convertToLLVMType() at the first time
59 mutable const llvm::Type *mLLVMType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070060
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070061 protected:
Zonr Chang6b6320a2010-10-05 22:42:01 +080062 RSExportType(RSContext *Context,
63 ExportClass Class,
64 const llvm::StringRef &Name);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070065
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070066 // Let's make it private since there're some prerequisites to call this
67 // function.
68 //
69 // @T was normalized by calling RSExportType::TypeExportable().
zonr6315f762010-10-05 15:35:14 +080070 // @TypeName was retrieve from RSExportType::GetTypeName() before calling
71 // this.
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070072 //
73 static RSExportType *Create(RSContext *Context,
74 const clang::Type *T,
zonr6315f762010-10-05 15:35:14 +080075 const llvm::StringRef &TypeName);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070076
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070077 static llvm::StringRef GetTypeName(const clang::Type *T);
78 // Return the type that can be used to create RSExportType, will always return
79 // the canonical type
80 static const clang::Type
zonr6315f762010-10-05 15:35:14 +080081 *TypeExportable(const clang::Type *T,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070082 // Contain the checked type for recursion
83 llvm::SmallPtrSet<const clang::Type*, 8> &SPS);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070084
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070085 // This function convert the RSExportType to LLVM type. Actually, it should be
86 // "convert Clang type to LLVM type." However, clang doesn't make this API
87 // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
88 //
89 // Once we can get LLVM type, we can use LLVM to get alignment information,
90 // allocation size of a given type and structure layout that LLVM used
91 // (all of these information are target dependent) without dealing with these
92 // by ourselves.
93 virtual const llvm::Type *convertToLLVMType() const = 0;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070094
zonr6315f762010-10-05 15:35:14 +080095 virtual ~RSExportType() {}
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070096 public:
97 static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName);
98 // @T may not be normalized
99 static RSExportType *Create(RSContext *Context, const clang::Type *T);
100 static RSExportType *CreateFromDecl(RSContext *Context,
101 const clang::VarDecl *VD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700102
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700103 static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700104
Zonr Chang6b6320a2010-10-05 22:42:01 +0800105 inline ExportClass getClass() const { return mClass; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700106
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700107 inline const llvm::Type *getLLVMType() const {
108 if (mLLVMType == NULL)
109 mLLVMType = convertToLLVMType();
110 return mLLVMType;
111 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700112
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700113 // Return the number of bits necessary to hold the specified RSExportType
114 static size_t GetTypeStoreSize(const RSExportType *ET);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700115
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700116 // The size of allocation of specified RSExportType (alignment considered)
117 static size_t GetTypeAllocSize(const RSExportType *ET);
118 static unsigned char GetTypeAlignment(const RSExportType *ET);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700119
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700120 const std::string &getName() const { return mName; }
121 inline RSContext *getRSContext() const { return mContext; }
122}; // RSExportType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700123
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700124// Primitive types
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700125class RSExportPrimitiveType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700126 friend class RSExportType;
127 friend class RSExportElement;
128 public:
129 // From graphics/java/android/renderscript/Element.java: Element.DataType
130 typedef enum {
131 DataTypeUnknown = -1,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700132
Shih-wei Liao91a37832010-10-03 19:11:51 -0700133 DataTypeFloat16 = 0,
134 DataTypeFloat32,
135 DataTypeFloat64,
136 DataTypeSigned8,
137 DataTypeSigned16,
138 DataTypeSigned32,
139 DataTypeSigned64,
140 DataTypeUnsigned8,
141 DataTypeUnsigned16,
142 DataTypeUnsigned32,
143 DataTypeUnSigned64,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700144
Shih-wei Liao91a37832010-10-03 19:11:51 -0700145 DataTypeBoolean,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700146
Shih-wei Liao91a37832010-10-03 19:11:51 -0700147 DataTypeUnsigned565,
148 DataTypeUnsigned5551,
149 DataTypeUnsigned4444,
Shih-wei Liaodd35e492010-06-21 14:42:40 -0700150
Zonr Chang92b344a2010-10-05 20:39:03 +0800151 // Actually, there's no any instance of RSExportPrimitiveType which mType
152 // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
153 // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
154 // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
155 // RSExportMatrixType.
Shih-wei Liao91a37832010-10-03 19:11:51 -0700156 DataTypeRSMatrix2x2,
157 DataTypeRSMatrix3x3,
158 DataTypeRSMatrix4x4,
159
160 DataTypeRSElement,
161 DataTypeRSType,
162 DataTypeRSAllocation,
163 DataTypeRSSampler,
164 DataTypeRSScript,
165 DataTypeRSMesh,
166 DataTypeRSProgramFragment,
167 DataTypeRSProgramVertex,
168 DataTypeRSProgramRaster,
169 DataTypeRSProgramStore,
170 DataTypeRSFont,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700171
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700172 DataTypeMax
173 } DataType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700174
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700175 // From graphics/java/android/renderscript/Element.java: Element.DataKind
176 typedef enum {
Shih-wei Liao91a37832010-10-03 19:11:51 -0700177 DataKindUser,
178 DataKindPixelL,
179 DataKindPixelA,
180 DataKindPixelLA,
181 DataKindPixelRGB,
182 DataKindPixelRGBA
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700183 } DataKind;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700184
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700185 private:
186 DataType mType;
187 DataKind mKind;
188 bool mNormalized;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700189
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700190 typedef llvm::StringMap<DataType> RSObjectTypeMapTy;
191 static RSObjectTypeMapTy *RSObjectTypeMap;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700192
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700193 static llvm::Type *RSObjectLLVMType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700194
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700195 static const size_t SizeOfDataTypeInBits[];
196 // @T was normalized by calling RSExportType::TypeExportable() before calling
197 // this.
198 // @TypeName was retrieved from RSExportType::GetTypeName() before calling
199 // this
200 static RSExportPrimitiveType *Create(RSContext *Context,
201 const clang::Type *T,
202 const llvm::StringRef &TypeName,
203 DataKind DK = DataKindUser,
204 bool Normalized = false);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700205
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700206 protected:
207 // T is normalized by calling RSExportType::TypeExportable() before
208 // calling this
209 static bool IsPrimitiveType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700210
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700211 static DataType GetDataType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700212
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700213 RSExportPrimitiveType(RSContext *Context,
Zonr Chang6b6320a2010-10-05 22:42:01 +0800214 // for derived class to set their type class
215 ExportClass Class,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700216 const llvm::StringRef &Name,
217 DataType DT,
218 DataKind DK,
zonr6315f762010-10-05 15:35:14 +0800219 bool Normalized)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800220 : RSExportType(Context, Class, Name),
zonr6315f762010-10-05 15:35:14 +0800221 mType(DT),
222 mKind(DK),
223 mNormalized(Normalized) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700224 return;
225 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700226
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700227 virtual const llvm::Type *convertToLLVMType() const;
228 public:
229 // @T may not be normalized
230 static RSExportPrimitiveType *Create(RSContext *Context,
231 const clang::Type *T,
232 DataKind DK = DataKindUser);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700233
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700234 static DataType GetRSObjectType(const llvm::StringRef &TypeName);
235 static DataType GetRSObjectType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700236
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700237 static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700238
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700239 inline DataType getType() const { return mType; }
240 inline DataKind getKind() const { return mKind; }
241 inline bool isRSObjectType() const {
242 return ((mType >= DataTypeRSElement) && (mType < DataTypeMax));
243 }
244}; // RSExportPrimitiveType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700245
246
247class RSExportPointerType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700248 friend class RSExportType;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700249 friend class RSExportFunc;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700250 private:
251 const RSExportType *mPointeeType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700252
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700253 RSExportPointerType(RSContext *Context,
254 const llvm::StringRef &Name,
zonr6315f762010-10-05 15:35:14 +0800255 const RSExportType *PointeeType)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800256 : RSExportType(Context, ExportClassPointer, Name),
zonr6315f762010-10-05 15:35:14 +0800257 mPointeeType(PointeeType) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700258 return;
259 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700260
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700261 // @PT was normalized by calling RSExportType::TypeExportable() before calling
262 // this.
263 static RSExportPointerType *Create(RSContext *Context,
264 const clang::PointerType *PT,
265 const llvm::StringRef &TypeName);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700266
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700267 virtual const llvm::Type *convertToLLVMType() const;
268 public:
269 static const clang::Type *IntegerType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700270
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700271 inline const RSExportType *getPointeeType() const { return mPointeeType; }
272}; // RSExportPointerType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700273
274
275class RSExportVectorType : public RSExportPrimitiveType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700276 friend class RSExportType;
277 friend class RSExportElement;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700278 private:
Zonr Chang92b344a2010-10-05 20:39:03 +0800279 unsigned mNumElement; // number of element
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700280
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700281 RSExportVectorType(RSContext *Context,
282 const llvm::StringRef &Name,
283 DataType DT,
284 DataKind DK,
285 bool Normalized,
Zonr Chang92b344a2010-10-05 20:39:03 +0800286 unsigned NumElement)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800287 : RSExportPrimitiveType(Context, ExportClassVector, Name,
288 DT, DK, Normalized),
zonr6315f762010-10-05 15:35:14 +0800289 mNumElement(NumElement) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700290 return;
291 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700292
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700293 // @EVT was normalized by calling RSExportType::TypeExportable() before
294 // calling this.
295 static RSExportVectorType *Create(RSContext *Context,
296 const clang::ExtVectorType *EVT,
297 const llvm::StringRef &TypeName,
298 DataKind DK = DataKindUser,
299 bool Normalized = false);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700300
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700301 static const char *VectorTypeNameStore[][3];
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700302
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700303 virtual const llvm::Type *convertToLLVMType() const;
304 public:
305 static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700306
Zonr Chang92b344a2010-10-05 20:39:03 +0800307 inline unsigned getNumElement() const { return mNumElement; }
308};
309
310// Only *square* *float* matrix is supported by now.
311//
312// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
313// form *exactly*:
314// typedef struct {
315// float m[{NxN}];
316// } rs_matrixNxN;
317//
318// where mDim will be N.
319class RSExportMatrixType : public RSExportType {
320 friend class RSExportType;
321 private:
Zonr Chang2e1dba62010-10-05 22:20:11 +0800322 unsigned mDim; // dimension
Zonr Chang92b344a2010-10-05 20:39:03 +0800323
324 RSExportMatrixType(RSContext *Context,
325 const llvm::StringRef &Name,
326 unsigned Dim)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800327 : RSExportType(Context, ExportClassMatrix, Name),
Zonr Chang92b344a2010-10-05 20:39:03 +0800328 mDim(Dim) {
329 return;
330 }
331
332 virtual const llvm::Type *convertToLLVMType() const;
333 public:
Zonr Chang92b344a2010-10-05 20:39:03 +0800334 // @RT was normalized by calling RSExportType::TypeExportable() before
335 // calling this.
336 static RSExportMatrixType *Create(RSContext *Context,
337 const clang::RecordType *RT,
338 const llvm::StringRef &TypeName,
339 unsigned Dim);
340
341 inline unsigned getDim() const { return mDim; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700342};
343
Zonr Chang2e1dba62010-10-05 22:20:11 +0800344class RSExportConstantArrayType : public RSExportType {
345 friend class RSExportType;
346 private:
347 const RSExportType *mElementType; // Array element type
348 unsigned mSize; // Array size
349
350 RSExportConstantArrayType(RSContext *Context,
351 const RSExportType *ElementType,
352 unsigned Size)
353 : RSExportType(Context,
Zonr Chang6b6320a2010-10-05 22:42:01 +0800354 ExportClassConstantArray,
Zonr Chang2e1dba62010-10-05 22:20:11 +0800355 DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
356 mElementType(ElementType),
357 mSize(Size) {
358 return;
359 }
360
361 // @CAT was normalized by calling RSExportType::TypeExportable() before
362 // calling this.
363 static RSExportConstantArrayType *Create(RSContext *Context,
364 const clang::ConstantArrayType *CAT);
365
366 virtual const llvm::Type *convertToLLVMType() const;
367 public:
Zonr Chang2e1dba62010-10-05 22:20:11 +0800368 inline unsigned getSize() const { return mSize; }
369 inline const RSExportType *getElementType() const { return mElementType; }
370};
371
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700372class RSExportRecordType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700373 friend class RSExportType;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700374 public:
375 class Field {
376 private:
377 const RSExportType *mType;
378 // Field name
379 std::string mName;
380 // Link to the struct that contain this field
381 const RSExportRecordType *mParent;
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800382 // Offset in the container
383 size_t mOffset;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700384
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700385 public:
386 Field(const RSExportType *T,
387 const llvm::StringRef &Name,
388 const RSExportRecordType *Parent,
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800389 size_t Offset)
zonr6315f762010-10-05 15:35:14 +0800390 : mType(T),
391 mName(Name.data(), Name.size()),
392 mParent(Parent),
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800393 mOffset(Offset) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700394 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700395 }
396
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700397 inline const RSExportRecordType *getParent() const { return mParent; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700398 inline const RSExportType *getType() const { return mType; }
399 inline const std::string &getName() const { return mName; }
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800400 inline size_t getOffsetInParent() const { return mOffset; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700401 };
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700402
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700403 typedef std::list<const Field*>::const_iterator const_field_iterator;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700404
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700405 inline const_field_iterator fields_begin() const {
406 return this->mFields.begin();
407 }
408 inline const_field_iterator fields_end() const {
409 return this->mFields.end();
410 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700411
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700412 private:
413 std::list<const Field*> mFields;
414 bool mIsPacked;
415 // Artificial export struct type is not exported by user (and thus it won't
416 // get reflected)
417 bool mIsArtificial;
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800418 size_t mAllocSize;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700419
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700420 RSExportRecordType(RSContext *Context,
421 const llvm::StringRef &Name,
422 bool IsPacked,
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800423 bool IsArtificial,
424 size_t AllocSize)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800425 : RSExportType(Context, ExportClassRecord, Name),
zonr6315f762010-10-05 15:35:14 +0800426 mIsPacked(IsPacked),
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800427 mIsArtificial(IsArtificial),
428 mAllocSize(AllocSize) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700429 return;
430 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700431
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700432 // @RT was normalized by calling RSExportType::TypeExportable() before calling
433 // this.
434 // @TypeName was retrieved from RSExportType::GetTypeName() before calling
435 // this.
436 static RSExportRecordType *Create(RSContext *Context,
437 const clang::RecordType *RT,
438 const llvm::StringRef &TypeName,
439 bool mIsArtificial = false);
440
441 virtual const llvm::Type *convertToLLVMType() const;
442 public:
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800443 inline const std::list<const Field*>& getFields() const { return mFields; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700444 inline bool isPacked() const { return mIsPacked; }
445 inline bool isArtificial() const { return mIsArtificial; }
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800446 inline size_t getAllocSize() const { return mAllocSize; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700447
448 ~RSExportRecordType() {
449 for (std::list<const Field*>::iterator I = mFields.begin(),
450 E = mFields.end();
451 I != E;
452 I++)
453 if (*I != NULL)
454 delete *I;
455 return;
456 }
457}; // RSExportRecordType
458
459} // namespace slang
460
zonr6315f762010-10-05 15:35:14 +0800461#endif // _SLANG_COMPILER_RS_EXPORT_TYPE_H