• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- DiagnosticNames.cpp - 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 "DiagnosticNames.h"
11 #include "clang/Basic/AllDiagnostics.h"
12 #include "llvm/ADT/STLExtras.h"
13 
14 using namespace clang;
15 using namespace diagtool;
16 
17 static const DiagnosticRecord BuiltinDiagnosticsByName[] = {
18 #define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
19 #include "clang/Basic/DiagnosticIndexName.inc"
20 #undef DIAG_NAME_INDEX
21 };
22 
getBuiltinDiagnosticsByName()23 llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
24   return llvm::makeArrayRef(BuiltinDiagnosticsByName);
25 }
26 
27 
28 // FIXME: Is it worth having two tables, especially when this one can get
29 // out of sync easily?
30 static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
31 #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,               \
32              SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY)            \
33   { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
34 #include "clang/Basic/DiagnosticCommonKinds.inc"
35 #include "clang/Basic/DiagnosticDriverKinds.inc"
36 #include "clang/Basic/DiagnosticFrontendKinds.inc"
37 #include "clang/Basic/DiagnosticSerializationKinds.inc"
38 #include "clang/Basic/DiagnosticLexKinds.inc"
39 #include "clang/Basic/DiagnosticParseKinds.inc"
40 #include "clang/Basic/DiagnosticASTKinds.inc"
41 #include "clang/Basic/DiagnosticCommentKinds.inc"
42 #include "clang/Basic/DiagnosticSemaKinds.inc"
43 #include "clang/Basic/DiagnosticAnalysisKinds.inc"
44 #undef DIAG
45 };
46 
orderByID(const DiagnosticRecord & Left,const DiagnosticRecord & Right)47 static bool orderByID(const DiagnosticRecord &Left,
48                       const DiagnosticRecord &Right) {
49   return Left.DiagID < Right.DiagID;
50 }
51 
getDiagnosticForID(short DiagID)52 const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
53   DiagnosticRecord Key = {nullptr, DiagID, 0};
54 
55   const DiagnosticRecord *Result =
56     std::lower_bound(std::begin(BuiltinDiagnosticsByID),
57                      std::end(BuiltinDiagnosticsByID),
58                      Key, orderByID);
59   assert(Result && "diagnostic not found; table may be out of date");
60   return *Result;
61 }
62 
63 
64 #define GET_DIAG_ARRAYS
65 #include "clang/Basic/DiagnosticGroups.inc"
66 #undef GET_DIAG_ARRAYS
67 
68 // Second the table of options, sorted by name for fast binary lookup.
69 static const GroupRecord OptionTable[] = {
70 #define GET_DIAG_TABLE
71 #include "clang/Basic/DiagnosticGroups.inc"
72 #undef GET_DIAG_TABLE
73 };
74 
getName() const75 llvm::StringRef GroupRecord::getName() const {
76   return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]);
77 }
78 
subgroup_begin() const79 GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
80   return DiagSubGroups + SubGroups;
81 }
82 
subgroup_end() const83 GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const {
84   return nullptr;
85 }
86 
diagnostics_begin() const87 GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
88   return DiagArrays + Members;
89 }
90 
diagnostics_end() const91 GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const {
92   return nullptr;
93 }
94 
getDiagnosticGroups()95 llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
96   return llvm::makeArrayRef(OptionTable);
97 }
98