Extend FindTypes with CompilerContext to allow filtering by language.
This patch is also motivated by the Swift branch and is effectively NFC for the single-TypeSystem llvm.org branch.
In multi-language projects it is extremely common to have, e.g., a
Clang type and a similarly-named rendition of that same type in
another language. When searching for a type It is much cheaper to pass
a set of supported languages to the SymbolFile than having it
materialize every result and then rejecting the materialized types
that have the wrong language.
Differential Revision: https://reviews.llvm.org/D66546
<rdar://problem/54471165>
llvm-svn: 369690
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index e0026e3..80b64fb 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -2083,12 +2083,11 @@
#pragma mark TypeSystem
struct TypeSystemInstance {
- TypeSystemInstance() : name(), description(), create_callback(nullptr) {}
-
ConstString name;
std::string description;
TypeSystemCreateInstance create_callback;
- TypeSystemEnumerateSupportedLanguages enumerate_callback;
+ LanguageSet supported_languages_for_types;
+ LanguageSet supported_languages_for_expressions;
};
typedef std::vector<TypeSystemInstance> TypeSystemInstances;
@@ -2103,11 +2102,11 @@
return g_instances;
}
-bool PluginManager::RegisterPlugin(ConstString name,
- const char *description,
- TypeSystemCreateInstance create_callback,
- TypeSystemEnumerateSupportedLanguages
- enumerate_supported_languages_callback) {
+bool PluginManager::RegisterPlugin(
+ ConstString name, const char *description,
+ TypeSystemCreateInstance create_callback,
+ LanguageSet supported_languages_for_types,
+ LanguageSet supported_languages_for_expressions) {
if (create_callback) {
TypeSystemInstance instance;
assert((bool)name);
@@ -2115,7 +2114,8 @@
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- instance.enumerate_callback = enumerate_supported_languages_callback;
+ instance.supported_languages_for_types = supported_languages_for_types;
+ instance.supported_languages_for_expressions = supported_languages_for_expressions;
std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
GetTypeSystemInstances().push_back(instance);
}
@@ -2163,30 +2163,22 @@
return nullptr;
}
-TypeSystemEnumerateSupportedLanguages
-PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(
- uint32_t idx) {
+LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForTypes() {
std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ LanguageSet all;
TypeSystemInstances &instances = GetTypeSystemInstances();
- if (idx < instances.size())
- return instances[idx].enumerate_callback;
- return nullptr;
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages_for_types.bitvector;
+ return all;
}
-TypeSystemEnumerateSupportedLanguages
-PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName(
- ConstString name) {
- if (name) {
- std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
- TypeSystemInstances &instances = GetTypeSystemInstances();
-
- TypeSystemInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++pos) {
- if (name == pos->name)
- return pos->enumerate_callback;
- }
- }
- return nullptr;
+LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
+ std::lock_guard<std::recursive_mutex> guard(GetTypeSystemMutex());
+ LanguageSet all;
+ TypeSystemInstances &instances = GetTypeSystemInstances();
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages_for_expressions.bitvector;
+ return all;
}
#pragma mark REPL
@@ -2197,7 +2189,7 @@
ConstString name;
std::string description;
REPLCreateInstance create_callback;
- REPLEnumerateSupportedLanguages enumerate_languages_callback;
+ LanguageSet supported_languages;
};
typedef std::vector<REPLInstance> REPLInstances;
@@ -2212,10 +2204,9 @@
return g_instances;
}
-bool PluginManager::RegisterPlugin(
- ConstString name, const char *description,
- REPLCreateInstance create_callback,
- REPLEnumerateSupportedLanguages enumerate_languages_callback) {
+bool PluginManager::RegisterPlugin(ConstString name, const char *description,
+ REPLCreateInstance create_callback,
+ LanguageSet supported_languages) {
if (create_callback) {
REPLInstance instance;
assert((bool)name);
@@ -2223,7 +2214,7 @@
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
- instance.enumerate_languages_callback = enumerate_languages_callback;
+ instance.supported_languages = supported_languages;
std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
GetREPLInstances().push_back(instance);
}
@@ -2269,29 +2260,13 @@
return nullptr;
}
-REPLEnumerateSupportedLanguages
-PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(uint32_t idx) {
+LanguageSet PluginManager::GetREPLAllTypeSystemSupportedLanguages() {
std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
+ LanguageSet all;
REPLInstances &instances = GetREPLInstances();
- if (idx < instances.size())
- return instances[idx].enumerate_languages_callback;
- return nullptr;
-}
-
-REPLEnumerateSupportedLanguages
-PluginManager::GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName(
- ConstString name) {
- if (name) {
- std::lock_guard<std::recursive_mutex> guard(GetREPLMutex());
- REPLInstances &instances = GetREPLInstances();
-
- REPLInstances::iterator pos, end = instances.end();
- for (pos = instances.begin(); pos != end; ++pos) {
- if (name == pos->name)
- return pos->enumerate_languages_callback;
- }
- }
- return nullptr;
+ for (unsigned i = 0; i < instances.size(); ++i)
+ all.bitvector |= instances[i].supported_languages.bitvector;
+ return all;
}
#pragma mark PluginManager