clang  14.0.0git
LogDiagnosticPrinter.h
Go to the documentation of this file.
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"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 
17 namespace clang {
18 class DiagnosticOptions;
19 class LangOptions;
20 
22  struct DiagEntry {
23  /// The primary message line of the diagnostic.
24  std::string Message;
25 
26  /// The source file name, if available.
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_ostream> StreamOwner;
53  const LangOptions *LangOpts;
55 
56  SourceLocation LastWarningLoc;
57  FullSourceLoc LastLoc;
58 
60 
61  std::string MainFilename;
62  std::string DwarfDebugFlags;
63 
64 public:
65  LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
66  std::unique_ptr<raw_ostream> StreamOwner);
67 
68  void setDwarfDebugFlags(StringRef Value) {
69  DwarfDebugFlags = std::string(Value);
70  }
71 
72  void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
73  LangOpts = &LO;
74  }
75 
76  void EndSourceFile() override;
77 
79  const Diagnostic &Info) override;
80 };
81 
82 } // end namespace clang
83 
84 #endif
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:194
clang::LogDiagnosticPrinter::BeginSourceFile
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: LogDiagnosticPrinter.h:72
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:370
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector< DiagEntry, 8 >
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1722
clang::LogDiagnosticPrinter::EndSourceFile
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: LogDiagnosticPrinter.cpp:76
Filename
StringRef Filename
Definition: Format.cpp:2333
clang::LogDiagnosticPrinter::setDwarfDebugFlags
void setDwarfDebugFlags(StringRef Value)
Definition: LogDiagnosticPrinter.h:68
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1547
Diagnostic.h
clang::LogDiagnosticPrinter::HandleDiagnostic
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: LogDiagnosticPrinter.cpp:111
Line
const AnnotatedLine * Line
Definition: UsingDeclarationsSorter.cpp:68
SourceLocation.h
clang::LogDiagnosticPrinter::LogDiagnosticPrinter
LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags, std::unique_ptr< raw_ostream > StreamOwner)
Definition: LogDiagnosticPrinter.cpp:20
Value
Value
Definition: UninitializedValues.cpp:102
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang
Definition: CalledOnceCheck.h:17
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::LogDiagnosticPrinter
Definition: LogDiagnosticPrinter.h:21
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:47
clang::DiagnosticOptions
Options for controlling the compiler diagnostics engine.
Definition: DiagnosticOptions.h:70