22
22
#include " swift/AST/DeclNameLoc.h"
23
23
#include " swift/AST/DiagnosticConsumer.h"
24
24
#include " swift/AST/TypeLoc.h"
25
+ #include " swift/Basic/PrintDiagnosticNamesMode.h"
25
26
#include " swift/Basic/Statistic.h"
26
27
#include " swift/Basic/Version.h"
27
28
#include " swift/Basic/WarningAsErrorRule.h"
@@ -1065,6 +1066,13 @@ namespace swift {
1065
1066
// / diagnostic message.
1066
1067
std::unique_ptr<diag::LocalizationProducer> localization;
1067
1068
1069
+ // / This allocator will retain diagnostic strings containing the
1070
+ // / diagnostic's message and identifier as `message [id]` for the duration
1071
+ // / of compiler invocation. This will be used when the frontend flags
1072
+ // / `-debug-diagnostic-names` or `-print-diagnostic-groups` are used.
1073
+ llvm::BumpPtrAllocator DiagnosticStringsAllocator;
1074
+ llvm::StringSaver DiagnosticStringsSaver;
1075
+
1068
1076
// / The number of open diagnostic transactions. Diagnostics are only
1069
1077
// / emitted once all transactions have closed.
1070
1078
unsigned TransactionCount = 0 ;
@@ -1074,9 +1082,11 @@ namespace swift {
1074
1082
// / input being compiled.
1075
1083
// / May be invalid.
1076
1084
SourceLoc bufferIndirectlyCausingDiagnostic;
1077
-
1078
- // / Print diagnostic names after their messages
1079
- bool printDiagnosticNames = false ;
1085
+
1086
+ // / When printing diagnostics, include either the diagnostic name
1087
+ // / (diag::whatever) at the end or the associated diagnostic group.
1088
+ PrintDiagnosticNamesMode printDiagnosticNamesMode =
1089
+ PrintDiagnosticNamesMode::None;
1080
1090
1081
1091
// / Path to diagnostic documentation directory.
1082
1092
std::string diagnosticDocumentationPath = " " ;
@@ -1102,7 +1112,8 @@ namespace swift {
1102
1112
public:
1103
1113
explicit DiagnosticEngine (SourceManager &SourceMgr)
1104
1114
: SourceMgr(SourceMgr), ActiveDiagnostic(),
1105
- TransactionStrings(TransactionAllocator) {}
1115
+ TransactionStrings(TransactionAllocator),
1116
+ DiagnosticStringsSaver(DiagnosticStringsAllocator) {}
1106
1117
1107
1118
// / hadAnyError - return true if any *error* diagnostics have been emitted.
1108
1119
bool hadAnyError () const { return state.hadAnyError (); }
@@ -1144,11 +1155,11 @@ namespace swift {
1144
1155
void setWarningsAsErrorsRules (const std::vector<WarningAsErrorRule> &rules);
1145
1156
1146
1157
// / Whether to print diagnostic names after their messages
1147
- void setPrintDiagnosticNames ( bool val) {
1148
- printDiagnosticNames = val;
1158
+ void setPrintDiagnosticNamesMode (PrintDiagnosticNamesMode val) {
1159
+ printDiagnosticNamesMode = val;
1149
1160
}
1150
- bool getPrintDiagnosticNames () const {
1151
- return printDiagnosticNames ;
1161
+ PrintDiagnosticNamesMode getPrintDiagnosticNamesMode () const {
1162
+ return printDiagnosticNamesMode ;
1152
1163
}
1153
1164
1154
1165
void setDiagnosticDocumentationPath (std::string path) {
@@ -1169,8 +1180,7 @@ namespace swift {
1169
1180
void setLocalization (StringRef locale, StringRef path) {
1170
1181
assert (!locale.empty ());
1171
1182
assert (!path.empty ());
1172
- localization = diag::LocalizationProducer::producerFor (
1173
- locale, path, getPrintDiagnosticNames ());
1183
+ localization = diag::LocalizationProducer::producerFor (locale, path);
1174
1184
}
1175
1185
1176
1186
void ignoreDiagnostic (DiagID id) {
@@ -1426,8 +1436,9 @@ namespace swift {
1426
1436
public:
1427
1437
DiagnosticKind declaredDiagnosticKindFor (const DiagID id);
1428
1438
1429
- llvm::StringRef diagnosticStringFor (const DiagID id,
1430
- bool printDiagnosticNames);
1439
+ llvm::StringRef
1440
+ diagnosticStringFor (const DiagID id,
1441
+ PrintDiagnosticNamesMode printDiagnosticNamesMode);
1431
1442
1432
1443
static llvm::StringRef diagnosticIDStringFor (const DiagID id);
1433
1444
0 commit comments