blob: d2a831ef96acdbc0a7552a7b0e6c087a79b9950f [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
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 Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_
Ying Wang3f8b44d2010-09-04 01:17:01 -070019
20#include <string>
21
22namespace slang {
23
Ying Wang0877f052010-09-09 17:19:33 -070024// BitCode storage type
25enum BitCodeStorageType {
26 BCST_APK_RESOURCE,
27 BCST_JAVA_CODE
28};
29
Ying Wang3f8b44d2010-09-04 01:17:01 -070030class RSSlangReflectUtils {
Ying Wang0877f052010-09-09 17:19:33 -070031 public:
Ying Wang0877f052010-09-09 17:19:33 -070032 // 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 {
zonr6315f762010-10-05 15:35:14 +080039 const char *rsFileName;
40 const char *bcFileName;
41 const char *reflectPath;
42 const char *packageName;
Ying Wang3f8b44d2010-09-04 01:17:01 -070043
Ying Wang0877f052010-09-09 17:19:33 -070044 BitCodeStorageType bcStorage;
45 };
Ying Wang3f8b44d2010-09-04 01:17:01 -070046
Ying Wangdba31112010-10-07 17:30:38 -070047 // 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 Wang0877f052010-09-09 17:19:33 -070053 // 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
zonr6315f762010-10-05 15:35:14 +080056 static std::string ComputePackagedPath(const char *prefixPath,
57 const char *packageName);
Ying Wang3f8b44d2010-09-04 01:17:01 -070058
Ying Wang0877f052010-09-09 17:19:33 -070059 // Compute Java class name from a .rs file name.
Stephen Hinesd4176402010-09-16 17:14:35 -070060 // 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 Wang0877f052010-09-09 17:19:33 -070063 // rsFileName: the input .rs file name (with or without path).
zonr6315f762010-10-05 15:35:14 +080064 static std::string JavaClassNameFromRSFileName(const char *rsFileName);
Ying Wang0877f052010-09-09 17:19:33 -070065
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 Hinesd4176402010-09-16 17:14:35 -070068 // class (something like R.raw.<bitcode_filename>), Any non-alnum,
69 // non-underscore character will be discarded.
Ying Wang0877f052010-09-09 17:19:33 -070070 // The difference from JavaClassNameFromRSFileName() is that the result is
Stephen Hinesd4176402010-09-16 17:14:35 -070071 // converted to lowercase.
72 // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns
73 // "myrenderscript_file"
Ying Wang0877f052010-09-09 17:19:33 -070074 // rsFileName: the input .rs file name (with or without path).
zonr6315f762010-10-05 15:35:14 +080075 static std::string BCFileNameFromRSFileName(const char *rsFileName);
Ying Wang0877f052010-09-09 17:19:33 -070076
Ying Wang0877f052010-09-09 17:19:33 -070077 // Generate the bit code accessor Java source file.
zonr6315f762010-10-05 15:35:14 +080078 static bool GenerateBitCodeAccessor(const BitCodeAccessorContext &context);
Ying Wang3f8b44d2010-09-04 01:17:01 -070079};
Ying Wang3f8b44d2010-09-04 01:17:01 -070080}
81
Stephen Hinese639eb52010-11-08 19:27:20 -080082#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_ NOLINT