Make raw & parsed commands subclasses of CommandObject rather than having the raw version implement an
Execute which was never going to get run and another ExecuteRawCommandString. Took the knowledge of how
to prepare raw & parsed commands out of CommandInterpreter and put it in CommandObject where it belongs.
Also took all the cases where there were the subcommands of Multiword commands declared in the .h file for
the overall command and moved them into the .cpp file.
Made the CommandObject flags work for raw as well as parsed commands.
Made "expr" use the flags so that it requires you to be paused to run "expr".
llvm-svn: 158235
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 3a5b98e..e18f829 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1562,35 +1562,7 @@
if (log)
log->Printf ("HandleCommand, command line after removing command name(s): '%s'", remainder.c_str());
-
- CommandOverrideCallback command_callback = cmd_obj->GetOverrideCallback();
- bool handled = false;
- if (wants_raw_input)
- {
- if (command_callback)
- {
- std::string full_command (cmd_obj->GetCommandName ());
- full_command += ' ';
- full_command += remainder;
- const char *argv[2] = { NULL, NULL };
- argv[0] = full_command.c_str();
- handled = command_callback (cmd_obj->GetOverrideCallbackBaton(), argv);
- }
- if (!handled)
- cmd_obj->ExecuteRawCommandString (remainder.c_str(), result);
- }
- else
- {
- Args cmd_args (remainder.c_str());
- if (command_callback)
- {
- Args full_args (cmd_obj->GetCommandName ());
- full_args.AppendArguments(cmd_args);
- handled = command_callback (cmd_obj->GetOverrideCallbackBaton(), full_args.GetConstArgumentVector());
- }
- if (!handled)
- cmd_obj->ExecuteWithOptions (cmd_args, result);
- }
+ cmd_obj->Execute (remainder.c_str(), result);
}
else
{
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index dbbd093..85b21f5 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -153,18 +153,6 @@
return NULL;
}
-Flags&
-CommandObject::GetFlags()
-{
- return m_flags;
-}
-
-const Flags&
-CommandObject::GetFlags() const
-{
- return m_flags;
-}
-
bool
CommandObject::ParseOptions
(
@@ -214,16 +202,12 @@
}
return true;
}
-bool
-CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result)
-{
- for (size_t i = 0; i < args.GetArgumentCount(); ++i)
- {
- const char *tmp_str = args.GetArgumentAtIndex (i);
- if (tmp_str[0] == '`') // back-quote
- args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str));
- }
+
+
+bool
+CommandObject::CheckFlags (CommandReturnObject &result)
+{
if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused))
{
Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
@@ -274,12 +258,7 @@
}
}
}
-
- if (!ParseOptions (args, result))
- return false;
-
- // Call the command-specific version of 'Execute', passing it the already processed arguments.
- return Execute (args, result);
+ return true;
}
class CommandDictCommandPartialMatch
@@ -846,6 +825,63 @@
return NULL;
}
+bool
+CommandObjectParsed::Execute (const char *args_string, CommandReturnObject &result)
+{
+ CommandOverrideCallback command_callback = GetOverrideCallback();
+ bool handled = false;
+ Args cmd_args (args_string);
+ if (command_callback)
+ {
+ Args full_args (GetCommandName ());
+ full_args.AppendArguments(cmd_args);
+ handled = command_callback (GetOverrideCallbackBaton(), full_args.GetConstArgumentVector());
+ }
+ if (!handled)
+ {
+ for (size_t i = 0; i < cmd_args.GetArgumentCount(); ++i)
+ {
+ const char *tmp_str = cmd_args.GetArgumentAtIndex (i);
+ if (tmp_str[0] == '`') // back-quote
+ cmd_args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str));
+ }
+
+ if (!CheckFlags(result))
+ return false;
+
+ if (!ParseOptions (cmd_args, result))
+ return false;
+
+ // Call the command-specific version of 'Execute', passing it the already processed arguments.
+ handled = DoExecute (cmd_args, result);
+ }
+ return handled;
+}
+
+bool
+CommandObjectRaw::Execute (const char *args_string, CommandReturnObject &result)
+{
+ CommandOverrideCallback command_callback = GetOverrideCallback();
+ bool handled = false;
+ if (command_callback)
+ {
+ std::string full_command (GetCommandName ());
+ full_command += ' ';
+ full_command += args_string;
+ const char *argv[2] = { NULL, NULL };
+ argv[0] = full_command.c_str();
+ handled = command_callback (GetOverrideCallbackBaton(), argv);
+ }
+ if (!handled)
+ {
+ if (!CheckFlags(result))
+ return false;
+ else
+ handled = DoExecute (args_string, result);
+ }
+ return handled;
+}
+
static
const char *arch_helper()
{
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 871922c..de6faba 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -30,7 +30,7 @@
const char *syntax,
uint32_t max_matches
) :
- CommandObject (interpreter, name, help, syntax),
+ CommandObjectRaw (interpreter, name, help, syntax),
m_max_matches (max_matches),
m_entries ()
{
@@ -45,18 +45,7 @@
bool
-CommandObjectRegexCommand::Execute
-(
- Args& command,
- CommandReturnObject &result
-)
-{
- return false;
-}
-
-
-bool
-CommandObjectRegexCommand::ExecuteRawCommandString
+CommandObjectRegexCommand::DoExecute
(
const char *command,
CommandReturnObject &result
diff --git a/lldb/source/Interpreter/CommandObjectScript.cpp b/lldb/source/Interpreter/CommandObjectScript.cpp
index 5ade400..76bfe6e 100644
--- a/lldb/source/Interpreter/CommandObjectScript.cpp
+++ b/lldb/source/Interpreter/CommandObjectScript.cpp
@@ -30,10 +30,10 @@
//-------------------------------------------------------------------------
CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
- CommandObject (interpreter,
- "script",
- "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
- "script [<script-expression-for-evaluation>]"),
+ CommandObjectRaw (interpreter,
+ "script",
+ "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
+ "script [<script-expression-for-evaluation>]"),
m_script_lang (script_lang)
{
}
@@ -43,7 +43,7 @@
}
bool
-CommandObjectScript::ExecuteRawCommandString
+CommandObjectScript::DoExecute
(
const char *command,
CommandReturnObject &result
@@ -74,21 +74,3 @@
return result.Succeeded();
}
-
-bool
-CommandObjectScript::WantsRawCommandString()
-{
- return true;
-}
-
-bool
-CommandObjectScript::Execute
-(
- Args& command,
- CommandReturnObject &result
-)
-{
- // everything should be handled in ExecuteRawCommandString
- return false;
-}
-
diff --git a/lldb/source/Interpreter/CommandObjectScript.h b/lldb/source/Interpreter/CommandObjectScript.h
index b9fa759..c812539 100644
--- a/lldb/source/Interpreter/CommandObjectScript.h
+++ b/lldb/source/Interpreter/CommandObjectScript.h
@@ -22,7 +22,7 @@
// CommandObjectScript
//-------------------------------------------------------------------------
-class CommandObjectScript : public CommandObject
+class CommandObjectScript : public CommandObjectRaw
{
public:
@@ -32,15 +32,9 @@
virtual
~CommandObjectScript ();
- bool WantsRawCommandString();
-
+protected:
virtual bool
- ExecuteRawCommandString (const char *command,
- CommandReturnObject &result);
-
- virtual bool
- Execute (Args& command,
- CommandReturnObject &result);
+ DoExecute (const char *command, CommandReturnObject &result);
private:
lldb::ScriptLanguage m_script_lang;