Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 1 | #ifndef _SLANG_COMPILER_RS_CONTEXT_HPP |
| 2 | # define _SLANG_COMPILER_RS_CONTEXT_HPP |
| 3 | |
| 4 | #include "slang_rs_export_element.hpp" |
| 5 | |
| 6 | #include <map> |
| 7 | #include <list> |
| 8 | #include <string> |
| 9 | #include <cstdio> |
| 10 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 11 | #include "llvm/ADT/StringSet.h" |
| 12 | #include "llvm/ADT/StringMap.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 13 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 14 | #include "clang/Lex/Preprocessor.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 15 | |
| 16 | namespace llvm { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 17 | class LLVMContext; |
| 18 | class TargetData; |
| 19 | } // namespace llvm |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 20 | |
| 21 | namespace clang { |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 22 | class VarDecl; |
| 23 | class ASTContext; |
| 24 | class TargetInfo; |
| 25 | class FunctionDecl; |
| 26 | class SourceManager; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 27 | } // namespace clang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 28 | |
| 29 | namespace slang { |
| 30 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 31 | class RSExportVar; |
| 32 | class RSExportFunc; |
| 33 | class RSExportType; |
| 34 | class RSPragmaHandler; |
| 35 | |
| 36 | class RSContext { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 37 | typedef llvm::StringSet<> NeedExportVarSet; |
| 38 | typedef llvm::StringSet<> NeedExportFuncSet; |
| 39 | typedef llvm::StringSet<> NeedExportTypeSet; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 40 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 41 | public: |
| 42 | typedef std::list<RSExportVar*> ExportVarList; |
| 43 | typedef std::list<RSExportFunc*> ExportFuncList; |
| 44 | typedef llvm::StringMap<RSExportType*> ExportTypeMap; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 45 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 46 | private: |
| 47 | clang::Preprocessor *mPP; |
| 48 | clang::ASTContext *mCtx; |
| 49 | const clang::TargetInfo *mTarget; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 50 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 51 | llvm::TargetData *mTargetData; |
| 52 | llvm::LLVMContext &mLLVMContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 53 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 54 | // Record the variables/types/elements annotated in #pragma to be exported |
| 55 | NeedExportVarSet mNeedExportVars; |
| 56 | NeedExportFuncSet mNeedExportFuncs; |
| 57 | NeedExportTypeSet mNeedExportTypes; |
| 58 | bool mExportAllNonStaticVars; |
| 59 | bool mExportAllNonStaticFuncs; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 60 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 61 | std::string *mLicenseNote; |
| 62 | std::string mReflectJavaPackageName; |
| 63 | std::string mReflectJavaPathName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 64 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 65 | bool processExportVar(const clang::VarDecl *VD); |
| 66 | bool processExportFunc(const clang::FunctionDecl *FD); |
| 67 | bool processExportType(const llvm::StringRef &Name); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 68 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 69 | ExportVarList mExportVars; |
| 70 | ExportFuncList mExportFuncs; |
| 71 | ExportTypeMap mExportTypes; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 72 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 73 | public: |
| 74 | RSContext(clang::Preprocessor *PP, |
| 75 | clang::ASTContext *Ctx, |
| 76 | const clang::TargetInfo *Target); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 77 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 78 | inline clang::Preprocessor *getPreprocessor() const { return mPP; } |
| 79 | inline clang::ASTContext *getASTContext() const { return mCtx; } |
| 80 | inline const llvm::TargetData *getTargetData() const { return mTargetData; } |
| 81 | inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; } |
| 82 | inline const clang::SourceManager *getSourceManager() const { |
| 83 | return &mPP->getSourceManager(); |
| 84 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 85 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 86 | inline void setLicenseNote(const std::string &S) { |
| 87 | mLicenseNote = new std::string(S); |
| 88 | } |
| 89 | inline const std::string *getLicenseNote() const { return mLicenseNote; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 90 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 91 | inline void addExportVar(const std::string &S) { |
| 92 | mNeedExportVars.insert(S); |
| 93 | return; |
| 94 | } |
| 95 | inline void addExportFunc(const std::string &S) { |
| 96 | mNeedExportFuncs.insert(S); |
| 97 | return; |
| 98 | } |
| 99 | inline void addExportType(const std::string &S) { |
| 100 | mNeedExportTypes.insert(S); |
| 101 | return; |
| 102 | } |
Victor Hsieh | d8a0d18 | 2010-07-07 19:22:33 +0800 | [diff] [blame] | 103 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 104 | inline void setExportAllNonStaticVars(bool flag) { |
| 105 | mExportAllNonStaticVars = flag; |
| 106 | } |
| 107 | inline void setExportAllNonStaticFuncs(bool flag) { |
| 108 | mExportAllNonStaticFuncs = flag; |
| 109 | } |
| 110 | inline void setReflectJavaPackageName(const std::string &S) { |
| 111 | mReflectJavaPackageName = S; |
| 112 | return; |
| 113 | } |
| 114 | inline void setReflectJavaPathName(const std::string &S) { |
| 115 | mReflectJavaPathName = S; |
| 116 | return; |
| 117 | } |
| 118 | inline std::string getReflectJavaPathName() const { |
| 119 | return mReflectJavaPathName; |
| 120 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 121 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 122 | void processExport(); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 123 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 124 | typedef ExportVarList::const_iterator const_export_var_iterator; |
| 125 | const_export_var_iterator export_vars_begin() const { |
| 126 | return mExportVars.begin(); |
| 127 | } |
| 128 | const_export_var_iterator export_vars_end() const { |
| 129 | return mExportVars.end(); |
| 130 | } |
| 131 | inline bool hasExportVar() const { |
| 132 | return !mExportVars.empty(); |
| 133 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 134 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 135 | typedef ExportFuncList::const_iterator const_export_func_iterator; |
| 136 | const_export_func_iterator export_funcs_begin() const { |
| 137 | return mExportFuncs.begin(); |
| 138 | } |
| 139 | const_export_func_iterator export_funcs_end() const { |
| 140 | return mExportFuncs.end(); |
| 141 | } |
| 142 | inline bool hasExportFunc() const { return !mExportFuncs.empty(); } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 143 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 144 | typedef ExportTypeMap::iterator export_type_iterator; |
| 145 | typedef ExportTypeMap::const_iterator const_export_type_iterator; |
| 146 | export_type_iterator export_types_begin() { return mExportTypes.begin(); } |
| 147 | export_type_iterator export_types_end() { return mExportTypes.end(); } |
| 148 | const_export_type_iterator export_types_begin() const { |
| 149 | return mExportTypes.begin(); |
| 150 | } |
| 151 | const_export_type_iterator export_types_end() const { |
| 152 | return mExportTypes.end(); |
| 153 | } |
| 154 | inline bool hasExportType() const { return !mExportTypes.empty(); } |
| 155 | export_type_iterator findExportType(const llvm::StringRef &TypeName) { |
| 156 | return mExportTypes.find(TypeName); |
| 157 | } |
| 158 | const_export_type_iterator findExportType(const llvm::StringRef &TypeName) |
| 159 | const { |
| 160 | return mExportTypes.find(TypeName); |
| 161 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 162 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 163 | // Insert the specified Typename/Type pair into the map. If the key already |
| 164 | // exists in the map, return false and ignore the request, otherwise insert it |
| 165 | // and return true. |
| 166 | bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 167 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 168 | bool reflectToJava(const char *OutputPackageName, |
| 169 | const std::string &InputFileName, |
| 170 | const std::string &OutputBCFileName, |
| 171 | char realPackageName[], |
| 172 | int bSize); |
| 173 | bool reflectToJavaPath(const char *OutputPathName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 174 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 175 | ~RSContext(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 178 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 179 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame^] | 180 | #endif // _SLANG_COMPILER_RS_CONTEXT_HPP |