DiagnosticNames.h revision 354f20a8720732aa1745d1ff9595382cee324ee2
1//===- DiagnosticNames.h - Defines a table of all builtin diagnostics ------==//
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#include "llvm/ADT/ArrayRef.h"
11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/DataTypes.h"
13
14namespace diagtool {
15
16  struct DiagnosticRecord {
17    const char *NameStr;
18    short DiagID;
19    uint8_t NameLen;
20
21    llvm::StringRef getName() const {
22      return llvm::StringRef(NameStr, NameLen);
23    }
24
25    bool operator<(const DiagnosticRecord &Other) const {
26      return getName() < Other.getName();
27    }
28  };
29
30  /// \brief Get every diagnostic in the system, sorted by name.
31  llvm::ArrayRef<DiagnosticRecord> getBuiltinDiagnosticsByName();
32
33  /// \brief Get a diagnostic by its ID.
34  const DiagnosticRecord &getDiagnosticForID(short DiagID);
35
36
37  struct GroupRecord {
38    uint16_t NameOffset;
39    uint16_t Members;
40    uint16_t SubGroups;
41
42    llvm::StringRef getName() const;
43
44    template<typename RecordType>
45    class group_iterator {
46      const short *CurrentID;
47
48      friend struct GroupRecord;
49      group_iterator(const short *Start) : CurrentID(Start) {
50        if (CurrentID && *CurrentID == -1)
51          CurrentID = 0;
52      }
53
54    public:
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;
60
61      inline reference operator*() const;
62      inline pointer operator->() const {
63        return &operator*();
64      }
65
66      inline short getID() const {
67        return *CurrentID;
68      }
69
70      group_iterator &operator++() {
71        ++CurrentID;
72        if (*CurrentID == -1)
73          CurrentID = 0;
74        return *this;
75      }
76
77      bool operator==(group_iterator &Other) const {
78        return CurrentID == Other.CurrentID;
79      }
80
81      bool operator!=(group_iterator &Other) const {
82        return CurrentID != Other.CurrentID;
83      }
84    };
85
86    typedef group_iterator<GroupRecord> subgroup_iterator;
87    subgroup_iterator subgroup_begin() const;
88    subgroup_iterator subgroup_end() const;
89
90    typedef group_iterator<DiagnosticRecord> diagnostics_iterator;
91    diagnostics_iterator diagnostics_begin() const;
92    diagnostics_iterator diagnostics_end() const;
93
94    bool operator<(llvm::StringRef Other) const {
95      return getName() < Other;
96    }
97  };
98
99  /// \brief Get every diagnostic group in the system, sorted by name.
100  llvm::ArrayRef<GroupRecord> getDiagnosticGroups();
101
102  template<>
103  inline GroupRecord::subgroup_iterator::reference
104  GroupRecord::subgroup_iterator::operator*() const {
105    return getDiagnosticGroups()[*CurrentID];
106  }
107
108  template<>
109  inline GroupRecord::diagnostics_iterator::reference
110  GroupRecord::diagnostics_iterator::operator*() const {
111    return getDiagnosticForID(*CurrentID);
112  }
113} // end namespace diagtool
114
115