Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | d5a84f6 | 2012-04-04 17:44:38 -0700 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 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 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 19 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 20 | #include <list> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 21 | #include <set> |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 22 | #include <string> |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 23 | #include <sstream> |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 24 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 25 | #include "clang/AST/Decl.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
| 27 | |
| 28 | #include "llvm/ADT/SmallPtrSet.h" |
| 29 | #include "llvm/ADT/StringMap.h" |
| 30 | #include "llvm/ADT/StringRef.h" |
| 31 | |
| 32 | #include "llvm/Support/ManagedStatic.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 33 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 34 | #include "slang_rs_exportable.h" |
| 35 | |
Jean-Luc Brouillet | b095e05 | 2014-05-16 20:10:00 -0700 | [diff] [blame] | 36 | |
| 37 | inline const clang::Type* GetCanonicalType(const clang::Type* T) { |
| 38 | if (T == NULL) { |
| 39 | return NULL; |
| 40 | } |
| 41 | return T->getCanonicalTypeInternal().getTypePtr(); |
| 42 | } |
| 43 | |
| 44 | inline const clang::Type* GetCanonicalType(clang::QualType QT) { |
| 45 | return GetCanonicalType(QT.getTypePtr()); |
| 46 | } |
| 47 | |
| 48 | inline const clang::Type* GetExtVectorElementType(const clang::ExtVectorType *T) { |
| 49 | if (T == NULL) { |
| 50 | return NULL; |
| 51 | } |
| 52 | return GetCanonicalType(T->getElementType()); |
| 53 | } |
| 54 | |
| 55 | inline const clang::Type* GetPointeeType(const clang::PointerType *T) { |
| 56 | if (T == NULL) { |
| 57 | return NULL; |
| 58 | } |
| 59 | return GetCanonicalType(T->getPointeeType()); |
| 60 | } |
| 61 | |
| 62 | inline const clang::Type* GetConstantArrayElementType(const clang::ConstantArrayType *T) { |
| 63 | if (T == NULL) { |
| 64 | return NULL; |
| 65 | } |
| 66 | return GetCanonicalType(T->getElementType()); |
| 67 | } |
| 68 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 69 | |
| 70 | namespace llvm { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 71 | class Type; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 72 | } // namespace llvm |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 73 | |
| 74 | namespace slang { |
| 75 | |
Jean-Luc Brouillet | cec9b65 | 2014-05-14 19:33:57 -0700 | [diff] [blame] | 76 | class RSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 77 | |
Jean-Luc Brouillet | cec9b65 | 2014-05-14 19:33:57 -0700 | [diff] [blame] | 78 | // Broad grouping of the data types |
| 79 | enum DataTypeCategory { |
| 80 | PrimitiveDataType, |
| 81 | MatrixDataType, |
| 82 | ObjectDataType |
| 83 | }; |
| 84 | |
| 85 | // From graphics/java/android/renderscript/Element.java: Element.DataType |
| 86 | /* NOTE: The values of the enums are found compiled in the bit code (i.e. as |
| 87 | * values, not symbolic. When adding new types, you must add them to the end. |
| 88 | * If removing types, you can't re-use the integer value. |
| 89 | * |
| 90 | * TODO: but if you do this, you won't be able to keep using First* & Last* |
| 91 | * for validation. |
| 92 | * |
| 93 | * IMPORTANT: This enum should correspond one-for-one to the entries found in the |
| 94 | * gReflectionsTypes table (except for the two negative numbers). Don't edit one without |
| 95 | * the other. |
| 96 | */ |
| 97 | enum DataType { |
| 98 | DataTypeIsStruct = -2, |
| 99 | DataTypeUnknown = -1, |
| 100 | |
| 101 | DataTypeFloat16 = 0, |
| 102 | DataTypeFloat32 = 1, |
| 103 | DataTypeFloat64 = 2, |
| 104 | DataTypeSigned8 = 3, |
| 105 | DataTypeSigned16 = 4, |
| 106 | DataTypeSigned32 = 5, |
| 107 | DataTypeSigned64 = 6, |
| 108 | DataTypeUnsigned8 = 7, |
| 109 | DataTypeUnsigned16 = 8, |
| 110 | DataTypeUnsigned32 = 9, |
| 111 | DataTypeUnsigned64 = 10, |
| 112 | DataTypeBoolean = 11, |
| 113 | DataTypeUnsigned565 = 12, |
| 114 | DataTypeUnsigned5551 = 13, |
| 115 | DataTypeUnsigned4444 = 14, |
| 116 | |
| 117 | DataTypeRSMatrix2x2 = 15, |
| 118 | DataTypeRSMatrix3x3 = 16, |
| 119 | DataTypeRSMatrix4x4 = 17, |
| 120 | |
| 121 | DataTypeRSElement = 18, |
| 122 | DataTypeRSType = 19, |
| 123 | DataTypeRSAllocation = 20, |
| 124 | DataTypeRSSampler = 21, |
| 125 | DataTypeRSScript = 22, |
| 126 | DataTypeRSMesh = 23, |
| 127 | DataTypeRSPath = 24, |
| 128 | DataTypeRSProgramFragment = 25, |
| 129 | DataTypeRSProgramVertex = 26, |
| 130 | DataTypeRSProgramRaster = 27, |
| 131 | DataTypeRSProgramStore = 28, |
| 132 | DataTypeRSFont = 29, |
| 133 | |
| 134 | // This should always be last and correspond to the size of the gReflectionTypes table. |
| 135 | DataTypeMax |
| 136 | }; |
Jean-Luc Brouillet | 474655a | 2014-04-28 15:25:51 -0700 | [diff] [blame] | 137 | |
Stephen Hines | fdd1ba1 | 2012-03-08 17:26:32 -0800 | [diff] [blame] | 138 | typedef struct { |
Jean-Luc Brouillet | 474655a | 2014-04-28 15:25:51 -0700 | [diff] [blame] | 139 | DataTypeCategory category; |
Stephen Hines | fdd1ba1 | 2012-03-08 17:26:32 -0800 | [diff] [blame] | 140 | const char * rs_type; |
| 141 | const char * rs_short_type; |
| 142 | uint32_t size_in_bits; |
| 143 | const char * c_name; |
| 144 | const char * java_name; |
| 145 | const char * rs_c_vector_prefix; |
| 146 | const char * rs_java_vector_prefix; |
| 147 | bool java_promotion; |
| 148 | } RSReflectionType; |
| 149 | |
Jason Sams | 1b6a088 | 2012-03-12 15:07:58 -0700 | [diff] [blame] | 150 | |
| 151 | typedef struct RSReflectionTypeData_rec { |
| 152 | const RSReflectionType *type; |
| 153 | uint32_t vecSize; |
| 154 | bool isPointer; |
| 155 | uint32_t arraySize; |
| 156 | |
| 157 | // Subelements |
| 158 | //std::vector<const struct RSReflectionTypeData_rec *> fields; |
| 159 | //std::vector< std::string > fieldNames; |
| 160 | //std::vector< uint32_t> fieldOffsetBytes; |
| 161 | } RSReflectionTypeData; |
| 162 | |
Jean-Luc Brouillet | eca0534 | 2014-05-15 12:44:21 -0700 | [diff] [blame] | 163 | // Make a name for types that are too complicated to create the real names. |
| 164 | std::string CreateDummyName(const char *type, const std::string &name); |
| 165 | |
| 166 | inline bool IsDummyName(const llvm::StringRef &Name) { |
| 167 | return Name.startswith("<"); |
| 168 | } |
Jason Sams | 1b6a088 | 2012-03-12 15:07:58 -0700 | [diff] [blame] | 169 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 170 | class RSExportType : public RSExportable { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 171 | friend class RSExportElement; |
| 172 | public: |
| 173 | typedef enum { |
| 174 | ExportClassPrimitive, |
| 175 | ExportClassPointer, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 176 | ExportClassVector, |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 177 | ExportClassMatrix, |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 178 | ExportClassConstantArray, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 179 | ExportClassRecord |
| 180 | } ExportClass; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 181 | |
Jason Sams | 1b6a088 | 2012-03-12 15:07:58 -0700 | [diff] [blame] | 182 | void convertToRTD(RSReflectionTypeData *rtd) const; |
| 183 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 184 | private: |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 185 | ExportClass mClass; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 186 | std::string mName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 187 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 188 | // Cache the result after calling convertToLLVMType() at the first time |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 189 | mutable llvm::Type *mLLVMType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 190 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 191 | protected: |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 192 | RSExportType(RSContext *Context, |
| 193 | ExportClass Class, |
| 194 | const llvm::StringRef &Name); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 195 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 196 | // Let's make it private since there're some prerequisites to call this |
| 197 | // function. |
| 198 | // |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 199 | // @T was normalized by calling RSExportType::NormalizeType(). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 200 | // @TypeName was retrieve from RSExportType::GetTypeName() before calling |
| 201 | // this. |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 202 | // |
| 203 | static RSExportType *Create(RSContext *Context, |
| 204 | const clang::Type *T, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 205 | const llvm::StringRef &TypeName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 206 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 207 | static llvm::StringRef GetTypeName(const clang::Type *T); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 208 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 209 | // This function convert the RSExportType to LLVM type. Actually, it should be |
| 210 | // "convert Clang type to LLVM type." However, clang doesn't make this API |
| 211 | // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves. |
| 212 | // |
| 213 | // Once we can get LLVM type, we can use LLVM to get alignment information, |
| 214 | // allocation size of a given type and structure layout that LLVM used |
| 215 | // (all of these information are target dependent) without dealing with these |
| 216 | // by ourselves. |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 217 | virtual llvm::Type *convertToLLVMType() const = 0; |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 218 | // Record type may recursively reference its type definition. We need a |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 219 | // temporary type setup before the type construction gets done. |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 220 | inline void setAbstractLLVMType(llvm::Type *LLVMType) const { |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 221 | mLLVMType = LLVMType; |
| 222 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 223 | |
Zonr Chang | a7a828d | 2010-10-22 03:44:27 +0800 | [diff] [blame] | 224 | virtual ~RSExportType(); |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 225 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 226 | public: |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 227 | // This function additionally verifies that the Type T is exportable. |
| 228 | // If it is not, this function returns false. Otherwise it returns true. |
| 229 | static bool NormalizeType(const clang::Type *&T, |
| 230 | llvm::StringRef &TypeName, |
Stephen Hines | 48d893d | 2013-12-06 18:00:27 -0800 | [diff] [blame] | 231 | RSContext *Context, |
Stephen Hines | 5bfec8d | 2012-04-04 08:18:57 -0700 | [diff] [blame] | 232 | const clang::VarDecl *VD); |
Stephen Hines | 78e69cb | 2011-04-22 15:03:19 -0700 | [diff] [blame] | 233 | |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 234 | // This function checks whether the specified type can be handled by RS/FS. |
| 235 | // If it cannot, this function returns false. Otherwise it returns true. |
| 236 | // Filterscript has additional restrictions on supported types. |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 237 | static bool ValidateType(slang::RSContext *Context, clang::ASTContext &C, |
| 238 | clang::QualType QT, clang::NamedDecl *ND, |
| 239 | clang::SourceLocation Loc, unsigned int TargetAPI, |
| 240 | bool IsFilterscript); |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 241 | |
Stephen Hines | 78e69cb | 2011-04-22 15:03:19 -0700 | [diff] [blame] | 242 | // This function ensures that the VarDecl can be properly handled by RS. |
| 243 | // If it cannot, this function returns false. Otherwise it returns true. |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 244 | // Filterscript has additional restrictions on supported types. |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 245 | static bool ValidateVarDecl(slang::RSContext *Context, clang::VarDecl *VD, |
| 246 | unsigned int TargetAPI, bool IsFilterscript); |
Stephen Hines | 78e69cb | 2011-04-22 15:03:19 -0700 | [diff] [blame] | 247 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 248 | // @T may not be normalized |
| 249 | static RSExportType *Create(RSContext *Context, const clang::Type *T); |
| 250 | static RSExportType *CreateFromDecl(RSContext *Context, |
| 251 | const clang::VarDecl *VD); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 252 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 253 | static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 254 | |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 255 | inline ExportClass getClass() const { return mClass; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 256 | |
Stephen Hines | 0d26cef | 2012-05-01 19:23:01 -0700 | [diff] [blame] | 257 | virtual unsigned getSize() const { return 1; } |
| 258 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 259 | inline llvm::Type *getLLVMType() const { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 260 | if (mLLVMType == NULL) |
| 261 | mLLVMType = convertToLLVMType(); |
| 262 | return mLLVMType; |
| 263 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 264 | |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 265 | // Return the maximum number of bytes that may be written when this type is stored. |
| 266 | virtual size_t getStoreSize() const; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 267 | |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 268 | // Return the distance in bytes between successive elements of this type; it includes padding. |
| 269 | virtual size_t getAllocSize() const; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 270 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 271 | inline const std::string &getName() const { return mName; } |
| 272 | |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 273 | virtual std::string getElementName() const { |
| 274 | // Base case is actually an invalid C/Java identifier. |
| 275 | return "@@INVALID@@"; |
| 276 | } |
| 277 | |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 278 | virtual bool keep(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 279 | virtual bool equals(const RSExportable *E) const; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 280 | }; // RSExportType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 281 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 282 | // Primitive types |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 283 | class RSExportPrimitiveType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 284 | friend class RSExportType; |
| 285 | friend class RSExportElement; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 286 | private: |
| 287 | DataType mType; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 288 | bool mNormalized; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 289 | |
Zonr Chang | b1771ef | 2010-10-22 18:03:46 +0800 | [diff] [blame] | 290 | typedef llvm::StringMap<DataType> RSSpecificTypeMapTy; |
| 291 | static llvm::ManagedStatic<RSSpecificTypeMapTy> RSSpecificTypeMap; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 292 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 293 | static llvm::Type *RSObjectLLVMType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 294 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 295 | static const size_t SizeOfDataTypeInBits[]; |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 296 | // @T was normalized by calling RSExportType::NormalizeType() before calling |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 297 | // this. |
| 298 | // @TypeName was retrieved from RSExportType::GetTypeName() before calling |
| 299 | // this |
| 300 | static RSExportPrimitiveType *Create(RSContext *Context, |
| 301 | const clang::Type *T, |
| 302 | const llvm::StringRef &TypeName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 303 | bool Normalized = false); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 304 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 305 | protected: |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 306 | RSExportPrimitiveType(RSContext *Context, |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 307 | // for derived class to set their type class |
| 308 | ExportClass Class, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 309 | const llvm::StringRef &Name, |
| 310 | DataType DT, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 311 | bool Normalized) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 312 | : RSExportType(Context, Class, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 313 | mType(DT), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 314 | mNormalized(Normalized) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 315 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 316 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 317 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | 2ef9bc0 | 2010-12-13 18:33:23 -0800 | [diff] [blame] | 318 | |
| 319 | static DataType GetDataType(RSContext *Context, const clang::Type *T); |
| 320 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 321 | public: |
Stephen Hines | dd6206b | 2010-12-09 19:39:22 -0800 | [diff] [blame] | 322 | // T is normalized by calling RSExportType::NormalizeType() before |
| 323 | // calling this |
| 324 | static bool IsPrimitiveType(const clang::Type *T); |
| 325 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 326 | // @T may not be normalized |
| 327 | static RSExportPrimitiveType *Create(RSContext *Context, |
Stephen Hines | 2b8fb64 | 2012-03-09 00:12:47 -0800 | [diff] [blame] | 328 | const clang::Type *T); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 329 | |
Zonr Chang | b1771ef | 2010-10-22 18:03:46 +0800 | [diff] [blame] | 330 | static DataType GetRSSpecificType(const llvm::StringRef &TypeName); |
| 331 | static DataType GetRSSpecificType(const clang::Type *T); |
| 332 | |
| 333 | static bool IsRSMatrixType(DataType DT); |
| 334 | static bool IsRSObjectType(DataType DT); |
Stephen Hines | f2174cf | 2011-02-09 23:21:37 -0800 | [diff] [blame] | 335 | static bool IsRSObjectType(const clang::Type *T) { |
| 336 | return IsRSObjectType(GetRSSpecificType(T)); |
| 337 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 338 | |
Stephen Hines | feaca06 | 2011-02-04 14:08:13 -0800 | [diff] [blame] | 339 | // Determines whether T is [an array of] struct that contains at least one |
| 340 | // RS object type within it. |
| 341 | static bool IsStructureTypeWithRSObject(const clang::Type *T); |
| 342 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 343 | static size_t GetSizeInBits(const RSExportPrimitiveType *EPT); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 344 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 345 | inline DataType getType() const { return mType; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 346 | inline bool isRSObjectType() const { |
Jean-Luc Brouillet | 474655a | 2014-04-28 15:25:51 -0700 | [diff] [blame] | 347 | return IsRSObjectType(mType); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 348 | } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 349 | |
| 350 | virtual bool equals(const RSExportable *E) const; |
Stephen Hines | fdd1ba1 | 2012-03-08 17:26:32 -0800 | [diff] [blame] | 351 | |
| 352 | static RSReflectionType *getRSReflectionType(DataType DT); |
| 353 | static RSReflectionType *getRSReflectionType( |
| 354 | const RSExportPrimitiveType *EPT) { |
| 355 | return getRSReflectionType(EPT->getType()); |
| 356 | } |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 357 | |
Stephen Hines | 1f6c331 | 2012-07-03 17:23:33 -0700 | [diff] [blame] | 358 | virtual unsigned getSize() const { return (GetSizeInBits(this) >> 3); } |
| 359 | |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 360 | std::string getElementName() const { |
| 361 | return getRSReflectionType(this)->rs_short_type; |
| 362 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 363 | }; // RSExportPrimitiveType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 364 | |
| 365 | |
| 366 | class RSExportPointerType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 367 | friend class RSExportType; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 368 | friend class RSExportFunc; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 369 | private: |
| 370 | const RSExportType *mPointeeType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 371 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 372 | RSExportPointerType(RSContext *Context, |
| 373 | const llvm::StringRef &Name, |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 374 | const RSExportType *PointeeType) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 375 | : RSExportType(Context, ExportClassPointer, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 376 | mPointeeType(PointeeType) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 377 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 378 | |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 379 | // @PT was normalized by calling RSExportType::NormalizeType() before calling |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 380 | // this. |
| 381 | static RSExportPointerType *Create(RSContext *Context, |
| 382 | const clang::PointerType *PT, |
| 383 | const llvm::StringRef &TypeName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 384 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 385 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 386 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 387 | public: |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 388 | virtual bool keep(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 389 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 390 | inline const RSExportType *getPointeeType() const { return mPointeeType; } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 391 | |
| 392 | virtual bool equals(const RSExportable *E) const; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 393 | }; // RSExportPointerType |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 394 | |
| 395 | |
| 396 | class RSExportVectorType : public RSExportPrimitiveType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 397 | friend class RSExportType; |
| 398 | friend class RSExportElement; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 399 | private: |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 400 | unsigned mNumElement; // number of element |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 401 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 402 | RSExportVectorType(RSContext *Context, |
| 403 | const llvm::StringRef &Name, |
| 404 | DataType DT, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 405 | bool Normalized, |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 406 | unsigned NumElement) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 407 | : RSExportPrimitiveType(Context, ExportClassVector, Name, |
Stephen Hines | 2b8fb64 | 2012-03-09 00:12:47 -0800 | [diff] [blame] | 408 | DT, Normalized), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 409 | mNumElement(NumElement) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 410 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 411 | |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 412 | // @EVT was normalized by calling RSExportType::NormalizeType() before |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 413 | // calling this. |
| 414 | static RSExportVectorType *Create(RSContext *Context, |
| 415 | const clang::ExtVectorType *EVT, |
| 416 | const llvm::StringRef &TypeName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 417 | bool Normalized = false); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 418 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 419 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 420 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 421 | public: |
| 422 | static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 423 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 424 | inline unsigned getNumElement() const { return mNumElement; } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 425 | |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 426 | std::string getElementName() const { |
| 427 | std::stringstream Name; |
| 428 | Name << RSExportPrimitiveType::getRSReflectionType(this)->rs_short_type |
| 429 | << "_" << getNumElement(); |
| 430 | return Name.str(); |
| 431 | } |
| 432 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 433 | virtual bool equals(const RSExportable *E) const; |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | // Only *square* *float* matrix is supported by now. |
| 437 | // |
| 438 | // struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following |
| 439 | // form *exactly*: |
| 440 | // typedef struct { |
| 441 | // float m[{NxN}]; |
| 442 | // } rs_matrixNxN; |
| 443 | // |
| 444 | // where mDim will be N. |
| 445 | class RSExportMatrixType : public RSExportType { |
| 446 | friend class RSExportType; |
| 447 | private: |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 448 | unsigned mDim; // dimension |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 449 | |
| 450 | RSExportMatrixType(RSContext *Context, |
| 451 | const llvm::StringRef &Name, |
| 452 | unsigned Dim) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 453 | : RSExportType(Context, ExportClassMatrix, Name), |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 454 | mDim(Dim) { |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 455 | } |
| 456 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 457 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 458 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 459 | public: |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 460 | // @RT was normalized by calling RSExportType::NormalizeType() before |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 461 | // calling this. |
| 462 | static RSExportMatrixType *Create(RSContext *Context, |
| 463 | const clang::RecordType *RT, |
| 464 | const llvm::StringRef &TypeName, |
| 465 | unsigned Dim); |
| 466 | |
| 467 | inline unsigned getDim() const { return mDim; } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 468 | |
| 469 | virtual bool equals(const RSExportable *E) const; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 470 | }; |
| 471 | |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 472 | class RSExportConstantArrayType : public RSExportType { |
| 473 | friend class RSExportType; |
| 474 | private: |
| 475 | const RSExportType *mElementType; // Array element type |
| 476 | unsigned mSize; // Array size |
| 477 | |
| 478 | RSExportConstantArrayType(RSContext *Context, |
| 479 | const RSExportType *ElementType, |
| 480 | unsigned Size) |
| 481 | : RSExportType(Context, |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 482 | ExportClassConstantArray, |
Jean-Luc Brouillet | eca0534 | 2014-05-15 12:44:21 -0700 | [diff] [blame] | 483 | CreateDummyName("ConstantArray", std::string())), |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 484 | mElementType(ElementType), |
| 485 | mSize(Size) { |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 486 | } |
| 487 | |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 488 | // @CAT was normalized by calling RSExportType::NormalizeType() before |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 489 | // calling this. |
| 490 | static RSExportConstantArrayType *Create(RSContext *Context, |
| 491 | const clang::ConstantArrayType *CAT); |
| 492 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 493 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 494 | |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 495 | public: |
Stephen Hines | 0d26cef | 2012-05-01 19:23:01 -0700 | [diff] [blame] | 496 | virtual unsigned getSize() const { return mSize; } |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 497 | inline const RSExportType *getElementType() const { return mElementType; } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 498 | |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 499 | std::string getElementName() const { |
| 500 | return mElementType->getElementName(); |
| 501 | } |
| 502 | |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 503 | virtual bool keep(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 504 | virtual bool equals(const RSExportable *E) const; |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 505 | }; |
| 506 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 507 | class RSExportRecordType : public RSExportType { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 508 | friend class RSExportType; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 509 | public: |
| 510 | class Field { |
| 511 | private: |
| 512 | const RSExportType *mType; |
| 513 | // Field name |
| 514 | std::string mName; |
| 515 | // Link to the struct that contain this field |
| 516 | const RSExportRecordType *mParent; |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 517 | // Offset in the container |
| 518 | size_t mOffset; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 519 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 520 | public: |
| 521 | Field(const RSExportType *T, |
| 522 | const llvm::StringRef &Name, |
| 523 | const RSExportRecordType *Parent, |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 524 | size_t Offset) |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 525 | : mType(T), |
| 526 | mName(Name.data(), Name.size()), |
| 527 | mParent(Parent), |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 528 | mOffset(Offset) { |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 531 | inline const RSExportRecordType *getParent() const { return mParent; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 532 | inline const RSExportType *getType() const { return mType; } |
| 533 | inline const std::string &getName() const { return mName; } |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 534 | inline size_t getOffsetInParent() const { return mOffset; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 535 | }; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 536 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 537 | typedef std::list<const Field*>::const_iterator const_field_iterator; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 538 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 539 | inline const_field_iterator fields_begin() const { |
| 540 | return this->mFields.begin(); |
| 541 | } |
| 542 | inline const_field_iterator fields_end() const { |
| 543 | return this->mFields.end(); |
| 544 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 545 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 546 | private: |
| 547 | std::list<const Field*> mFields; |
| 548 | bool mIsPacked; |
| 549 | // Artificial export struct type is not exported by user (and thus it won't |
| 550 | // get reflected) |
| 551 | bool mIsArtificial; |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 552 | size_t mStoreSize; |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 553 | size_t mAllocSize; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 554 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 555 | RSExportRecordType(RSContext *Context, |
| 556 | const llvm::StringRef &Name, |
| 557 | bool IsPacked, |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 558 | bool IsArtificial, |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 559 | size_t StoreSize, |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 560 | size_t AllocSize) |
Zonr Chang | 6b6320a | 2010-10-05 22:42:01 +0800 | [diff] [blame] | 561 | : RSExportType(Context, ExportClassRecord, Name), |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 562 | mIsPacked(IsPacked), |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 563 | mIsArtificial(IsArtificial), |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 564 | mStoreSize(StoreSize), |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 565 | mAllocSize(AllocSize) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 566 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 567 | |
Stephen Hines | e5e6443 | 2010-12-02 18:48:20 -0800 | [diff] [blame] | 568 | // @RT was normalized by calling RSExportType::NormalizeType() before calling |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 569 | // this. |
| 570 | // @TypeName was retrieved from RSExportType::GetTypeName() before calling |
| 571 | // this. |
| 572 | static RSExportRecordType *Create(RSContext *Context, |
| 573 | const clang::RecordType *RT, |
| 574 | const llvm::StringRef &TypeName, |
| 575 | bool mIsArtificial = false); |
| 576 | |
Shih-wei Liao | 7c67e57 | 2011-07-19 05:54:53 -0700 | [diff] [blame] | 577 | virtual llvm::Type *convertToLLVMType() const; |
Stephen Hines | ecddee3 | 2011-07-20 18:30:09 -0700 | [diff] [blame] | 578 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 579 | public: |
Zonr Chang | 0da0a7d | 2010-10-05 21:26:37 +0800 | [diff] [blame] | 580 | inline const std::list<const Field*>& getFields() const { return mFields; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 581 | inline bool isPacked() const { return mIsPacked; } |
| 582 | inline bool isArtificial() const { return mIsArtificial; } |
Jean-Luc Brouillet | c95381a | 2014-05-14 21:24:45 -0700 | [diff] [blame] | 583 | virtual size_t getStoreSize() const { return mStoreSize; } |
| 584 | virtual size_t getAllocSize() const { return mAllocSize; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 585 | |
Stephen Hines | a6b5414 | 2012-04-09 18:25:08 -0700 | [diff] [blame] | 586 | virtual std::string getElementName() const { |
| 587 | return "ScriptField_" + getName(); |
| 588 | } |
| 589 | |
Zonr Chang | 3cd3dd3 | 2010-10-22 02:11:35 +0800 | [diff] [blame] | 590 | virtual bool keep(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 591 | virtual bool equals(const RSExportable *E) const; |
| 592 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 593 | ~RSExportRecordType() { |
| 594 | for (std::list<const Field*>::iterator I = mFields.begin(), |
| 595 | E = mFields.end(); |
| 596 | I != E; |
| 597 | I++) |
| 598 | if (*I != NULL) |
| 599 | delete *I; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 600 | } |
| 601 | }; // RSExportRecordType |
| 602 | |
| 603 | } // namespace slang |
| 604 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 605 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_ NOLINT |