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/ADT/ArrayRef.h"
15 #include "llvm/Bitcode/BitstreamReader.h"
16 #include "llvm/Support/ErrorOr.h"
19 namespace serialized_diags {
25 MalformedTopLevelBlock,
27 MalformedBlockInfoBlock,
28 MalformedMetadataBlock,
29 MalformedDiagnosticBlock,
30 MalformedDiagnosticRecord,
34 /// A generic error for subclass handlers that don't want or need to define
35 /// their own error_category.
39 const std::error_category &SDErrorCategory();
41 inline std::error_code make_error_code(SDError E) {
42 return std::error_code(static_cast<int>(E), SDErrorCategory());
45 /// \brief A location that is represented in the serialized diagnostics.
51 Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
52 : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
55 /// \brief A base class that handles reading serialized diagnostics from a file.
57 /// Subclasses should override the visit* methods with their logic for handling
58 /// the various constructs that are found in serialized diagnostics.
59 class SerializedDiagnosticReader {
61 SerializedDiagnosticReader() {}
62 virtual ~SerializedDiagnosticReader() {}
64 /// \brief Read the diagnostics in \c File
65 std::error_code readDiagnostics(StringRef File);
70 /// \brief Read to the next record or block to process.
71 llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
72 unsigned &BlockOrRecordId);
74 /// \brief Read a metadata block from \c Stream.
75 std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
77 /// \brief Read a diagnostic block from \c Stream.
78 std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
81 /// \brief Visit the start of a diagnostic block.
82 virtual std::error_code visitStartOfDiagnostic() {
83 return std::error_code();
85 /// \brief Visit the end of a diagnostic block.
86 virtual std::error_code visitEndOfDiagnostic() { return std::error_code(); }
87 /// \brief Visit a category. This associates the category \c ID to a \c Name.
88 virtual std::error_code visitCategoryRecord(unsigned ID, StringRef Name) {
89 return std::error_code();
91 /// \brief Visit a flag. This associates the flag's \c ID to a \c Name.
92 virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) {
93 return std::error_code();
95 /// \brief Visit a diagnostic.
96 virtual std::error_code
97 visitDiagnosticRecord(unsigned Severity, const Location &Location,
98 unsigned Category, unsigned Flag, StringRef Message) {
99 return std::error_code();
101 /// \brief Visit a filename. This associates the file's \c ID to a \c Name.
102 virtual std::error_code visitFilenameRecord(unsigned ID, unsigned Size,
105 return std::error_code();
107 /// \brief Visit a fixit hint.
108 virtual std::error_code
109 visitFixitRecord(const Location &Start, const Location &End, StringRef Text) {
110 return std::error_code();
112 /// \brief Visit a source range.
113 virtual std::error_code visitSourceRangeRecord(const Location &Start,
114 const Location &End) {
115 return std::error_code();
117 /// \brief Visit the version of the set of diagnostics.
118 virtual std::error_code visitVersionRecord(unsigned Version) {
119 return std::error_code();
123 } // end serialized_diags namespace
124 } // end clang namespace
128 struct is_error_code_enum<clang::serialized_diags::SDError> : std::true_type {};