106f32e7eSjoerg //===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- C++ -*-===//
206f32e7eSjoerg //
306f32e7eSjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406f32e7eSjoerg // See https://llvm.org/LICENSE.txt for license information.
506f32e7eSjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606f32e7eSjoerg //
706f32e7eSjoerg //===----------------------------------------------------------------------===//
806f32e7eSjoerg 
906f32e7eSjoerg #ifndef LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
1006f32e7eSjoerg #define LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
1106f32e7eSjoerg 
1206f32e7eSjoerg #include "clang/Basic/Diagnostic.h"
1306f32e7eSjoerg #include "clang/Basic/SourceLocation.h"
1406f32e7eSjoerg #include "llvm/ADT/SmallVector.h"
1506f32e7eSjoerg #include "llvm/ADT/StringRef.h"
1606f32e7eSjoerg 
1706f32e7eSjoerg namespace clang {
1806f32e7eSjoerg class DiagnosticOptions;
1906f32e7eSjoerg class LangOptions;
2006f32e7eSjoerg 
2106f32e7eSjoerg class LogDiagnosticPrinter : public DiagnosticConsumer {
2206f32e7eSjoerg   struct DiagEntry {
2306f32e7eSjoerg     /// The primary message line of the diagnostic.
2406f32e7eSjoerg     std::string Message;
2506f32e7eSjoerg 
2606f32e7eSjoerg     /// The source file name, if available.
2706f32e7eSjoerg     std::string Filename;
2806f32e7eSjoerg 
2906f32e7eSjoerg     /// The source file line number, if available.
3006f32e7eSjoerg     unsigned Line;
3106f32e7eSjoerg 
3206f32e7eSjoerg     /// The source file column number, if available.
3306f32e7eSjoerg     unsigned Column;
3406f32e7eSjoerg 
3506f32e7eSjoerg     /// The ID of the diagnostic.
3606f32e7eSjoerg     unsigned DiagnosticID;
3706f32e7eSjoerg 
3806f32e7eSjoerg     /// The Option Flag for the diagnostic
3906f32e7eSjoerg     std::string WarningOption;
4006f32e7eSjoerg 
4106f32e7eSjoerg     /// The level of the diagnostic.
4206f32e7eSjoerg     DiagnosticsEngine::Level DiagnosticLevel;
4306f32e7eSjoerg   };
4406f32e7eSjoerg 
4506f32e7eSjoerg   void EmitDiagEntry(llvm::raw_ostream &OS,
4606f32e7eSjoerg                      const LogDiagnosticPrinter::DiagEntry &DE);
4706f32e7eSjoerg 
4806f32e7eSjoerg   // Conditional ownership (when StreamOwner is non-null, it's keeping OS
4906f32e7eSjoerg   // alive). We might want to replace this with a wrapper for conditional
5006f32e7eSjoerg   // ownership eventually - it seems to pop up often enough.
5106f32e7eSjoerg   raw_ostream &OS;
5206f32e7eSjoerg   std::unique_ptr<raw_ostream> StreamOwner;
5306f32e7eSjoerg   const LangOptions *LangOpts;
5406f32e7eSjoerg   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
5506f32e7eSjoerg 
5606f32e7eSjoerg   SourceLocation LastWarningLoc;
5706f32e7eSjoerg   FullSourceLoc LastLoc;
5806f32e7eSjoerg 
5906f32e7eSjoerg   SmallVector<DiagEntry, 8> Entries;
6006f32e7eSjoerg 
6106f32e7eSjoerg   std::string MainFilename;
6206f32e7eSjoerg   std::string DwarfDebugFlags;
6306f32e7eSjoerg 
6406f32e7eSjoerg public:
6506f32e7eSjoerg   LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
6606f32e7eSjoerg                        std::unique_ptr<raw_ostream> StreamOwner);
6706f32e7eSjoerg 
setDwarfDebugFlags(StringRef Value)6806f32e7eSjoerg   void setDwarfDebugFlags(StringRef Value) {
69*13fbcb42Sjoerg     DwarfDebugFlags = std::string(Value);
7006f32e7eSjoerg   }
7106f32e7eSjoerg 
BeginSourceFile(const LangOptions & LO,const Preprocessor * PP)7206f32e7eSjoerg   void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
7306f32e7eSjoerg     LangOpts = &LO;
7406f32e7eSjoerg   }
7506f32e7eSjoerg 
7606f32e7eSjoerg   void EndSourceFile() override;
7706f32e7eSjoerg 
7806f32e7eSjoerg   void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
7906f32e7eSjoerg                         const Diagnostic &Info) override;
8006f32e7eSjoerg };
8106f32e7eSjoerg 
8206f32e7eSjoerg } // end namespace clang
8306f32e7eSjoerg 
8406f32e7eSjoerg #endif
85