LLDB mainline
DiagnosticsRendering.h
Go to the documentation of this file.
1//===-- DiagnosticsRendering.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_UTILITY_DIAGNOSTICSRENDERING_H
10#define LLDB_UTILITY_DIAGNOSTICSRENDERING_H
11
12#include "lldb/Utility/Status.h"
13#include "lldb/Utility/Stream.h"
14#include "llvm/Support/WithColor.h"
15
16namespace lldb_private {
17
18/// A compiler-independent representation of an \c
19/// lldb_private::Diagnostic. Expression evaluation failures often
20/// have more than one diagnostic that a UI layer might want to render
21/// differently, for example to colorize it.
22///
23/// Running example:
24/// (lldb) expr 1 + foo
25/// error: <user expression 0>:1:3: use of undeclared identifier 'foo'
26/// 1 + foo
27/// ^~~
29 /// A source location consisting of a file name and position.
31 /// \c "<user expression 0>" in the example above.
33 /// \c 1 in the example above.
34 unsigned line = 0;
35 /// \c 5 in the example above.
36 uint16_t column = 0;
37 /// \c 3 in the example above.
38 uint16_t length = 0;
39 /// Whether this source location should be surfaced to the
40 /// user. For example, syntax errors diagnosed in LLDB's
41 /// expression wrapper code have this set to true.
42 bool hidden = false;
43 /// Whether this source location refers to something the user
44 /// typed as part of the command, i.e., if this qualifies for
45 /// inline display, or if the source line would need to be echoed
46 /// again for the message to make sense.
47 bool in_user_input = false;
48 };
49 /// Contains this diagnostic's source location, if applicable.
50 std::optional<SourceLocation> source_location;
51 /// Contains \c eSeverityError in the example above.
53 /// Contains "use of undeclared identifier 'foo'" in the example above.
54 std::string message;
55 /// Contains the fully rendered error message, without "error: ",
56 /// but including the source context.
57 std::string rendered;
58};
59
60StructuredData::ObjectSP Serialize(llvm::ArrayRef<DiagnosticDetail> details);
61
63 std::optional<uint16_t> offset_in_command,
64 bool show_inline,
65 llvm::ArrayRef<DiagnosticDetail> details);
66
68 : public llvm::ErrorInfo<DiagnosticError, CloneableECError> {
69public:
70 using llvm::ErrorInfo<DiagnosticError, CloneableECError>::ErrorInfo;
71 DiagnosticError(std::error_code ec) : ErrorInfo(ec) {}
72 lldb::ErrorType GetErrorType() const override;
73 virtual llvm::ArrayRef<DiagnosticDetail> GetDetails() const = 0;
75 return Serialize(GetDetails());
76 }
77 static char ID;
78};
79
80} // namespace lldb_private
81#endif
Common base class for all error-code errors.
Definition: Status.h:48
StructuredData::ObjectSP GetAsStructuredData() const override
virtual llvm::ArrayRef< DiagnosticDetail > GetDetails() const =0
lldb::ErrorType GetErrorType() const override
A file utility class.
Definition: FileSpec.h:56
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
StructuredData::ObjectSP Serialize(llvm::ArrayRef< DiagnosticDetail > details)
void RenderDiagnosticDetails(Stream &stream, std::optional< uint16_t > offset_in_command, bool show_inline, llvm::ArrayRef< DiagnosticDetail > details)
Severity
Used for expressing severity in logs and diagnostics.
A source location consisting of a file name and position.
bool in_user_input
Whether this source location refers to something the user typed as part of the command,...
FileSpec file
"<user expression 0>" in the example above.
bool hidden
Whether this source location should be surfaced to the user.
A compiler-independent representation of an lldb_private::Diagnostic.
std::optional< SourceLocation > source_location
Contains this diagnostic's source location, if applicable.
lldb::Severity severity
Contains eSeverityError in the example above.
std::string rendered
Contains the fully rendered error message, without "error: ", but including the source context.
std::string message
Contains "use of undeclared identifier 'foo'" in the example above.