Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 2 | * Copyright 2010-2011, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 19 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 20 | #include <fstream> |
| 21 | #include <iostream> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 22 | #include <map> |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 23 | #include <set> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 26 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
| 28 | |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 29 | #include "slang_assert.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 30 | #include "slang_rs_export_type.h" |
| 31 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 32 | namespace slang { |
| 33 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 34 | class RSContext; |
| 35 | class RSExportVar; |
| 36 | class RSExportFunc; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 37 | class RSExportForEach; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 38 | |
| 39 | class RSReflection { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 40 | private: |
| 41 | const RSContext *mRSContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 42 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 43 | std::string mLastError; |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 44 | std::vector<std::string> *mGeneratedFileNames; |
| 45 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 46 | inline void setError(const std::string &Error) { mLastError = Error; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 47 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 48 | class Context { |
| 49 | private: |
| 50 | static const char *const ApacheLicenseNote; |
Victor Hsieh | d8a0d18 | 2010-07-07 19:22:33 +0800 | [diff] [blame] | 51 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 52 | static const char *const Import[]; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 53 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 54 | bool mVerbose; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 55 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 56 | std::string mOutputPathBase; |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 57 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 58 | std::string mInputRSFile; |
Ying Wang | 4e34844 | 2010-08-18 10:29:12 -0700 | [diff] [blame] | 59 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 60 | std::string mPackageName; |
| 61 | std::string mResourceId; |
Stephen Hines | a9ae5ae | 2011-11-11 21:16:59 -0800 | [diff] [blame] | 62 | std::string mPaddingPrefix; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 63 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 64 | std::string mClassName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 65 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 66 | std::string mLicenseNote; |
Shih-wei Liao | cecd11d | 2010-09-21 08:07:58 -0700 | [diff] [blame] | 67 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 68 | std::string mIndent; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 69 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 70 | int mPaddingFieldIndex; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 71 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 72 | int mNextExportVarSlot; |
| 73 | int mNextExportFuncSlot; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 74 | int mNextExportForEachSlot; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 75 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 76 | // A mapping from a field in a record type to its index in the rsType |
| 77 | // instance. Only used when generates TypeClass (ScriptField_*). |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 78 | typedef std::map<const RSExportRecordType::Field*, unsigned> |
| 79 | FieldIndexMapTy; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 80 | FieldIndexMapTy mFieldIndexMap; |
| 81 | // Field index of current processing TypeClass. |
| 82 | unsigned mFieldIndex; |
Shih-wei Liao | 9c631ff | 2010-09-17 11:57:29 -0700 | [diff] [blame] | 83 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 84 | inline void clear() { |
| 85 | mClassName = ""; |
| 86 | mIndent = ""; |
| 87 | mPaddingFieldIndex = 1; |
| 88 | mNextExportVarSlot = 0; |
| 89 | mNextExportFuncSlot = 0; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 90 | mNextExportForEachSlot = 0; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 91 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 94 | bool openClassFile(const std::string &ClassName, |
| 95 | std::string &ErrorMsg); |
| 96 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 97 | public: |
| 98 | typedef enum { |
| 99 | AM_Public, |
| 100 | AM_Protected, |
Alex Sakhartchouk | 38eca1a | 2011-08-25 10:47:52 -0700 | [diff] [blame] | 101 | AM_Private, |
| 102 | AM_PublicSynchronized |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 103 | } AccessModifier; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 104 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 105 | bool mUseStdout; |
| 106 | mutable std::ofstream mOF; |
| 107 | |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 108 | std::set<std::string> mTypesToCheck; |
| 109 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 110 | static const char *AccessModifierStr(AccessModifier AM); |
| 111 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 112 | Context(const std::string &OutputPathBase, |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 113 | const std::string &InputRSFile, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 114 | const std::string &PackageName, |
| 115 | const std::string &ResourceId, |
Stephen Hines | a9ae5ae | 2011-11-11 21:16:59 -0800 | [diff] [blame] | 116 | const std::string &PaddingPrefix, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 117 | bool UseStdout) |
| 118 | : mVerbose(true), |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 119 | mOutputPathBase(OutputPathBase), |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 120 | mInputRSFile(InputRSFile), |
| 121 | mPackageName(PackageName), |
| 122 | mResourceId(ResourceId), |
Stephen Hines | a9ae5ae | 2011-11-11 21:16:59 -0800 | [diff] [blame] | 123 | mPaddingPrefix(PaddingPrefix), |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 124 | mLicenseNote(ApacheLicenseNote), |
| 125 | mUseStdout(UseStdout) { |
| 126 | clear(); |
Zonr Chang | 66aa299 | 2010-10-05 15:56:31 +0800 | [diff] [blame] | 127 | resetFieldIndex(); |
| 128 | clearFieldIndexMap(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 129 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 130 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 131 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 132 | inline std::ostream &out() const { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 133 | return ((mUseStdout) ? std::cout : mOF); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 134 | } |
| 135 | inline std::ostream &indent() const { |
| 136 | out() << mIndent; |
| 137 | return out(); |
| 138 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 139 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 140 | inline void incIndentLevel() { |
| 141 | mIndent.append(4, ' '); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | inline void decIndentLevel() { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 146 | slangAssert(getIndentLevel() > 0 && "No indent"); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 147 | mIndent.erase(0, 4); |
| 148 | return; |
| 149 | } |
| 150 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 151 | inline int getIndentLevel() { return (mIndent.length() >> 2); } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 152 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 153 | inline int getNextExportVarSlot() { return mNextExportVarSlot++; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 154 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 155 | inline int getNextExportFuncSlot() { return mNextExportFuncSlot++; } |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 156 | inline int getNextExportForEachSlot() { return mNextExportForEachSlot++; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 157 | |
| 158 | // Will remove later due to field name information is not necessary for |
| 159 | // C-reflect-to-Java |
| 160 | inline std::string createPaddingField() { |
Stephen Hines | a9ae5ae | 2011-11-11 21:16:59 -0800 | [diff] [blame] | 161 | return mPaddingPrefix + llvm::itostr(mPaddingFieldIndex++); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | inline void setLicenseNote(const std::string &LicenseNote) { |
| 165 | mLicenseNote = LicenseNote; |
| 166 | } |
| 167 | |
| 168 | bool startClass(AccessModifier AM, |
| 169 | bool IsStatic, |
| 170 | const std::string &ClassName, |
| 171 | const char *SuperClassName, |
| 172 | std::string &ErrorMsg); |
| 173 | void endClass(); |
| 174 | |
| 175 | void startFunction(AccessModifier AM, |
| 176 | bool IsStatic, |
| 177 | const char *ReturnType, |
| 178 | const std::string &FunctionName, |
| 179 | int Argc, ...); |
| 180 | |
| 181 | typedef std::vector<std::pair<std::string, std::string> > ArgTy; |
| 182 | void startFunction(AccessModifier AM, |
| 183 | bool IsStatic, |
| 184 | const char *ReturnType, |
| 185 | const std::string &FunctionName, |
| 186 | const ArgTy &Args); |
| 187 | void endFunction(); |
| 188 | |
| 189 | void startBlock(bool ShouldIndent = false); |
| 190 | void endBlock(); |
| 191 | |
| 192 | inline const std::string &getPackageName() const { return mPackageName; } |
| 193 | inline const std::string &getClassName() const { return mClassName; } |
| 194 | inline const std::string &getResourceId() const { return mResourceId; } |
| 195 | |
| 196 | void startTypeClass(const std::string &ClassName); |
| 197 | void endTypeClass(); |
| 198 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 199 | inline void incFieldIndex() { mFieldIndex++; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 200 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 201 | inline void resetFieldIndex() { mFieldIndex = 0; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 202 | |
| 203 | inline void addFieldIndexMapping(const RSExportRecordType::Field *F) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 204 | slangAssert((mFieldIndexMap.find(F) == mFieldIndexMap.end()) && |
| 205 | "Nested structure never occurs in C language."); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 206 | mFieldIndexMap.insert(std::make_pair(F, mFieldIndex)); |
| 207 | } |
| 208 | |
| 209 | inline unsigned getFieldIndex(const RSExportRecordType::Field *F) const { |
| 210 | FieldIndexMapTy::const_iterator I = mFieldIndexMap.find(F); |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 211 | slangAssert((I != mFieldIndexMap.end()) && |
| 212 | "Requesting field is out of scope."); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 213 | return I->second; |
| 214 | } |
| 215 | |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 216 | inline void clearFieldIndexMap() { mFieldIndexMap.clear(); } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 219 | bool genScriptClass(Context &C, |
| 220 | const std::string &ClassName, |
| 221 | std::string &ErrorMsg); |
| 222 | void genScriptClassConstructor(Context &C); |
| 223 | |
Stephen Hines | 5d67178 | 2012-01-31 19:32:04 -0800 | [diff] [blame^] | 224 | static void genInitBoolExportVariable(Context &C, |
| 225 | const std::string &VarName, |
| 226 | const clang::APValue &Val); |
| 227 | static void genInitPrimitiveExportVariable(Context &C, |
| 228 | const std::string &VarName, |
| 229 | const clang::APValue &Val); |
| 230 | static void genInitExportVariable(Context &C, |
| 231 | const RSExportType *ET, |
| 232 | const std::string &VarName, |
| 233 | const clang::APValue &Val); |
| 234 | static void genInitValue(Context &C, const clang::APValue &Val); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 235 | void genExportVariable(Context &C, const RSExportVar *EV); |
| 236 | void genPrimitiveTypeExportVariable(Context &C, const RSExportVar *EV); |
| 237 | void genPointerTypeExportVariable(Context &C, const RSExportVar *EV); |
| 238 | void genVectorTypeExportVariable(Context &C, const RSExportVar *EV); |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 239 | void genMatrixTypeExportVariable(Context &C, const RSExportVar *EV); |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 240 | void genConstantArrayTypeExportVariable(Context &C, const RSExportVar *EV); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 241 | void genRecordTypeExportVariable(Context &C, const RSExportVar *EV); |
| 242 | void genGetExportVariable(Context &C, |
| 243 | const std::string &TypeName, |
| 244 | const std::string &VarName); |
| 245 | |
| 246 | void genExportFunction(Context &C, |
| 247 | const RSExportFunc *EF); |
| 248 | |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 249 | void genExportForEach(Context &C, |
| 250 | const RSExportForEach *EF); |
| 251 | |
Stephen Hines | 48b72bf | 2011-06-10 15:37:27 -0700 | [diff] [blame] | 252 | static void genTypeCheck(Context &C, |
| 253 | const RSExportType *ET, |
| 254 | const char *VarName); |
| 255 | |
| 256 | static void genTypeInstance(Context &C, |
| 257 | const RSExportType *ET); |
Stephen Hines | b5a89fb | 2011-05-17 14:48:02 -0700 | [diff] [blame] | 258 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 259 | bool genTypeClass(Context &C, |
| 260 | const RSExportRecordType *ERT, |
| 261 | std::string &ErrorMsg); |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 262 | void genTypeItemClass(Context &C, const RSExportRecordType *ERT); |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 263 | void genTypeClassConstructor(Context &C, const RSExportRecordType *ERT); |
| 264 | void genTypeClassCopyToArray(Context &C, const RSExportRecordType *ERT); |
Alex Sakhartchouk | 38eca1a | 2011-08-25 10:47:52 -0700 | [diff] [blame] | 265 | void genTypeClassCopyToArrayLocal(Context &C, const RSExportRecordType *ERT); |
Zonr Chang | 92b344a | 2010-10-05 20:39:03 +0800 | [diff] [blame] | 266 | void genTypeClassItemSetter(Context &C, const RSExportRecordType *ERT); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 267 | void genTypeClassItemGetter(Context &C, const RSExportRecordType *ERT); |
| 268 | void genTypeClassComponentSetter(Context &C, const RSExportRecordType *ERT); |
| 269 | void genTypeClassComponentGetter(Context &C, const RSExportRecordType *ERT); |
| 270 | void genTypeClassCopyAll(Context &C, const RSExportRecordType *ERT); |
Zonr Chang | d42a429 | 2010-10-17 02:38:43 +0800 | [diff] [blame] | 271 | void genTypeClassResize(Context &C); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 272 | |
| 273 | void genBuildElement(Context &C, |
Zonr Chang | 89273bd | 2010-10-14 20:57:38 +0800 | [diff] [blame] | 274 | const char *ElementBuilderName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 275 | const RSExportRecordType *ERT, |
Zonr Chang | 89273bd | 2010-10-14 20:57:38 +0800 | [diff] [blame] | 276 | const char *RenderScriptVar, |
| 277 | bool IsInline); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 278 | void genAddElementToElementBuilder(Context &C, |
| 279 | const RSExportType *ERT, |
| 280 | const std::string &VarName, |
| 281 | const char *ElementBuilderName, |
Zonr Chang | 89273bd | 2010-10-14 20:57:38 +0800 | [diff] [blame] | 282 | const char *RenderScriptVar, |
| 283 | unsigned ArraySize); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 284 | void genAddPaddingToElementBuiler(Context &C, |
| 285 | int PaddingSize, |
| 286 | const char *ElementBuilderName, |
| 287 | const char *RenderScriptVar); |
| 288 | |
| 289 | bool genCreateFieldPacker(Context &C, |
| 290 | const RSExportType *T, |
| 291 | const char *FieldPackerName); |
| 292 | void genPackVarOfType(Context &C, |
| 293 | const RSExportType *T, |
| 294 | const char *VarName, |
| 295 | const char *FieldPackerName); |
Zonr Chang | 2e1dba6 | 2010-10-05 22:20:11 +0800 | [diff] [blame] | 296 | void genAllocateVarOfType(Context &C, |
| 297 | const RSExportType *T, |
| 298 | const std::string &VarName); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 299 | void genNewItemBufferIfNull(Context &C, const char *Index); |
| 300 | void genNewItemBufferPackerIfNull(Context &C); |
| 301 | |
| 302 | public: |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 303 | explicit RSReflection(const RSContext *Context, |
| 304 | std::vector<std::string> *GeneratedFileNames) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 305 | : mRSContext(Context), |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 306 | mLastError(""), |
| 307 | mGeneratedFileNames(GeneratedFileNames) { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 308 | slangAssert(mGeneratedFileNames && "Must supply GeneratedFileNames"); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 309 | return; |
| 310 | } |
| 311 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 312 | bool reflect(const std::string &OutputPathBase, |
| 313 | const std::string &OutputPackageName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 314 | const std::string &InputFileName, |
| 315 | const std::string &OutputBCFileName); |
| 316 | |
| 317 | inline const char *getLastError() const { |
| 318 | if (mLastError.empty()) |
| 319 | return NULL; |
| 320 | else |
| 321 | return mLastError.c_str(); |
| 322 | } |
| 323 | }; // class RSReflection |
| 324 | |
| 325 | } // namespace slang |
| 326 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 327 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_H_ NOLINT |