Home | History | Annotate | Download | only in slang
      1 /*
      2  * Copyright 2012, 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_RS_REFLECTION_BASE_H_  // NOLINT
     18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_BASE_H_
     19 
     20 #include <fstream>
     21 #include <iostream>
     22 #include <map>
     23 #include <set>
     24 #include <string>
     25 #include <vector>
     26 
     27 #include "llvm/ADT/StringExtras.h"
     28 
     29 #include "slang_assert.h"
     30 #include "slang_rs_export_type.h"
     31 
     32 namespace slang {
     33     class RSContext;
     34     class RSExportVar;
     35     class RSExportFunc;
     36     class RSExportForEach;
     37 
     38 class RSReflectionBase {
     39 protected:
     40     const RSContext *mRSContext;
     41 
     42     // Generated RS Elements for type-checking code.
     43     std::set<std::string> mTypesToCheck;
     44 
     45     RSReflectionBase(const RSContext *);
     46 
     47 
     48     bool mVerbose;
     49 
     50     std::string mLicenseNote;
     51     std::string mInputFileName;
     52 
     53     std::string mClassName;
     54     std::string mOutputPath;
     55     std::string mOutputBCFileName;
     56 
     57     std::vector< std::string > mText;
     58     std::string mIndent;
     59 
     60     bool openFile(const std::string &name, std::string &errorMsg);
     61     void startFile(const std::string &filename);
     62     void incIndent();
     63     void decIndent();
     64     void write(const std::string &t);
     65     void write(const std::stringstream &t);
     66 
     67     std::string stripRS(const std::string &s) const;
     68 
     69     bool writeFile(const std::string &filename, const std::vector< std::string > &txt);
     70 
     71     bool addTypeNameForElement(const std::string &TypeName);
     72 
     73     static const char *getVectorAccessor(unsigned index);
     74 
     75 private:
     76 
     77 public:
     78     typedef std::vector<std::pair<std::string, std::string> > ArgTy;
     79 
     80     virtual ~RSReflectionBase();
     81 
     82     static std::string genInitValue(const clang::APValue &Val, bool asBool=false);
     83 
     84 };  // class RSReflection
     85 
     86 }   // namespace slang
     87 
     88 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_BASE_H_  NOLINT
     89