[Lldb-commits] [lldb] r283413 - Convert some Args index-based iteration to range-style iteration.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 5 16:40:24 PDT 2016


Author: zturner
Date: Wed Oct  5 18:40:23 2016
New Revision: 283413

URL: http://llvm.org/viewvc/llvm-project?rev=283413&view=rev
Log:
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.

Modified:
    lldb/trunk/include/lldb/Core/Mangled.h
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Commands/CommandObjectHelp.cpp
    lldb/trunk/source/Commands/CommandObjectPlatform.cpp
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Commands/CommandObjectSettings.cpp
    lldb/trunk/source/Commands/CommandObjectSyntax.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Commands/CommandObjectThread.cpp
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/source/Core/Mangled.cpp
    lldb/trunk/source/Host/linux/ProcessLauncherLinux.cpp
    lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp
    lldb/trunk/source/Interpreter/CommandAlias.cpp
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp
    lldb/trunk/source/Interpreter/CommandObject.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp

Modified: lldb/trunk/include/lldb/Core/Mangled.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Mangled.h?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Mangled.h (original)
+++ lldb/trunk/include/lldb/Core/Mangled.h Wed Oct  5 18:40:23 2016
@@ -63,7 +63,8 @@ public:
   ///     If \b true then \a name is a mangled name, if \b false then
   ///     \a name is demangled.
   //----------------------------------------------------------------------
-  explicit Mangled(const ConstString &name, bool is_mangled);
+  Mangled(const ConstString &name, bool is_mangled);
+  Mangled(llvm::StringRef name, bool is_mangled);
 
   //----------------------------------------------------------------------
   /// Construct with name.
@@ -76,6 +77,8 @@ public:
   //----------------------------------------------------------------------
   explicit Mangled(const ConstString &name);
 
+  explicit Mangled(llvm::StringRef name);
+
   //----------------------------------------------------------------------
   /// Destructor
   ///

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Wed Oct  5 18:40:23 2016
@@ -1096,10 +1096,9 @@ protected:
         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;
       }

Modified: lldb/trunk/source/Commands/CommandObjectHelp.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectHelp.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectHelp.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectHelp.cpp Wed Oct  5 18:40:23 2016
@@ -114,26 +114,25 @@ bool CommandObjectHelp::DoExecute(Args &
       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;
         }
       }

Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Wed Oct  5 18:40:23 2016
@@ -1453,12 +1453,14 @@ protected:
 
         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 @@ protected:
                              pid);
               }
               ostrm.EOL();
-            } else {
-              result.AppendErrorWithFormat("invalid process ID argument '%s'",
-                                           arg);
-              result.SetStatus(eReturnStatusFailed);
-              break;
             }
           }
         } else {

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Oct  5 18:40:23 2016
@@ -1037,11 +1037,10 @@ protected:
   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 @@ protected:
 
       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 @@ protected:
   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 {

Modified: lldb/trunk/source/Commands/CommandObjectSettings.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSettings.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSettings.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSettings.cpp Wed Oct  5 18:40:23 2016
@@ -294,7 +294,9 @@ protected:
     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 @@ protected:
     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);
 

Modified: lldb/trunk/source/Commands/CommandObjectSyntax.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSyntax.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSyntax.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSyntax.cpp Wed Oct  5 18:40:23 2016
@@ -57,6 +57,8 @@ bool CommandObjectSyntax::DoExecute(Args
   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()) {

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Oct  5 18:40:23 2016
@@ -569,14 +569,11 @@ protected:
         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 @@ protected:
 
     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 @@ protected:
           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 @@ protected:
           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 @@ protected:
       } 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 @@ protected:
               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;
             }
           }

Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Wed Oct  5 18:40:23 2016
@@ -770,28 +770,22 @@ public:
             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();
+        for (auto &entry : command.entries()) {
+          uint32_t thread_idx;
+          if (entry.ref.getAsInteger(0, thread_idx)) {
+            result.AppendErrorWithFormat(
+                "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;
-            }
+          if (thread) {
+            resume_threads.push_back(thread);
           } else {
-            result.AppendErrorWithFormat(
-                "invalid thread index argument: \"%s\".\n",
-                command.GetArgumentAtIndex(i));
+            result.AppendErrorWithFormat("invalid thread index %u.\n",
+                                         thread_idx);
             result.SetStatus(eReturnStatusFailed);
             return false;
           }

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Wed Oct  5 18:40:23 2016
@@ -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 @@ public:
 
 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 @@ protected:
 
     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 @@ bool CommandObjectTypeSummaryAdd::Execut
         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 @@ bool CommandObjectTypeSummaryAdd::Execut
 
   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 @@ bool CommandObjectTypeSummaryAdd::Execut
 
   // 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 @@ protected:
       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 @@ bool CommandObjectTypeSynthAdd::Execute_
       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 @@ bool CommandObjectTypeSynthAdd::Execute_
 
   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 @@ protected:
 
     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);

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Wed Oct  5 18:40:23 2016
@@ -65,7 +65,7 @@ static bool CheckTargetForWatchpointOper
 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 @@ bool CommandObjectMultiwordWatchpoint::V
 
   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.

Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Wed Oct  5 18:40:23 2016
@@ -124,11 +124,21 @@ Mangled::Mangled(const ConstString &s, b
     SetValue(s, mangled);
 }
 
+Mangled::Mangled(llvm::StringRef name, bool is_mangled) {
+  if (!name.empty())
+    SetValue(ConstString(name), is_mangled);
+}
+
 Mangled::Mangled(const ConstString &s) : m_mangled(), m_demangled() {
   if (s)
     SetValue(s);
 }
 
+Mangled::Mangled(llvm::StringRef name) {
+  if (!name.empty())
+    SetValue(ConstString(name));
+}
+
 //----------------------------------------------------------------------
 // Destructor
 //----------------------------------------------------------------------

Modified: lldb/trunk/source/Host/linux/ProcessLauncherLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/ProcessLauncherLinux.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/ProcessLauncherLinux.cpp (original)
+++ lldb/trunk/source/Host/linux/ProcessLauncherLinux.cpp Wed Oct  5 18:40:23 2016
@@ -31,10 +31,8 @@ static void FixupEnvironment(Args &env)
   // path to /system/bin. It is required because the default path used by
   // execve() is wrong on android.
   static const char *path = "PATH=";
-  static const int path_len = ::strlen(path);
-  for (size_t i = 0; i < env.GetArgumentCount(); ++i) {
-    const char *arg = env.GetArgumentAtIndex(i);
-    if (::strncmp(path, arg, path_len) == 0)
+  for (auto &entry : entries) {
+    if (entry.ref.startswith(path))
       return;
   }
   env.AppendArgument(llvm::StringRef("PATH=/system/bin"));

Modified: lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp (original)
+++ lldb/trunk/source/Host/windows/ProcessLauncherWindows.cpp Wed Oct  5 18:40:23 2016
@@ -26,9 +26,9 @@ void CreateEnvironmentBuffer(const Args
     return;
 
   // Environment buffer is a null terminated list of null terminated strings
-  for (size_t i = 0; i < env.GetArgumentCount(); ++i) {
+  for (auto &entry : env.entries()) {
     std::wstring warg;
-    if (llvm::ConvertUTF8toWide(env.GetArgumentAtIndex(i), warg)) {
+    if (llvm::ConvertUTF8toWide(entry.ref, warg)) {
       buffer.insert(buffer.end(), (char *)warg.c_str(),
                     (char *)(warg.c_str() + warg.size() + 1));
     }

Modified: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Wed Oct  5 18:40:23 2016
@@ -57,11 +57,10 @@ static bool ProcessAliasOptionsArgs(lldb
     if (cmd_obj_sp->WantsRawCommandString())
       option_arg_vector->emplace_back("<argument>", -1, options_string);
     else {
-      const size_t argc = args.GetArgumentCount();
-      for (size_t i = 0; i < argc; ++i)
-        if (strcmp(args.GetArgumentAtIndex(i), "") != 0)
-          option_arg_vector->emplace_back("<argument>", -1,
-                                          args.GetArgumentAtIndex(i));
+      for (auto &entry : args.entries()) {
+        if (!entry.ref.empty())
+          option_arg_vector->emplace_back("<argument>", -1, entry.ref);
+      }
     }
   }
 

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Wed Oct  5 18:40:23 2016
@@ -2023,9 +2023,9 @@ void CommandInterpreter::BuildAliasComma
       }
     }
 
-    for (size_t j = 0; j < cmd_args.GetArgumentCount(); ++j) {
-      if (!used[j] && !wants_raw_input)
-        new_args.AppendArgument(cmd_args.GetArgumentAtIndex(j));
+    for (auto entry : llvm::enumerate(cmd_args.entries())) {
+      if (!used[entry.Index] && !wants_raw_input)
+        new_args.AppendArgument(entry.Value.ref);
     }
 
     cmd_args.Clear();

Modified: lldb/trunk/source/Interpreter/CommandObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandObject.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandObject.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandObject.cpp Wed Oct  5 18:40:23 2016
@@ -993,12 +993,12 @@ bool CommandObjectParsed::Execute(const
         InvokeOverrideCallback(full_args.GetConstArgumentVector(), result);
   }
   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
+    for (auto entry : llvm::enumerate(cmd_args.entries())) {
+      if (entry.Value.ref.front() == '`') {
         cmd_args.ReplaceArgumentAtIndex(
-            i, llvm::StringRef::withNullAsEmpty(
-                   m_interpreter.ProcessEmbeddedScriptCommands(tmp_str)));
+            entry.Index,
+            m_interpreter.ProcessEmbeddedScriptCommands(entry.Value.c_str()));
+      }
     }
 
     if (CheckRequirements(result)) {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=283413&r1=283412&r2=283413&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Wed Oct  5 18:40:23 2016
@@ -362,32 +362,30 @@ protected:
   bool DoExecute(Args &command, CommandReturnObject &result) override {
     bool demangled_any = false;
     bool error_any = false;
-    for (size_t i = 0; i < command.GetArgumentCount(); i++) {
-      auto arg = command.GetArgumentAtIndex(i);
-      if (arg && *arg) {
-        ConstString mangled_cs(arg);
+    for (auto &entry : command.entries()) {
+      if (entry.ref.empty())
+        continue;
 
-        // the actual Mangled class should be strict about this, but on the
-        // command line
-        // if you're copying mangled names out of 'nm' on Darwin, they will come
-        // out with
-        // an extra underscore - be willing to strip this on behalf of the user
-        // This is the moral equivalent of the -_/-n options to c++filt
-        if (mangled_cs.GetStringRef().startswith("__Z"))
-          mangled_cs.SetCString(arg + 1);
+      // the actual Mangled class should be strict about this, but on the
+      // command line if you're copying mangled names out of 'nm' on Darwin,
+      // they will come out with an extra underscore - be willing to strip
+      // this on behalf of the user.   This is the moral equivalent of the -_/-n
+      // options to c++filt
+      auto name = entry.ref;
+      if (name.startswith("__Z"))
+        name = name.drop_front();
 
-        Mangled mangled(mangled_cs, true);
-        if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus) {
-          ConstString demangled(
-              mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus));
-          demangled_any = true;
-          result.AppendMessageWithFormat("%s ---> %s\n", arg,
-                                         demangled.GetCString());
-        } else {
-          error_any = true;
-          result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n",
-                                       arg);
-        }
+      Mangled mangled(name, true);
+      if (mangled.GuessLanguage() == lldb::eLanguageTypeC_plus_plus) {
+        ConstString demangled(
+            mangled.GetDisplayDemangledName(lldb::eLanguageTypeC_plus_plus));
+        demangled_any = true;
+        result.AppendMessageWithFormat("%s ---> %s\n", entry.ref.str().c_str(),
+                                       demangled.GetCString());
+      } else {
+        error_any = true;
+        result.AppendErrorWithFormat("%s is not a valid C++ mangled name\n",
+                                     entry.ref.str().c_str());
       }
     }
 




More information about the lldb-commits mailing list