Decoupled Options from CommandInterpreter.

Options used to store a reference to the CommandInterpreter instance
in the base Options class.  This made it impossible to parse options
independent of a CommandInterpreter.

This change removes the reference from the base class.  Instead, it
modifies the options-parsing-related methods to take an
ExecutionContext pointer, which the options may inspect if they need
to do so.

Closes https://reviews.llvm.org/D23416
Reviewers: clayborg, jingham

llvm-svn: 278440
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index dd2fd9a..0cba318 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -44,7 +44,7 @@
                             "command history",
                             "Dump the history of commands in this session.",
                             nullptr),
-        m_options (interpreter)
+        m_options()
     {
     }
 
@@ -60,8 +60,8 @@
     class CommandOptions : public Options
     {
     public:
-        CommandOptions (CommandInterpreter &interpreter) :
-            Options (interpreter),
+        CommandOptions() :
+            Options(),
             m_start_idx(0),
             m_stop_idx(0),
             m_count(0),
@@ -72,7 +72,8 @@
         ~CommandOptions() override = default;
 
         Error
-        SetOptionValue (uint32_t option_idx, const char *option_arg) override
+        SetOptionValue (uint32_t option_idx, const char *option_arg,
+                        ExecutionContext *execution_context) override
         {
             Error error;
             const int short_option = m_getopt_table[option_idx].val;
@@ -107,7 +108,7 @@
         }
 
         void
-        OptionParsingStarting () override
+        OptionParsingStarting (ExecutionContext *execution_context) override
         {
             m_start_idx.Clear();
             m_stop_idx.Clear();
@@ -238,7 +239,7 @@
     CommandObjectCommandsSource(CommandInterpreter &interpreter)
         : CommandObjectParsed(interpreter, "command source", "Read and execute LLDB commands from the file <filename>.",
                               nullptr),
-          m_options(interpreter)
+          m_options()
     {
         CommandArgumentEntry arg;
         CommandArgumentData file_arg;
@@ -274,8 +275,8 @@
     {
         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
         completion_str.erase (cursor_char_position);
-        
-        CommandCompletions::InvokeCommonCompletionCallbacks(m_interpreter,
+
+        CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
                                                             CommandCompletions::eDiskFileCompletion,
                                                             completion_str.c_str(),
                                                             match_start_point,
@@ -296,8 +297,8 @@
     class CommandOptions : public Options
     {
     public:
-        CommandOptions (CommandInterpreter &interpreter) :
-            Options (interpreter),
+        CommandOptions() :
+            Options(),
             m_stop_on_error (true),
             m_silent_run (false),
             m_stop_on_continue (true)
@@ -307,7 +308,8 @@
         ~CommandOptions() override = default;
 
         Error
-        SetOptionValue (uint32_t option_idx, const char *option_arg) override
+        SetOptionValue (uint32_t option_idx, const char *option_arg,
+                        ExecutionContext *execution_context) override
         {
             Error error;
             const int short_option = m_getopt_table[option_idx].val;
@@ -335,7 +337,7 @@
         }
 
         void
-        OptionParsingStarting () override
+        OptionParsingStarting (ExecutionContext *execution_context) override
         {
             m_stop_on_error.Clear();
             m_silent_run.Clear();
@@ -454,9 +456,9 @@
         }
         
         Error
-        SetOptionValue (CommandInterpreter &interpreter,
-                        uint32_t option_idx,
-                        const char *option_value) override
+        SetOptionValue (uint32_t option_idx,
+                        const char *option_value,
+                        ExecutionContext *execution_context) override
         {
             Error error;
             
@@ -483,7 +485,7 @@
         }
         
         void
-        OptionParsingStarting (CommandInterpreter &interpreter) override
+        OptionParsingStarting (ExecutionContext *execution_context) override
         {
             m_help.Clear();
             m_long_help.Clear();
@@ -509,7 +511,7 @@
     CommandObjectCommandsAlias(CommandInterpreter &interpreter)
         : CommandObjectRaw(interpreter, "command alias", "Define a custom command in terms of an existing command.",
                            nullptr),
-          m_option_group(interpreter),
+          m_option_group(),
           m_command_options()
     {
         m_option_group.Append(&m_command_options);
@@ -630,8 +632,9 @@
             result.AppendError ("'command alias' requires at least two arguments");
             return false;
         }
-        
-        m_option_group.NotifyOptionParsingStarting();
+
+        ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
+        m_option_group.NotifyOptionParsingStarting(&exe_ctx);
         
         const char * remainder = nullptr;
         
@@ -663,7 +666,7 @@
                 if (!ParseOptions (args, result))
                     return false;
                 
-                Error error (m_option_group.NotifyOptionParsingFinished());
+                Error error (m_option_group.NotifyOptionParsingFinished(&exe_ctx));
                 if (error.Fail())
                 {
                     result.AppendError (error.AsCString());
@@ -1092,7 +1095,7 @@
                               "Define a custom command in terms of existing commands by matching regular expressions.",
                               "command regex <cmd-name> [s/<regex>/<subst>/ ...]"),
           IOHandlerDelegateMultiline("", IOHandlerDelegate::Completion::LLDBCommand),
-          m_options(interpreter)
+          m_options()
     {
         SetHelpLong(R"(
 )" "This command allows the user to create powerful regular expression commands \
@@ -1359,15 +1362,16 @@
      class CommandOptions : public Options
      {
      public:
-         CommandOptions (CommandInterpreter &interpreter) :
-            Options (interpreter)
+         CommandOptions() :
+            Options()
          {
          }
 
          ~CommandOptions() override = default;
 
          Error
-         SetOptionValue (uint32_t option_idx, const char *option_arg) override
+         SetOptionValue (uint32_t option_idx, const char *option_arg,
+                         ExecutionContext *execution_context) override
          {
              Error error;
              const int short_option = m_getopt_table[option_idx].val;
@@ -1389,7 +1393,7 @@
          }
          
          void
-         OptionParsingStarting () override
+         OptionParsingStarting (ExecutionContext *execution_context) override
          {
              m_help.clear();
              m_syntax.clear();
@@ -1676,7 +1680,7 @@
                             "command script import",
                             "Import a scripting module in LLDB.",
                             nullptr),
-        m_options(interpreter)
+        m_options()
     {
         CommandArgumentEntry arg1;
         CommandArgumentData cmd_arg;
@@ -1706,8 +1710,8 @@
     {
         std::string completion_str (input.GetArgumentAtIndex(cursor_index));
         completion_str.erase (cursor_char_position);
-        
-        CommandCompletions::InvokeCommonCompletionCallbacks(m_interpreter,
+
+        CommandCompletions::InvokeCommonCompletionCallbacks(GetCommandInterpreter(),
                                                             CommandCompletions::eDiskFileCompletion,
                                                             completion_str.c_str(),
                                                             match_start_point,
@@ -1728,15 +1732,16 @@
     class CommandOptions : public Options
     {
     public:
-        CommandOptions (CommandInterpreter &interpreter) :
-            Options (interpreter)
+        CommandOptions() :
+            Options()
         {
         }
 
         ~CommandOptions() override = default;
 
         Error
-        SetOptionValue (uint32_t option_idx, const char *option_arg) override
+        SetOptionValue (uint32_t option_idx, const char *option_arg,
+                        ExecutionContext *execution_context) override
         {
             Error error;
             const int short_option = m_getopt_table[option_idx].val;
@@ -1755,7 +1760,7 @@
         }
         
         void
-        OptionParsingStarting () override
+        OptionParsingStarting(ExecutionContext *execution_context) override
         {
             m_allow_reload = true;
         }
@@ -1850,7 +1855,7 @@
                             "Add a scripted function as an LLDB command.",
                             nullptr),
         IOHandlerDelegateMultiline ("DONE"),
-        m_options (interpreter)
+        m_options()
     {
         CommandArgumentEntry arg1;
         CommandArgumentData cmd_arg;
@@ -1878,8 +1883,8 @@
     class CommandOptions : public Options
     {
     public:
-        CommandOptions (CommandInterpreter &interpreter) :
-            Options (interpreter),
+        CommandOptions() :
+            Options(),
             m_class_name(),
             m_funct_name(),
             m_short_help(),
@@ -1890,7 +1895,8 @@
         ~CommandOptions() override = default;
 
         Error
-        SetOptionValue (uint32_t option_idx, const char *option_arg) override
+        SetOptionValue (uint32_t option_idx, const char *option_arg,
+                        ExecutionContext *execution_context) override
         {
             Error error;
             const int short_option = m_getopt_table[option_idx].val;
@@ -1923,7 +1929,7 @@
         }
         
         void
-        OptionParsingStarting () override
+        OptionParsingStarting(ExecutionContext *execution_context) override
         {
             m_class_name.clear();
             m_funct_name.clear();