xref: /minix3/external/bsd/llvm/dist/clang/tools/diagtool/DiagnosticNames.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- DiagnosticNames.cpp - Defines a table of all builtin diagnostics ----==//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc #include "DiagnosticNames.h"
11f4a2713aSLionel Sambuc #include "clang/Basic/AllDiagnostics.h"
12f4a2713aSLionel Sambuc #include "llvm/ADT/STLExtras.h"
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc using namespace clang;
15f4a2713aSLionel Sambuc using namespace diagtool;
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc static const DiagnosticRecord BuiltinDiagnosticsByName[] = {
18f4a2713aSLionel Sambuc #define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
19f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticIndexName.inc"
20f4a2713aSLionel Sambuc #undef DIAG_NAME_INDEX
21f4a2713aSLionel Sambuc };
22f4a2713aSLionel Sambuc 
getBuiltinDiagnosticsByName()23f4a2713aSLionel Sambuc llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
24f4a2713aSLionel Sambuc   return llvm::makeArrayRef(BuiltinDiagnosticsByName);
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc 
28f4a2713aSLionel Sambuc // FIXME: Is it worth having two tables, especially when this one can get
29f4a2713aSLionel Sambuc // out of sync easily?
30f4a2713aSLionel Sambuc static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
31f4a2713aSLionel Sambuc #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,               \
32f4a2713aSLionel Sambuc              SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY)            \
33f4a2713aSLionel Sambuc   { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
34f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticCommonKinds.inc"
35f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticDriverKinds.inc"
36f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticFrontendKinds.inc"
37f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticSerializationKinds.inc"
38f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticLexKinds.inc"
39f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticParseKinds.inc"
40f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticASTKinds.inc"
41f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticCommentKinds.inc"
42f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticSemaKinds.inc"
43f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticAnalysisKinds.inc"
44f4a2713aSLionel Sambuc #undef DIAG
45f4a2713aSLionel Sambuc };
46f4a2713aSLionel Sambuc 
orderByID(const DiagnosticRecord & Left,const DiagnosticRecord & Right)47f4a2713aSLionel Sambuc static bool orderByID(const DiagnosticRecord &Left,
48f4a2713aSLionel Sambuc                       const DiagnosticRecord &Right) {
49f4a2713aSLionel Sambuc   return Left.DiagID < Right.DiagID;
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc 
getDiagnosticForID(short DiagID)52f4a2713aSLionel Sambuc const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
53*0a6a1f1dSLionel Sambuc   DiagnosticRecord Key = {nullptr, DiagID, 0};
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc   const DiagnosticRecord *Result =
56*0a6a1f1dSLionel Sambuc     std::lower_bound(std::begin(BuiltinDiagnosticsByID),
57*0a6a1f1dSLionel Sambuc                      std::end(BuiltinDiagnosticsByID),
58f4a2713aSLionel Sambuc                      Key, orderByID);
59f4a2713aSLionel Sambuc   assert(Result && "diagnostic not found; table may be out of date");
60f4a2713aSLionel Sambuc   return *Result;
61f4a2713aSLionel Sambuc }
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc #define GET_DIAG_ARRAYS
65f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticGroups.inc"
66f4a2713aSLionel Sambuc #undef GET_DIAG_ARRAYS
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc // Second the table of options, sorted by name for fast binary lookup.
69f4a2713aSLionel Sambuc static const GroupRecord OptionTable[] = {
70f4a2713aSLionel Sambuc #define GET_DIAG_TABLE
71f4a2713aSLionel Sambuc #include "clang/Basic/DiagnosticGroups.inc"
72f4a2713aSLionel Sambuc #undef GET_DIAG_TABLE
73f4a2713aSLionel Sambuc };
74f4a2713aSLionel Sambuc 
getName() const75f4a2713aSLionel Sambuc llvm::StringRef GroupRecord::getName() const {
76f4a2713aSLionel Sambuc   return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]);
77f4a2713aSLionel Sambuc }
78f4a2713aSLionel Sambuc 
subgroup_begin() const79f4a2713aSLionel Sambuc GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
80f4a2713aSLionel Sambuc   return DiagSubGroups + SubGroups;
81f4a2713aSLionel Sambuc }
82f4a2713aSLionel Sambuc 
subgroup_end() const83f4a2713aSLionel Sambuc GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const {
84*0a6a1f1dSLionel Sambuc   return nullptr;
85f4a2713aSLionel Sambuc }
86f4a2713aSLionel Sambuc 
diagnostics_begin() const87f4a2713aSLionel Sambuc GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
88f4a2713aSLionel Sambuc   return DiagArrays + Members;
89f4a2713aSLionel Sambuc }
90f4a2713aSLionel Sambuc 
diagnostics_end() const91f4a2713aSLionel Sambuc GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const {
92*0a6a1f1dSLionel Sambuc   return nullptr;
93f4a2713aSLionel Sambuc }
94f4a2713aSLionel Sambuc 
getDiagnosticGroups()95f4a2713aSLionel Sambuc llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
96f4a2713aSLionel Sambuc   return llvm::makeArrayRef(OptionTable);
97f4a2713aSLionel Sambuc }
98