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 /// Get every diagnostic in the system, sorted by name.
34 llvm::ArrayRef<DiagnosticRecord> getBuiltinDiagnosticsByName();
36 /// 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;
92 llvm::iterator_range<subgroup_iterator> subgroups() const;
94 typedef group_iterator<DiagnosticRecord> diagnostics_iterator;
95 diagnostics_iterator diagnostics_begin() const;
96 diagnostics_iterator diagnostics_end() const;
97 llvm::iterator_range<diagnostics_iterator> diagnostics() const;
99 bool operator<(llvm::StringRef Other) const {
100 return getName() < Other;
104 /// Get every diagnostic group in the system, sorted by name.
105 llvm::ArrayRef<GroupRecord> getDiagnosticGroups();
108 inline GroupRecord::subgroup_iterator::reference
109 GroupRecord::subgroup_iterator::operator*() const {
110 return getDiagnosticGroups()[*CurrentID];
114 inline GroupRecord::diagnostics_iterator::reference
115 GroupRecord::diagnostics_iterator::operator*() const {
116 return getDiagnosticForID(*CurrentID);
118 } // end namespace diagtool