File indexing completed on 2026-05-10 08:36:55
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
0010 #define LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
0011
0012 #include "clang/Basic/LLVM.h"
0013 #include "llvm/Bitstream/BitstreamReader.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/Support/ErrorOr.h"
0016 #include <system_error>
0017
0018 namespace clang {
0019 namespace serialized_diags {
0020
0021 enum class SDError {
0022 CouldNotLoad = 1,
0023 InvalidSignature,
0024 InvalidDiagnostics,
0025 MalformedTopLevelBlock,
0026 MalformedSubBlock,
0027 MalformedBlockInfoBlock,
0028 MalformedMetadataBlock,
0029 MalformedDiagnosticBlock,
0030 MalformedDiagnosticRecord,
0031 MissingVersion,
0032 VersionMismatch,
0033 UnsupportedConstruct,
0034
0035
0036 HandlerFailed
0037 };
0038
0039 const std::error_category &SDErrorCategory();
0040
0041 inline std::error_code make_error_code(SDError E) {
0042 return std::error_code(static_cast<int>(E), SDErrorCategory());
0043 }
0044
0045
0046 struct Location {
0047 unsigned FileID;
0048 unsigned Line;
0049 unsigned Col;
0050 unsigned Offset;
0051
0052 Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
0053 : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
0054 };
0055
0056
0057
0058
0059
0060 class SerializedDiagnosticReader {
0061 public:
0062 SerializedDiagnosticReader() = default;
0063 virtual ~SerializedDiagnosticReader() = default;
0064
0065
0066 std::error_code readDiagnostics(StringRef File);
0067
0068 private:
0069 enum class Cursor;
0070
0071
0072 llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
0073 unsigned &BlockOrRecordId);
0074
0075
0076 std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
0077
0078
0079 std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
0080
0081 protected:
0082
0083 virtual std::error_code visitStartOfDiagnostic() { return {}; }
0084
0085
0086 virtual std::error_code visitEndOfDiagnostic() { return {}; }
0087
0088
0089 virtual std::error_code visitCategoryRecord(unsigned ID, StringRef Name) {
0090 return {};
0091 }
0092
0093
0094 virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) {
0095 return {};
0096 }
0097
0098
0099 virtual std::error_code
0100 visitDiagnosticRecord(unsigned Severity, const Location &Location,
0101 unsigned Category, unsigned Flag, StringRef Message) {
0102 return {};
0103 }
0104
0105
0106 virtual std::error_code visitFilenameRecord(unsigned ID, unsigned Size,
0107 unsigned Timestamp,
0108 StringRef Name) {
0109 return {};
0110 }
0111
0112
0113 virtual std::error_code
0114 visitFixitRecord(const Location &Start, const Location &End, StringRef Text) {
0115 return {};
0116 }
0117
0118
0119 virtual std::error_code visitSourceRangeRecord(const Location &Start,
0120 const Location &End) {
0121 return {};
0122 }
0123
0124
0125 virtual std::error_code visitVersionRecord(unsigned Version) { return {}; }
0126 };
0127
0128 }
0129 }
0130
0131 template <>
0132 struct std::is_error_code_enum<clang::serialized_diags::SDError>
0133 : std::true_type {};
0134
0135 #endif