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