Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 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> |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 24 | #include <vector> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 25 | |
| 26 | #include "clang/Lex/Preprocessor.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 27 | #include "clang/AST/Mangle.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 28 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 29 | #include "llvm/ADT/StringSet.h" |
| 30 | #include "llvm/ADT/StringMap.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 31 | |
David Gross | 34e6205 | 2015-11-05 09:55:03 -0800 | [diff] [blame] | 32 | #include "slang_pragma_list.h" |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 33 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 34 | namespace llvm { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 35 | class LLVMContext; |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 36 | class DataLayout; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 37 | } // namespace llvm |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 38 | |
| 39 | namespace clang { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 40 | class VarDecl; |
| 41 | class ASTContext; |
| 42 | class TargetInfo; |
| 43 | class FunctionDecl; |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 44 | class QualType; |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 45 | class SourceManager; |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 46 | class TypeDecl; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 47 | } // namespace clang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 48 | |
| 49 | namespace slang { |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 50 | class RSExportable; |
| 51 | class RSExportVar; |
| 52 | class RSExportFunc; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 53 | class RSExportForEach; |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 54 | class RSExportReduce; |
David Gross | 15e44e6 | 2015-11-10 11:12:48 -0800 | [diff] [blame] | 55 | class RSExportReduceNew; |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 56 | class RSExportType; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 57 | |
| 58 | class RSContext { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 59 | typedef llvm::StringSet<> NeedExportVarSet; |
| 60 | typedef llvm::StringSet<> NeedExportFuncSet; |
| 61 | typedef llvm::StringSet<> NeedExportTypeSet; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 62 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 63 | public: |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 64 | typedef std::list<RSExportable*> ExportableList; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 65 | typedef std::list<RSExportVar*> ExportVarList; |
| 66 | typedef std::list<RSExportFunc*> ExportFuncList; |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 67 | typedef std::vector<RSExportForEach*> ExportForEachVector; |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 68 | typedef std::list<RSExportReduce*> ExportReduceList; |
David Gross | 15e44e6 | 2015-11-10 11:12:48 -0800 | [diff] [blame] | 69 | typedef std::list<RSExportReduceNew*> ExportReduceNewList; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 70 | typedef llvm::StringMap<RSExportType*> ExportTypeMap; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 71 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 72 | private: |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 73 | clang::Preprocessor &mPP; |
| 74 | clang::ASTContext &mCtx; |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 75 | PragmaList *mPragmas; |
Jean-Luc Brouillet | 109e90a | 2014-07-07 17:36:07 -0700 | [diff] [blame] | 76 | // Precision specified via pragma, either rs_fp_full or rs_fp_relaxed. If |
| 77 | // empty, rs_fp_full is assumed. |
| 78 | std::string mPrecision; |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 79 | unsigned int mTargetAPI; |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 80 | bool mVerbose; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 81 | |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 82 | llvm::DataLayout *mDataLayout; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 83 | llvm::LLVMContext &mLLVMContext; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 84 | |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 85 | ExportableList mExportables; |
| 86 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 87 | NeedExportTypeSet mNeedExportTypes; |
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 | std::string *mLicenseNote; |
| 90 | std::string mReflectJavaPackageName; |
| 91 | std::string mReflectJavaPathName; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 92 | |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 93 | std::string mRSPackageName; |
| 94 | |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 95 | int version; |
Stephen Hines | 82754d8 | 2013-01-18 19:46:06 -0800 | [diff] [blame] | 96 | |
Stephen Hines | 2eb9a3f | 2014-07-15 16:50:03 -0700 | [diff] [blame] | 97 | std::unique_ptr<clang::MangleContext> mMangleCtx; |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 98 | |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 99 | bool mIs64Bit; |
| 100 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 101 | bool processExportVar(const clang::VarDecl *VD); |
| 102 | bool processExportFunc(const clang::FunctionDecl *FD); |
| 103 | bool processExportType(const llvm::StringRef &Name); |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 104 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 105 | int getForEachSlotNumber(const clang::StringRef& funcName); |
| 106 | unsigned mNextSlot; |
Stephen Hines | c17e198 | 2012-02-22 12:30:45 -0800 | [diff] [blame] | 107 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 108 | ExportVarList mExportVars; |
| 109 | ExportFuncList mExportFuncs; |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 110 | std::map<llvm::StringRef, unsigned> mExportForEachMap; |
| 111 | ExportForEachVector mExportForEach; |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 112 | ExportReduceList mExportReduce; |
David Gross | 15e44e6 | 2015-11-10 11:12:48 -0800 | [diff] [blame] | 113 | ExportReduceNewList mExportReduceNew; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 114 | ExportTypeMap mExportTypes; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 115 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 116 | clang::QualType mAllocationType; |
| 117 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 118 | public: |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 119 | RSContext(clang::Preprocessor &PP, |
| 120 | clang::ASTContext &Ctx, |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 121 | const clang::TargetInfo &Target, |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 122 | PragmaList *Pragmas, |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 123 | unsigned int TargetAPI, |
| 124 | bool Verbose); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 125 | |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 126 | inline clang::Preprocessor &getPreprocessor() const { return mPP; } |
| 127 | inline clang::ASTContext &getASTContext() const { return mCtx; } |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 128 | inline clang::MangleContext &getMangleContext() const { |
| 129 | return *mMangleCtx; |
Stephen Hines | f2174cf | 2011-02-09 23:21:37 -0800 | [diff] [blame] | 130 | } |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 131 | inline const llvm::DataLayout *getDataLayout() const { return mDataLayout; } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 132 | inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; } |
| 133 | inline const clang::SourceManager *getSourceManager() const { |
Stephen Hines | 9e5b503 | 2010-11-03 13:19:14 -0700 | [diff] [blame] | 134 | return &mPP.getSourceManager(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 135 | } |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 136 | inline clang::DiagnosticsEngine *getDiagnostics() const { |
Stephen Hines | 2ef9bc0 | 2010-12-13 18:33:23 -0800 | [diff] [blame] | 137 | return &mPP.getDiagnostics(); |
| 138 | } |
Chris Wailes | c9454af | 2014-06-13 17:25:40 -0700 | [diff] [blame] | 139 | inline unsigned int getTargetAPI() const { |
Stephen Hines | 4a4bf92 | 2011-08-18 17:20:33 -0700 | [diff] [blame] | 140 | return mTargetAPI; |
| 141 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 142 | |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 143 | inline bool getVerbose() const { |
| 144 | return mVerbose; |
| 145 | } |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 146 | inline bool is64Bit() const { |
| 147 | return mIs64Bit; |
| 148 | } |
Stephen Hines | fc4f78b | 2014-06-10 18:07:10 -0700 | [diff] [blame] | 149 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 150 | inline void setLicenseNote(const std::string &S) { |
| 151 | mLicenseNote = new std::string(S); |
| 152 | } |
| 153 | inline const std::string *getLicenseNote() const { return mLicenseNote; } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 154 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 155 | inline void addExportType(const std::string &S) { |
| 156 | mNeedExportTypes.insert(S); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 157 | } |
Victor Hsieh | d8a0d18 | 2010-07-07 19:22:33 +0800 | [diff] [blame] | 158 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 159 | inline void setReflectJavaPackageName(const std::string &S) { |
| 160 | mReflectJavaPackageName = S; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 161 | } |
Tim Murray | dde9853 | 2013-07-23 15:55:19 -0700 | [diff] [blame] | 162 | inline const std::string &getReflectJavaPackageName() const { |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 163 | return mReflectJavaPackageName; |
| 164 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 165 | |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 166 | inline void setRSPackageName(const std::string &S) { |
| 167 | mRSPackageName = S; |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 168 | } |
Jean-Luc Brouillet | 12fc283 | 2014-06-04 21:32:31 +0000 | [diff] [blame] | 169 | |
| 170 | inline const std::string &getRSPackageName() const { return mRSPackageName; } |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 171 | |
Yang Ni | 88f21e1 | 2015-11-18 15:59:00 -0800 | [diff] [blame] | 172 | void setAllocationType(const clang::TypeDecl* TD); |
| 173 | inline const clang::QualType& getAllocationType() const { |
| 174 | return mAllocationType; |
| 175 | } |
| 176 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 177 | bool addForEach(const clang::FunctionDecl* FD); |
| 178 | bool processExports(); |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 179 | inline void newExportable(RSExportable *E) { |
Chris Wailes | 5abbe0e | 2014-08-12 15:58:29 -0700 | [diff] [blame] | 180 | if (E != nullptr) |
Zonr Chang | a41ce1d | 2010-10-06 02:23:12 +0800 | [diff] [blame] | 181 | mExportables.push_back(E); |
| 182 | } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 183 | typedef ExportableList::iterator exportable_iterator; |
| 184 | exportable_iterator exportable_begin() { |
| 185 | return mExportables.begin(); |
| 186 | } |
| 187 | exportable_iterator exportable_end() { |
| 188 | return mExportables.end(); |
| 189 | } |
Shih-wei Liao | 537446c | 2010-06-11 16:05:55 -0700 | [diff] [blame] | 190 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 191 | typedef ExportVarList::const_iterator const_export_var_iterator; |
| 192 | const_export_var_iterator export_vars_begin() const { |
| 193 | return mExportVars.begin(); |
| 194 | } |
| 195 | const_export_var_iterator export_vars_end() const { |
| 196 | return mExportVars.end(); |
| 197 | } |
| 198 | inline bool hasExportVar() const { |
| 199 | return !mExportVars.empty(); |
| 200 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 201 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 202 | typedef ExportFuncList::const_iterator const_export_func_iterator; |
| 203 | const_export_func_iterator export_funcs_begin() const { |
| 204 | return mExportFuncs.begin(); |
| 205 | } |
| 206 | const_export_func_iterator export_funcs_end() const { |
| 207 | return mExportFuncs.end(); |
| 208 | } |
| 209 | inline bool hasExportFunc() const { return !mExportFuncs.empty(); } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 210 | |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 211 | typedef ExportForEachVector::const_iterator const_export_foreach_iterator; |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 212 | const_export_foreach_iterator export_foreach_begin() const { |
| 213 | return mExportForEach.begin(); |
| 214 | } |
| 215 | const_export_foreach_iterator export_foreach_end() const { |
| 216 | return mExportForEach.end(); |
| 217 | } |
| 218 | inline bool hasExportForEach() const { return !mExportForEach.empty(); } |
Yang Ni | fb40ee2 | 2015-10-13 20:34:06 +0000 | [diff] [blame] | 219 | int getForEachSlotNumber(const clang::FunctionDecl* FD); |
Stephen Hines | 593a894 | 2011-05-10 15:29:50 -0700 | [diff] [blame] | 220 | |
Matt Wala | c0c5dd8 | 2015-07-23 17:29:37 -0700 | [diff] [blame] | 221 | typedef ExportReduceList::const_iterator const_export_reduce_iterator; |
| 222 | const_export_reduce_iterator export_reduce_begin() const { |
| 223 | return mExportReduce.begin(); |
| 224 | } |
| 225 | const_export_reduce_iterator export_reduce_end() const { |
| 226 | return mExportReduce.end(); |
| 227 | } |
| 228 | inline bool hasExportReduce() const { return !mExportReduce.empty(); } |
| 229 | |
David Gross | 15e44e6 | 2015-11-10 11:12:48 -0800 | [diff] [blame] | 230 | typedef ExportReduceNewList::const_iterator const_export_reduce_new_iterator; |
| 231 | const_export_reduce_new_iterator export_reduce_new_begin() const { |
| 232 | return mExportReduceNew.begin(); |
| 233 | } |
| 234 | const_export_reduce_new_iterator export_reduce_new_end() const { |
| 235 | return mExportReduceNew.end(); |
| 236 | } |
| 237 | inline bool hasExportReduceNew() const { return !mExportReduceNew.empty(); } |
| 238 | void addExportReduceNew(RSExportReduceNew *ReduceNew) { |
| 239 | mExportReduceNew.push_back(ReduceNew); |
| 240 | } |
| 241 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 242 | typedef ExportTypeMap::iterator export_type_iterator; |
| 243 | typedef ExportTypeMap::const_iterator const_export_type_iterator; |
| 244 | export_type_iterator export_types_begin() { return mExportTypes.begin(); } |
| 245 | export_type_iterator export_types_end() { return mExportTypes.end(); } |
| 246 | const_export_type_iterator export_types_begin() const { |
| 247 | return mExportTypes.begin(); |
| 248 | } |
| 249 | const_export_type_iterator export_types_end() const { |
| 250 | return mExportTypes.end(); |
| 251 | } |
| 252 | inline bool hasExportType() const { return !mExportTypes.empty(); } |
| 253 | export_type_iterator findExportType(const llvm::StringRef &TypeName) { |
| 254 | return mExportTypes.find(TypeName); |
| 255 | } |
| 256 | const_export_type_iterator findExportType(const llvm::StringRef &TypeName) |
| 257 | const { |
| 258 | return mExportTypes.find(TypeName); |
| 259 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 260 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 261 | // Insert the specified Typename/Type pair into the map. If the key already |
| 262 | // exists in the map, return false and ignore the request, otherwise insert it |
| 263 | // and return true. |
| 264 | bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 265 | |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 266 | int getVersion() const { return version; } |
| 267 | void setVersion(int v) { |
| 268 | version = v; |
Stephen Hines | 96ab06c | 2011-01-05 15:29:26 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Jean-Luc Brouillet | 12fc283 | 2014-06-04 21:32:31 +0000 | [diff] [blame] | 271 | bool isCompatLib() const { |
| 272 | // If we are not targeting the actual Android Renderscript classes, |
| 273 | // we should reflect code that works with the compatibility library. |
| 274 | return (mRSPackageName.compare("android.renderscript") != 0); |
| 275 | } |
Stephen Hines | 82754d8 | 2013-01-18 19:46:06 -0800 | [diff] [blame] | 276 | |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 277 | void addPragma(const std::string &T, const std::string &V) { |
| 278 | mPragmas->push_back(make_pair(T, V)); |
| 279 | } |
Jean-Luc Brouillet | 109e90a | 2014-07-07 17:36:07 -0700 | [diff] [blame] | 280 | void setPrecision(const std::string &P) { mPrecision = P; } |
| 281 | std::string getPrecision() { return mPrecision; } |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 282 | |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 283 | // Report an error or a warning to the user. |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 284 | template <unsigned N> |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 285 | clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level, |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 286 | const char (&Message)[N]) { |
| 287 | clang::DiagnosticsEngine *DiagEngine = getDiagnostics(); |
| 288 | return DiagEngine->Report(DiagEngine->getCustomDiagID(Level, Message)); |
| 289 | } |
| 290 | |
| 291 | template <unsigned N> |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 292 | clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level, |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 293 | const clang::SourceLocation Loc, |
| 294 | const char (&Message)[N]) { |
| 295 | clang::DiagnosticsEngine *DiagEngine = getDiagnostics(); |
| 296 | const clang::SourceManager *SM = getSourceManager(); |
| 297 | return DiagEngine->Report(clang::FullSourceLoc(Loc, *SM), |
| 298 | DiagEngine->getCustomDiagID(Level, Message)); |
| 299 | } |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 300 | |
| 301 | // Utility functions to report errors and warnings to make the calling code |
| 302 | // easier to read. |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 303 | template <unsigned N> |
| 304 | clang::DiagnosticBuilder ReportError(const char (&Message)[N]) { |
| 305 | return Report<N>(clang::DiagnosticsEngine::Error, Message); |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 306 | } |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 307 | |
| 308 | template <unsigned N> |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 309 | clang::DiagnosticBuilder ReportError(const clang::SourceLocation Loc, |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 310 | const char (&Message)[N]) { |
| 311 | return Report<N>(clang::DiagnosticsEngine::Error, Loc, Message); |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 312 | } |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 313 | |
| 314 | template <unsigned N> |
| 315 | clang::DiagnosticBuilder ReportWarning(const char (&Message)[N]) { |
| 316 | return Report<N>(clang::DiagnosticsEngine::Warning, Message); |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 317 | } |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 318 | |
| 319 | template <unsigned N> |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 320 | clang::DiagnosticBuilder ReportWarning(const clang::SourceLocation Loc, |
Tim Murray | ee4016d | 2014-04-10 15:49:08 -0700 | [diff] [blame] | 321 | const char (&Message)[N]) { |
| 322 | return Report<N>(clang::DiagnosticsEngine::Warning, Loc, Message); |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 325 | ~RSContext(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 328 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 329 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 330 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_ NOLINT |