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_DIAGNOSTIC_BUFFER_H_ // NOLINT |
| 18 | #define _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 19 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 20 | #include <set> |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 21 | #include <string> |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 22 | |
| 23 | #include "clang/Basic/Diagnostic.h" |
| 24 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 26 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 27 | namespace llvm { |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 28 | class raw_string_ostream; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 29 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 30 | |
| 31 | namespace slang { |
| 32 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 33 | // The diagnostics consumer instance (for reading the processed diagnostics) |
| 34 | class DiagnosticBuffer : public clang::DiagnosticConsumer { |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 35 | private: |
| 36 | // We keed track of the messages that have been already added to this |
| 37 | // diagnostic buffer, to avoid duplicates. This can happen because for a |
| 38 | // given script we'll usually compile for both 32 and 64 bit targets. |
| 39 | std::set<std::string> mIncludedMessages; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 40 | std::string mDiags; |
Stephen Hines | 2eb9a3f | 2014-07-15 16:50:03 -0700 | [diff] [blame] | 41 | std::unique_ptr<llvm::raw_string_ostream> mSOS; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 42 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 43 | public: |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 44 | DiagnosticBuffer(); |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 45 | virtual ~DiagnosticBuffer(); |
| 46 | |
| 47 | virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 48 | const clang::Diagnostic &Info) override; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 49 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 50 | inline const std::string &str() const { |
| 51 | mSOS->flush(); |
| 52 | return mDiags; |
| 53 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 54 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 55 | inline void reset() { |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 56 | mIncludedMessages.clear(); |
| 57 | mSOS.reset(); |
| 58 | mDiags.clear(); |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 59 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 60 | }; |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 61 | |
Stephen Hines | e67239d | 2012-02-24 15:08:36 -0800 | [diff] [blame] | 62 | } // namespace slang |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 63 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 64 | #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT |