Skip to content

Commit e7086d1

Browse files
authored
Merge pull request #33502 from HassanElDesouky/localization-refactor-DE
[Diag] Refactor `diagnosticStringFor` to return StringRef
2 parents 4c684d7 + 4a429d0 commit e7086d1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/DiagnosticConsumer.h"
2323
#include "swift/AST/LocalizationFormat.h"
2424
#include "swift/AST/TypeLoc.h"
25+
#include "llvm/ADT/StringRef.h"
2526
#include "llvm/ADT/StringSet.h"
2627
#include "llvm/Support/Allocator.h"
2728
#include "llvm/Support/FileSystem.h"
@@ -987,7 +988,8 @@ namespace swift {
987988
void emitTentativeDiagnostics();
988989

989990
public:
990-
const char *diagnosticStringFor(const DiagID id, bool printDiagnosticName);
991+
llvm::StringRef diagnosticStringFor(const DiagID id,
992+
bool printDiagnosticName);
991993

992994
/// If there is no clear .dia file for a diagnostic, put it in the one
993995
/// corresponding to the SourceLoc given here.

lib/AST/DiagnosticEngine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,9 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
10101010
emitDiagnostic(childNote);
10111011
}
10121012

1013-
const char *DiagnosticEngine::diagnosticStringFor(const DiagID id,
1014-
bool printDiagnosticName) {
1013+
llvm::StringRef
1014+
DiagnosticEngine::diagnosticStringFor(const DiagID id,
1015+
bool printDiagnosticName) {
10151016
// TODO: Print diagnostic names from `localization`.
10161017
if (printDiagnosticName) {
10171018
return debugDiagnosticStrings[(unsigned)id];
@@ -1020,7 +1021,7 @@ const char *DiagnosticEngine::diagnosticStringFor(const DiagID id,
10201021
if (localization) {
10211022
auto localizedMessage =
10221023
localization.get()->getMessageOr(id, defaultMessage);
1023-
return localizedMessage.data();
1024+
return localizedMessage;
10241025
}
10251026
return defaultMessage;
10261027
}

0 commit comments

Comments
 (0)