blob: cc7385a11a45cd20e182ac1b64267a2cbc6e3aa7 [file] [log] [blame]
Jordan Rose2fe20dc2012-06-04 16:57:50 +00001//===- DiagnosticNames.cpp - Defines a table of all builtin diagnostics ----==//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Jordan Rose2fe20dc2012-06-04 16:57:50 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "DiagnosticNames.h"
10#include "clang/Basic/AllDiagnostics.h"
Jordan Rose473e8772012-06-24 00:07:45 +000011#include "llvm/ADT/STLExtras.h"
Jordan Rose2fe20dc2012-06-04 16:57:50 +000012
13using namespace clang;
Jordan Rose473e8772012-06-24 00:07:45 +000014using namespace diagtool;
Jordan Rose2fe20dc2012-06-04 16:57:50 +000015
Jordan Rose473e8772012-06-24 00:07:45 +000016static const DiagnosticRecord BuiltinDiagnosticsByName[] = {
Jordan Rose2fe20dc2012-06-04 16:57:50 +000017#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
18#include "clang/Basic/DiagnosticIndexName.inc"
19#undef DIAG_NAME_INDEX
Jordan Rose2fe20dc2012-06-04 16:57:50 +000020};
21
Jordan Rose473e8772012-06-24 00:07:45 +000022llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
Jordan Rose21e22db2012-06-24 00:27:36 +000023 return llvm::makeArrayRef(BuiltinDiagnosticsByName);
Jordan Rose473e8772012-06-24 00:07:45 +000024}
Jordan Rose2fe20dc2012-06-04 16:57:50 +000025
Jordan Rose473e8772012-06-24 00:07:45 +000026
27// FIXME: Is it worth having two tables, especially when this one can get
28// out of sync easily?
29static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
30#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Richard Smith16e1b072013-11-12 02:41:45 +000031 SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \
Jordan Rose473e8772012-06-24 00:07:45 +000032 { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
33#include "clang/Basic/DiagnosticCommonKinds.inc"
Gabor Horvathe350b0a2017-09-22 11:11:01 +000034#include "clang/Basic/DiagnosticCrossTUKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000035#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"
Dmitri Gribenkof26054f2012-07-11 21:38:39 +000041#include "clang/Basic/DiagnosticCommentKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000042#include "clang/Basic/DiagnosticSemaKinds.inc"
43#include "clang/Basic/DiagnosticAnalysisKinds.inc"
Alex Lorenzf5ca27c2017-10-16 18:28:26 +000044#include "clang/Basic/DiagnosticRefactoringKinds.inc"
Jordan Rose473e8772012-06-24 00:07:45 +000045#undef DIAG
46};
47
48static bool orderByID(const DiagnosticRecord &Left,
49 const DiagnosticRecord &Right) {
50 return Left.DiagID < Right.DiagID;
51}
52
53const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
Craig Topper69186e72014-06-08 08:38:04 +000054 DiagnosticRecord Key = {nullptr, DiagID, 0};
Jordan Rose473e8772012-06-24 00:07:45 +000055
56 const DiagnosticRecord *Result =
Benjamin Kramer5c323b82014-04-12 15:42:48 +000057 std::lower_bound(std::begin(BuiltinDiagnosticsByID),
58 std::end(BuiltinDiagnosticsByID),
Jordan Rose473e8772012-06-24 00:07:45 +000059 Key, orderByID);
60 assert(Result && "diagnostic not found; table may be out of date");
61 return *Result;
62}
63
64
65#define GET_DIAG_ARRAYS
66#include "clang/Basic/DiagnosticGroups.inc"
67#undef GET_DIAG_ARRAYS
68
69// Second the table of options, sorted by name for fast binary lookup.
70static const GroupRecord OptionTable[] = {
71#define GET_DIAG_TABLE
72#include "clang/Basic/DiagnosticGroups.inc"
73#undef GET_DIAG_TABLE
74};
75
Craig Topperda7cf8a2013-08-29 05:18:04 +000076llvm::StringRef GroupRecord::getName() const {
77 return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]);
78}
79
Craig Topperd80c17e2013-08-28 04:02:50 +000080GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
81 return DiagSubGroups + SubGroups;
82}
83
84GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000085 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +000086}
87
Jonas Devliegheree4563d12017-09-05 18:04:34 +000088llvm::iterator_range<diagtool::GroupRecord::subgroup_iterator>
89GroupRecord::subgroups() const {
90 return llvm::make_range(subgroup_begin(), subgroup_end());
91}
92
Craig Topperd80c17e2013-08-28 04:02:50 +000093GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
94 return DiagArrays + Members;
95}
96
97GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000098 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +000099}
100
Jonas Devliegheree4563d12017-09-05 18:04:34 +0000101llvm::iterator_range<diagtool::GroupRecord::diagnostics_iterator>
102GroupRecord::diagnostics() const {
103 return llvm::make_range(diagnostics_begin(), diagnostics_end());
104}
105
Jordan Rose473e8772012-06-24 00:07:45 +0000106llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
Jordan Rose21e22db2012-06-24 00:27:36 +0000107 return llvm::makeArrayRef(OptionTable);
Jordan Rose473e8772012-06-24 00:07:45 +0000108}