slang_rs_export_type.h revision d5a84f6d49d64738e4bb7c9dea7242e48acad959
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/*
2d5a84f6d49d64738e4bb7c9dea7242e48acad959Stephen Hines * Copyright 2010-2012, 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
63fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hinestypedef struct {
64fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * rs_type;
65fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * rs_short_type;
66fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    uint32_t size_in_bits;
67fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * c_name;
68fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * java_name;
69fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * rs_c_vector_prefix;
70fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    const char * rs_java_vector_prefix;
71fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    bool java_promotion;
72fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines} RSReflectionType;
73fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines
741b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams
751b6a0883cd6984e11e59b0c847fb334df1f41afcJason Samstypedef struct RSReflectionTypeData_rec {
761b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    const RSReflectionType *type;
771b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    uint32_t vecSize;
781b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    bool isPointer;
791b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    uint32_t arraySize;
801b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams
811b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    // Subelements
821b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    //std::vector<const struct RSReflectionTypeData_rec *> fields;
831b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    //std::vector< std::string > fieldNames;
841b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams    //std::vector< uint32_t> fieldOffsetBytes;
851b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams} RSReflectionTypeData;
861b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams
871b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams
88a41ce1d98094da84643995d40d71c529905123fcZonr Changclass RSExportType : public RSExportable {
899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPrimitive,
939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassPointer,
949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassVector,
9592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    ExportClassMatrix,
962e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    ExportClassConstantArray,
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    ExportClassRecord
989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } ExportClass;
99462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1001b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams  void convertToRTD(RSReflectionTypeData *rtd) const;
1011b6a0883cd6984e11e59b0c847fb334df1f41afcJason Sams
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
1036b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  ExportClass mClass;
1049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mName;
1059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Cache the result after calling convertToLLVMType() at the first time
1077c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  mutable llvm::Type *mLLVMType;
108a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  // Cache the result after calling convertToSpecType() at the first time
109a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  mutable union RSType *mSpecType;
1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
1126b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  RSExportType(RSContext *Context,
1136b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               ExportClass Class,
1146b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang               const llvm::StringRef &Name);
1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Let's make it private since there're some prerequisites to call this
1179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // function.
1189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
119e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @T was normalized by calling RSExportType::NormalizeType().
1206315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  // @TypeName was retrieve from RSExportType::GetTypeName() before calling
1216315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  //           this.
1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context,
1249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                              const clang::Type *T,
1256315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                              const llvm::StringRef &TypeName);
1269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::Type *T);
1289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // This function convert the RSExportType to LLVM type. Actually, it should be
1309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // "convert Clang type to LLVM type." However, clang doesn't make this API
1319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (lib/CodeGen/CodeGenTypes.h) public, we need to do by ourselves.
1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  //
1339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Once we can get LLVM type, we can use LLVM to get alignment information,
1349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // allocation size of a given type and structure layout that LLVM used
1359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // (all of these information are target dependent) without dealing with these
1369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // by ourselves.
1377c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const = 0;
138e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines  // Record type may recursively reference its type definition. We need a
1393cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  // temporary type setup before the type construction gets done.
1407c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  inline void setAbstractLLVMType(llvm::Type *LLVMType) const {
1413cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang    mLLVMType = LLVMType;
1423cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  }
1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
144a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const = 0;
145a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  inline void setSpecTypeTemporarily(union RSType *SpecType) const {
146a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    mSpecType = SpecType;
147a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  }
148a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang
149a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual ~RSExportType();
150ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
152e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // This function additionally verifies that the Type T is exportable.
153e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // If it is not, this function returns false. Otherwise it returns true.
154e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  static bool NormalizeType(const clang::Type *&T,
155e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines                            llvm::StringRef &TypeName,
1569207a2e495c8363606861e4f034504ec5c153dabLogan Chien                            clang::DiagnosticsEngine *Diags,
1575bfec8dd08b3bde9ba3b331e2115210b0e910eaeStephen Hines                            const clang::VarDecl *VD);
15878e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines
15978e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines  // This function ensures that the VarDecl can be properly handled by RS.
16078e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines  // If it cannot, this function returns false. Otherwise it returns true.
161d5a84f6d49d64738e4bb7c9dea7242e48acad959Stephen Hines  static bool ValidateVarDecl(clang::VarDecl *VD, unsigned int TargetAPI);
16278e69cb06b9b0683b2ac9dcafde87b867690ef2fStephen Hines
1639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
1649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *Create(RSContext *Context, const clang::Type *T);
1659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportType *CreateFromDecl(RSContext *Context,
1669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                      const clang::VarDecl *VD);
1679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const clang::Type *GetTypeOfDecl(const clang::DeclaratorDecl *DD);
1699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1706b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang  inline ExportClass getClass() const { return mClass; }
1719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1727c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  inline llvm::Type *getLLVMType() const {
1739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    if (mLLVMType == NULL)
1749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      mLLVMType = convertToLLVMType();
1759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mLLVMType;
1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
177462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
178a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  inline const union RSType *getSpecType() const {
179a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    if (mSpecType == NULL)
180a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang      mSpecType = convertToSpecType();
181a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang    return mSpecType;
182a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  }
183a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang
1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Return the number of bits necessary to hold the specified RSExportType
1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeStoreSize(const RSExportType *ET);
186462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // The size of allocation of specified RSExportType (alignment considered)
1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetTypeAllocSize(const RSExportType *ET);
189462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
190641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  inline const std::string &getName() const { return mName; }
191641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
1923cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
193641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportType
195462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Primitive types
197462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPrimitiveType : public RSExportType {
1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
1999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // From graphics/java/android/renderscript/Element.java: Element.DataType
2029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef enum {
203feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines    DataTypeIsStruct = -2,
2049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeUnknown = -1,
2059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
206b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_PRIMITIVE_DATA_TYPE_RANGE(begin_type, end_type)  \
207b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstPrimitiveType = DataType ## begin_type,  \
208b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastPrimitiveType = DataType ## end_type,
209b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
210b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_RS_MATRIX_DATA_TYPE_RANGE(begin_type, end_type)  \
211b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstRSMatrixType = DataType ## begin_type,  \
212b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastRSMatrixType = DataType ## end_type,
213b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
214b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang#define ENUM_RS_OBJECT_DATA_TYPE_RANGE(begin_type, end_type)  \
215b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    FirstRSObjectType = DataType ## begin_type,  \
216b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang    LastRSObjectType = DataType ## end_type,
217b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
218a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#define ENUM_RS_DATA_TYPE(type, cname, bits)  \
219a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang    DataType ## type,
220b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
221a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang#include "RSDataTypeEnums.inc"
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    DataTypeMax
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  } DataType;
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
227a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // NOTE: There's no any instance of RSExportPrimitiveType which mType
228a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // is of the value DataTypeRSMatrix*. DataTypeRSMatrix* enumeration here is
229a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // only for RSExportPrimitiveType::GetRSObjectType to *recognize* the struct
230a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // rs_matrix{2x2, 3x3, 4x4}. These matrix type are represented as
231a65ec168e41e3ee9c6e8ac04cde694bbbfc2590aZonr Chang  // RSExportMatrixType.
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  DataType mType;
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mNormalized;
2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
235b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  typedef llvm::StringMap<DataType> RSSpecificTypeMapTy;
236b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static llvm::ManagedStatic<RSSpecificTypeMapTy> RSSpecificTypeMap;
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::Type *RSObjectLLVMType;
2399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static const size_t SizeOfDataTypeInBits[];
241e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @T was normalized by calling RSExportType::NormalizeType() before calling
2429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
2439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const clang::Type *T,
2479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       const llvm::StringRef &TypeName,
2489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                       bool Normalized = false);
2499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao protected:
2519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPrimitiveType(RSContext *Context,
2526b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        // for derived class to set their type class
2536b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                        ExportClass Class,
2549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        const llvm::StringRef &Name,
2559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                        DataType DT,
2566315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                        bool Normalized)
2576b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, Class, Name),
2586315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mType(DT),
2596315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNormalized(Normalized) {
2609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
2619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2637c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
264a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
2652ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines
2662ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines  static DataType GetDataType(RSContext *Context, const clang::Type *T);
2672ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines
2689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
269dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  // T is normalized by calling RSExportType::NormalizeType() before
270dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  // calling this
271dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines  static bool IsPrimitiveType(const clang::Type *T);
272dd6206bb61bf8df2ed6b643abe8a29c48a315685Stephen Hines
2739ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @T may not be normalized
2749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPrimitiveType *Create(RSContext *Context,
2752b8fb64be3047df940a219872b331eb11de2758dStephen Hines                                       const clang::Type *T);
276462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
277b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static DataType GetRSSpecificType(const llvm::StringRef &TypeName);
278b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static DataType GetRSSpecificType(const clang::Type *T);
279b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang
280b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static bool IsRSMatrixType(DataType DT);
281b1771ef128b10c4d4575634828006bfba20b1d9cZonr Chang  static bool IsRSObjectType(DataType DT);
282f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  static bool IsRSObjectType(const clang::Type *T) {
283f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines    return IsRSObjectType(GetRSSpecificType(T));
284f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  }
285462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
286feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  // Determines whether T is [an array of] struct that contains at least one
287feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  // RS object type within it.
288feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines  static bool IsStructureTypeWithRSObject(const clang::Type *T);
289feaca06fcb0772e9e972a0d61b17259fc5124d50Stephen Hines
2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static size_t GetSizeInBits(const RSExportPrimitiveType *EPT);
291462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline DataType getType() const { return mType; }
2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isRSObjectType() const {
294b3a12fe7c18a06f99201dc491a932a90ab7d975cStephen Hines    return ((mType >= FirstRSObjectType) && (mType <= LastRSObjectType));
2959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
296641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
297641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
298fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines
299fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines  static RSReflectionType *getRSReflectionType(DataType DT);
300fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines  static RSReflectionType *getRSReflectionType(
301fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines      const RSExportPrimitiveType *EPT) {
302fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines    return getRSReflectionType(EPT->getType());
303fdd1ba13a69501a1b91fdc9be31413215d467497Stephen Hines  }
3049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPrimitiveType
305462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
306462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
307462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportPointerType : public RSExportType {
3089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportFunc;
3109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
3119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const RSExportType *mPointeeType;
3129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportPointerType(RSContext *Context,
3149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                      const llvm::StringRef &Name,
3156315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr                      const RSExportType *PointeeType)
3166b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassPointer, Name),
3176315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mPointeeType(PointeeType) {
3189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
3199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
3209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
321e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @PT was normalized by calling RSExportType::NormalizeType() before calling
3229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
3239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportPointerType *Create(RSContext *Context,
3249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const clang::PointerType *PT,
3259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                     const llvm::StringRef &TypeName);
3269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3277c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
328a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
329ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
3309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3313cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
332641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
3339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const RSExportType *getPointeeType() const { return mPointeeType; }
334641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
335641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
3369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportPointerType
337462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
338462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
339462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportVectorType : public RSExportPrimitiveType {
3409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
3419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportElement;
3429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
34392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  unsigned mNumElement;   // number of element
3449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportVectorType(RSContext *Context,
3469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
3479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     DataType DT,
3489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool Normalized,
34992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned NumElement)
3506b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportPrimitiveType(Context, ExportClassVector, Name,
3512b8fb64be3047df940a219872b331eb11de2758dStephen Hines                              DT, Normalized),
3526315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mNumElement(NumElement) {
3539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
3549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
3559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
356e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @EVT was normalized by calling RSExportType::NormalizeType() before
3579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // calling this.
3589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportVectorType *Create(RSContext *Context,
3599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::ExtVectorType *EVT,
3609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
3619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool Normalized = false);
3629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
3637c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
364a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
365ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
3669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
3679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static llvm::StringRef GetTypeName(const clang::ExtVectorType *EVT);
368462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
36992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getNumElement() const { return mNumElement; }
370641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
371641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
37292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang};
37392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
37492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// Only *square* *float* matrix is supported by now.
37592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
37692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// struct rs_matrix{2x2,3x3,4x4, ..., NxN} should be defined as the following
37792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang// form *exactly*:
37892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  typedef struct {
37992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//    float m[{NxN}];
38092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  } rs_matrixNxN;
38192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//
38292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang//  where mDim will be N.
38392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Changclass RSExportMatrixType : public RSExportType {
38492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  friend class RSExportType;
38592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang private:
3862e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mDim;  // dimension
38792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
38892b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  RSExportMatrixType(RSContext *Context,
38992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     const llvm::StringRef &Name,
39092b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                     unsigned Dim)
3916b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang    : RSExportType(Context, ExportClassMatrix, Name),
39292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang      mDim(Dim) {
39392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang    return;
39492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  }
39592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
3967c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
397a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
398ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
39992b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang public:
400e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @RT was normalized by calling RSExportType::NormalizeType() before
40192b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  // calling this.
40292b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  static RSExportMatrixType *Create(RSContext *Context,
40392b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const clang::RecordType *RT,
40492b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    const llvm::StringRef &TypeName,
40592b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang                                    unsigned Dim);
40692b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang
40792b344a51c6c4934e96882bd401e4b13d6d03db8Zonr Chang  inline unsigned getDim() const { return mDim; }
408641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
409641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
410462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
411462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4122e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Changclass RSExportConstantArrayType : public RSExportType {
4132e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  friend class RSExportType;
4142e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang private:
4152e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  const RSExportType *mElementType;  // Array element type
4162e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  unsigned mSize;  // Array size
4172e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
4182e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  RSExportConstantArrayType(RSContext *Context,
4192e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            const RSExportType *ElementType,
4202e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                            unsigned Size)
4212e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    : RSExportType(Context,
4226b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang                   ExportClassConstantArray,
4232e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                   DUMMY_TYPE_NAME_FOR_RS_CONSTANT_ARRAY_TYPE),
4242e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mElementType(ElementType),
4252e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang      mSize(Size) {
4262e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang    return;
4272e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  }
4282e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
429e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @CAT was normalized by calling RSExportType::NormalizeType() before
4302e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  // calling this.
4312e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  static RSExportConstantArrayType *Create(RSContext *Context,
4322e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang                                           const clang::ConstantArrayType *CAT);
4332e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
4347c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
435a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
436ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
4372e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang public:
4382e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline unsigned getSize() const { return mSize; }
4392e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang  inline const RSExportType *getElementType() const { return mElementType; }
440641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
4413cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
442641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
4432e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang};
4442e1dba6c779a0ae55c76d36a3c03553e16725ab7Zonr Chang
445462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSExportRecordType : public RSExportType {
4469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  friend class RSExportType;
4479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
4489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  class Field {
4499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   private:
4509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportType *mType;
4519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Field name
4529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    std::string mName;
4539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    // Link to the struct that contain this field
4549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    const RSExportRecordType *mParent;
4550da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    // Offset in the container
4560da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    size_t mOffset;
4579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao   public:
4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    Field(const RSExportType *T,
4609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const llvm::StringRef &Name,
4619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao          const RSExportRecordType *Parent,
4620da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          size_t Offset)
4636315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        : mType(T),
4646315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mName(Name.data(), Name.size()),
4656315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr          mParent(Parent),
4660da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang          mOffset(Offset) {
4679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      return;
468462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao    }
469462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportRecordType *getParent() const { return mParent; }
4719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const RSExportType *getType() const { return mType; }
4729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    inline const std::string &getName() const { return mName; }
4730da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang    inline size_t getOffsetInParent() const { return mOffset; }
4749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  };
475462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<const Field*>::const_iterator const_field_iterator;
477462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
4789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_begin() const {
4799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.begin();
4809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const_field_iterator fields_end() const {
4829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return this->mFields.end();
4839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
4849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
4869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::list<const Field*> mFields;
4879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsPacked;
4889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Artificial export struct type is not exported by user (and thus it won't
4899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // get reflected)
4909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool mIsArtificial;
4910da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  size_t mAllocSize;
4929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
4939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  RSExportRecordType(RSContext *Context,
4949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     const llvm::StringRef &Name,
4959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                     bool IsPacked,
4960da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     bool IsArtificial,
4970da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang                     size_t AllocSize)
4986b6320ad5faee29e0f75fe937e40156746ef9e80Zonr Chang      : RSExportType(Context, ExportClassRecord, Name),
4996315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr        mIsPacked(IsPacked),
5000da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mIsArtificial(IsArtificial),
5010da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang        mAllocSize(AllocSize) {
5029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
5039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
5049ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
505e5e64432476a44b59c61ded233b1149109c7a7c3Stephen Hines  // @RT was normalized by calling RSExportType::NormalizeType() before calling
5069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
5079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // @TypeName was retrieved from RSExportType::GetTypeName() before calling
5089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // this.
5099ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  static RSExportRecordType *Create(RSContext *Context,
5109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const clang::RecordType *RT,
5119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    const llvm::StringRef &TypeName,
5129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao                                    bool mIsArtificial = false);
5139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
5147c67e578c760408dba0c2f64da6e074dd8b56fd9Shih-wei Liao  virtual llvm::Type *convertToLLVMType() const;
515a7a828d1ff95c5a8f2327f56a137a2bcb3a9a8faZonr Chang  virtual union RSType *convertToSpecType() const;
516ecddee364d731c09c77b4c3fa647fa4f50e26756Stephen Hines
5179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
5180da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline const std::list<const Field*>& getFields() const { return mFields; }
5199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isPacked() const { return mIsPacked; }
5209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool isArtificial() const { return mIsArtificial; }
5210da0a7dc51c25943fe31d0bfccbdfee326a3199cZonr Chang  inline size_t getAllocSize() const { return mAllocSize; }
5229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
5233cd3dd327445fcfa49f0e96cb2de2055bce541e9Zonr Chang  virtual bool keep();
524641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  virtual bool equals(const RSExportable *E) const;
525641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang
5269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSExportRecordType() {
5279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    for (std::list<const Field*>::iterator I = mFields.begin(),
5289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao             E = mFields.end();
5299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I != E;
5309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao         I++)
5319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      if (*I != NULL)
5329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao        delete *I;
5339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return;
5349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
5359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao};  // RSExportRecordType
5369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
5379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
5389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
539e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_TYPE_H_  NOLINT
540