Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:57

0001 //===-- DiagnosticsRendering.h ----------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_DIAGNOSTICSRENDERING_H
0010 #define LLDB_UTILITY_DIAGNOSTICSRENDERING_H
0011 
0012 #include "lldb/Utility/Status.h"
0013 #include "lldb/Utility/Stream.h"
0014 #include "llvm/Support/WithColor.h"
0015 
0016 namespace lldb_private {
0017 
0018 /// A compiler-independent representation of an \c
0019 /// lldb_private::Diagnostic. Expression evaluation failures often
0020 /// have more than one diagnostic that a UI layer might want to render
0021 /// differently, for example to colorize it.
0022 ///
0023 /// Running example:
0024 ///   (lldb) expr 1 + foo
0025 ///   error: <user expression 0>:1:3: use of undeclared identifier 'foo'
0026 ///   1 + foo
0027 ///       ^~~
0028 struct DiagnosticDetail {
0029   /// A source location consisting of a file name and position.
0030   struct SourceLocation {
0031     /// \c "<user expression 0>" in the example above.
0032     FileSpec file;
0033     /// \c 1 in the example above.
0034     unsigned line = 0;
0035     /// \c 5 in the example above.
0036     uint16_t column = 0;
0037     /// \c 3 in the example above.
0038     uint16_t length = 0;
0039     /// Whether this source location should be surfaced to the
0040     /// user. For example, syntax errors diagnosed in LLDB's
0041     /// expression wrapper code have this set to true.
0042     bool hidden = false;
0043     /// Whether this source location refers to something the user
0044     /// typed as part of the command, i.e., if this qualifies for
0045     /// inline display, or if the source line would need to be echoed
0046     /// again for the message to make sense.
0047     bool in_user_input = false;
0048   };
0049   /// Contains this diagnostic's source location, if applicable.
0050   std::optional<SourceLocation> source_location;
0051   /// Contains \c eSeverityError in the example above.
0052   lldb::Severity severity = lldb::eSeverityInfo;
0053   /// Contains "use of undeclared identifier 'foo'" in the example above.
0054   std::string message;
0055   /// Contains the fully rendered error message, without "error: ",
0056   /// but including the source context.
0057   std::string rendered;
0058 };
0059 
0060 StructuredData::ObjectSP Serialize(llvm::ArrayRef<DiagnosticDetail> details);
0061 
0062 void RenderDiagnosticDetails(Stream &stream,
0063                              std::optional<uint16_t> offset_in_command,
0064                              bool show_inline,
0065                              llvm::ArrayRef<DiagnosticDetail> details);
0066 
0067 class DiagnosticError
0068     : public llvm::ErrorInfo<DiagnosticError, CloneableECError> {
0069 public:
0070   using llvm::ErrorInfo<DiagnosticError, CloneableECError>::ErrorInfo;
0071   DiagnosticError(std::error_code ec) : ErrorInfo(ec) {}
0072   lldb::ErrorType GetErrorType() const override;
0073   virtual llvm::ArrayRef<DiagnosticDetail> GetDetails() const = 0;
0074   StructuredData::ObjectSP GetAsStructuredData() const override {
0075     return Serialize(GetDetails());
0076   }
0077   static char ID;
0078 };
0079 
0080 } // namespace lldb_private
0081 #endif