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 };
     29 
     30 class RSSlangReflectUtils {
     31  public:
     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 {
     39     const char *rsFileName;
     40     const char *bcFileName;
     41     const char *reflectPath;
     42     const char *packageName;
     43 
     44     BitCodeStorageType bcStorage;
     45   };
     46 
     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 
     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
     56   static std::string ComputePackagedPath(const char *prefixPath,
     57                                          const char *packageName);
     58 
     59   // Compute Java class name from a .rs file name.
     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".
     63   // rsFileName: the input .rs file name (with or without path).
     64   static std::string JavaClassNameFromRSFileName(const char *rsFileName);
     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
     68   // class (something like R.raw.<bitcode_filename>), Any non-alnum,
     69   // non-underscore character will be discarded.
     70   // The difference from JavaClassNameFromRSFileName() is that the result is
     71   // converted to lowercase.
     72   // E.g. with rsFileName=./foo/bar/my-Renderscript_file.rs it returns
     73   // "myrenderscript_file"
     74   // rsFileName: the input .rs file name (with or without path).
     75   static std::string BCFileNameFromRSFileName(const char *rsFileName);
     76 
     77   // Generate the bit code accessor Java source file.
     78   static bool GenerateBitCodeAccessor(const BitCodeAccessorContext &context);
     79 };
     80 }
     81 
     82 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_REFLECT_UTILS_H_  NOLINT
     83