1 //===- DiagnosticNames.h - Defines a table of all builtin diagnostics ------==//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H
10 #define LLVM_CLANG_TOOLS_DIAGTOOL_DIAGNOSTICNAMES_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/DataTypes.h"
18 struct DiagnosticRecord
{
23 llvm::StringRef
getName() const {
24 return llvm::StringRef(NameStr
, NameLen
);
27 bool operator<(const DiagnosticRecord
&Other
) const {
28 return getName() < Other
.getName();
32 /// Get every diagnostic in the system, sorted by name.
33 llvm::ArrayRef
<DiagnosticRecord
> getBuiltinDiagnosticsByName();
35 /// Get a diagnostic by its ID.
36 const DiagnosticRecord
&getDiagnosticForID(short DiagID
);
44 llvm::StringRef
getName() const;
46 template<typename RecordType
>
47 class group_iterator
{
48 const short *CurrentID
;
50 friend struct GroupRecord
;
51 group_iterator(const short *Start
) : CurrentID(Start
) {
52 if (CurrentID
&& *CurrentID
== -1)
57 typedef RecordType value_type
;
58 typedef const value_type
& reference
;
59 typedef const value_type
* pointer
;
60 typedef std::forward_iterator_tag iterator_category
;
61 typedef std::ptrdiff_t difference_type
;
63 inline reference
operator*() const;
64 inline pointer
operator->() const {
68 inline short getID() const {
72 group_iterator
&operator++() {
79 bool operator==(const group_iterator
&Other
) const {
80 return CurrentID
== Other
.CurrentID
;
83 bool operator!=(const group_iterator
&Other
) const {
84 return CurrentID
!= Other
.CurrentID
;
88 typedef group_iterator
<GroupRecord
> subgroup_iterator
;
89 subgroup_iterator
subgroup_begin() const;
90 subgroup_iterator
subgroup_end() const;
91 llvm::iterator_range
<subgroup_iterator
> subgroups() const;
93 typedef group_iterator
<DiagnosticRecord
> diagnostics_iterator
;
94 diagnostics_iterator
diagnostics_begin() const;
95 diagnostics_iterator
diagnostics_end() const;
96 llvm::iterator_range
<diagnostics_iterator
> diagnostics() const;
98 bool operator<(llvm::StringRef Other
) const {
99 return getName() < Other
;
103 /// Get every diagnostic group in the system, sorted by name.
104 llvm::ArrayRef
<GroupRecord
> getDiagnosticGroups();
107 inline GroupRecord::subgroup_iterator::reference
108 GroupRecord::subgroup_iterator::operator*() const {
109 return getDiagnosticGroups()[*CurrentID
];
113 inline GroupRecord::diagnostics_iterator::reference
114 GroupRecord::diagnostics_iterator::operator*() const {
115 return getDiagnosticForID(*CurrentID
);
117 } // end namespace diagtool