[Lldb-commits] [lldb] c327f99 - [lldb] Refactor deduction of the instance variable's name (NFC)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 21 15:22:13 PDT 2023
Author: Dave Lee
Date: 2023-03-21T15:22:07-07:00
New Revision: c327f9925428870e6288fa65bb709dcc3c0a0f31
URL: https://github.com/llvm/llvm-project/commit/c327f9925428870e6288fa65bb709dcc3c0a0f31
DIFF: https://github.com/llvm/llvm-project/commit/c327f9925428870e6288fa65bb709dcc3c0a0f31.diff
LOG: [lldb] Refactor deduction of the instance variable's name (NFC)
Move responsibility of providing the instance variable name (`this`, `self`) from
`TypeSystem` to `Language`.
`Language` the natural place for this, but also has downstream benefits. Some languages
have multiple `TypeSystem` implementations (ex Swift), and by placing this logic in the
`Language`, redundancy is avoided.
This change relies on the tests from D145348 and D146320.
Differential Revision: https://reviews.llvm.org/D146548
Added:
Modified:
lldb/include/lldb/Symbol/CompilerDeclContext.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/include/lldb/Target/Language.h
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerDeclContext.cpp
lldb/source/Symbol/SymbolContext.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Symbol/CompilerDeclContext.h b/lldb/include/lldb/Symbol/CompilerDeclContext.h
index 63e5f7b680e63..61a9c9c341bfe 100644
--- a/lldb/include/lldb/Symbol/CompilerDeclContext.h
+++ b/lldb/include/lldb/Symbol/CompilerDeclContext.h
@@ -69,14 +69,6 @@ class CompilerDeclContext {
/// Determines the original language of the decl context.
lldb::LanguageType GetLanguage();
- /// Determines the name of the instance variable for the this decl context.
- ///
- /// For C++ the name is "this", for Objective-C the name is "self".
- ///
- /// \return
- /// Returns a string for the name of the instance variable.
- ConstString GetInstanceVariableName(lldb::LanguageType language);
-
/// Check if the given other decl context is contained in the lookup
/// of this decl context (for example because the other context is a nested
/// inline namespace).
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index 0777d4d5ad6f3..a16f4af2be6d6 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -202,10 +202,6 @@ class TypeSystem : public PluginInterface,
// TypeSystems can support more than one language
virtual bool SupportsLanguage(lldb::LanguageType language) = 0;
- /// The name of the variable used for explicitly accessing data scoped to the
- /// current instance (or type). C++ uses "this", ObjC uses "self".
- virtual ConstString GetInstanceVariableName(lldb::LanguageType language) = 0;
-
// Type Completion
virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0;
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 8cc1e72e138a5..59ea17bcefb26 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -326,6 +326,8 @@ class Language : public PluginInterface {
return ConstString();
}
+ virtual ConstString GetInstanceVariableName() { return {}; }
+
protected:
// Classes that inherit from Language can see and modify these
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
index 809996497c11a..a3e78c39044aa 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
@@ -165,6 +165,8 @@ class CPlusPlusLanguage : public Language {
ConstString FindBestAlternateFunctionMangledName(
const Mangled mangled, const SymbolContext &sym_ctx) const override;
+ ConstString GetInstanceVariableName() override { return ConstString("this"); }
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
index b61348a3280ed..1344e97e469c6 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -155,6 +155,8 @@ class ObjCLanguage : public Language {
return false;
}
+ ConstString GetInstanceVariableName() override { return ConstString("self"); }
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
diff --git a/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h b/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
index 20184fd709d5c..5fb256db46481 100644
--- a/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
+++ b/lldb/source/Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h
@@ -40,6 +40,8 @@ class ObjCPlusPlusLanguage : public Language {
static lldb_private::Language *CreateInstance(lldb::LanguageType language);
+ ConstString GetInstanceVariableName() override { return ConstString("self"); }
+
static llvm::StringRef GetPluginNameStatic() { return "objcplusplus"; }
// PluginInterface protocol
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index a739494cffcc4..b661ec4453325 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3727,22 +3727,6 @@ bool TypeSystemClang::SupportsLanguage(lldb::LanguageType language) {
return TypeSystemClangSupportsLanguage(language);
}
-ConstString
-TypeSystemClang::GetInstanceVariableName(lldb::LanguageType language) {
- switch (language) {
- case LanguageType::eLanguageTypeC_plus_plus:
- case LanguageType::eLanguageTypeC_plus_plus_03:
- case LanguageType::eLanguageTypeC_plus_plus_11:
- case LanguageType::eLanguageTypeC_plus_plus_14:
- return ConstString("this");
- case LanguageType::eLanguageTypeObjC:
- case LanguageType::eLanguageTypeObjC_plus_plus:
- return ConstString("self");
- default:
- return {};
- }
-}
-
std::optional<std::string>
TypeSystemClang::GetCXXClassName(const CompilerType &type) {
if (!type)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index baddf6253beb4..414b51911cf89 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -711,8 +711,6 @@ class TypeSystemClang : public TypeSystem {
bool SupportsLanguage(lldb::LanguageType language) override;
- ConstString GetInstanceVariableName(lldb::LanguageType language) override;
-
static std::optional<std::string> GetCXXClassName(const CompilerType &type);
// Type Completion
diff --git a/lldb/source/Symbol/CompilerDeclContext.cpp b/lldb/source/Symbol/CompilerDeclContext.cpp
index 36b9131055f83..a188e60251f7c 100644
--- a/lldb/source/Symbol/CompilerDeclContext.cpp
+++ b/lldb/source/Symbol/CompilerDeclContext.cpp
@@ -46,13 +46,6 @@ lldb::LanguageType CompilerDeclContext::GetLanguage() {
return {};
}
-ConstString
-CompilerDeclContext::GetInstanceVariableName(lldb::LanguageType language) {
- if (IsValid())
- return m_type_system->GetInstanceVariableName(language);
- return {};
-}
-
bool CompilerDeclContext::IsContainedInLookup(CompilerDeclContext other) const {
if (!IsValid())
return false;
diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 5d4fb1cec6969..0a00802f064b9 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -19,10 +19,12 @@
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Symbol/Variable.h"
+#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
+#include "lldb/lldb-enumerations.h"
using namespace lldb;
using namespace lldb_private;
@@ -540,13 +542,17 @@ Block *SymbolContext::GetFunctionBlock() {
}
ConstString SymbolContext::GetInstanceVariableName() {
+ LanguageType lang_type = eLanguageTypeUnknown;
+
if (Block *function_block = GetFunctionBlock())
- if (CompilerDeclContext decl_ctx = function_block->GetDeclContext()) {
- auto language = decl_ctx.GetLanguage();
- if (language == eLanguageTypeUnknown)
- language = GetLanguage();
- return decl_ctx.GetInstanceVariableName(language);
- }
+ if (CompilerDeclContext decl_ctx = function_block->GetDeclContext())
+ lang_type = decl_ctx.GetLanguage();
+
+ if (lang_type == eLanguageTypeUnknown)
+ lang_type = GetLanguage();
+
+ if (auto *lang = Language::FindPlugin(lang_type))
+ return lang->GetInstanceVariableName();
return {};
}
More information about the lldb-commits
mailing list