dmt
(Dima Galimzianov)
1
I want to add an option to the compiler -print-diagnostic-groups which acts pretty much like the -debug-diagnostic-names but prints the name of the group instead of the diagID.
And I stumbled across a rather strange design of the -debug-diagnostic-names flag.
There're two places where code depends on printDiagnosticNames flag: DiagnosticEngine.cpp (DiagnosticEngine::diagnosticStringFor ) and LocalizationFormat.cpp (LocalizationProducer::getMessageOr ).
Each of them implement concatenation message + diagID , but slightly different. DiagnosticEngine computes the constexpr arrays debugDiagnosticStrings and diagnosticStrings . And LocalizationFormat concatenates the message and diagnosticNameStrings , and stores it in localizationSaver .
So now I need another option - printDiagnosticGroups , and for simplicity I'd rather have this logic in a single place - in DiagnosticEngine.
But before I start any refactoring, I want to check if this is appropriate. And why did the LocalizationProducer become responsible for handling the printDiagnosticNames flag in the first place?
dmt
(Dima Galimzianov)
3
I'm moving this concatenation to DiagnosticEngine::diagnosticStringFor. I'll publish a PR as soon as this one is merged, but basically here's what I'm doing:
llvm::StringRef DiagnosticEngine::diagnosticStringFor(const DiagID id,
bool printDiagnosticNames,
bool printDiagnosticGroups) {
llvm::StringRef message = diagnosticStrings[(unsigned)id];
if (auto producer = localization.get()) {
message = producer->getMessageOr(id, message);
}
if (printDiagnosticNames || printDiagnosticGroups) {
auto messageStr = message.str();
if (printDiagnosticNames) {
messageStr += " [";
messageStr += diagnosticIDStringFor(id).str();
messageStr += "]";
}
if (printDiagnosticGroups) {
auto groupID = storedDiagnosticInfos[(unsigned)id].groupID;
if (groupID != DiagGroupID::no_group) {
messageStr += " [group:";
messageStr += getDiagGroupInfoByID(groupID).name;
messageStr += "]";
}
}
message = DiagnosticStringsSaver.save(messageStr);
}
return message;
}
dmt
(Dima Galimzianov)
4
@xedin If you disagree or have better ideas, I'd be glad to hear them.