Skip to content

Commit 2c37244

Browse files
authored
[lldb][Language] Add Language::GetDisplayNameForLanguageType API (#161803)
The intention for this API is to be used when presenting language names to the user, e.g., in expression evaluation diagnostics or LLDB errors. Most uses of `GetNameForLanguageType` can be probably replaced with `GetDisplayNameForLanguageType`, but that's out of scope of this PR. This uses `llvm::dwarf::LanguageDescription` under the hood, so we would lose the version numbers in the names. If we deem those to be important, we could switch to an implementation that hardcodes a list of user-friendly names with version numbers included. The intention is to use it from #161688 Depends on #161804
1 parent 7f51a2a commit 2c37244

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lldb/include/lldb/Target/Language.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,15 @@ class Language : public PluginInterface {
404404
GetLanguageTypeFromString(const char *string) = delete;
405405
static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
406406

407+
/// Returns the internal LLDB name for the specified language. When presenting
408+
/// the language name to users, use \ref GetDisplayNameForLanguageType
409+
/// instead.
407410
static const char *GetNameForLanguageType(lldb::LanguageType language);
408411

412+
/// Returns a user-friendly name for the specified language.
413+
static llvm::StringRef
414+
GetDisplayNameForLanguageType(lldb::LanguageType language);
415+
409416
static void PrintAllLanguages(Stream &s, const char *prefix,
410417
const char *suffix);
411418

lldb/source/Target/Language.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ const char *Language::GetNameForLanguageType(LanguageType language) {
271271
return language_names[eLanguageTypeUnknown].name;
272272
}
273273

274+
llvm::StringRef Language::GetDisplayNameForLanguageType(LanguageType language) {
275+
return SourceLanguage(language).GetDescription();
276+
}
277+
274278
void Language::PrintSupportedLanguagesForExpressions(Stream &s,
275279
llvm::StringRef prefix,
276280
llvm::StringRef suffix) {

0 commit comments

Comments
 (0)