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 #ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H
11 #define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/DataTypes.h"
19 struct DiagnosticRecord {
24 llvm::StringRef getName() const {
25 return llvm::StringRef(NameStr, NameLen);
28 bool operator<(const DiagnosticRecord &Other) const {
29 return getName() < Other.getName();
33 /// \brief Get every diagnostic in the system, sorted by name.
34 llvm::ArrayRef<DiagnosticRecord> getBuiltinDiagnosticsByName();
36 /// \brief Get a diagnostic by its ID.
37 const DiagnosticRecord &getDiagnosticForID(short DiagID);
45 llvm::StringRef getName() const;
47 template<typename RecordType>
48 class group_iterator {
49 const short *CurrentID;
51 friend struct GroupRecord;
52 group_iterator(const short *Start) : CurrentID(Start) {
53 if (CurrentID && *CurrentID == -1)
58 typedef RecordType value_type;
59 typedef const value_type & reference;
60 typedef const value_type * pointer;
61 typedef std::forward_iterator_tag iterator_category;
62 typedef std::ptrdiff_t difference_type;
64 inline reference operator*() const;
65 inline pointer operator->() const {
69 inline short getID() const {
73 group_iterator &operator++() {
80 bool operator==(group_iterator &Other) const {
81 return CurrentID == Other.CurrentID;
84 bool operator!=(group_iterator &Other) const {
85 return CurrentID != Other.CurrentID;
89 typedef group_iterator<GroupRecord> subgroup_iterator;
90 subgroup_iterator subgroup_begin() const;
91 subgroup_iterator subgroup_end() const;
93 typedef group_iterator<DiagnosticRecord> diagnostics_iterator;
94 diagnostics_iterator diagnostics_begin() const;
95 diagnostics_iterator diagnostics_end() const;
97 bool operator<(llvm::StringRef Other) const {
98 return getName() < Other;
102 /// \brief Get every diagnostic group in the system, sorted by name.
103 llvm::ArrayRef<GroupRecord> getDiagnosticGroups();
106 inline GroupRecord::subgroup_iterator::reference
107 GroupRecord::subgroup_iterator::operator*() const {
108 return getDiagnosticGroups()[*CurrentID];
112 inline GroupRecord::diagnostics_iterator::reference
113 GroupRecord::diagnostics_iterator::operator*() const {
114 return getDiagnosticForID(*CurrentID);
116 } // end namespace diagtool