Made the REPL choose a default language if only one REPL can be chosen.

This requires REPLs to enumerate the languages they support.

llvm-svn: 250913
This commit is contained in:
Sean Callanan 2015-10-21 17:43:18 +00:00
parent 45d29670ae
commit bea731292f
7 changed files with 40 additions and 8 deletions

View File

@ -449,7 +449,8 @@ public:
static bool
RegisterPlugin (const ConstString &name,
const char *description,
REPLCreateInstance create_callback);
REPLCreateInstance create_callback,
REPLEnumerateSupportedLanguages enumerate_languages_callback);
static bool
UnregisterPlugin (REPLCreateInstance create_callback);
@ -460,6 +461,12 @@ public:
static REPLCreateInstance
GetREPLCreateCallbackForPluginName (const ConstString &name);
static REPLEnumerateSupportedLanguages
GetREPLEnumerateSupportedLanguagesCallbackAtIndex (uint32_t idx);
static REPLEnumerateSupportedLanguages
GetREPLSystemEnumerateSupportedLanguagesCallbackForPluginName (const ConstString &name);
//------------------------------------------------------------------
// Some plug-ins might register a DebuggerInitializeCallback
// callback when registering the plug-in. After a new Debugger

View File

@ -149,6 +149,9 @@ public:
static void
GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages,
std::set<lldb::LanguageType> &languages_for_expressions);
static void
GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages);
protected:
//------------------------------------------------------------------

View File

@ -51,6 +51,7 @@ namespace lldb_private
typedef lldb::TypeSystemSP (*TypeSystemCreateInstance) (lldb::LanguageType language, Module *module, Target *target);
typedef lldb::REPLSP (*REPLCreateInstance) (Error &error, lldb::LanguageType language, Debugger *debugger, Target *target, const char *repl_options);
typedef void (*TypeSystemEnumerateSupportedLanguages) (std::set<lldb::LanguageType> &languages_for_types, std::set<lldb::LanguageType> &languages_for_expressions);
typedef void (*REPLEnumerateSupportedLanguages) (std::set<lldb::LanguageType> &languages);
typedef int (*ComparisonFunction)(const void *, const void *);
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);

View File

@ -1805,11 +1805,6 @@ Debugger::RunREPL (LanguageType language, const char *repl_options)
{
Error err;
FileSpec repl_executable;
if (language == eLanguageTypeUnknown)
{
err.SetErrorString ("must specify a language for a REPL"); // TODO make it possible to specify a default language
return err;
}
Target *const target = nullptr; // passing in an empty target means the REPL must create one

View File

@ -2662,6 +2662,7 @@ struct REPLInstance
ConstString name;
std::string description;
REPLCreateInstance create_callback;
REPLEnumerateSupportedLanguages enumerate_languages_callback;
};
typedef std::vector<REPLInstance> REPLInstances;
@ -2683,7 +2684,8 @@ GetREPLInstances ()
bool
PluginManager::RegisterPlugin (const ConstString &name,
const char *description,
REPLCreateInstance create_callback)
REPLCreateInstance create_callback,
REPLEnumerateSupportedLanguages enumerate_languages_callback)
{
if (create_callback)
{
@ -2693,6 +2695,7 @@ PluginManager::RegisterPlugin (const ConstString &name,
if (description && description[0])
instance.description = description;
instance.create_callback = create_callback;
instance.enumerate_languages_callback = enumerate_languages_callback;
Mutex::Locker locker (GetREPLMutex ());
GetREPLInstances ().push_back (instance);
}

View File

@ -299,6 +299,17 @@ Language::GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &langu
}
}
static void
GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages)
{
uint32_t idx = 0;
while (REPLEnumerateSupportedLanguages enumerate = PluginManager::GetREPLEnumerateSupportedLanguagesCallbackAtIndex(idx++))
{
(*enumerate)(languages);
}
}
std::unique_ptr<Language::TypeScavenger>
Language::GetTypeScavenger ()
{

View File

@ -218,7 +218,19 @@ Target::GetREPL (Error &err, lldb::LanguageType language, const char *repl_optio
{
if (language == eLanguageTypeUnknown)
{
return REPLSP(); // must provide a language
std::set<LanguageType> repl_languages;
Language::GetLanguagesSupportingREPLs(repl_languages);
if (repl_languages.size() == 1)
{
language = *repl_languages.begin();
}
else
{
err.SetErrorStringWithFormat("Multiple possible REPL languages. Please specify a language.");
return REPLSP(); // must provide a language
}
}
REPLMap::iterator pos = m_repl_map.find(language);