1 //===- DiagnosticNames.h - Defines a table of all builtin diagnostics ------==//
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 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/DataTypes.h"
16 struct DiagnosticRecord {
21 llvm::StringRef getName() const {
22 return llvm::StringRef(NameStr, NameLen);
25 bool operator<(const DiagnosticRecord &Other) const {
26 return getName() < Other.getName();
30 /// \brief Get every diagnostic in the system, sorted by name.
31 llvm::ArrayRef<DiagnosticRecord> getBuiltinDiagnosticsByName();
33 /// \brief Get a diagnostic by its ID.
34 const DiagnosticRecord &getDiagnosticForID(short DiagID);
42 llvm::StringRef getName() const;
44 template<typename RecordType>
45 class group_iterator {
46 const short *CurrentID;
48 friend struct GroupRecord;
49 group_iterator(const short *Start) : CurrentID(Start) {
50 if (CurrentID && *CurrentID == -1)
55 typedef RecordType value_type;
56 typedef const value_type & reference;
57 typedef const value_type * pointer;
58 typedef std::forward_iterator_tag iterator_category;
59 typedef std::ptrdiff_t difference_type;
61 inline reference operator*() const;
62 inline pointer operator->() const {
66 inline short getID() const {
70 group_iterator &operator++() {
77 bool operator==(group_iterator &Other) const {
78 return CurrentID == Other.CurrentID;
81 bool operator!=(group_iterator &Other) const {
82 return CurrentID != Other.CurrentID;
86 typedef group_iterator<GroupRecord> subgroup_iterator;
87 subgroup_iterator subgroup_begin() const;
88 subgroup_iterator subgroup_end() const;
90 typedef group_iterator<DiagnosticRecord> diagnostics_iterator;
91 diagnostics_iterator diagnostics_begin() const;
92 diagnostics_iterator diagnostics_end() const;
94 bool operator<(llvm::StringRef Other) const {
95 return getName() < Other;
99 /// \brief Get every diagnostic group in the system, sorted by name.
100 llvm::ArrayRef<GroupRecord> getDiagnosticGroups();
103 inline GroupRecord::subgroup_iterator::reference
104 GroupRecord::subgroup_iterator::operator*() const {
105 return getDiagnosticGroups()[*CurrentID];
109 inline GroupRecord::diagnostics_iterator::reference
110 GroupRecord::diagnostics_iterator::operator*() const {
111 return getDiagnosticForID(*CurrentID);
113 } // end namespace diagtool