Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 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 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 17 | #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 19 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 20 | #include <cstdio> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 21 | #include <list> |
| 22 | #include <map> |
| 23 | #include <string> |
| 24 | |
| 25 | #include "clang/Lex/Preprocessor.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 26 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 27 | #include "llvm/ADT/StringSet.h" |
| 28 | #include "llvm/ADT/StringMap.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 29 | |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 30 | #include "slang_pragma_recorder.h" |
| 31 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 32 | namespace llvm { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 33 | class LLVMContext; |
| 34 | class TargetData; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 35 | } // namespace llvm |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 36 | |
| 37 | namespace clang { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 38 | class VarDecl; |
| 39 | class ASTContext; |
| 40 | class TargetInfo; |
| 41 | class FunctionDecl; |
| 42 | class SourceManager; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 43 | } // namespace clang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 44 | |
| 45 | namespace slang { |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 46 | class RSExportable; |
| 47 | class RSExportVar; |
| 48 | class RSExportFunc; |
| 49 | class RSExportType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 50 | |
| 51 | class RSContext { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 52 | typedef llvm::StringSet<> NeedExportVarSet; |
| 53 | typedef llvm::StringSet<> NeedExportFuncSet; |
| 54 | typedef llvm::StringSet<> NeedExportTypeSet; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 55 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 56 | public: |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 57 | typedef std::list<RSExportable*> ExportableList; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 58 | typedef std::list<RSExportVar*> ExportVarList; |
| 59 | typedef std::list<RSExportFunc*> ExportFuncList; |
| 60 | typedef llvm::StringMap<RSExportType*> ExportTypeMap; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 61 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 62 | private: |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 63 | clang::Preprocessor &mPP; |
| 64 | clang::ASTContext &mCtx; |
| 65 | const clang::TargetInfo &mTarget; |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 66 | PragmaList *mPragmas; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 67 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 68 | llvm::TargetData *mTargetData; |
| 69 | llvm::LLVMContext &mLLVMContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 70 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 71 | ExportableList mExportables; |
| 72 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 73 | NeedExportTypeSet mNeedExportTypes; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 74 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 75 | std::string *mLicenseNote; |
| 76 | std::string mReflectJavaPackageName; |
| 77 | std::string mReflectJavaPathName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 78 | |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 79 | int version; |
| 80 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 81 | bool processExportVar(const clang::VarDecl *VD); |
| 82 | bool processExportFunc(const clang::FunctionDecl *FD); |
| 83 | bool processExportType(const llvm::StringRef &Name); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 84 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 85 | ExportVarList mExportVars; |
| 86 | ExportFuncList mExportFuncs; |
| 87 | ExportTypeMap mExportTypes; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 88 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 89 | public: |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 90 | RSContext(clang::Preprocessor &PP, |
| 91 | clang::ASTContext &Ctx, |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 92 | const clang::TargetInfo &Target, |
| 93 | PragmaList *Pragmas); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 94 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 95 | inline clang::Preprocessor &getPreprocessor() const { return mPP; } |
| 96 | inline clang::ASTContext &getASTContext() const { return mCtx; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 97 | inline const llvm::TargetData *getTargetData() const { return mTargetData; } |
| 98 | inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; } |
| 99 | inline const clang::SourceManager *getSourceManager() const { |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 100 | return &mPP.getSourceManager(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 101 | } |
Stephen Hines | 2ef9bc0 | 2010-12-13 18:33:23 -0800 | [diff] [blame] | 102 | inline clang::Diagnostic *getDiagnostics() const { |
| 103 | return &mPP.getDiagnostics(); |
| 104 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 105 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 106 | inline void setLicenseNote(const std::string &S) { |
| 107 | mLicenseNote = new std::string(S); |
| 108 | } |
| 109 | inline const std::string *getLicenseNote() const { return mLicenseNote; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 110 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 111 | inline void addExportType(const std::string &S) { |
| 112 | mNeedExportTypes.insert(S); |
| 113 | return; |
| 114 | } |
Victor Hsieh | d8a0d18 | 2010-07-07 19:22:33 +0800 | [diff] [blame] | 115 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 116 | inline void setReflectJavaPackageName(const std::string &S) { |
| 117 | mReflectJavaPackageName = S; |
| 118 | return; |
| 119 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 120 | |
Stephen Hines | c808a99 | 2010-11-29 17:20:42 -0800 | [diff] [blame] | 121 | bool processExport(); |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 122 | inline void newExportable(RSExportable *E) { |
| 123 | if (E != NULL) |
| 124 | mExportables.push_back(E); |
| 125 | } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 126 | typedef ExportableList::iterator exportable_iterator; |
| 127 | exportable_iterator exportable_begin() { |
| 128 | return mExportables.begin(); |
| 129 | } |
| 130 | exportable_iterator exportable_end() { |
| 131 | return mExportables.end(); |
| 132 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 133 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 134 | typedef ExportVarList::const_iterator const_export_var_iterator; |
| 135 | const_export_var_iterator export_vars_begin() const { |
| 136 | return mExportVars.begin(); |
| 137 | } |
| 138 | const_export_var_iterator export_vars_end() const { |
| 139 | return mExportVars.end(); |
| 140 | } |
| 141 | inline bool hasExportVar() const { |
| 142 | return !mExportVars.empty(); |
| 143 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 144 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 145 | typedef ExportFuncList::const_iterator const_export_func_iterator; |
| 146 | const_export_func_iterator export_funcs_begin() const { |
| 147 | return mExportFuncs.begin(); |
| 148 | } |
| 149 | const_export_func_iterator export_funcs_end() const { |
| 150 | return mExportFuncs.end(); |
| 151 | } |
| 152 | inline bool hasExportFunc() const { return !mExportFuncs.empty(); } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 153 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 154 | typedef ExportTypeMap::iterator export_type_iterator; |
| 155 | typedef ExportTypeMap::const_iterator const_export_type_iterator; |
| 156 | export_type_iterator export_types_begin() { return mExportTypes.begin(); } |
| 157 | export_type_iterator export_types_end() { return mExportTypes.end(); } |
| 158 | const_export_type_iterator export_types_begin() const { |
| 159 | return mExportTypes.begin(); |
| 160 | } |
| 161 | const_export_type_iterator export_types_end() const { |
| 162 | return mExportTypes.end(); |
| 163 | } |
| 164 | inline bool hasExportType() const { return !mExportTypes.empty(); } |
| 165 | export_type_iterator findExportType(const llvm::StringRef &TypeName) { |
| 166 | return mExportTypes.find(TypeName); |
| 167 | } |
| 168 | const_export_type_iterator findExportType(const llvm::StringRef &TypeName) |
| 169 | const { |
| 170 | return mExportTypes.find(TypeName); |
| 171 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 172 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 173 | // Insert the specified Typename/Type pair into the map. If the key already |
| 174 | // exists in the map, return false and ignore the request, otherwise insert it |
| 175 | // and return true. |
| 176 | bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 177 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 178 | bool reflectToJava(const std::string &OutputPathBase, |
| 179 | const std::string &OutputPackageName, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 180 | const std::string &InputFileName, |
| 181 | const std::string &OutputBCFileName, |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 182 | std::string *RealPackageName); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 183 | |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 184 | int getVersion() const { return version; } |
| 185 | void setVersion(int v) { |
| 186 | version = v; |
| 187 | return; |
| 188 | } |
| 189 | |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 190 | void addPragma(const std::string &T, const std::string &V) { |
| 191 | mPragmas->push_back(make_pair(T, V)); |
| 192 | } |
| 193 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 194 | ~RSContext(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 197 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 198 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 199 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ NOLINT |