blob: c6bb315b845155890b7483983fe04d2d0c293902 [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
Zonr Changa41ce1d2010-10-06 02:23:12 +08008#include "llvm/Support/ManagedStatic.h"
9
zonr6315f762010-10-05 15:35:14 +080010#include "llvm/ADT/StringRef.h"
11#include "llvm/ADT/StringMap.h"
12#include "llvm/ADT/SmallPtrSet.h"
13
14#include "clang/AST/Type.h"
15#include "clang/AST/Decl.h"
16
Zonr Changa41ce1d2010-10-06 02:23:12 +080017#include "slang_rs_exportable.h"
18
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070019#define GET_CANONICAL_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080020 (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr())
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070021#define UNSAFE_CAST_TYPE(TT, T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080022 static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr())
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070023#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080024 (((T) == NULL) ? NULL : \
25 GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070026#define GET_POINTEE_TYPE(T) \
Zonr Chang2e1dba62010-10-05 22:20:11 +080027 (((T) == NULL) ? NULL : \
28 GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr()))
29#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T) \
30 (((T) == NULL) ? NULL : \
31 GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
Zonr Chang0da0a7d2010-10-05 21:26:37 +080032#define DUMMY_RS_TYPE_NAME_PREFIX "<"
33#define DUMMY_RS_TYPE_NAME_POSTFIX ">"
Zonr Chang2e1dba62010-10-05 22:20:11 +080034#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE \
35 DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX
Shih-wei Liao462aefd2010-06-04 15:32:04 -070036
37namespace llvm {
zonr6315f762010-10-05 15:35:14 +080038 class Type;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070039} // namespace llvm
Shih-wei Liao462aefd2010-06-04 15:32:04 -070040
41namespace slang {
42
zonr6315f762010-10-05 15:35:14 +080043 class RSContext;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070044
Zonr Changa41ce1d2010-10-06 02:23:12 +080045class RSExportType : public RSExportable {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070046 friend class RSExportElement;
47 public:
48 typedef enum {
49 ExportClassPrimitive,
50 ExportClassPointer,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070051 ExportClassVector,
Zonr Chang92b344a2010-10-05 20:39:03 +080052 ExportClassMatrix,
Zonr Chang2e1dba62010-10-05 22:20:11 +080053 ExportClassConstantArray,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 ExportClassRecord
55 } ExportClass;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070056
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070057 private:
58 RSContext *mContext;
Zonr Chang6b6320a2010-10-05 22:42:01 +080059 ExportClass mClass;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070060 std::string mName;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070061
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070062 // Cache the result after calling convertToLLVMType() at the first time
63 mutable const llvm::Type *mLLVMType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070064
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070065 protected:
Zonr Chang6b6320a2010-10-05 22:42:01 +080066 RSExportType(RSContext *Context,
67 ExportClass Class,
68 const llvm::StringRef &Name);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070069
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070070 // Let's make it private since there're some prerequisites to call this
71 // function.
72 //
73 // @T was normalized by calling RSExportType::TypeExportable().
zonr6315f762010-10-05 15:35:14 +080074 // @TypeName was retrieve from RSExportType::GetTypeName() before calling
75 // this.
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070076 //
77 static RSExportType *Create(RSContext *Context,
78 const clang::Type *T,
zonr6315f762010-10-05 15:35:14 +080079 const llvm::StringRef &TypeName);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070080
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070081 static llvm::StringRef GetTypeName(const clang::Type *T);
82 // Return the type that can be used to create RSExportType, will always return
83 // the canonical type
84 static const clang::Type
zonr6315f762010-10-05 15:35:14 +080085 *TypeExportable(const clang::Type *T,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070086 // Contain the checked type for recursion
87 llvm::SmallPtrSet<const clang::Type*, 8> &SPS);
Shih-wei Liao462aefd2010-06-04 15:32:04 -070088
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070089 // This function convert the RSExportType to LLVM type. Actually, it should be
90 // "convert Clang type to LLVM type." However, clang doesn't make this API
91 // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
92 //
93 // Once we can get LLVM type, we can use LLVM to get alignment information,
94 // allocation size of a given type and structure layout that LLVM used
95 // (all of these information are target dependent) without dealing with these
96 // by ourselves.
97 virtual const llvm::Type *convertToLLVMType() const = 0;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070098
zonr6315f762010-10-05 15:35:14 +080099 virtual ~RSExportType() {}
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700100 public:
101 static bool NormalizeType(const clang::Type *&T, llvm::StringRef &TypeName);
102 // @T may not be normalized
103 static RSExportType *Create(RSContext *Context, const clang::Type *T);
104 static RSExportType *CreateFromDecl(RSContext *Context,
105 const clang::VarDecl *VD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700106
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700107 static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700108
Zonr Chang6b6320a2010-10-05 22:42:01 +0800109 inline ExportClass getClass() const { return mClass; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700110
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700111 inline const llvm::Type *getLLVMType() const {
112 if (mLLVMType == NULL)
113 mLLVMType = convertToLLVMType();
114 return mLLVMType;
115 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700116
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700117 // Return the number of bits necessary to hold the specified RSExportType
118 static size_t GetTypeStoreSize(const RSExportType *ET);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700119
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700120 // The size of allocation of specified RSExportType (alignment considered)
121 static size_t GetTypeAllocSize(const RSExportType *ET);
122 static unsigned char GetTypeAlignment(const RSExportType *ET);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700123
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700124 const std::string &getName() const { return mName; }
125 inline RSContext *getRSContext() const { return mContext; }
126}; // RSExportType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700127
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700128// Primitive types
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700129class RSExportPrimitiveType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700130 friend class RSExportType;
131 friend class RSExportElement;
132 public:
133 // From graphics/java/android/renderscript/Element.java: Element.DataType
134 typedef enum {
135 DataTypeUnknown = -1,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700136
Shih-wei Liao91a37832010-10-03 19:11:51 -0700137 DataTypeFloat16 = 0,
138 DataTypeFloat32,
139 DataTypeFloat64,
140 DataTypeSigned8,
141 DataTypeSigned16,
142 DataTypeSigned32,
143 DataTypeSigned64,
144 DataTypeUnsigned8,
145 DataTypeUnsigned16,
146 DataTypeUnsigned32,
147 DataTypeUnSigned64,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700148
Shih-wei Liao91a37832010-10-03 19:11:51 -0700149 DataTypeBoolean,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700150
Shih-wei Liao91a37832010-10-03 19:11:51 -0700151 DataTypeUnsigned565,
152 DataTypeUnsigned5551,
153 DataTypeUnsigned4444,
Shih-wei Liaodd35e492010-06-21 14:42:40 -0700154
Zonr Chang92b344a2010-10-05 20:39:03 +0800155 // Actually, there's no any instance of RSExportPrimitiveType which mType
156 // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
157 // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
158 // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
159 // RSExportMatrixType.
Shih-wei Liao91a37832010-10-03 19:11:51 -0700160 DataTypeRSMatrix2x2,
161 DataTypeRSMatrix3x3,
162 DataTypeRSMatrix4x4,
163
164 DataTypeRSElement,
165 DataTypeRSType,
166 DataTypeRSAllocation,
167 DataTypeRSSampler,
168 DataTypeRSScript,
169 DataTypeRSMesh,
170 DataTypeRSProgramFragment,
171 DataTypeRSProgramVertex,
172 DataTypeRSProgramRaster,
173 DataTypeRSProgramStore,
174 DataTypeRSFont,
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700175
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700176 DataTypeMax
177 } DataType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700178
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700179 // From graphics/java/android/renderscript/Element.java: Element.DataKind
180 typedef enum {
Shih-wei Liao91a37832010-10-03 19:11:51 -0700181 DataKindUser,
182 DataKindPixelL,
183 DataKindPixelA,
184 DataKindPixelLA,
185 DataKindPixelRGB,
186 DataKindPixelRGBA
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700187 } DataKind;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700188
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700189 private:
190 DataType mType;
191 DataKind mKind;
192 bool mNormalized;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700193
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700194 typedef llvm::StringMap<DataType> RSObjectTypeMapTy;
Zonr Changa41ce1d2010-10-06 02:23:12 +0800195 static llvm::ManagedStatic<RSObjectTypeMapTy> RSObjectTypeMap;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700196
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700197 static llvm::Type *RSObjectLLVMType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700198
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700199 static const size_t SizeOfDataTypeInBits[];
200 // @T was normalized by calling RSExportType::TypeExportable() before calling
201 // this.
202 // @TypeName was retrieved from RSExportType::GetTypeName() before calling
203 // this
204 static RSExportPrimitiveType *Create(RSContext *Context,
205 const clang::Type *T,
206 const llvm::StringRef &TypeName,
207 DataKind DK = DataKindUser,
208 bool Normalized = false);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700209
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700210 protected:
211 // T is normalized by calling RSExportType::TypeExportable() before
212 // calling this
213 static bool IsPrimitiveType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700214
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700215 static DataType GetDataType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700216
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700217 RSExportPrimitiveType(RSContext *Context,
Zonr Chang6b6320a2010-10-05 22:42:01 +0800218 // for derived class to set their type class
219 ExportClass Class,
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700220 const llvm::StringRef &Name,
221 DataType DT,
222 DataKind DK,
zonr6315f762010-10-05 15:35:14 +0800223 bool Normalized)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800224 : RSExportType(Context, Class, Name),
zonr6315f762010-10-05 15:35:14 +0800225 mType(DT),
226 mKind(DK),
227 mNormalized(Normalized) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700228 return;
229 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700230
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700231 virtual const llvm::Type *convertToLLVMType() const;
232 public:
233 // @T may not be normalized
234 static RSExportPrimitiveType *Create(RSContext *Context,
235 const clang::Type *T,
236 DataKind DK = DataKindUser);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700237
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700238 static DataType GetRSObjectType(const llvm::StringRef &TypeName);
239 static DataType GetRSObjectType(const clang::Type *T);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700240
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700241 static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700242
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700243 inline DataType getType() const { return mType; }
244 inline DataKind getKind() const { return mKind; }
245 inline bool isRSObjectType() const {
246 return ((mType >= DataTypeRSElement) && (mType < DataTypeMax));
247 }
248}; // RSExportPrimitiveType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700249
250
251class RSExportPointerType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700252 friend class RSExportType;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700253 friend class RSExportFunc;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700254 private:
255 const RSExportType *mPointeeType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700256
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700257 RSExportPointerType(RSContext *Context,
258 const llvm::StringRef &Name,
zonr6315f762010-10-05 15:35:14 +0800259 const RSExportType *PointeeType)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800260 : RSExportType(Context, ExportClassPointer, Name),
zonr6315f762010-10-05 15:35:14 +0800261 mPointeeType(PointeeType) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700262 return;
263 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700264
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700265 // @PT was normalized by calling RSExportType::TypeExportable() before calling
266 // this.
267 static RSExportPointerType *Create(RSContext *Context,
268 const clang::PointerType *PT,
269 const llvm::StringRef &TypeName);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700270
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700271 virtual const llvm::Type *convertToLLVMType() const;
272 public:
273 static const clang::Type *IntegerType;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700274
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700275 inline const RSExportType *getPointeeType() const { return mPointeeType; }
276}; // RSExportPointerType
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700277
278
279class RSExportVectorType : public RSExportPrimitiveType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700280 friend class RSExportType;
281 friend class RSExportElement;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700282 private:
Zonr Chang92b344a2010-10-05 20:39:03 +0800283 unsigned mNumElement; // number of element
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700284
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700285 RSExportVectorType(RSContext *Context,
286 const llvm::StringRef &Name,
287 DataType DT,
288 DataKind DK,
289 bool Normalized,
Zonr Chang92b344a2010-10-05 20:39:03 +0800290 unsigned NumElement)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800291 : RSExportPrimitiveType(Context, ExportClassVector, Name,
292 DT, DK, Normalized),
zonr6315f762010-10-05 15:35:14 +0800293 mNumElement(NumElement) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700294 return;
295 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700296
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700297 // @EVT was normalized by calling RSExportType::TypeExportable() before
298 // calling this.
299 static RSExportVectorType *Create(RSContext *Context,
300 const clang::ExtVectorType *EVT,
301 const llvm::StringRef &TypeName,
302 DataKind DK = DataKindUser,
303 bool Normalized = false);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700304
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700305 static const char *VectorTypeNameStore[][3];
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700306
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700307 virtual const llvm::Type *convertToLLVMType() const;
308 public:
309 static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700310
Zonr Chang92b344a2010-10-05 20:39:03 +0800311 inline unsigned getNumElement() const { return mNumElement; }
312};
313
314// Only *square* *float* matrix is supported by now.
315//
316// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
317// form *exactly*:
318// typedef struct {
319// float m[{NxN}];
320// } rs_matrixNxN;
321//
322// where mDim will be N.
323class RSExportMatrixType : public RSExportType {
324 friend class RSExportType;
325 private:
Zonr Chang2e1dba62010-10-05 22:20:11 +0800326 unsigned mDim; // dimension
Zonr Chang92b344a2010-10-05 20:39:03 +0800327
328 RSExportMatrixType(RSContext *Context,
329 const llvm::StringRef &Name,
330 unsigned Dim)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800331 : RSExportType(Context, ExportClassMatrix, Name),
Zonr Chang92b344a2010-10-05 20:39:03 +0800332 mDim(Dim) {
333 return;
334 }
335
336 virtual const llvm::Type *convertToLLVMType() const;
337 public:
Zonr Chang92b344a2010-10-05 20:39:03 +0800338 // @RT was normalized by calling RSExportType::TypeExportable() before
339 // calling this.
340 static RSExportMatrixType *Create(RSContext *Context,
341 const clang::RecordType *RT,
342 const llvm::StringRef &TypeName,
343 unsigned Dim);
344
345 inline unsigned getDim() const { return mDim; }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700346};
347
Zonr Chang2e1dba62010-10-05 22:20:11 +0800348class RSExportConstantArrayType : public RSExportType {
349 friend class RSExportType;
350 private:
351 const RSExportType *mElementType; // Array element type
352 unsigned mSize; // Array size
353
354 RSExportConstantArrayType(RSContext *Context,
355 const RSExportType *ElementType,
356 unsigned Size)
357 : RSExportType(Context,
Zonr Chang6b6320a2010-10-05 22:42:01 +0800358 ExportClassConstantArray,
Zonr Chang2e1dba62010-10-05 22:20:11 +0800359 DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
360 mElementType(ElementType),
361 mSize(Size) {
362 return;
363 }
364
365 // @CAT was normalized by calling RSExportType::TypeExportable() before
366 // calling this.
367 static RSExportConstantArrayType *Create(RSContext *Context,
368 const clang::ConstantArrayType *CAT);
369
370 virtual const llvm::Type *convertToLLVMType() const;
371 public:
Zonr Chang2e1dba62010-10-05 22:20:11 +0800372 inline unsigned getSize() const { return mSize; }
373 inline const RSExportType *getElementType() const { return mElementType; }
374};
375
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700376class RSExportRecordType : public RSExportType {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700377 friend class RSExportType;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700378 public:
379 class Field {
380 private:
381 const RSExportType *mType;
382 // Field name
383 std::string mName;
384 // Link to the struct that contain this field
385 const RSExportRecordType *mParent;
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800386 // Offset in the container
387 size_t mOffset;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700388
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700389 public:
390 Field(const RSExportType *T,
391 const llvm::StringRef &Name,
392 const RSExportRecordType *Parent,
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800393 size_t Offset)
zonr6315f762010-10-05 15:35:14 +0800394 : mType(T),
395 mName(Name.data(), Name.size()),
396 mParent(Parent),
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800397 mOffset(Offset) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700398 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700399 }
400
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700401 inline const RSExportRecordType *getParent() const { return mParent; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700402 inline const RSExportType *getType() const { return mType; }
403 inline const std::string &getName() const { return mName; }
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800404 inline size_t getOffsetInParent() const { return mOffset; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700405 };
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700406
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700407 typedef std::list<const Field*>::const_iterator const_field_iterator;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700408
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700409 inline const_field_iterator fields_begin() const {
410 return this->mFields.begin();
411 }
412 inline const_field_iterator fields_end() const {
413 return this->mFields.end();
414 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700415
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700416 private:
417 std::list<const Field*> mFields;
418 bool mIsPacked;
419 // Artificial export struct type is not exported by user (and thus it won't
420 // get reflected)
421 bool mIsArtificial;
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800422 size_t mAllocSize;
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700423
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700424 RSExportRecordType(RSContext *Context,
425 const llvm::StringRef &Name,
426 bool IsPacked,
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800427 bool IsArtificial,
428 size_t AllocSize)
Zonr Chang6b6320a2010-10-05 22:42:01 +0800429 : RSExportType(Context, ExportClassRecord, Name),
zonr6315f762010-10-05 15:35:14 +0800430 mIsPacked(IsPacked),
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800431 mIsArtificial(IsArtificial),
432 mAllocSize(AllocSize) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700433 return;
434 }
Shih-wei Liao462aefd2010-06-04 15:32:04 -0700435
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700436 // @RT was normalized by calling RSExportType::TypeExportable() before calling
437 // this.
438 // @TypeName was retrieved from RSExportType::GetTypeName() before calling
439 // this.
440 static RSExportRecordType *Create(RSContext *Context,
441 const clang::RecordType *RT,
442 const llvm::StringRef &TypeName,
443 bool mIsArtificial = false);
444
445 virtual const llvm::Type *convertToLLVMType() const;
446 public:
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800447 inline const std::list<const Field*>& getFields() const { return mFields; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700448 inline bool isPacked() const { return mIsPacked; }
449 inline bool isArtificial() const { return mIsArtificial; }
Zonr Chang0da0a7d2010-10-05 21:26:37 +0800450 inline size_t getAllocSize() const { return mAllocSize; }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -0700451
452 ~RSExportRecordType() {
453 for (std::list<const Field*>::iterator I = mFields.begin(),
454 E = mFields.end();
455 I != E;
456 I++)
457 if (*I != NULL)
458 delete *I;
459 return;
460 }
461}; // RSExportRecordType
462
463} // namespace slang
464
zonr6315f762010-10-05 15:35:14 +0800465#endif // _SLANG_COMPILER_RS_EXPORT_TYPE_H