LLDB mainline
DiagnosticManager.h
Go to the documentation of this file.
1//===-- DiagnosticManager.h -------------------------------------*- 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 LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
10#define LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
11
12#include "lldb/lldb-defines.h"
13#include "lldb/lldb-types.h"
14
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/StringRef.h"
17
18#include <string>
19#include <vector>
20
21namespace lldb_private {
22
29};
30
35};
36
38
40 friend class DiagnosticManager;
41
42public:
43 DiagnosticOrigin getKind() const { return m_origin; }
44
45 static bool classof(const Diagnostic *diag) {
46 DiagnosticOrigin kind = diag->getKind();
47 switch (kind) {
51 return true;
54 return false;
55 }
56 }
57
58 Diagnostic(llvm::StringRef message, DiagnosticSeverity severity,
59 DiagnosticOrigin origin, uint32_t compiler_id)
60 : m_message(message), m_severity(severity), m_origin(origin),
61 m_compiler_id(compiler_id) {}
62
66
67 virtual ~Diagnostic() = default;
68
69 virtual bool HasFixIts() const { return false; }
70
72
73 uint32_t GetCompilerID() const { return m_compiler_id; }
74
75 llvm::StringRef GetMessage() const { return m_message; }
76
77 void AppendMessage(llvm::StringRef message,
78 bool precede_with_newline = true) {
79 if (precede_with_newline)
80 m_message.push_back('\n');
81 m_message += message;
82 }
83
84protected:
85 std::string m_message;
88 uint32_t m_compiler_id; // Compiler-specific diagnostic ID
89};
90
91typedef std::vector<std::unique_ptr<Diagnostic>> DiagnosticList;
92
94public:
95 void Clear() {
96 m_diagnostics.clear();
97 m_fixed_expression.clear();
98 }
99
101
102 bool HasFixIts() const {
103 return llvm::any_of(m_diagnostics,
104 [](const std::unique_ptr<Diagnostic> &diag) {
105 return diag->HasFixIts();
106 });
107 }
108
109 void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity,
110 DiagnosticOrigin origin,
111 uint32_t compiler_id = LLDB_INVALID_COMPILER_ID) {
112 m_diagnostics.emplace_back(
113 std::make_unique<Diagnostic>(message, severity, origin, compiler_id));
114 }
115
116 void AddDiagnostic(std::unique_ptr<Diagnostic> diagnostic) {
117 if (diagnostic)
118 m_diagnostics.push_back(std::move(diagnostic));
119 }
120
121 /// Moves over the contents of a second diagnostic manager over. Leaves other
122 /// diagnostic manager in an empty state.
124 std::move(other.m_diagnostics.begin(), other.m_diagnostics.end(),
125 std::back_inserter(m_diagnostics));
126 m_fixed_expression = std::move(other.m_fixed_expression);
127 other.Clear();
128 }
129
130 size_t Printf(DiagnosticSeverity severity, const char *format, ...)
131 __attribute__((format(printf, 3, 4)));
132 void PutString(DiagnosticSeverity severity, llvm::StringRef str);
133
134 void AppendMessageToDiagnostic(llvm::StringRef str) {
135 if (!m_diagnostics.empty())
136 m_diagnostics.back()->AppendMessage(str);
137 }
138
139 // Returns a string containing errors in this format:
140 //
141 // "error: error text\n
142 // warning: warning text\n
143 // remark text\n"
144 std::string GetString(char separator = '\n');
145
146 void Dump(Log *log);
147
148 const std::string &GetFixedExpression() { return m_fixed_expression; }
149
150 // Moves fixed_expression to the internal storage.
151 void SetFixedExpression(std::string fixed_expression) {
152 m_fixed_expression = std::move(fixed_expression);
153 }
154
155protected:
158};
159}
160
161#endif // LLDB_EXPRESSION_DIAGNOSTICMANAGER_H
size_t Printf(DiagnosticSeverity severity, const char *format,...) __attribute__((format(printf
void Consume(DiagnosticManager &&other)
Moves over the contents of a second diagnostic manager over.
void SetFixedExpression(std::string fixed_expression)
void AppendMessageToDiagnostic(llvm::StringRef str)
void AddDiagnostic(std::unique_ptr< Diagnostic > diagnostic)
std::string GetString(char separator='\n')
const DiagnosticList & Diagnostics()
size_t void PutString(DiagnosticSeverity severity, llvm::StringRef str)
void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity, DiagnosticOrigin origin, uint32_t compiler_id=LLDB_INVALID_COMPILER_ID)
const std::string & GetFixedExpression()
DiagnosticSeverity m_severity
Diagnostic(const Diagnostic &rhs)
DiagnosticSeverity GetSeverity() const
virtual ~Diagnostic()=default
void AppendMessage(llvm::StringRef message, bool precede_with_newline=true)
uint32_t GetCompilerID() const
virtual bool HasFixIts() const
Diagnostic(llvm::StringRef message, DiagnosticSeverity severity, DiagnosticOrigin origin, uint32_t compiler_id)
DiagnosticOrigin getKind() const
llvm::StringRef GetMessage() const
static bool classof(const Diagnostic *diag)
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
const uint32_t LLDB_INVALID_COMPILER_ID
std::vector< std::unique_ptr< Diagnostic > > DiagnosticList
Definition: Debugger.h:53