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
62/// Renders an array of DiagnosticDetail instances.
63///
64/// \param[in] stream
65/// The stream to render the diagnostics to.
66/// \param offset_in_command
67/// An optional offset to the column position of the diagnostic in the
68/// source.
69/// \param show_inline
70/// Whether to show the diagnostics inline.
71/// \param details
72/// The array of DiagnosticsDetail to render.
73/// \param force_ascii
74/// Whether to force ascii rendering. If false, Unicode characters will be
75/// used if the output file supports them.
76///
77/// \see lldb_private::Terminal::SupportsUnicode
79 std::optional<uint16_t> offset_in_command,
80 bool show_inline,
81 llvm::ArrayRef<DiagnosticDetail> details,
82 bool force_ascii = false);
83
85 : public llvm::ErrorInfo<DiagnosticError, CloneableECError> {
86public:
87 using llvm::ErrorInfo<DiagnosticError, CloneableECError>::ErrorInfo;
88 DiagnosticError(std::error_code ec) : ErrorInfo(ec) {}
89 lldb::ErrorType GetErrorType() const override;
90 virtual llvm::ArrayRef<DiagnosticDetail> GetDetails() const = 0;
94 static char ID;
95};
96
97} // namespace lldb_private
98#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:57
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.
void RenderDiagnosticDetails(Stream &stream, std::optional< uint16_t > offset_in_command, bool show_inline, llvm::ArrayRef< DiagnosticDetail > details, bool force_ascii=false)
Renders an array of DiagnosticDetail instances.
StructuredData::ObjectSP Serialize(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.