clang  6.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_SERIALIZED_DIAGNOSTIC_READER_H_
11 #define LLVM_CLANG_FRONTEND_SERIALIZED_DIAGNOSTIC_READER_H_
12 
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/Bitcode/BitstreamReader.h"
15 #include "llvm/Support/ErrorOr.h"
16 
17 namespace clang {
18 namespace serialized_diags {
19 
20 enum class SDError {
21  CouldNotLoad = 1,
33  /// A generic error for subclass handlers that don't want or need to define
34  /// their own error_category.
36 };
37 
38 const std::error_category &SDErrorCategory();
39 
40 inline std::error_code make_error_code(SDError E) {
41  return std::error_code(static_cast<int>(E), SDErrorCategory());
42 }
43 
44 /// \brief A location that is represented in the serialized diagnostics.
45 struct Location {
46  unsigned FileID;
47  unsigned Line;
48  unsigned Col;
49  unsigned Offset;
50  Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
51  : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
52 };
53 
54 /// \brief A base class that handles reading serialized diagnostics from a file.
55 ///
56 /// Subclasses should override the visit* methods with their logic for handling
57 /// the various constructs that are found in serialized diagnostics.
59 public:
62 
63  /// \brief Read the diagnostics in \c File
64  std::error_code readDiagnostics(StringRef File);
65 
66 private:
67  enum class Cursor;
68 
69  /// \brief Read to the next record or block to process.
70  llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
71  unsigned &BlockOrRecordId);
72 
73  /// \brief Read a metadata block from \c Stream.
74  std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
75 
76  /// \brief Read a diagnostic block from \c Stream.
77  std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
78 
79 protected:
80  /// \brief Visit the start of a diagnostic block.
81  virtual std::error_code visitStartOfDiagnostic() {
82  return std::error_code();
83  }
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();
89  }
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();
93  }
94  /// \brief Visit a diagnostic.
95  virtual std::error_code
97  unsigned Category, unsigned Flag, StringRef Message) {
98  return std::error_code();
99  }
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,
102  unsigned Timestamp,
103  StringRef Name) {
104  return std::error_code();
105  }
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();
110  }
111  /// \brief Visit a source range.
112  virtual std::error_code visitSourceRangeRecord(const Location &Start,
113  const Location &End) {
114  return std::error_code();
115  }
116  /// \brief Visit the version of the set of diagnostics.
117  virtual std::error_code visitVersionRecord(unsigned Version) {
118  return std::error_code();
119  }
120 };
121 
122 } // end serialized_diags namespace
123 } // end clang namespace
124 
125 namespace std {
126 template <>
127 struct is_error_code_enum<clang::serialized_diags::SDError> : std::true_type {};
128 }
129 
130 #endif
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:1900
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:1348
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:1346
virtual std::error_code visitDiagnosticRecord(unsigned Severity, const Location &Location, unsigned Category, unsigned Flag, StringRef Message)
Visit a diagnostic.