slang_rs_reflection_cpp.h revision 003ac666e57669d4312b5792068c3db302ee7b84
1/* 2 * Copyright 2012, The Android Open Source Project 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 17#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ // NOLINT 18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ 19 20#include "slang_rs_reflection_base.h" 21 22#include <set> 23#include <string> 24 25namespace slang { 26 27class RSReflectionCpp : public RSReflectionBase { 28 public: 29 explicit RSReflectionCpp(const RSContext *); 30 virtual ~RSReflectionCpp(); 31 32 bool reflect(const std::string &OutputPathBase, 33 const std::string &InputFileName, 34 const std::string &OutputBCFileName); 35 36 37 private: 38 unsigned int mNextExportVarSlot; 39 unsigned int mNextExportFuncSlot; 40 unsigned int mNextExportForEachSlot; 41 42 inline void clear() { 43 mNextExportVarSlot = 0; 44 mNextExportFuncSlot = 0; 45 mNextExportForEachSlot = 0; 46 mTypesToCheck.clear(); 47 } 48 49 inline unsigned int getNextExportVarSlot() { 50 return mNextExportVarSlot++; 51 } 52 53 inline unsigned int getNextExportFuncSlot() { 54 return mNextExportFuncSlot++; 55 } 56 57 inline unsigned int getNextExportForEachSlot() { 58 return mNextExportForEachSlot++; 59 } 60 61 bool makeHeader(const std::string &baseClass); 62 bool makeImpl(const std::string &baseClass); 63 void makeFunctionSignature(std::stringstream &ss, bool isDefinition, 64 const RSExportFunc *ef); 65 bool writeBC(); 66 67 bool startScriptHeader(); 68 69 // Produce an argument string of the form "T1 t, T2 u, T3 v". 70 void makeArgs(std::stringstream &ss, const ArgTy& Args); 71 72 // Write out code for an export variable. 73 void genExportVariable(const RSExportVar *EV); 74 75 void genPrimitiveTypeExportVariable(const RSExportVar *EV); 76 void genPointerTypeExportVariable(const RSExportVar *EV); 77 void genVectorTypeExportVariable(const RSExportVar *EV); 78 void genMatrixTypeExportVariable(const RSExportVar *EV); 79 void genConstantArrayTypeExportVariable(const RSExportVar *EV); 80 void genRecordTypeExportVariable(const RSExportVar *EV); 81 82 // Write out a local FieldPacker (if necessary). 83 bool genCreateFieldPacker(const RSExportType *T, 84 const char *FieldPackerName); 85 86 // Populate (write) the FieldPacker with add() operations. 87 void genPackVarOfType(const RSExportType *ET, 88 const char *VarName, 89 const char *FieldPackerName); 90 91 // Generate a runtime type check for VarName. 92 void genTypeCheck(const RSExportType *ET, const char *VarName); 93 94 // Generate a type instance for a given forEach argument type. 95 void genTypeInstanceFromPointer(const RSExportType *ET); 96 void genTypeInstance(const RSExportType *ET); 97 98}; // class RSReflectionCpp 99 100} // namespace slang 101 102#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ NOLINT 103