Skip to content

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Oct 3, 2025

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

@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/161803.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Target/Language.h (+7)
  • (modified) lldb/source/Target/Language.cpp (+4)
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 3d0aa326d5a6d..48a7ac2cea42f 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -404,8 +404,15 @@ class Language : public PluginInterface {
   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);
 
diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index 484d9badde397..f0fc48e18793b 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -270,6 +270,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) {

@Michael137 Michael137 force-pushed the lldb/language-display-name-api branch from 7020913 to b728905 Compare October 3, 2025 08:40
@Michael137 Michael137 changed the title [lldb][Lanugage] Add Language::GetDisplayNameForLanguageType API [lldb][Language] Add Language::GetDisplayNameForLanguageType API Oct 3, 2025
@Michael137 Michael137 enabled auto-merge (squash) October 3, 2025 22:16
@Michael137 Michael137 disabled auto-merge October 3, 2025 22:16
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.
@Michael137 Michael137 force-pushed the lldb/language-display-name-api branch from bc9045d to 2fddcf3 Compare October 3, 2025 22:18
@Michael137 Michael137 enabled auto-merge (squash) October 3, 2025 22:18
@Michael137 Michael137 merged commit 2c37244 into llvm:main Oct 3, 2025
9 checks passed
@Michael137 Michael137 deleted the lldb/language-display-name-api branch October 3, 2025 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants