Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010, 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 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_ |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | namespace slang { |
| 23 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 24 | // BitCode storage type |
| 25 | enum BitCodeStorageType { |
| 26 | BCST_APK_RESOURCE, |
| 27 | BCST_JAVA_CODE |
| 28 | }; |
| 29 | |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 30 | class RSSlangReflectUtils { |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 31 | public: |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 32 | // Encode a binary bitcode file into a Java source file. |
| 33 | // rsFileName: the original .rs file name (with or without path). |
| 34 | // bcFileName: where is the bit code file |
| 35 | // reflectPath: where to output the generated Java file, no package name in |
| 36 | // it. |
| 37 | // packageName: the package of the output Java file. |
| 38 | struct BitCodeAccessorContext { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 39 | const char *rsFileName; |
| 40 | const char *bcFileName; |
| 41 | const char *reflectPath; |
| 42 | const char *packageName; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 43 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 44 | BitCodeStorageType bcStorage; |
| 45 | }; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 46 | |
Ying Wang | dba3111 | 2010-10-07 17:30:38 -0700 | [diff] [blame] | 47 | // Return the stem of the file name, i.e., remove the dir and the extension. |
| 48 | // Eg, foo.ext -> foo |
| 49 | // foo.bar.ext -> foo.bar |
| 50 | // ./path/foo.ext -> foo |
| 51 | static std::string GetFileNameStem(const char* fileName); |
| 52 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 53 | // Compuate a Java source file path from a given prefixPath and its package. |
| 54 | // Eg, given prefixPath=./foo/bar and packageName=com.x.y, then it returns |
| 55 | // ./foo/bar/com/x/y |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 56 | static std::string ComputePackagedPath(const char *prefixPath, |
| 57 | const char *packageName); |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 58 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 59 | // Compute Java class name from a .rs file name. |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 60 | // Any non-alnum, non-underscore characters will be discarded. |
| 61 | // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns |
| 62 | // "myRenderscript_file". |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 63 | // rsFileName: the input .rs file name (with or without path). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 64 | static std::string JavaClassNameFromRSFileName(const char *rsFileName); |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 65 | |
| 66 | // Compute a bitcode file name (no extension) from a .rs file name. |
| 67 | // Because the bitcode file name may be used as Resource ID in the generated |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 68 | // class (something like R.raw.<bitcode_filename>), Any non-alnum, |
| 69 | // non-underscore character will be discarded. |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 70 | // The difference from JavaClassNameFromRSFileName() is that the result is |
Stephen Hines | d417640 | 2010-09-16 17:14:35 -0700 | [diff] [blame] | 71 | // converted to lowercase. |
| 72 | // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns |
| 73 | // "myrenderscript_file" |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 74 | // rsFileName: the input .rs file name (with or without path). |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 75 | static std::string BCFileNameFromRSFileName(const char *rsFileName); |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 76 | |
Ying Wang | 0877f05 | 2010-09-09 17:19:33 -0700 | [diff] [blame] | 77 | // Generate the bit code accessor Java source file. |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 78 | static bool GenerateBitCodeAccessor(const BitCodeAccessorContext &context); |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 79 | }; |
Ying Wang | 3f8b44d | 2010-09-04 01:17:01 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 82 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_ NOLINT |