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_LOG_DIAGNOSTIC_PRINTER_H_
00011 #define LLVM_CLANG_FRONTEND_LOG_DIAGNOSTIC_PRINTER_H_
00012 
00013 #include "clang/Basic/Diagnostic.h"
00014 #include "clang/Basic/SourceLocation.h"
00015 #include "llvm/ADT/StringRef.h"
00016 #include "llvm/ADT/SmallVector.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 level of the diagnostic.
00040     DiagnosticsEngine::Level DiagnosticLevel;
00041   };
00042   
00043   raw_ostream &OS;
00044   const LangOptions *LangOpts;
00045   const DiagnosticOptions *DiagOpts;
00046 
00047   SourceLocation LastWarningLoc;
00048   FullSourceLoc LastLoc;
00049   unsigned OwnsOutputStream : 1;
00050 
00051   SmallVector<DiagEntry, 8> Entries;
00052 
00053   std::string MainFilename;
00054   std::string DwarfDebugFlags;
00055 
00056 public:
00057   LogDiagnosticPrinter(raw_ostream &OS, const DiagnosticOptions &Diags,
00058                        bool OwnsOutputStream = false);
00059   virtual ~LogDiagnosticPrinter();
00060 
00061   void setDwarfDebugFlags(StringRef Value) {
00062     DwarfDebugFlags = Value;
00063   }
00064 
00065   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) {
00066     LangOpts = &LO;
00067   }
00068 
00069   void EndSourceFile();
00070 
00071   virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
00072                                 const Diagnostic &Info);
00073   
00074   DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
00075 };
00076 
00077 } // end namespace clang
00078 
00079 #endif