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