clang  8.0.0svn
SerializedDiagnosticReader.h
Go to the documentation of this file.
1 //===- SerializedDiagnosticReader.h - Reads diagnostics ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
11 #define LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
12 
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/Bitcode/BitstreamReader.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/ErrorOr.h"
17 #include <system_error>
18 
19 namespace clang {
20 namespace serialized_diags {
21 
22 enum class SDError {
23  CouldNotLoad = 1,
35  /// A generic error for subclass handlers that don't want or need to define
36  /// their own error_category.
38 };
39 
40 const std::error_category &SDErrorCategory();
41 
42 inline std::error_code make_error_code(SDError E) {
43  return std::error_code(static_cast<int>(E), SDErrorCategory());
44 }
45 
46 /// A location that is represented in the serialized diagnostics.
47 struct Location {
48  unsigned FileID;
49  unsigned Line;
50  unsigned Col;
51  unsigned Offset;
52 
53  Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
54  : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
55 };
56 
57 /// A base class that handles reading serialized diagnostics from a file.
58 ///
59 /// Subclasses should override the visit* methods with their logic for handling
60 /// the various constructs that are found in serialized diagnostics.
62 public:
63  SerializedDiagnosticReader() = default;
64  virtual ~SerializedDiagnosticReader() = default;
65 
66  /// Read the diagnostics in \c File
67  std::error_code readDiagnostics(StringRef File);
68 
69 private:
70  enum class Cursor;
71 
72  /// Read to the next record or block to process.
73  llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
74  unsigned &BlockOrRecordId);
75 
76  /// Read a metadata block from \c Stream.
77  std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
78 
79  /// Read a diagnostic block from \c Stream.
80  std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
81 
82 protected:
83  /// Visit the start of a diagnostic block.
84  virtual std::error_code visitStartOfDiagnostic() { return {}; }
85 
86  /// Visit the end of a diagnostic block.
87  virtual std::error_code visitEndOfDiagnostic() { return {}; }
88 
89  /// Visit a category. This associates the category \c ID to a \c Name.
90  virtual std::error_code visitCategoryRecord(unsigned ID, StringRef Name) {
91  return {};
92  }
93 
94  /// Visit a flag. This associates the flag's \c ID to a \c Name.
95  virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name) {
96  return {};
97  }
98 
99  /// Visit a diagnostic.
100  virtual std::error_code
102  unsigned Category, unsigned Flag, StringRef Message) {
103  return {};
104  }
105 
106  /// Visit a filename. This associates the file's \c ID to a \c Name.
107  virtual std::error_code visitFilenameRecord(unsigned ID, unsigned Size,
108  unsigned Timestamp,
109  StringRef Name) {
110  return {};
111  }
112 
113  /// Visit a fixit hint.
114  virtual std::error_code
115  visitFixitRecord(const Location &Start, const Location &End, StringRef Text) {
116  return {};
117  }
118 
119  /// Visit a source range.
120  virtual std::error_code visitSourceRangeRecord(const Location &Start,
121  const Location &End) {
122  return {};
123  }
124 
125  /// Visit the version of the set of diagnostics.
126  virtual std::error_code visitVersionRecord(unsigned Version) { return {}; }
127 };
128 
129 } // namespace serialized_diags
130 } // namespace clang
131 
132 namespace std {
133 
134 template <>
135 struct is_error_code_enum<clang::serialized_diags::SDError> : std::true_type {};
136 
137 } // namespace std
138 
139 #endif // LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
std::error_code make_error_code(SDError E)
virtual std::error_code visitStartOfDiagnostic()
Visit the start of a diagnostic block.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing)...
Definition: DiagnosticIDs.h:80
Definition: Format.h:2031
Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
A generic error for subclass handlers that don&#39;t want or need to define their own error_category...
int Category
Definition: Format.cpp:1605
virtual std::error_code visitSourceRangeRecord(const Location &Start, const Location &End)
Visit a source range.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceLocation End
virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name)
Visit a flag. This associates the flag&#39;s ID to a Name.
virtual std::error_code visitVersionRecord(unsigned Version)
Visit the version of the set of diagnostics.
Dataflow Directional Tag Classes.
A base class that handles reading serialized diagnostics from a file.
virtual std::error_code visitFixitRecord(const Location &Start, const Location &End, StringRef Text)
Visit a fixit hint.
A location that is represented in the serialized diagnostics.
virtual std::error_code visitCategoryRecord(unsigned ID, StringRef Name)
Visit a category. This associates the category ID to a Name.
virtual std::error_code visitFilenameRecord(unsigned ID, unsigned Size, unsigned Timestamp, StringRef Name)
Visit a filename. This associates the file&#39;s ID to a Name.
const std::error_category & SDErrorCategory()
virtual std::error_code visitEndOfDiagnostic()
Visit the end of a diagnostic block.
StringRef Text
Definition: Format.cpp:1603
virtual std::error_code visitDiagnosticRecord(unsigned Severity, const Location &Location, unsigned Category, unsigned Flag, StringRef Message)
Visit a diagnostic.