Convert some Args index-based iteration to range-style iteration.

This is better for a number of reasons.  Mostly style, but also:

1) Signed-unsigned comparison warnings disappear since there is
   no loop index.
2) Iterating with the range-for style gives you back an entry
   that has more than just a const char*, so it's more efficient
   and more useful.
3) Makes code safter since the type system enforces that it's
   impossible to index out of bounds.

llvm-svn: 283413
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index abf2c74..3df7fb7 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1096,10 +1096,9 @@
         result.SetStatus(eReturnStatusSuccessFinishNoResult);
       }
     } else {
-      for (size_t arg_idx = 1; arg_idx < argc; ++arg_idx) {
-        llvm::StringRef arg_strref(command.GetArgumentAtIndex(arg_idx));
+      for (auto &entry : command.entries().drop_front()) {
         bool check_only = false;
-        error = AppendRegexSubstitution(arg_strref, check_only);
+        error = AppendRegexSubstitution(entry.ref, check_only);
         if (error.Fail())
           break;
       }
diff --git a/lldb/source/Commands/CommandObjectHelp.cpp b/lldb/source/Commands/CommandObjectHelp.cpp
index 7d1fdcf..b4a3e01 100644
--- a/lldb/source/Commands/CommandObjectHelp.cpp
+++ b/lldb/source/Commands/CommandObjectHelp.cpp
@@ -114,26 +114,25 @@
       bool all_okay = true;
       CommandObject *sub_cmd_obj = cmd_obj;
       // Loop down through sub_command dictionaries until we find the command
-      // object that corresponds
-      // to the help command entered.
+      // object that corresponds to the help command entered.
       std::string sub_command;
-      for (size_t i = 1; i < argc && all_okay; ++i) {
-        sub_command = command.GetArgumentAtIndex(i);
+      for (auto &entry : command.entries().drop_front()) {
+        sub_command = entry.ref;
         matches.Clear();
         if (sub_cmd_obj->IsAlias())
           sub_cmd_obj =
               ((CommandAlias *)sub_cmd_obj)->GetUnderlyingCommand().get();
         if (!sub_cmd_obj->IsMultiwordObject()) {
           all_okay = false;
+          break;
         } else {
           CommandObject *found_cmd;
           found_cmd =
               sub_cmd_obj->GetSubcommandObject(sub_command.c_str(), &matches);
-          if (found_cmd == nullptr)
+          if (found_cmd == nullptr || matches.GetSize() > 1) {
             all_okay = false;
-          else if (matches.GetSize() > 1)
-            all_okay = false;
-          else
+            break;
+          } else
             sub_cmd_obj = found_cmd;
         }
       }
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 702fee9..e4cd5a4 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1453,12 +1453,14 @@
 
         if (platform_sp->IsConnected()) {
           Stream &ostrm = result.GetOutputStream();
-          bool success;
-          for (size_t i = 0; i < argc; ++i) {
-            const char *arg = args.GetArgumentAtIndex(i);
-            lldb::pid_t pid = StringConvert::ToUInt32(
-                arg, LLDB_INVALID_PROCESS_ID, 0, &success);
-            if (success) {
+          for (auto &entry : args.entries()) {
+            lldb::pid_t pid;
+            if (entry.ref.getAsInteger(0, pid)) {
+              result.AppendErrorWithFormat("invalid process ID argument '%s'",
+                                           entry.ref.str().c_str());
+              result.SetStatus(eReturnStatusFailed);
+              break;
+            } else {
               ProcessInstanceInfo proc_info;
               if (platform_sp->GetProcessInfo(pid, proc_info)) {
                 ostrm.Printf("Process information for process %" PRIu64 ":\n",
@@ -1470,11 +1472,6 @@
                              pid);
               }
               ostrm.EOL();
-            } else {
-              result.AppendErrorWithFormat("invalid process ID argument '%s'",
-                                           arg);
-              result.SetStatus(eReturnStatusFailed);
-              break;
             }
           }
         } else {
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index e47ac0d..cc38959 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -1037,11 +1037,10 @@
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     Process *process = m_exe_ctx.GetProcessPtr();
 
-    const size_t argc = command.GetArgumentCount();
-    for (uint32_t i = 0; i < argc; ++i) {
+    for (auto &entry : command.entries()) {
       Error error;
       PlatformSP platform = process->GetTarget().GetPlatform();
-      const char *image_path = command.GetArgumentAtIndex(i);
+      llvm::StringRef image_path = entry.ref;
       uint32_t image_token = LLDB_INVALID_IMAGE_TOKEN;
 
       if (!m_options.do_install) {
@@ -1063,10 +1062,12 @@
 
       if (image_token != LLDB_INVALID_IMAGE_TOKEN) {
         result.AppendMessageWithFormat(
-            "Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token);
+            "Loading \"%s\"...ok\nImage %u loaded.\n", image_path.str().c_str(),
+            image_token);
         result.SetStatus(eReturnStatusSuccessFinishResult);
       } else {
-        result.AppendErrorWithFormat("failed to load '%s': %s", image_path,
+        result.AppendErrorWithFormat("failed to load '%s': %s",
+                                     image_path.str().c_str(),
                                      error.AsCString());
         result.SetStatus(eReturnStatusFailed);
       }
@@ -1099,15 +1100,11 @@
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     Process *process = m_exe_ctx.GetProcessPtr();
 
-    const size_t argc = command.GetArgumentCount();
-
-    for (uint32_t i = 0; i < argc; ++i) {
-      const char *image_token_cstr = command.GetArgumentAtIndex(i);
-      uint32_t image_token = StringConvert::ToUInt32(
-          image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0);
-      if (image_token == LLDB_INVALID_IMAGE_TOKEN) {
+    for (auto &entry : command.entries()) {
+      uint32_t image_token;
+      if (entry.ref.getAsInteger(0, image_token)) {
         result.AppendErrorWithFormat("invalid image index argument '%s'",
-                                     image_token_cstr);
+                                     entry.ref.str().c_str());
         result.SetStatus(eReturnStatusFailed);
         break;
       } else {
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 9c7493a..21a636f 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -294,7 +294,9 @@
     result.SetStatus(eReturnStatusSuccessFinishResult);
 
     const size_t argc = args.GetArgumentCount();
-    if (argc > 0) {
+    if (!args.empty()) {
+      // TODO: Convert this to StringRef based enumeration.  Requires converting
+      // DumpPropertyValue first.
       for (size_t i = 0; i < argc; ++i) {
         const char *property_path = args.GetArgumentAtIndex(i);
 
@@ -374,6 +376,8 @@
     if (argc > 0) {
       const bool dump_qualified_name = true;
 
+      // TODO: Convert to StringRef based enumeration.  Requires converting
+      // GetPropertyAtPath first.
       for (size_t i = 0; i < argc; ++i) {
         const char *property_path = args.GetArgumentAtIndex(i);
 
diff --git a/lldb/source/Commands/CommandObjectSyntax.cpp b/lldb/source/Commands/CommandObjectSyntax.cpp
index 67dee8e..338671b 100644
--- a/lldb/source/Commands/CommandObjectSyntax.cpp
+++ b/lldb/source/Commands/CommandObjectSyntax.cpp
@@ -57,6 +57,8 @@
   if (argc > 0) {
     cmd_obj = m_interpreter.GetCommandObject(command.GetArgumentAtIndex(0));
     bool all_okay = true;
+    // TODO: Convert to entry-based iteration.  Requires converting
+    // GetSubcommandObject.
     for (size_t i = 1; i < argc; ++i) {
       std::string sub_command = command.GetArgumentAtIndex(i);
       if (!cmd_obj->IsMultiwordObject()) {
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 635bb0a..ba4aeb8 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -569,14 +569,11 @@
         return false;
       }
 
-      for (uint32_t arg_idx = 0; arg_idx < argc; ++arg_idx) {
-        const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
-        bool success = false;
-        uint32_t target_idx =
-            StringConvert::ToUInt32(target_idx_arg, UINT32_MAX, 0, &success);
-        if (!success) {
+      for (auto &entry : args.entries()) {
+        uint32_t target_idx;
+        if (entry.ref.getAsInteger(0, target_idx)) {
           result.AppendErrorWithFormat("invalid target index '%s'\n",
-                                       target_idx_arg);
+                                       entry.c_str());
           result.SetStatus(eReturnStatusFailed);
           return false;
         }
@@ -799,6 +796,8 @@
 
     if (argc > 0) {
 
+      // TODO: Convert to entry-based iteration.  Requires converting
+      // DumpValueObject.
       for (size_t idx = 0; idx < argc; ++idx) {
         VariableList variable_list;
         ValueObjectList valobj_list;
@@ -2479,48 +2478,48 @@
           return false;
         }
       } else {
-        for (size_t i = 0; i < argc; ++i) {
-          const char *path = args.GetArgumentAtIndex(i);
-          if (path) {
-            FileSpec file_spec(path, true);
-            if (file_spec.Exists()) {
-              ModuleSpec module_spec(file_spec);
-              if (m_uuid_option_group.GetOptionValue().OptionWasSet())
-                module_spec.GetUUID() =
-                    m_uuid_option_group.GetOptionValue().GetCurrentValue();
-              if (m_symbol_file.GetOptionValue().OptionWasSet())
-                module_spec.GetSymbolFileSpec() =
-                    m_symbol_file.GetOptionValue().GetCurrentValue();
-              if (!module_spec.GetArchitecture().IsValid())
-                module_spec.GetArchitecture() = target->GetArchitecture();
-              Error error;
-              ModuleSP module_sp(target->GetSharedModule(module_spec, &error));
-              if (!module_sp) {
-                const char *error_cstr = error.AsCString();
-                if (error_cstr)
-                  result.AppendError(error_cstr);
-                else
-                  result.AppendErrorWithFormat("unsupported module: %s", path);
-                result.SetStatus(eReturnStatusFailed);
-                return false;
-              } else {
-                flush = true;
-              }
-              result.SetStatus(eReturnStatusSuccessFinishResult);
-            } else {
-              char resolved_path[PATH_MAX];
+        for (auto &entry : args.entries()) {
+          if (entry.ref.empty())
+            continue;
+
+          FileSpec file_spec(entry.ref, true);
+          if (file_spec.Exists()) {
+            ModuleSpec module_spec(file_spec);
+            if (m_uuid_option_group.GetOptionValue().OptionWasSet())
+              module_spec.GetUUID() =
+                  m_uuid_option_group.GetOptionValue().GetCurrentValue();
+            if (m_symbol_file.GetOptionValue().OptionWasSet())
+              module_spec.GetSymbolFileSpec() =
+                  m_symbol_file.GetOptionValue().GetCurrentValue();
+            if (!module_spec.GetArchitecture().IsValid())
+              module_spec.GetArchitecture() = target->GetArchitecture();
+            Error error;
+            ModuleSP module_sp(target->GetSharedModule(module_spec, &error));
+            if (!module_sp) {
+              const char *error_cstr = error.AsCString();
+              if (error_cstr)
+                result.AppendError(error_cstr);
+              else
+                result.AppendErrorWithFormat("unsupported module: %s",
+                                             entry.c_str());
               result.SetStatus(eReturnStatusFailed);
-              if (file_spec.GetPath(resolved_path, sizeof(resolved_path))) {
-                if (strcmp(resolved_path, path) != 0) {
-                  result.AppendErrorWithFormat(
-                      "invalid module path '%s' with resolved path '%s'\n",
-                      path, resolved_path);
-                  break;
-                }
-              }
-              result.AppendErrorWithFormat("invalid module path '%s'\n", path);
+              return false;
+            } else {
+              flush = true;
+            }
+            result.SetStatus(eReturnStatusSuccessFinishResult);
+          } else {
+            std::string resolved_path = file_spec.GetPath();
+            result.SetStatus(eReturnStatusFailed);
+            if (resolved_path != entry.ref) {
+              result.AppendErrorWithFormat(
+                  "invalid module path '%s' with resolved path '%s'\n",
+                  entry.ref.str().c_str(), resolved_path.c_str());
               break;
             }
+            result.AppendErrorWithFormat("invalid module path '%s'\n",
+                                         entry.c_str());
+            break;
           }
         }
       }
@@ -2921,6 +2920,8 @@
           module_list_ptr = &target->GetImages();
         }
       } else {
+        // TODO: Convert to entry based iteration.  Requires converting
+        // FindModulesByName.
         for (size_t i = 0; i < argc; ++i) {
           // Dump specified images (by basename or fullpath)
           const char *arg_cstr = command.GetArgumentAtIndex(i);
@@ -4226,10 +4227,9 @@
       } else {
         PlatformSP platform_sp(target->GetPlatform());
 
-        for (size_t i = 0; i < argc; ++i) {
-          const char *symfile_path = args.GetArgumentAtIndex(i);
-          if (symfile_path) {
-            module_spec.GetSymbolFileSpec().SetFile(symfile_path, true);
+        for (auto &entry : args.entries()) {
+          if (!entry.ref.empty()) {
+            module_spec.GetSymbolFileSpec().SetFile(entry.ref, true);
             if (platform_sp) {
               FileSpec symfile_spec;
               if (platform_sp
@@ -4245,18 +4245,16 @@
               if (!AddModuleSymbols(target, module_spec, flush, result))
                 break;
             } else {
-              char resolved_symfile_path[PATH_MAX];
-              if (module_spec.GetSymbolFileSpec().GetPath(
-                      resolved_symfile_path, sizeof(resolved_symfile_path))) {
-                if (strcmp(resolved_symfile_path, symfile_path) != 0) {
-                  result.AppendErrorWithFormat(
-                      "invalid module path '%s' with resolved path '%s'\n",
-                      symfile_path, resolved_symfile_path);
-                  break;
-                }
+              std::string resolved_symfile_path =
+                  module_spec.GetSymbolFileSpec().GetPath();
+              if (resolved_symfile_path != entry.ref) {
+                result.AppendErrorWithFormat(
+                    "invalid module path '%s' with resolved path '%s'\n",
+                    entry.c_str(), resolved_symfile_path.c_str());
+                break;
               }
               result.AppendErrorWithFormat("invalid module path '%s'\n",
-                                           symfile_path);
+                                           entry.c_str());
               break;
             }
           }
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index 3e75e64..41416d3 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -770,28 +770,22 @@
             process->GetThreadList().GetMutex());
         const uint32_t num_threads = process->GetThreadList().GetSize();
         std::vector<Thread *> resume_threads;
-        for (uint32_t i = 0; i < argc; ++i) {
-          bool success;
-          const int base = 0;
-          uint32_t thread_idx =
-              StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
-                                      LLDB_INVALID_INDEX32, base, &success);
-          if (success) {
-            Thread *thread =
-                process->GetThreadList().FindThreadByIndexID(thread_idx).get();
-
-            if (thread) {
-              resume_threads.push_back(thread);
-            } else {
-              result.AppendErrorWithFormat("invalid thread index %u.\n",
-                                           thread_idx);
-              result.SetStatus(eReturnStatusFailed);
-              return false;
-            }
-          } else {
+        for (auto &entry : command.entries()) {
+          uint32_t thread_idx;
+          if (entry.ref.getAsInteger(0, thread_idx)) {
             result.AppendErrorWithFormat(
-                "invalid thread index argument: \"%s\".\n",
-                command.GetArgumentAtIndex(i));
+                "invalid thread index argument: \"%s\".\n", entry.c_str());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+          }
+          Thread *thread =
+              process->GetThreadList().FindThreadByIndexID(thread_idx).get();
+
+          if (thread) {
+            resume_threads.push_back(thread);
+          } else {
+            result.AppendErrorWithFormat("invalid thread index %u.\n",
+                                         thread_idx);
             result.SetStatus(eReturnStatusFailed);
             return false;
           }
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 16b894f..2c44ad4 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -15,9 +15,6 @@
 #include <cctype>
 #include <functional>
 
-// Other libraries and framework includes
-#include "llvm/ADT/StringRef.h"
-
 // Project includes
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Debugger.h"
@@ -42,6 +39,9 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadList.h"
 
+// Other libraries and framework includes
+#include "llvm/ADT/STLExtras.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -78,20 +78,20 @@
 
 static bool WarnOnPotentialUnquotedUnsignedType(Args &command,
                                                 CommandReturnObject &result) {
-  for (unsigned idx = 0; idx < command.GetArgumentCount(); idx++) {
-    const char *arg = command.GetArgumentAtIndex(idx);
-    if (idx + 1 < command.GetArgumentCount()) {
-      if (arg && 0 == strcmp(arg, "unsigned")) {
-        const char *next = command.GetArgumentAtIndex(idx + 1);
-        if (next && (0 == strcmp(next, "int") || 0 == strcmp(next, "short") ||
-                     0 == strcmp(next, "char") || 0 == strcmp(next, "long"))) {
-          result.AppendWarningWithFormat("%s %s being treated as two types. if "
-                                         "you meant the combined type name use "
-                                         "quotes, as in \"%s %s\"\n",
-                                         arg, next, arg, next);
-          return true;
-        }
-      }
+  if (command.empty())
+    return false;
+
+  for (auto entry : llvm::enumerate(command.entries().drop_back())) {
+    if (entry.Value.ref != "unsigned")
+      continue;
+    auto next = command.entries()[entry.Index + 1].ref;
+    if (next == "int" || next == "short" || next == "char" || next == "long") {
+      result.AppendWarningWithFormat(
+          "unsigned %s being treated as two types. if you meant the combined "
+          "type "
+          "name use  quotes, as in \"unsigned %s\"\n",
+          next.str().c_str(), next.str().c_str());
+      return true;
     }
   }
   return false;
@@ -727,27 +727,26 @@
 
     WarnOnPotentialUnquotedUnsignedType(command, result);
 
-    for (size_t i = 0; i < argc; i++) {
-      const char *typeA = command.GetArgumentAtIndex(i);
-      ConstString typeCS(typeA);
-      if (typeCS) {
-        if (m_command_options.m_regex) {
-          RegularExpressionSP typeRX(new RegularExpression());
-          if (!typeRX->Compile(typeCS.GetStringRef())) {
-            result.AppendError(
-                "regex format error (maybe this is not really a regex?)");
-            result.SetStatus(eReturnStatusFailed);
-            return false;
-          }
-          category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
-          category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
-        } else
-          category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
-      } else {
+    for (auto &arg_entry : command.entries()) {
+      if (arg_entry.ref.empty()) {
         result.AppendError("empty typenames not allowed");
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
+
+      ConstString typeCS(arg_entry.ref);
+      if (m_command_options.m_regex) {
+        RegularExpressionSP typeRX(new RegularExpression());
+        if (!typeRX->Compile(arg_entry.ref)) {
+          result.AppendError(
+              "regex format error (maybe this is not really a regex?)");
+          result.SetStatus(eReturnStatusFailed);
+          return false;
+        }
+        category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
+        category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
+      } else
+        category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
     }
 
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -1406,15 +1405,14 @@
         new ScriptAddOptions(m_options.m_flags, m_options.m_regex,
                              m_options.m_name, m_options.m_category);
 
-    for (size_t i = 0; i < argc; i++) {
-      const char *typeA = command.GetArgumentAtIndex(i);
-      if (typeA && *typeA)
-        options->m_target_types << typeA;
-      else {
+    for (auto &entry : command.entries()) {
+      if (entry.ref.empty()) {
         result.AppendError("empty typenames not allowed");
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
+
+      options->m_target_types << entry.ref;
     }
 
     m_interpreter.GetPythonCommandsFromIOHandler(
@@ -1433,10 +1431,9 @@
 
   Error error;
 
-  for (size_t i = 0; i < command.GetArgumentCount(); i++) {
-    const char *type_name = command.GetArgumentAtIndex(i);
+  for (auto &entry : command.entries()) {
     CommandObjectTypeSummaryAdd::AddSummary(
-        ConstString(type_name), script_format,
+        ConstString(entry.ref), script_format,
         (m_options.m_regex ? eRegexSummary : eRegularSummary),
         m_options.m_category, &error);
     if (error.Fail()) {
@@ -1508,14 +1505,13 @@
 
   // now I have a valid format, let's add it to every type
   Error error;
-  for (size_t i = 0; i < argc; i++) {
-    const char *typeA = command.GetArgumentAtIndex(i);
-    if (!typeA || typeA[0] == '\0') {
+  for (auto &arg_entry : command.entries()) {
+    if (arg_entry.ref.empty()) {
       result.AppendError("empty typenames not allowed");
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
-    ConstString typeCS(typeA);
+    ConstString typeCS(arg_entry.ref);
 
     AddSummary(typeCS, entry,
                (m_options.m_regex ? eRegexSummary : eRegularSummary),
@@ -1880,10 +1876,9 @@
       return false;
     }
 
-    for (size_t i = 0; i < argc; i++) {
-      const char *cateName = command.GetArgumentAtIndex(i);
+    for (auto &entry : command.entries()) {
       TypeCategoryImplSP category_sp;
-      if (DataVisualization::Categories::GetCategory(ConstString(cateName),
+      if (DataVisualization::Categories::GetCategory(ConstString(entry.ref),
                                                      category_sp) &&
           category_sp) {
         category_sp->AddLanguage(m_options.m_cate_language.GetCurrentValue());
@@ -2358,17 +2353,14 @@
       m_options.m_skip_pointers, m_options.m_skip_references,
       m_options.m_cascade, m_options.m_regex, m_options.m_category);
 
-  const size_t argc = command.GetArgumentCount();
-
-  for (size_t i = 0; i < argc; i++) {
-    const char *typeA = command.GetArgumentAtIndex(i);
-    if (typeA && *typeA)
-      options->m_target_types << typeA;
-    else {
+  for (auto &entry : command.entries()) {
+    if (entry.ref.empty()) {
       result.AppendError("empty typenames not allowed");
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
+
+    options->m_target_types << entry.ref;
   }
 
   m_interpreter.GetPythonCommandsFromIOHandler(
@@ -2426,22 +2418,21 @@
 
   Error error;
 
-  for (size_t i = 0; i < argc; i++) {
-    const char *typeA = command.GetArgumentAtIndex(i);
-    ConstString typeCS(typeA);
-    if (typeCS) {
-      if (!AddSynth(typeCS, entry,
-                    m_options.m_regex ? eRegexSynth : eRegularSynth,
-                    m_options.m_category, &error)) {
-        result.AppendError(error.AsCString());
-        result.SetStatus(eReturnStatusFailed);
-        return false;
-      }
-    } else {
+  for (auto &arg_entry : command.entries()) {
+    if (arg_entry.ref.empty()) {
       result.AppendError("empty typenames not allowed");
       result.SetStatus(eReturnStatusFailed);
       return false;
     }
+
+    ConstString typeCS(arg_entry.ref);
+    if (!AddSynth(typeCS, entry,
+                  m_options.m_regex ? eRegexSynth : eRegularSynth,
+                  m_options.m_category, &error)) {
+      result.AppendError(error.AsCString());
+      result.SetStatus(eReturnStatusFailed);
+      return false;
+    }
   }
 
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -2740,22 +2731,21 @@
 
     WarnOnPotentialUnquotedUnsignedType(command, result);
 
-    for (size_t i = 0; i < argc; i++) {
-      const char *typeA = command.GetArgumentAtIndex(i);
-      ConstString typeCS(typeA);
-      if (typeCS) {
-        if (!AddFilter(typeCS, entry,
-                       m_options.m_regex ? eRegexFilter : eRegularFilter,
-                       m_options.m_category, &error)) {
-          result.AppendError(error.AsCString());
-          result.SetStatus(eReturnStatusFailed);
-          return false;
-        }
-      } else {
+    for (auto &arg_entry : command.entries()) {
+      if (arg_entry.ref.empty()) {
         result.AppendError("empty typenames not allowed");
         result.SetStatus(eReturnStatusFailed);
         return false;
       }
+
+      ConstString typeCS(arg_entry.ref);
+      if (!AddFilter(typeCS, entry,
+                     m_options.m_regex ? eRegexFilter : eRegularFilter,
+                     m_options.m_category, &error)) {
+        result.AppendError(error.AsCString());
+        result.SetStatus(eReturnStatusFailed);
+        return false;
+      }
     }
 
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index 342913f..5979130 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -65,7 +65,7 @@
 static const char *RSA[4] = {"-", "to", "To", "TO"};
 
 // Return the index to RSA if found; otherwise -1 is returned.
-static int32_t WithRSAIndex(llvm::StringRef &Arg) {
+static int32_t WithRSAIndex(llvm::StringRef Arg) {
 
   uint32_t i;
   for (i = 0; i < 4; ++i)
@@ -92,24 +92,24 @@
 
   llvm::StringRef Minus("-");
   std::vector<llvm::StringRef> StrRefArgs;
-  std::pair<llvm::StringRef, llvm::StringRef> Pair;
+  llvm::StringRef first;
+  llvm::StringRef second;
   size_t i;
   int32_t idx;
   // Go through the arguments and make a canonical form of arg list containing
   // only numbers with possible "-" in between.
-  for (i = 0; i < args.GetArgumentCount(); ++i) {
-    llvm::StringRef Arg(args.GetArgumentAtIndex(i));
-    if ((idx = WithRSAIndex(Arg)) == -1) {
-      StrRefArgs.push_back(Arg);
+  for (auto &entry : args.entries()) {
+    if ((idx = WithRSAIndex(entry.ref)) == -1) {
+      StrRefArgs.push_back(entry.ref);
       continue;
     }
     // The Arg contains the range specifier, split it, then.
-    Pair = Arg.split(RSA[idx]);
-    if (!Pair.first.empty())
-      StrRefArgs.push_back(Pair.first);
+    std::tie(first, second) = entry.ref.split(RSA[idx]);
+    if (!first.empty())
+      StrRefArgs.push_back(first);
     StrRefArgs.push_back(Minus);
-    if (!Pair.second.empty())
-      StrRefArgs.push_back(Pair.second);
+    if (!second.empty())
+      StrRefArgs.push_back(second);
   }
   // Now process the canonical list and fill in the vector of uint32_t's.
   // If there is any error, return false and the client should ignore wp_ids.