slang_rs_reflect_utils.h revision dba3111408b307d8454830107ff61089ab7c5d6d
1#ifndef _SLANG_COMPILER_SLANG_REFLECT_UTILS_H 2#define _SLANG_COMPILER_SLANG_REFLECT_UTILS_H 3 4#include <string> 5 6namespace slang { 7 8// BitCode storage type 9enum BitCodeStorageType { 10 BCST_APK_RESOURCE, 11 BCST_JAVA_CODE 12}; 13 14class RSSlangReflectUtils { 15 public: 16 17 // Encode a binary bitcode file into a Java source file. 18 // rsFileName: the original .rs file name (with or without path). 19 // bcFileName: where is the bit code file 20 // reflectPath: where to output the generated Java file, no package name in 21 // it. 22 // packageName: the package of the output Java file. 23 struct BitCodeAccessorContext { 24 const char *rsFileName; 25 const char *bcFileName; 26 const char *reflectPath; 27 const char *packageName; 28 29 BitCodeStorageType bcStorage; 30 }; 31 32 // Return the stem of the file name, i.e., remove the dir and the extension. 33 // Eg, foo.ext -> foo 34 // foo.bar.ext -> foo.bar 35 // ./path/foo.ext -> foo 36 static std::string GetFileNameStem(const char* fileName); 37 38 // Compuate a Java source file path from a given prefixPath and its package. 39 // Eg, given prefixPath=./foo/bar and packageName=com.x.y, then it returns 40 // ./foo/bar/com/x/y 41 static std::string ComputePackagedPath(const char *prefixPath, 42 const char *packageName); 43 44 // Compute Java class name from a .rs file name. 45 // Any non-alnum, non-underscore characters will be discarded. 46 // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns 47 // "myRenderscript_file". 48 // rsFileName: the input .rs file name (with or without path). 49 static std::string JavaClassNameFromRSFileName(const char *rsFileName); 50 51 // Compute a bitcode file name (no extension) from a .rs file name. 52 // Because the bitcode file name may be used as Resource ID in the generated 53 // class (something like R.raw.<bitcode_filename>), Any non-alnum, 54 // non-underscore character will be discarded. 55 // The difference from JavaClassNameFromRSFileName() is that the result is 56 // converted to lowercase. 57 // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns 58 // "myrenderscript_file" 59 // rsFileName: the input .rs file name (with or without path). 60 static std::string BCFileNameFromRSFileName(const char *rsFileName); 61 62 // "mkdir -p" 63 static bool mkdir_p(const char *path); 64 65 66 // Generate the bit code accessor Java source file. 67 static bool GenerateBitCodeAccessor(const BitCodeAccessorContext &context); 68}; 69} 70 71#endif // _SLANG_COMPILER_SLANG_REFLECT_UTILS_H 72