Added auto completion for architecture names and for platforms.

Modified the OptionGroupOptions to be able to specify only some of the options
that should be appended by using the usage_mask in the group defintions and
also provided a way to remap them to a new usage mask after the copy. This 
allows options to be re-used and also targetted for specific option groups.

Modfied the CommandArgumentType to have a new eArgTypePlatform enumeration.
Taught the option parser to be able to automatically use the appropriate
auto completion for a given options if nothing is explicitly specified
in the option definition. So you don't have to specify it in the option
definition tables.

Renamed the default host platform name to "host", and the default platform
hostname to be "localhost".

Modified the "file" and "platform select" commands to make sure all options
and args are good prior to creating a new platform. Also defer the computation
of the architecture in the file command until all options are parsed and the
platform has either not been specified or reset to a new value to avoid
computing the arch more than once.

Switch the PluginManager code over to using llvm::StringRef for string
comparisons and got rid of all the AccessorXXX functions in lieu of the newer
mutex + collection singleton accessors.




git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@129483 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectFile.cpp b/source/Commands/CommandObjectFile.cpp
index 372baf9..563cbe2 100644
--- a/source/Commands/CommandObjectFile.cpp
+++ b/source/Commands/CommandObjectFile.cpp
@@ -26,7 +26,6 @@
 using namespace lldb_private;
 
 FileOptionGroup::FileOptionGroup() :
-    m_arch (),
     m_arch_str ()
 {
 }
@@ -53,6 +52,17 @@
     return g_file_option_table;
 }
 
+bool
+FileOptionGroup::GetArchitecture (Platform *platform, ArchSpec &arch)
+{
+    if (m_arch_str.empty())
+        arch.Clear();
+    else
+        arch.SetTriple(m_arch_str.c_str(), platform);
+    return arch.IsValid();
+}
+
+
 Error
 FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter,
                                  uint32_t option_idx,
@@ -64,17 +74,7 @@
     switch (short_option)
     {
         case 'a':
-            {
-                // Save the arch value in case we specify a platform after specifying the arch
-                m_arch_str.assign (option_arg);
-                // Check to see if we already have a platform?
-                m_arch_platform_sp = interpreter.GetPlatform (false);
-                ArchSpec option_arch (option_arg, m_arch_platform_sp.get());
-                if (option_arch.IsValid())
-                    m_arch = option_arch;
-                else
-                    error.SetErrorStringWithFormat ("Invalid arch string '%s'.\n", option_arg);
-            }
+            m_arch_str.assign (option_arg);
             break;
 
         default:
@@ -88,26 +88,7 @@
 void
 FileOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter)
 {
-    m_arch.Clear();
-}
-
-Error
-FileOptionGroup::OptionParsingFinished (CommandInterpreter &interpreter)
-{
-    Error error;
-    if (m_arch.IsValid())
-    {
-        PlatformSP curr_platform_sp (interpreter.GetPlatform (false));
-        if (curr_platform_sp.get() != m_arch_platform_sp.get())
-        {
-            ArchSpec option_arch (m_arch_str.c_str(), curr_platform_sp.get());
-            if (option_arch.IsValid())
-                m_arch = option_arch;
-            else
-                error.SetErrorStringWithFormat ("invalid arch '%s' for platform '%s'", m_arch_str.c_str(), curr_platform_sp->GetName());
-        }
-    }
-    return error;
+    m_arch_str.clear();
 }
 
 //-------------------------------------------------------------------------
@@ -136,8 +117,8 @@
     // Push the data for the first argument into the m_arguments vector.
     m_arguments.push_back (arg);
     
-    m_option_group.Append (&m_file_options);
-    m_option_group.Append (&m_platform_options);
+    m_option_group.Append (&m_file_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+    m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
     m_option_group.Finalize();
 }
 
@@ -164,18 +145,46 @@
     if (argc == 1)
     {
         FileSpec file_spec (file_path, true);
+        
+        bool select = true;
+        PlatformSP platform_sp;
+        
+        Error error;
+        
+        if (!m_platform_options.platform_name.empty())
+        {
+            platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error);
+            if (!platform_sp)
+            {
+                result.AppendError(error.AsCString());
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+        }
+        ArchSpec file_arch;
+        
+        if (!m_file_options.m_arch_str.empty())
+        {        
+            if (!platform_sp)
+                platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
+            if (!m_file_options.GetArchitecture(platform_sp.get(), file_arch))
+            {
+                result.AppendErrorWithFormat("invalid architecture '%s'", m_file_options.m_arch_str.c_str());
+                result.SetStatus (eReturnStatusFailed);
+                return false;
+            }
+        }
 
         if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation())
         {
             result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
             result.SetStatus (eReturnStatusFailed);
-            return result.Succeeded();
+            return false;
         }
 
         TargetSP target_sp;
-
         Debugger &debugger = m_interpreter.GetDebugger();
-        Error error = debugger.GetTargetList().CreateTarget (debugger, file_spec, m_file_options.m_arch, true, target_sp);
+        error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp);
 
         if (target_sp)
         {