[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
https://github.com/llvm/llvm-project/pull/161688

Depends on https://github.com/llvm/llvm-project/pull/161804
This commit is contained in:
Michael Buch 2025-10-03 23:23:08 +01:00 committed by GitHub
parent 7f51a2a47d
commit 2c3724419c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -404,8 +404,15 @@ public:
GetLanguageTypeFromString(const char *string) = delete;
static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
/// Returns the internal LLDB name for the specified language. When presenting
/// the language name to users, use \ref GetDisplayNameForLanguageType
/// instead.
static const char *GetNameForLanguageType(lldb::LanguageType language);
/// Returns a user-friendly name for the specified language.
static llvm::StringRef
GetDisplayNameForLanguageType(lldb::LanguageType language);
static void PrintAllLanguages(Stream &s, const char *prefix,
const char *suffix);

View File

@ -271,6 +271,10 @@ const char *Language::GetNameForLanguageType(LanguageType language) {
return language_names[eLanguageTypeUnknown].name;
}
llvm::StringRef Language::GetDisplayNameForLanguageType(LanguageType language) {
return SourceLanguage(language).GetDescription();
}
void Language::PrintSupportedLanguagesForExpressions(Stream &s,
llvm::StringRef prefix,
llvm::StringRef suffix) {