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 17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ // NOLINT 18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ 19 20 #include <set> 21 #include <string> 22 23 #include "clang/Basic/Diagnostic.h" 24 25 #include "llvm/Support/raw_ostream.h" 26 27 namespace llvm { 28 class raw_string_ostream; 29 } 30 31 namespace slang { 32 33 // The diagnostics consumer instance (for reading the processed diagnostics) 34 class DiagnosticBuffer : public clang::DiagnosticConsumer { 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; 40 std::string mDiags; 41 std::unique_ptr<llvm::raw_string_ostream> mSOS; 42 43 public: 44 DiagnosticBuffer(); 45 virtual ~DiagnosticBuffer(); 46 47 virtual void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, 48 const clang::Diagnostic &Info) override; 49 50 inline const std::string &str() const { 51 mSOS->flush(); 52 return mDiags; 53 } 54 55 inline void reset() { 56 mIncludedMessages.clear(); 57 mSOS.reset(); 58 mDiags.clear(); 59 } 60 }; 61 62 } // namespace slang 63 64 #endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT 65