slang_diagnostic_buffer.h revision e639eb5caa2c386b4a60659a4929e8a6141a2cbe
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 <string> 21 22#include "clang/Basic/Diagnostic.h" 23 24#include "llvm/Support/raw_ostream.h" 25 26namespace llvm { 27 class raw_string_ostream; 28} 29 30namespace slang { 31 32// The diagnostics client instance (for reading the processed diagnostics) 33class DiagnosticBuffer : public clang::DiagnosticClient { 34 private: 35 std::string mDiags; 36 llvm::raw_string_ostream *mSOS; 37 38 public: 39 DiagnosticBuffer(); 40 41 virtual void HandleDiagnostic(clang::Diagnostic::Level DiagLevel, 42 const clang::DiagnosticInfo& Info); 43 44 inline const std::string &str() const { 45 mSOS->flush(); 46 return mDiags; 47 } 48 49 inline void reset() { 50 this->mSOS->str().clear(); 51 return; 52 } 53 54 virtual ~DiagnosticBuffer(); 55}; 56} 57 58#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_DIAGNOSTIC_BUFFER_H_ NOLINT 59