bulbazord created this revision. bulbazord added a reviewer: teemperor. bulbazord requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
There are several instances where one may want to ask questions about the name of a method/function/whatever. Classes like CPlusPlusLanguage::MethodName and ObjCLanguage::MethodName fulfill this purpose right now, but users of these have to have knowledge on these classes (from plugins) to function. I propose a new class `Language::MethodNameInfo` to abstract this away so that lldb's Core libraries can ask questions about a method name without knowing the details of a plugin. Currently the class only has one method to override, `GetSelector`, but I imagine it will have more in the future. I only added the one method needed to replace the use of `ObjCLanguage` in Symtab. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D103210 Files: lldb/include/lldb/Target/Language.h lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp lldb/source/Plugins/Language/ObjC/ObjCLanguage.h lldb/source/Symbol/Symtab.cpp lldb/source/Target/Language.cpp
Index: lldb/source/Target/Language.cpp =================================================================== --- lldb/source/Target/Language.cpp +++ lldb/source/Target/Language.cpp @@ -356,6 +356,11 @@ return PluginManager::GetREPLAllTypeSystemSupportedLanguages(); } +std::unique_ptr<Language::MethodNameInfo> +Language::GetMethodNameInfo(llvm::StringRef name) { + return nullptr; +} + std::unique_ptr<Language::TypeScavenger> Language::GetTypeScavenger() { return nullptr; } Index: lldb/source/Symbol/Symtab.cpp =================================================================== --- lldb/source/Symbol/Symtab.cpp +++ lldb/source/Symbol/Symtab.cpp @@ -9,8 +9,6 @@ #include <map> #include <set> -#include "Plugins/Language/ObjC/ObjCLanguage.h" - #include "lldb/Core/Module.h" #include "lldb/Core/RichManglingContext.h" #include "lldb/Core/Section.h" @@ -18,6 +16,7 @@ #include "lldb/Symbol/Symbol.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/Symtab.h" +#include "lldb/Target/Language.h" #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/Timer.h" @@ -311,13 +310,16 @@ // If the demangled name turns out to be an ObjC name, and is a category // name, add the version without categories to the index too. - ObjCLanguage::MethodName objc_method(name.GetStringRef(), true); - if (objc_method.IsValid(true)) { - m_selector_to_index.Append(objc_method.GetSelector(), value); - - if (ConstString objc_method_no_category = - objc_method.GetFullNameWithoutCategory(true)) - m_name_to_index.Append(objc_method_no_category, value); + if (auto *objc_lang = Language::FindPlugin(lldb::eLanguageTypeObjC)) { + if (std::unique_ptr<Language::MethodNameInfo> method_name_info = + objc_lang->GetMethodNameInfo(name.GetStringRef())) { + m_selector_to_index.Append( + method_name_info->GetSelector().getValue(), value); + for (ConstString objc_method_variant : + objc_lang->GetMethodNameVariants(name)) { + m_name_to_index.Append(objc_method_variant, value); + } + } } } } Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.h =================================================================== --- lldb/source/Plugins/Language/ObjC/ObjCLanguage.h +++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.h @@ -85,6 +85,18 @@ bool m_category_is_valid; }; + class ObjCMethodNameInfo : public Language::MethodNameInfo { + ObjCLanguage::MethodName m_method_name; + + public: + ObjCMethodNameInfo(llvm::StringRef name) : m_method_name(name, true) {} + + bool IsValid() { return m_method_name.IsValid(true); } + llvm::Optional<ConstString> GetSelector() override { + return m_method_name.GetSelector(); + } + }; + ObjCLanguage() = default; ~ObjCLanguage() override = default; @@ -111,6 +123,9 @@ GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) override; + std::unique_ptr<Language::MethodNameInfo> + GetMethodNameInfo(llvm::StringRef name) override; + std::unique_ptr<TypeScavenger> GetTypeScavenger() override; bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint, Index: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp =================================================================== --- lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp +++ lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp @@ -935,6 +935,16 @@ return result; } +std::unique_ptr<Language::MethodNameInfo> +ObjCLanguage::GetMethodNameInfo(llvm::StringRef name) { + if (auto ret = std::make_unique<ObjCMethodNameInfo>(name)) { + if (ret->IsValid()) { + return ret; + } + } + return nullptr; +} + std::unique_ptr<Language::TypeScavenger> ObjCLanguage::GetTypeScavenger() { class ObjCScavengerResult : public Language::TypeScavenger::Result { public: Index: lldb/include/lldb/Target/Language.h =================================================================== --- lldb/include/lldb/Target/Language.h +++ lldb/include/lldb/Target/Language.h @@ -28,6 +28,12 @@ class Language : public PluginInterface { public: + class MethodNameInfo { + public: + virtual llvm::Optional<ConstString> GetSelector() = 0; + virtual ~MethodNameInfo() = default; + }; + class TypeScavenger { public: class Result { @@ -180,6 +186,9 @@ GetPossibleFormattersMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic); + virtual std::unique_ptr<MethodNameInfo> + GetMethodNameInfo(llvm::StringRef name); + virtual std::unique_ptr<TypeScavenger> GetTypeScavenger(); virtual const char *GetLanguageSpecificTypeLookupHelp();
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits