blob: a08da89577f1b62539e386d6939b3a558de98491 [file] [log] [blame]
Jordan Rose2fe20dc2012-06-04 16:57:50 +00001//===- 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"
Jordan Rose473e8772012-06-24 00:07:45 +000012#include "llvm/ADT/STLExtras.h"
Jordan Rose2fe20dc2012-06-04 16:57:50 +000013
14using namespace clang;
Jordan Rose473e8772012-06-24 00:07:45 +000015using namespace diagtool;
Jordan Rose2fe20dc2012-06-04 16:57:50 +000016
Jordan Rose473e8772012-06-24 00:07:45 +000017static const DiagnosticRecord BuiltinDiagnosticsByName[] = {
Jordan Rose2fe20dc2012-06-04 16:57:50 +000018#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) },
19#include "clang/Basic/DiagnosticIndexName.inc"
20#undef DIAG_NAME_INDEX
Jordan Rose2fe20dc2012-06-04 16:57:50 +000021};
22
Jordan Rose473e8772012-06-24 00:07:45 +000023llvm::ArrayRef<DiagnosticRecord> diagtool::getBuiltinDiagnosticsByName() {
Jordan Rose21e22db2012-06-24 00:27:36 +000024 return llvm::makeArrayRef(BuiltinDiagnosticsByName);
Jordan Rose473e8772012-06-24 00:07:45 +000025}
Jordan Rose2fe20dc2012-06-04 16:57:50 +000026
Jordan Rose473e8772012-06-24 00:07:45 +000027
28// FIXME: Is it worth having two tables, especially when this one can get
29// out of sync easily?
30static const DiagnosticRecord BuiltinDiagnosticsByID[] = {
31#define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP, \
Richard Smith16e1b072013-11-12 02:41:45 +000032 SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) \
Jordan Rose473e8772012-06-24 00:07:45 +000033 { #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"
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"
44#undef DIAG
45};
46
47static bool orderByID(const DiagnosticRecord &Left,
48 const DiagnosticRecord &Right) {
49 return Left.DiagID < Right.DiagID;
50}
51
52const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
Craig Topper69186e72014-06-08 08:38:04 +000053 DiagnosticRecord Key = {nullptr, DiagID, 0};
Jordan Rose473e8772012-06-24 00:07:45 +000054
55 const DiagnosticRecord *Result =
Benjamin Kramer5c323b82014-04-12 15:42:48 +000056 std::lower_bound(std::begin(BuiltinDiagnosticsByID),
57 std::end(BuiltinDiagnosticsByID),
Jordan Rose473e8772012-06-24 00:07:45 +000058 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.
69static const GroupRecord OptionTable[] = {
70#define GET_DIAG_TABLE
71#include "clang/Basic/DiagnosticGroups.inc"
72#undef GET_DIAG_TABLE
73};
74
Craig Topperda7cf8a2013-08-29 05:18:04 +000075llvm::StringRef GroupRecord::getName() const {
76 return StringRef(DiagGroupNames + NameOffset + 1, DiagGroupNames[NameOffset]);
77}
78
Craig Topperd80c17e2013-08-28 04:02:50 +000079GroupRecord::subgroup_iterator GroupRecord::subgroup_begin() const {
80 return DiagSubGroups + SubGroups;
81}
82
83GroupRecord::subgroup_iterator GroupRecord::subgroup_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000084 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +000085}
86
87GroupRecord::diagnostics_iterator GroupRecord::diagnostics_begin() const {
88 return DiagArrays + Members;
89}
90
91GroupRecord::diagnostics_iterator GroupRecord::diagnostics_end() const {
Craig Topper69186e72014-06-08 08:38:04 +000092 return nullptr;
Craig Topperd80c17e2013-08-28 04:02:50 +000093}
94
Jordan Rose473e8772012-06-24 00:07:45 +000095llvm::ArrayRef<GroupRecord> diagtool::getDiagnosticGroups() {
Jordan Rose21e22db2012-06-24 00:27:36 +000096 return llvm::makeArrayRef(OptionTable);
Jordan Rose473e8772012-06-24 00:07:45 +000097}