slang_rs_export_type.h revision 7c67e578c760408dba0c2f64da6e074dd8b56fd9
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/*
2c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Copyright 2010, The Android Open Source Project
3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License");
5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License.
6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at
7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *     http://www.apache.org/licenses/LICENSE-2.0
9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang *
10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software
11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS,
12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and
14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License.
15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */
16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang
17e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_  // NOLINT
18e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_
19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <list>
21e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <set>
229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include <string>
239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
24e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/Decl.h"
25e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/Type.h"
26a41ce1d98094da84643995d40d71c529905123fcZonr Chang
276315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "llvm/ADT/SmallPtrSet.h"
28e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/ADT/StringMap.h"
29e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/ADT/StringRef.h"
306315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr
31e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/ManagedStatic.h"
326315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr
33a41ce1d98094da84643995d40d71c529905123fcZonr Chang#include "slang_rs_exportable.h"
34a41ce1d98094da84643995d40d71c529905123fcZonr Chang
359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_CANONICAL_TYPE(T) \
362e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : (T)->getCanonicalTypeInternal().getTypePtr())
379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define UNSAFE_CAST_TYPE(TT, T) \
382e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    static_cast<TT*>(T->getCanonicalTypeInternal().getTypePtr())
399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_EXT_VECTOR_ELEMENT_TYPE(T) \
402e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
412e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#define GET_POINTEE_TYPE(T) \
432e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
442e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getPointeeType().getTypePtr()))
452e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define GET_CONSTANT_ARRAY_ELEMENT_TYPE(T)  \
462e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    (((T) == NULL) ? NULL : \
472e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                     GET_CANONICAL_TYPE((T)->getElementType().getTypePtr()))
480da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_PREFIX   "<"
490da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang#define DUMMY_RS_TYPE_NAME_POSTFIX  ">"
502e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang#define DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE  \
512e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    DUMMY_RS_TYPE_NAME_PREFIX"ConstantArray"DUMMY_RS_TYPE_NAME_POSTFIX
52462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
53a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Changunion RSType;
54a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang
55462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
566315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class Type;
579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace llvm
58462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
59462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
60462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
616315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class RSContext;
62462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
63a41ce1d98094da84643995d40d71c529905123fcZonr Changclass RSExportType : public RSExportable {
649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPrimitive,
689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPointer,
699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassVector,
7092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    ExportClassMatrix,
712e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    ExportClassConstantArray,
729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassRecord
739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } ExportClass;
74462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
766b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  ExportClass mClass;
779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mName;
789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Cache the result after calling convertToLLVMType() at the first time
807c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  mutable llvm::Type *mLLVMType;
81a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  // Cache the result after calling convertToSpecType() at the first time
82a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  mutable union RSType *mSpecType;
839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
856b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  RSExportType(RSContext *Context,
866b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               ExportClass Class,
876b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               const llvm::StringRef &Name);
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Let's make it private since there're some prerequisites to call this
909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // function.
919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
92e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @T was normalized by calling RSExportType::NormalizeType().
936315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  // @TypeName was retrieve from RSExportType::GetTypeName() before calling
946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  //           this.
959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context,
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                              const clang::Type *T,
986315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                              const llvm::StringRef &TypeName);
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::Type *T);
1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // This function convert the RSExportType to LLVM type. Actually, it should be
1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // "convert Clang type to LLVM type." However, clang doesn't make this API
1049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Once we can get LLVM type, we can use LLVM to get alignment information,
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // allocation size of a given type and structure layout that LLVM used
1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (all of these information are target dependent) without dealing with these
1099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // by ourselves.
1107c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const = 0;
111e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines  // Record type may recursively reference its type definition. We need a
1123cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  // temporary type setup before the type construction gets done.
1137c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  inline void setAbstractLLVMType(llvm::Type *LLVMType) const {
1143cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang    mLLVMType = LLVMType;
1153cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  }
1169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
117a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const = 0;
118a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  inline void setSpecTypeTemporarily(union RSType *SpecType) const {
119a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    mSpecType = SpecType;
120a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  }
121a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang
122a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual ~RSExportType();
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
124e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // This function additionally verifies that the Type T is exportable.
125e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // If it is not, this function returns false. Otherwise it returns true.
126e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  static bool NormalizeType(const clang::Type *&T,
127e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines                            llvm::StringRef &TypeName,
128e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines                            clang::Diagnostic *Diags,
129dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines                            const clang::VarDecl *VD);
13078e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines
13178e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines  // This function ensures that the VarDecl can be properly handled by RS.
13278e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines  // If it cannot, this function returns false. Otherwise it returns true.
13378e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines  static bool ValidateVarDecl(clang::VarDecl *VD);
13478e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines
1359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
1369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context, const clang::Type *T);
1379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *CreateFromDecl(RSContext *Context,
1389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                      const clang::VarDecl *VD);
1399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
1419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1426b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  inline ExportClass getClass() const { return mClass; }
1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1447c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  inline llvm::Type *getLLVMType() const {
1459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    if (mLLVMType == NULL)
1469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      mLLVMType = convertToLLVMType();
1479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mLLVMType;
1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
149462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
150a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  inline const union RSType *getSpecType() const {
151a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    if (mSpecType == NULL)
152a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang      mSpecType = convertToSpecType();
153a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    return mSpecType;
154a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  }
155a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang
1569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the number of bits necessary to hold the specified RSExportType
1579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeStoreSize(const RSExportType *ET);
158462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // The size of allocation of specified RSExportType (alignment considered)
1609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeAllocSize(const RSExportType *ET);
161462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
162641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  inline const std::string &getName() const { return mName; }
163641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
1643cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
165641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
1669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportType
167462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types
169462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType {
1709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
1729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataType
1749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
175feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines    DataTypeIsStruct = -2,
1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeUnknown = -1,
1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
178b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_PRIMITIVE_DATA_TYPE_RANGE(begin_type, end_type)  \
179b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstPrimitiveType = DataType ## begin_type,  \
180b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastPrimitiveType = DataType ## end_type,
181b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
182b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_RS_MATRIX_DATA_TYPE_RANGE(begin_type, end_type)  \
183b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstRSMatrixType = DataType ## begin_type,  \
184b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastRSMatrixType = DataType ## end_type,
185b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
186b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_RS_OBJECT_DATA_TYPE_RANGE(begin_type, end_type)  \
187b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstRSObjectType = DataType ## begin_type,  \
188b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastRSObjectType = DataType ## end_type,
189b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
190a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_TYPE(type, cname, bits)  \
191a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    DataType ## type,
192b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
193a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataTypeEnums.inc"
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeMax
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataType;
1979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataKind
1999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
200a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    DataKindUnknown = -1
201a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_KIND(kind) \
202a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    , DataKind ## kind
203a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataKindEnums.inc"
2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataKind;
205462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
207a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // NOTE: There's no any instance of RSExportPrimitiveType which mType
208a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
209a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
210a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
211a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // RSExportMatrixType.
2129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataType mType;
2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataKind mKind;
2149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mNormalized;
2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
216b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  typedef llvm::StringMap<DataType> RSSpecificTypeMapTy;
217b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static llvm::ManagedStatic<RSSpecificTypeMapTy> RSSpecificTypeMap;
2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::Type *RSObjectLLVMType;
2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const size_t SizeOfDataTypeInBits[];
222e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @T was normalized by calling RSExportType::NormalizeType() before calling
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const llvm::StringRef &TypeName,
2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser,
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       bool Normalized = false);
2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPrimitiveType(RSContext *Context,
2346b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        // for derived class to set their type class
2356b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        ExportClass Class,
2369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        const llvm::StringRef &Name,
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataType DT,
2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataKind DK,
2396315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                        bool Normalized)
2406b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, Class, Name),
2416315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mType(DT),
2426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mKind(DK),
2436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNormalized(Normalized) {
2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2477c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
248a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
2492ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines
2502ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines  static DataType GetDataType(RSContext *Context, const clang::Type *T);
2512ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines
2529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
253dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  // T is normalized by calling RSExportType::NormalizeType() before
254dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  // calling this
255dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  static bool IsPrimitiveType(const clang::Type *T);
256dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines
2579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
2589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       DataKind DK = DataKindUser);
261462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
262b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static DataType GetRSSpecificType(const llvm::StringRef &TypeName);
263b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static DataType GetRSSpecificType(const clang::Type *T);
264b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
265b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static bool IsRSMatrixType(DataType DT);
266b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static bool IsRSObjectType(DataType DT);
267f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  static bool IsRSObjectType(const clang::Type *T) {
268f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines    return IsRSObjectType(GetRSSpecificType(T));
269f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  }
270462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
271feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  // Determines whether T is [an array of] struct that contains at least one
272feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  // RS object type within it.
273feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  static bool IsStructureTypeWithRSObject(const clang::Type *T);
274feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines
2759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
276462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataType getType() const { return mType; }
2789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataKind getKind() const { return mKind; }
2799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isRSObjectType() const {
280b3a12fe7c18a06f99201dc491a932a90ab7d975cStephen Hines    return ((mType >= FirstRSObjectType) && (mType <= LastRSObjectType));
2819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
282641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
283641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
2849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPrimitiveType
285462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
286462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
287462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType {
2889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
2899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportFunc;
2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const RSExportType *mPointeeType;
2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPointerType(RSContext *Context,
2949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                      const llvm::StringRef &Name,
2956315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                      const RSExportType *PointeeType)
2966b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassPointer, Name),
2976315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mPointeeType(PointeeType) {
2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
301e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @PT was normalized by calling RSExportType::NormalizeType() before calling
3029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
3039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPointerType *Create(RSContext *Context,
3049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const clang::PointerType *PT,
3059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const llvm::StringRef &TypeName);
3069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3077c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
308a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
3099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3103cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
311641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
3129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const RSExportType *getPointeeType() const { return mPointeeType; }
313641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
314641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
3159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPointerType
316462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
317462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
318462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType {
3199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
3219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
32292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  unsigned mNumElement;   // number of element
3239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportVectorType(RSContext *Context,
3259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
3269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataType DT,
3279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataKind DK,
3289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool Normalized,
32992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned NumElement)
3306b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportPrimitiveType(Context, ExportClassVector, Name,
3316b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                              DT, DK, Normalized),
3326315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNumElement(NumElement) {
3339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
3349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
3359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
336e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @EVT was normalized by calling RSExportType::NormalizeType() before
3379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this.
3389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportVectorType *Create(RSContext *Context,
3399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::ExtVectorType *EVT,
3409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
3419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    DataKind DK = DataKindUser,
3429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool Normalized = false);
3439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3447c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
345a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
3469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
348462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
34992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getNumElement() const { return mNumElement; }
350641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
351641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
35292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang};
35392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
35492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now.
35592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
35692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
35792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*:
35892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  typedef struct {
35992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//    float m[{NxN}];
36092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  } rs_matrixNxN;
36192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
36292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  where mDim will be N.
36392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType {
36492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  friend class RSExportType;
36592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private:
3662e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mDim;  // dimension
36792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
36892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  RSExportMatrixType(RSContext *Context,
36992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     const llvm::StringRef &Name,
37092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned Dim)
3716b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang    : RSExportType(Context, ExportClassMatrix, Name),
37292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang      mDim(Dim) {
37392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    return;
37492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  }
37592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
3767c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
377a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
37892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public:
379e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @RT was normalized by calling RSExportType::NormalizeType() before
38092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // calling this.
38192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  static RSExportMatrixType *Create(RSContext *Context,
38292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const clang::RecordType *RT,
38392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const llvm::StringRef &TypeName,
38492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    unsigned Dim);
38592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
38692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getDim() const { return mDim; }
387641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
388641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
389462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
390462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3912e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType {
3922e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  friend class RSExportType;
3932e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private:
3942e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  const RSExportType *mElementType;  // Array element type
3952e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mSize;  // Array size
3962e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
3972e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  RSExportConstantArrayType(RSContext *Context,
3982e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            const RSExportType *ElementType,
3992e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            unsigned Size)
4002e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    : RSExportType(Context,
4016b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                   ExportClassConstantArray,
4022e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                   DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
4032e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mElementType(ElementType),
4042e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mSize(Size) {
4052e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    return;
4062e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  }
4072e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
408e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @CAT was normalized by calling RSExportType::NormalizeType() before
4092e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // calling this.
4102e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  static RSExportConstantArrayType *Create(RSContext *Context,
4112e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                                           const clang::ConstantArrayType *CAT);
4122e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
4137c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
414a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
4152e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public:
4162e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline unsigned getSize() const { return mSize; }
4172e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline const RSExportType *getElementType() const { return mElementType; }
418641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
4193cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
420641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
4212e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang};
4222e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
423462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType {
4249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
4259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  class Field {
4279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   private:
4289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportType *mType;
4299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Field name
4309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    std::string mName;
4319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Link to the struct that contain this field
4329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportRecordType *mParent;
4330da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    // Offset in the container
4340da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    size_t mOffset;
4359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   public:
4379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    Field(const RSExportType *T,
4389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const llvm::StringRef &Name,
4399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const RSExportRecordType *Parent,
4400da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          size_t Offset)
4416315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        : mType(T),
4426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mName(Name.data(), Name.size()),
4436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mParent(Parent),
4440da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          mOffset(Offset) {
4459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      return;
446462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao    }
447462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportRecordType *getParent() const { return mParent; }
4499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportType *getType() const { return mType; }
4509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const std::string &getName() const { return mName; }
4510da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    inline size_t getOffsetInParent() const { return mOffset; }
4529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  };
453462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<const Field*>::const_iterator const_field_iterator;
455462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_begin() const {
4579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.begin();
4589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_end() const {
4609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.end();
4619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
4649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::list<const Field*> mFields;
4659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsPacked;
4669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Artificial export struct type is not exported by user (and thus it won't
4679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // get reflected)
4689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsArtificial;
4690da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  size_t mAllocSize;
4709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportRecordType(RSContext *Context,
4729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
4739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool IsPacked,
4740da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     bool IsArtificial,
4750da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     size_t AllocSize)
4766b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassRecord, Name),
4776315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mIsPacked(IsPacked),
4780da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mIsArtificial(IsArtificial),
4790da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mAllocSize(AllocSize) {
4809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
4819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
483e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @RT was normalized by calling RSExportType::NormalizeType() before calling
4849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
4869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
4879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportRecordType *Create(RSContext *Context,
4889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::RecordType *RT,
4899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
4909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool mIsArtificial = false);
4919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4927c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
493a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
4949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4950da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline const std::list<const Field*>& getFields() const { return mFields; }
4969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isPacked() const { return mIsPacked; }
4979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isArtificial() const { return mIsArtificial; }
4980da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline size_t getAllocSize() const { return mAllocSize; }
4999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
5003cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
501641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
502641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
5039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSExportRecordType() {
5049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    for (std::list<const Field*>::iterator I = mFields.begin(),
5059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao             E = mFields.end();
5069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I != E;
5079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I++)
5089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      if (*I != NULL)
5099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao        delete *I;
5109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
5119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
5129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportRecordType
5139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
5149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
5159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
516e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_  NOLINT
517