1 //===--- SerializedDiagnosticReader.h - Reads diagnostics -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_SERIALIZED_DIAGNOSTIC_READER_H_
11 #define LLVM_CLANG_FRONTEND_SERIALIZED_DIAGNOSTIC_READER_H_
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/Bitcode/BitstreamReader.h"
15 #include "llvm/Support/ErrorOr.h"
18 namespace serialized_diags {
24 MalformedTopLevelBlock,
26 MalformedBlockInfoBlock,
27 MalformedMetadataBlock,
28 MalformedDiagnosticBlock,
29 MalformedDiagnosticRecord,
33 /// A generic error for subclass handlers that don't want or need to define
34 /// their own error_category.
38 const std::error_category &SDErrorCategory();
40 inline std::error_code make_error_code(SDError E) {
41 return std::error_code(static_cast<int>(E), SDErrorCategory());
44 /// \brief A location that is represented in the serialized diagnostics.
50 Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
51 : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
54 /// \brief A base class that handles reading serialized diagnostics from a file.
56 /// Subclasses should override the visit* methods with their logic for handling
57 /// the various constructs that are found in serialized diagnostics.
58 class SerializedDiagnosticReader {
60 SerializedDiagnosticReader() {}
61 virtual ~SerializedDiagnosticReader() {}
63 /// \brief Read the diagnostics in \c File
64 std::error_code readDiagnostics(StringRef File);
69 /// \brief Read to the next record or block to process.
70 llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
71 unsigned &BlockOrRecordId);
73 /// \brief Read a metadata block from \c Stream.
74 std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
76 /// \brief Read a diagnostic block from \c Stream.
77 std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
80 /// \brief Visit the start of a diagnostic block.
81 virtual std::error_code visitStartOfDiagnostic() {
82 return std::error_code();
84 /// \brief Visit the end of a diagnostic block.
85 virtual std::error_code visitEndOfDiagnostic() { return std::error_code(); }
86 /// \brief Visit a category. This associates the category \c ID to a \c Name.
87 virtual std::error_code visitCategoryRecord(unsigned ID, StringRef Name) {
88 return std::error_code();
90 /// \brief Visit a flag. This associates the flag's \c ID to a \c Name.
91 virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) {
92 return std::error_code();
94 /// \brief Visit a diagnostic.
95 virtual std::error_code
96 visitDiagnosticRecord(unsigned Severity, const Location &Location,
97 unsigned Category, unsigned Flag, StringRef Message) {
98 return std::error_code();
100 /// \brief Visit a filename. This associates the file's \c ID to a \c Name.
101 virtual std::error_code visitFilenameRecord(unsigned ID, unsigned Size,
104 return std::error_code();
106 /// \brief Visit a fixit hint.
107 virtual std::error_code
108 visitFixitRecord(const Location &Start, const Location &End, StringRef Text) {
109 return std::error_code();
111 /// \brief Visit a source range.
112 virtual std::error_code visitSourceRangeRecord(const Location &Start,
113 const Location &End) {
114 return std::error_code();
116 /// \brief Visit the version of the set of diagnostics.
117 virtual std::error_code visitVersionRecord(unsigned Version) {
118 return std::error_code();
122 } // end serialized_diags namespace
123 } // end clang namespace
127 struct is_error_code_enum<clang::serialized_diags::SDError> : std::true_type {};