|
17 | 17 | #include "llvm/ADT/STLExtras.h"
|
18 | 18 | #include "llvm/ADT/SmallVector.h"
|
19 | 19 | #include "llvm/Support/ErrorHandling.h"
|
| 20 | +#include <cstring> |
20 | 21 | #include <map>
|
21 | 22 | #include <optional>
|
22 | 23 | using namespace clang;
|
@@ -389,9 +390,15 @@ namespace clang {
|
389 | 390 | // Common Diagnostic implementation
|
390 | 391 | //===----------------------------------------------------------------------===//
|
391 | 392 |
|
392 |
| -DiagnosticIDs::DiagnosticIDs() {} |
| 393 | +static std::locale locale(std::getenv("LANG")); |
| 394 | +DiagnosticIDs::DiagnosticIDs() |
| 395 | + : msg(std::use_facet<std::messages<char>>(locale)), |
| 396 | + msg_catalog(msg.open("clang", locale)) { |
| 397 | +} |
393 | 398 |
|
394 |
| -DiagnosticIDs::~DiagnosticIDs() {} |
| 399 | +DiagnosticIDs::~DiagnosticIDs() { |
| 400 | + msg.close(msg_catalog); |
| 401 | +} |
395 | 402 |
|
396 | 403 | /// getCustomDiagID - Return an ID for a diagnostic with the specified message
|
397 | 404 | /// and level. If this is the first request for this diagnostic, it is
|
@@ -447,11 +454,28 @@ bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
|
447 | 454 |
|
448 | 455 | /// getDescription - Given a diagnostic ID, return a description of the
|
449 | 456 | /// issue.
|
| 457 | +static std::map<unsigned, std::string> descriptions; |
450 | 458 | StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
|
| 459 | + StringRef ref; |
| 460 | + |
451 | 461 | if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
|
452 |
| - return Info->getDescription(); |
453 |
| - assert(CustomDiagInfo && "Invalid CustomDiagInfo"); |
454 |
| - return CustomDiagInfo->getDescription(DiagID); |
| 462 | + { |
| 463 | + ref = Info->getDescription(); |
| 464 | + } |
| 465 | + else |
| 466 | + { |
| 467 | + assert(CustomDiagInfo && "Invalid CustomDiagInfo"); |
| 468 | + ref = CustomDiagInfo->getDescription(DiagID); |
| 469 | + } |
| 470 | + |
| 471 | + if (descriptions.count(DiagID) == 0) { |
| 472 | + std::string s; |
| 473 | + s = msg.get(msg_catalog, 0, 0, ref.data()); |
| 474 | + descriptions[DiagID] = s; |
| 475 | + // std::strcpy(descriptions[DiagID], s.data()); |
| 476 | + // descriptions[DiagID] = ref.data(); |
| 477 | + } |
| 478 | + return StringRef(descriptions[DiagID]); |
455 | 479 | }
|
456 | 480 |
|
457 | 481 | static DiagnosticIDs::Level toLevel(diag::Severity SV) {
|
|
0 commit comments