clang API Documentation

LogDiagnosticPrinter.h
Go to the documentation of this file.
00001 //===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
00011 #define LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
00012 
00013 #include "clang/Basic/Diagnostic.h"
00014 #include "clang/Basic/SourceLocation.h"
00015 #include "llvm/ADT/SmallVector.h"
00016 #include "llvm/ADT/StringRef.h"
00017 
00018 namespace clang {
00019 class DiagnosticOptions;
00020 class LangOptions;
00021 
00022 class LogDiagnosticPrinter : public DiagnosticConsumer {
00023   struct DiagEntry {
00024     /// The primary message line of the diagnostic.
00025     std::string Message;
00026   
00027     /// The source file name, if available.
00028     std::string Filename;
00029   
00030     /// The source file line number, if available.
00031     unsigned Line;
00032   
00033     /// The source file column number, if available.
00034     unsigned Column;
00035   
00036     /// The ID of the diagnostic.
00037     unsigned DiagnosticID;
00038 
00039     /// The Option Flag for the diagnostic
00040     std::string WarningOption;
00041   
00042     /// The level of the diagnostic.
00043     DiagnosticsEngine::Level DiagnosticLevel;
00044   };
00045 
00046   void EmitDiagEntry(llvm::raw_ostream &OS,
00047                      const LogDiagnosticPrinter::DiagEntry &DE);
00048 
00049   // Conditional ownership (when StreamOwner is non-null, it's keeping OS
00050   // alive). We might want to replace this with a wrapper for conditional
00051   // ownership eventually - it seems to pop up often enough.
00052   raw_ostream &OS;
00053   std::unique_ptr<raw_ostream> StreamOwner;
00054   const LangOptions *LangOpts;
00055   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
00056 
00057   SourceLocation LastWarningLoc;
00058   FullSourceLoc LastLoc;
00059 
00060   SmallVector<DiagEntry, 8> Entries;
00061 
00062   std::string MainFilename;
00063   std::string DwarfDebugFlags;
00064 
00065 public:
00066   LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
00067                        std::unique_ptr<raw_ostream> StreamOwner);
00068 
00069   void setDwarfDebugFlags(StringRef Value) {
00070     DwarfDebugFlags = Value;
00071   }
00072 
00073   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
00074     LangOpts = &LO;
00075   }
00076 
00077   void EndSourceFile() override;
00078 
00079   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
00080                         const Diagnostic &Info) override;
00081 };
00082 
00083 } // end namespace clang
00084 
00085 #endif