clang  3.7.0
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/ADT/ArrayRef.h"
15 #include "llvm/Bitcode/BitstreamReader.h"
16 #include "llvm/Support/ErrorOr.h"
17 
18 namespace clang {
19 namespace serialized_diags {
20 
21 enum class SDError {
22  CouldNotLoad = 1,
34  /// A generic error for subclass handlers that don't want or need to define
35  /// their own error_category.
37 };
38 
39 const std::error_category &SDErrorCategory();
40 
41 inline std::error_code make_error_code(SDError E) {
42  return std::error_code(static_cast<int>(E), SDErrorCategory());
43 }
44 
45 /// \brief A location that is represented in the serialized diagnostics.
46 struct Location {
47  unsigned FileID;
48  unsigned Line;
49  unsigned Col;
50  unsigned Offset;
51  Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
52  : FileID(FileID), Line(Line), Col(Col), Offset(Offset) {}
53 };
54 
55 /// \brief A base class that handles reading serialized diagnostics from a file.
56 ///
57 /// Subclasses should override the visit* methods with their logic for handling
58 /// the various constructs that are found in serialized diagnostics.
60 public:
63 
64  /// \brief Read the diagnostics in \c File
65  std::error_code readDiagnostics(StringRef File);
66 
67 private:
68  enum class Cursor;
69 
70  /// \brief Read to the next record or block to process.
71  llvm::ErrorOr<Cursor> skipUntilRecordOrBlock(llvm::BitstreamCursor &Stream,
72  unsigned &BlockOrRecordId);
73 
74  /// \brief Read a metadata block from \c Stream.
75  std::error_code readMetaBlock(llvm::BitstreamCursor &Stream);
76 
77  /// \brief Read a diagnostic block from \c Stream.
78  std::error_code readDiagnosticBlock(llvm::BitstreamCursor &Stream);
79 
80 protected:
81  /// \brief Visit the start of a diagnostic block.
82  virtual std::error_code visitStartOfDiagnostic() {
83  return std::error_code();
84  };
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();
90  };
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();
94  };
95  /// \brief Visit a diagnostic.
96  virtual std::error_code
98  unsigned Category, unsigned Flag, StringRef Message) {
99  return std::error_code();
100  };
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,
103  unsigned Timestamp,
104  StringRef Name) {
105  return std::error_code();
106  };
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();
111  };
112  /// \brief Visit a source range.
113  virtual std::error_code visitSourceRangeRecord(const Location &Start,
114  const Location &End) {
115  return std::error_code();
116  };
117  /// \brief Visit the version of the set of diagnostics.
118  virtual std::error_code visitVersionRecord(unsigned Version) {
119  return std::error_code();
120  };
121 };
122 
123 } // end serialized_diags namespace
124 } // end clang namespace
125 
126 namespace std {
127 template <>
128 struct is_error_code_enum<clang::serialized_diags::SDError> : std::true_type {};
129 }
130 
131 #endif
std::error_code make_error_code(SDError E)
virtual std::error_code visitStartOfDiagnostic()
Visit the start of a diagnostic block.
Location(unsigned FileID, unsigned Line, unsigned Col, unsigned Offset)
virtual std::error_code visitSourceRangeRecord(const Location &Start, const Location &End)
Visit a source range.
uint32_t Offset
Definition: CacheTokens.cpp:43
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::error_code readDiagnostics(StringRef File)
Read the diagnostics in File.
const SmallVectorImpl< AnnotatedLine * >::const_iterator End
ID
Defines the set of possible language-specific address spaces.
Definition: AddressSpaces.h:27
virtual std::error_code visitDiagFlagRecord(unsigned ID, StringRef Name)
Visit a flag. This associates the flag's ID to a Name.
virtual std::error_code visitVersionRecord(unsigned Version)
Visit the version of the set of diagnostics.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
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's ID to a Name.
const std::error_category & SDErrorCategory()
virtual std::error_code visitEndOfDiagnostic()
Visit the end of a diagnostic block.
virtual std::error_code visitDiagnosticRecord(unsigned Severity, const Location &Location, unsigned Category, unsigned Flag, StringRef Message)
Visit a diagnostic.