Added support for enumerating the languages that actually support TypeSystems

and expressions.  Also wired that into the OptionValue infrastructure, although
it isn't used for tab-completion yet.

llvm-svn: 249769
This commit is contained in:
Sean Callanan 2015-10-08 23:07:53 +00:00
parent 46e642f8c5
commit fe38c8506f
10 changed files with 117 additions and 7 deletions

View File

@ -425,7 +425,8 @@ public:
static bool
RegisterPlugin (const ConstString &name,
const char *description,
TypeSystemCreateInstance create_callback);
TypeSystemCreateInstance create_callback,
TypeSystemEnumerateSupportedLanguages enumerate_languages_callback);
static bool
UnregisterPlugin (TypeSystemCreateInstance create_callback);
@ -436,6 +437,12 @@ public:
static TypeSystemCreateInstance
GetTypeSystemCreateCallbackForPluginName (const ConstString &name);
static TypeSystemEnumerateSupportedLanguages
GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx);
static TypeSystemEnumerateSupportedLanguages
GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name);
//------------------------------------------------------------------
// Some plug-ins might register a DebuggerInitializeCallback
// callback when registering the plug-in. After a new Debugger

View File

@ -72,6 +72,9 @@ public:
static lldb::TypeSystemSP
CreateInstance (lldb::LanguageType language, Module *module, Target *target);
static void
EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions);
static void
Initialize ();

View File

@ -41,6 +41,9 @@ class GoASTContext : public TypeSystem
static lldb::TypeSystemSP
CreateInstance (lldb::LanguageType language, Module *module, Target *target);
static void
EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions);
static void
Initialize ();

View File

@ -139,7 +139,11 @@ public:
static bool
LanguageIsPascal (lldb::LanguageType language);
static void
GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
std::set<lldb::LanguageType> &languages_for_expressions);
protected:
//------------------------------------------------------------------
// Classes that inherit from Language can see and modify these

View File

@ -14,6 +14,8 @@
#include "lldb/lldb-private.h"
#include <set>
namespace lldb_private
{
typedef lldb::ABISP (*ABICreateInstance) (const ArchSpec &arch);
@ -47,6 +49,7 @@ namespace lldb_private
typedef lldb::InstrumentationRuntimeType (*InstrumentationRuntimeGetType) ();
typedef lldb::InstrumentationRuntimeSP (*InstrumentationRuntimeCreateInstance) (const lldb::ProcessSP &process_sp);
typedef lldb::TypeSystemSP (*TypeSystemCreateInstance) (lldb::LanguageType language, Module *module, Target *target);
typedef void (*TypeSystemEnumerateSupportedLanguages) (std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions);
typedef int (*ComparisonFunction)(const void *, const void *);
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);

View File

@ -2531,6 +2531,7 @@ struct TypeSystemInstance
ConstString name;
std::string description;
TypeSystemCreateInstance create_callback;
TypeSystemEnumerateSupportedLanguages enumerate_callback;
};
typedef std::vector<TypeSystemInstance> TypeSystemInstances;
@ -2552,7 +2553,8 @@ GetTypeSystemInstances ()
bool
PluginManager::RegisterPlugin (const ConstString &name,
const char *description,
TypeSystemCreateInstance create_callback)
TypeSystemCreateInstance create_callback,
TypeSystemEnumerateSupportedLanguages enumerate_supported_languages_callback)
{
if (create_callback)
{
@ -2617,6 +2619,33 @@ PluginManager::GetTypeSystemCreateCallbackForPluginName (const ConstString &name
return NULL;
}
TypeSystemEnumerateSupportedLanguages
PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx)
{
Mutex::Locker locker (GetTypeSystemMutex ());
TypeSystemInstances &instances = GetTypeSystemInstances ();
if (idx < instances.size())
return instances[idx].enumerate_callback;
return NULL;
}
TypeSystemEnumerateSupportedLanguages
PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name)
{
if (name)
{
Mutex::Locker locker (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 NULL;
}
#pragma mark PluginManager

View File

@ -48,8 +48,12 @@ OptionValueLanguage::SetValueFromString (llvm::StringRef value, VarSetOperationT
case eVarSetOperationAssign:
{
ConstString lang_name(value.trim());
std::set<lldb::LanguageType> languages_for_types;
std::set<lldb::LanguageType> languages_for_expressions;
Language::GetLanguagesSupportingTypeSystems(languages_for_types, languages_for_expressions);
LanguageType new_type = Language::GetLanguageTypeFromString(lang_name.GetCString());
if (new_type)
if (new_type && languages_for_types.count(new_type))
{
m_value_was_set = true;
m_current_value = new_type;
@ -59,7 +63,10 @@ OptionValueLanguage::SetValueFromString (llvm::StringRef value, VarSetOperationT
StreamString error_strm;
error_strm.Printf("invalid language type '%s', ", value.str().c_str());
error_strm.Printf("valid values are:\n");
Language::PrintAllLanguages(error_strm, " ", "\n");
for (lldb::LanguageType language : languages_for_types)
{
error_strm.Printf("%s%s%s", " ", Language::GetNameForLanguageType(language), "\n");
}
error.SetErrorString(error_strm.GetData());
}
}

View File

@ -13,6 +13,7 @@
// C++ Includes
#include <mutex> // std::once
#include <string>
#include <vector>
// Other libraries and framework includes
@ -424,13 +425,41 @@ ClangASTContext::CreateInstance (lldb::LanguageType language, Module *module, Ta
return lldb::TypeSystemSP();
}
void
ClangASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions)
{
static std::vector<lldb::LanguageType> s_supported_languages_for_types({
lldb::eLanguageTypeC89,
lldb::eLanguageTypeC,
lldb::eLanguageTypeC11,
lldb::eLanguageTypeC_plus_plus,
lldb::eLanguageTypeC99,
lldb::eLanguageTypeObjC,
lldb::eLanguageTypeObjC_plus_plus,
lldb::eLanguageTypeC_plus_plus_03,
lldb::eLanguageTypeC_plus_plus_11,
lldb::eLanguageTypeC11,
lldb::eLanguageTypeC_plus_plus_14});
static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({
lldb::eLanguageTypeC_plus_plus,
lldb::eLanguageTypeObjC_plus_plus,
lldb::eLanguageTypeC_plus_plus_03,
lldb::eLanguageTypeC_plus_plus_11,
lldb::eLanguageTypeC_plus_plus_14});
languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end());
languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end());
}
void
ClangASTContext::Initialize()
{
PluginManager::RegisterPlugin (GetPluginNameStatic(),
"clang base AST context plug-in",
CreateInstance);
CreateInstance,
EnumerateSupportedLanguages);
}
void

View File

@ -342,13 +342,26 @@ GoASTContext::CreateInstance (lldb::LanguageType language, Module *module, Targe
return lldb::TypeSystemSP();
}
void
GoASTContext::EnumerateSupportedLanguages(std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions)
{
static std::vector<lldb::LanguageType> s_supported_languages_for_types({
lldb::eLanguageTypeGo});
static std::vector<lldb::LanguageType> s_supported_languages_for_expressions({});
languages_for_types.insert(s_supported_languages_for_types.begin(), s_supported_languages_for_types.end());
languages_for_expressions.insert(s_supported_languages_for_expressions.begin(), s_supported_languages_for_expressions.end());
}
void
GoASTContext::Initialize()
{
PluginManager::RegisterPlugin (GetPluginNameStatic(),
"AST context plug-in",
CreateInstance);
CreateInstance,
EnumerateSupportedLanguages);
}
void

View File

@ -287,6 +287,18 @@ Language::LanguageIsPascal (LanguageType language)
}
}
void
Language::GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
std::set<lldb::LanguageType> &languages_for_expressions)
{
uint32_t idx = 0;
while (TypeSystemEnumerateSupportedLanguages enumerate = PluginManager::GetTypeSystemEnumerateSupportedLanguagesCallbackAtIndex(idx++))
{
(*enumerate)(languages, languages_for_expressions);
}
}
std::unique_ptr<Language::TypeScavenger>
Language::GetTypeScavenger ()
{