1 //===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_CLANG_FRONTEND_LOG_DIAGNOSTIC_PRINTER_H_ 11 #define LLVM_CLANG_FRONTEND_LOG_DIAGNOSTIC_PRINTER_H_ 12 13 #include "clang/Basic/Diagnostic.h" 14 #include "clang/Basic/SourceLocation.h" 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/ADT/SmallVector.h" 17 18 namespace clang { 19 class DiagnosticOptions; 20 class LangOptions; 21 22 class LogDiagnosticPrinter : public DiagnosticClient { 23 struct DiagEntry { 24 /// The primary message line of the diagnostic. 25 std::string Message; 26 27 /// The source file name, if available. 28 std::string Filename; 29 30 /// The source file line number, if available. 31 unsigned Line; 32 33 /// The source file column number, if available. 34 unsigned Column; 35 36 /// The ID of the diagnostic. 37 unsigned DiagnosticID; 38 39 /// The level of the diagnostic. 40 Diagnostic::Level DiagnosticLevel; 41 }; 42 43 llvm::raw_ostream &OS; 44 const LangOptions *LangOpts; 45 const DiagnosticOptions *DiagOpts; 46 47 SourceLocation LastWarningLoc; 48 FullSourceLoc LastLoc; 49 unsigned OwnsOutputStream : 1; 50 51 llvm::SmallVector<DiagEntry, 8> Entries; 52 53 std::string MainFilename; 54 std::string DwarfDebugFlags; 55 56 public: 57 LogDiagnosticPrinter(llvm::raw_ostream &OS, const DiagnosticOptions &Diags, 58 bool OwnsOutputStream = false); 59 virtual ~LogDiagnosticPrinter(); 60 setDwarfDebugFlags(llvm::StringRef Value)61 void setDwarfDebugFlags(llvm::StringRef Value) { 62 DwarfDebugFlags = Value; 63 } 64 BeginSourceFile(const LangOptions & LO,const Preprocessor * PP)65 void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) { 66 LangOpts = &LO; 67 } 68 69 void EndSourceFile(); 70 71 virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, 72 const DiagnosticInfo &Info); 73 }; 74 75 } // end namespace clang 76 77 #endif 78