Clang Project

clang_source_code/include/clang/Frontend/LogDiagnosticPrinter.h
1//===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
10#define LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
11
12#include "clang/Basic/Diagnostic.h"
13#include "clang/Basic/SourceLocation.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringRef.h"
16
17namespace clang {
18class DiagnosticOptions;
19class LangOptions;
20
21class LogDiagnosticPrinter : public DiagnosticConsumer {
22  struct DiagEntry {
23    /// The primary message line of the diagnostic.
24    std::string Message;
25
26    /// The source file name, if available.
27    std::string Filename;
28
29    /// The source file line number, if available.
30    unsigned Line;
31
32    /// The source file column number, if available.
33    unsigned Column;
34
35    /// The ID of the diagnostic.
36    unsigned DiagnosticID;
37
38    /// The Option Flag for the diagnostic
39    std::string WarningOption;
40
41    /// The level of the diagnostic.
42    DiagnosticsEngine::Level DiagnosticLevel;
43  };
44
45  void EmitDiagEntry(llvm::raw_ostream &OS,
46                     const LogDiagnosticPrinter::DiagEntry &DE);
47
48  // Conditional ownership (when StreamOwner is non-null, it's keeping OS
49  // alive). We might want to replace this with a wrapper for conditional
50  // ownership eventually - it seems to pop up often enough.
51  raw_ostream &OS;
52  std::unique_ptr<raw_ostreamStreamOwner;
53  const LangOptions *LangOpts;
54  IntrusiveRefCntPtr<DiagnosticOptionsDiagOpts;
55
56  SourceLocation LastWarningLoc;
57  FullSourceLoc LastLoc;
58
59  SmallVector<DiagEntry8Entries;
60
61  std::string MainFilename;
62  std::string DwarfDebugFlags;
63
64public:
65  LogDiagnosticPrinter(raw_ostream &OSDiagnosticOptions *Diags,
66                       std::unique_ptr<raw_ostreamStreamOwner);
67
68  void setDwarfDebugFlags(StringRef Value) {
69    DwarfDebugFlags = Value;
70  }
71
72  void BeginSourceFile(const LangOptions &LOconst Preprocessor *PP) override {
73    LangOpts = &LO;
74  }
75
76  void EndSourceFile() override;
77
78  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
79                        const Diagnostic &Info) override;
80};
81
82// end namespace clang
83
84#endif
85
clang::LogDiagnosticPrinter::DiagEntry
clang::LogDiagnosticPrinter::DiagEntry::Message
clang::LogDiagnosticPrinter::DiagEntry::Filename
clang::LogDiagnosticPrinter::DiagEntry::Line
clang::LogDiagnosticPrinter::DiagEntry::Column
clang::LogDiagnosticPrinter::DiagEntry::DiagnosticID
clang::LogDiagnosticPrinter::DiagEntry::WarningOption
clang::LogDiagnosticPrinter::DiagEntry::DiagnosticLevel
clang::LogDiagnosticPrinter::EmitDiagEntry
clang::LogDiagnosticPrinter::OS
clang::LogDiagnosticPrinter::StreamOwner
clang::LogDiagnosticPrinter::LangOpts
clang::LogDiagnosticPrinter::DiagOpts
clang::LogDiagnosticPrinter::LastWarningLoc
clang::LogDiagnosticPrinter::LastLoc
clang::LogDiagnosticPrinter::Entries
clang::LogDiagnosticPrinter::MainFilename
clang::LogDiagnosticPrinter::DwarfDebugFlags
clang::LogDiagnosticPrinter::setDwarfDebugFlags
clang::LogDiagnosticPrinter::BeginSourceFile
clang::LogDiagnosticPrinter::EndSourceFile
clang::LogDiagnosticPrinter::HandleDiagnostic