2222#include " swift/AST/DeclNameLoc.h"
2323#include " swift/AST/DiagnosticConsumer.h"
2424#include " swift/AST/TypeLoc.h"
25+ #include " swift/Basic/PrintDiagnosticNamesMode.h"
2526#include " swift/Basic/Statistic.h"
2627#include " swift/Basic/Version.h"
2728#include " swift/Basic/WarningAsErrorRule.h"
@@ -1065,6 +1066,13 @@ namespace swift {
10651066 // / diagnostic message.
10661067 std::unique_ptr<diag::LocalizationProducer> localization;
10671068
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+
10681076 // / The number of open diagnostic transactions. Diagnostics are only
10691077 // / emitted once all transactions have closed.
10701078 unsigned TransactionCount = 0 ;
@@ -1074,9 +1082,11 @@ namespace swift {
10741082 // / input being compiled.
10751083 // / May be invalid.
10761084 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;
10801090
10811091 // / Path to diagnostic documentation directory.
10821092 std::string diagnosticDocumentationPath = " " ;
@@ -1102,7 +1112,8 @@ namespace swift {
11021112 public:
11031113 explicit DiagnosticEngine (SourceManager &SourceMgr)
11041114 : SourceMgr(SourceMgr), ActiveDiagnostic(),
1105- TransactionStrings(TransactionAllocator) {}
1115+ TransactionStrings(TransactionAllocator),
1116+ DiagnosticStringsSaver(DiagnosticStringsAllocator) {}
11061117
11071118 // / hadAnyError - return true if any *error* diagnostics have been emitted.
11081119 bool hadAnyError () const { return state.hadAnyError (); }
@@ -1144,11 +1155,11 @@ namespace swift {
11441155 void setWarningsAsErrorsRules (const std::vector<WarningAsErrorRule> &rules);
11451156
11461157 // / Whether to print diagnostic names after their messages
1147- void setPrintDiagnosticNames ( bool val) {
1148- printDiagnosticNames = val;
1158+ void setPrintDiagnosticNamesMode (PrintDiagnosticNamesMode val) {
1159+ printDiagnosticNamesMode = val;
11491160 }
1150- bool getPrintDiagnosticNames () const {
1151- return printDiagnosticNames ;
1161+ PrintDiagnosticNamesMode getPrintDiagnosticNamesMode () const {
1162+ return printDiagnosticNamesMode ;
11521163 }
11531164
11541165 void setDiagnosticDocumentationPath (std::string path) {
@@ -1169,8 +1180,7 @@ namespace swift {
11691180 void setLocalization (StringRef locale, StringRef path) {
11701181 assert (!locale.empty ());
11711182 assert (!path.empty ());
1172- localization = diag::LocalizationProducer::producerFor (
1173- locale, path, getPrintDiagnosticNames ());
1183+ localization = diag::LocalizationProducer::producerFor (locale, path);
11741184 }
11751185
11761186 void ignoreDiagnostic (DiagID id) {
@@ -1426,8 +1436,9 @@ namespace swift {
14261436 public:
14271437 DiagnosticKind declaredDiagnosticKindFor (const DiagID id);
14281438
1429- llvm::StringRef diagnosticStringFor (const DiagID id,
1430- bool printDiagnosticNames);
1439+ llvm::StringRef
1440+ diagnosticStringFor (const DiagID id,
1441+ PrintDiagnosticNamesMode printDiagnosticNamesMode);
14311442
14321443 static llvm::StringRef diagnosticIDStringFor (const DiagID id);
14331444
0 commit comments