Reflow paragraphs in comments.

This is intended as a clean up after the big clang-format commit
(r280751), which unfortunately resulted in many of the comment
paragraphs in LLDB being very hard to read.

FYI, the script I used was:

import textwrap
import commands
import os
import sys
import re
tmp = "%s.tmp"%sys.argv[1]
out = open(tmp, "w+")
with open(sys.argv[1], "r") as f:
  header = ""
  text = ""
  comment = re.compile(r'^( *//) ([^ ].*)$')
  special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$')
  for line in f:
      match = comment.match(line)
      if match and not special.match(match.group(2)):
          # skip intentionally short comments.
          if not text and len(match.group(2)) < 40:
              out.write(line)
              continue

          if text:
              text += " " + match.group(2)
          else:
              header = match.group(1)
              text = match.group(2)

          continue

      if text:
          filled = textwrap.wrap(text, width=(78-len(header)),
                                 break_long_words=False)
          for l in filled:
              out.write(header+" "+l+'\n')
              text = ""

      out.write(line)

os.rename(tmp, sys.argv[1])

Differential Revision: https://reviews.llvm.org/D46144

llvm-svn: 331197
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index ef56a47..eb1d6af 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -681,10 +681,9 @@
           "bt [<digit> | all]", 2, 0, false));
   if (bt_regex_cmd_ap.get()) {
     // accept but don't document "bt -c <number>" -- before bt was a regex
-    // command if you wanted to backtrace
-    // three frames you would do "bt -c 3" but the intention is to have this
-    // emulate the gdb "bt" command and
-    // so now "bt 3" is the preferred form, in line with gdb.
+    // command if you wanted to backtrace three frames you would do "bt -c 3"
+    // but the intention is to have this emulate the gdb "bt" command and so
+    // now "bt 3" is the preferred form, in line with gdb.
     if (bt_regex_cmd_ap->AddRegexCommand("^([[:digit:]]+)$",
                                          "thread backtrace -c %1") &&
         bt_regex_cmd_ap->AddRegexCommand("^-c ([[:digit:]]+)$",
@@ -825,9 +824,8 @@
     unsigned int num_user_matches = 0;
 
     // Look through the command dictionaries one by one, and if we get only one
-    // match from any of
-    // them in toto, then return that, otherwise return an empty CommandObjectSP
-    // and the list of matches.
+    // match from any of them in toto, then return that, otherwise return an
+    // empty CommandObjectSP and the list of matches.
 
     if (HasCommands()) {
       num_cmd_matches =
@@ -953,10 +951,9 @@
     CommandObjectSP cmd_obj_sp = GetCommandSP(llvm::StringRef(cmd_words.GetArgumentAtIndex(0)),
                                               include_aliases, true, nullptr);
     if (cmd_obj_sp.get() != nullptr) {
-      // Loop through the rest of the words in the command (everything passed in
-      // was supposed to be part of a
-      // command name), and find the appropriate sub-command SP for each command
-      // word....
+      // Loop through the rest of the words in the command (everything passed
+      // in was supposed to be part of a command name), and find the
+      // appropriate sub-command SP for each command word....
       size_t end = cmd_words.GetArgumentCount();
       for (size_t j = 1; j < end; ++j) {
         if (cmd_obj_sp->IsMultiwordObject()) {
@@ -986,8 +983,7 @@
       GetCommandSP(cmd_str, false, true, matches).get();
 
   // If we didn't find an exact match to the command string in the commands,
-  // look in
-  // the aliases.
+  // look in the aliases.
 
   if (command_obj)
     return command_obj;
@@ -1002,8 +998,7 @@
   command_obj = GetCommandSP(cmd_str, false, false, nullptr).get();
 
   // Finally, if there wasn't an inexact match among the commands, look for an
-  // inexact
-  // match in both the commands and aliases.
+  // inexact match in both the commands and aliases.
 
   if (command_obj) {
     if (matches)
@@ -1166,8 +1161,8 @@
 CommandObject *CommandInterpreter::GetCommandObjectForCommand(
     llvm::StringRef &command_string) {
   // This function finds the final, lowest-level, alias-resolved command object
-  // whose 'Execute' function will
-  // eventually be invoked by the given command line.
+  // whose 'Execute' function will eventually be invoked by the given command
+  // line.
 
   CommandObject *cmd_obj = nullptr;
   size_t start = command_string.find_first_not_of(k_white_space);
@@ -1238,8 +1233,8 @@
       break;
     if (pos > 0) {
       if (isspace(s[pos - 1])) {
-        // Check if the string ends "\s--" (where \s is a space character)
-        // or if we have "\s--\s".
+        // Check if the string ends "\s--" (where \s is a space character) or
+        // if we have "\s--\s".
         if ((pos + 2 >= s_len) || isspace(s[pos + 2])) {
           return pos;
         }
@@ -1374,20 +1369,19 @@
 }
 
 Status CommandInterpreter::PreprocessCommand(std::string &command) {
-  // The command preprocessor needs to do things to the command
-  // line before any parsing of arguments or anything else is done.
-  // The only current stuff that gets preprocessed is anything enclosed
-  // in backtick ('`') characters is evaluated as an expression and
-  // the result of the expression must be a scalar that can be substituted
-  // into the command. An example would be:
+  // The command preprocessor needs to do things to the command line before any
+  // parsing of arguments or anything else is done. The only current stuff that
+  // gets preprocessed is anything enclosed in backtick ('`') characters is
+  // evaluated as an expression and the result of the expression must be a
+  // scalar that can be substituted into the command. An example would be:
   // (lldb) memory read `$rsp + 20`
   Status error; // Status for any expressions that might not evaluate
   size_t start_backtick;
   size_t pos = 0;
   while ((start_backtick = command.find('`', pos)) != std::string::npos) {
     if (start_backtick > 0 && command[start_backtick - 1] == '\\') {
-      // The backtick was preceded by a '\' character, remove the slash
-      // and don't treat the backtick as the start of an expression
+      // The backtick was preceded by a '\' character, remove the slash and
+      // don't treat the backtick as the start of an expression
       command.erase(start_backtick - 1, 1);
       // No need to add one to start_backtick since we just deleted a char
       pos = start_backtick;
@@ -1406,8 +1400,8 @@
         ExecutionContext exe_ctx(GetExecutionContext());
         Target *target = exe_ctx.GetTargetPtr();
         // Get a dummy target to allow for calculator mode while processing
-        // backticks.
-        // This also helps break the infinite loop caused when target is null.
+        // backticks. This also helps break the infinite loop caused when
+        // target is null.
         if (!target)
           target = m_debugger.GetDummyTarget();
         if (target) {
@@ -1559,8 +1553,8 @@
     const char *k_space_characters = "\t\n\v\f\r ";
 
     size_t non_space = command_string.find_first_not_of(k_space_characters);
-    // Check for empty line or comment line (lines whose first
-    // non-space character is the comment character for this interpreter)
+    // Check for empty line or comment line (lines whose first non-space
+    // character is the comment character for this interpreter)
     if (non_space == std::string::npos)
       empty_command = true;
     else if (command_string[non_space] == m_comment_char)
@@ -1633,8 +1627,8 @@
   CommandObject *cmd_obj = ResolveCommandImpl(command_string, result);
 
   // Although the user may have abbreviated the command, the command_string now
-  // has the command expanded to the full name.  For example, if the input
-  // was "br s -n main", command_string is now "breakpoint set -n main".
+  // has the command expanded to the full name.  For example, if the input was
+  // "br s -n main", command_string is now "breakpoint set -n main".
   if (log) {
     llvm::StringRef command_name = cmd_obj ? cmd_obj->GetCommandName() : "<not found>";
     log->Printf("HandleCommand, cmd_obj : '%s'", command_name.str().c_str());
@@ -1648,8 +1642,8 @@
 
   // Phase 2.
   // Take care of things like setting up the history command & calling the
-  // appropriate Execute method on the
-  // CommandObject, with the appropriate arguments.
+  // appropriate Execute method on the CommandObject, with the appropriate
+  // arguments.
 
   if (cmd_obj != nullptr) {
     if (add_to_history) {
@@ -1759,9 +1753,8 @@
 
   if (cursor_index > 0 || look_for_subcommand) {
     // We are completing further on into a commands arguments, so find the
-    // command and tell it
-    // to complete the command.
-    // First see if there is a matching initial command:
+    // command and tell it to complete the command. First see if there is a
+    // matching initial command:
     CommandObject *command_object =
         GetCommandObject(parsed_line.GetArgumentAtIndex(0));
     if (command_object == nullptr) {
@@ -1781,17 +1774,16 @@
 int CommandInterpreter::HandleCompletion(
     const char *current_line, const char *cursor, const char *last_char,
     int match_start_point, int max_return_elements, StringList &matches) {
-  // We parse the argument up to the cursor, so the last argument in parsed_line
-  // is
-  // the one containing the cursor, and the cursor is after the last character.
+  // We parse the argument up to the cursor, so the last argument in
+  // parsed_line is the one containing the cursor, and the cursor is after the
+  // last character.
 
   Args parsed_line(llvm::StringRef(current_line, last_char - current_line));
   Args partial_parsed_line(
       llvm::StringRef(current_line, cursor - current_line));
 
   // Don't complete comments, and if the line we are completing is just the
-  // history repeat character,
-  // substitute the appropriate history line.
+  // history repeat character, substitute the appropriate history line.
   const char *first_arg = parsed_line.GetArgumentAtIndex(0);
   if (first_arg) {
     if (first_arg[0] == m_comment_char)
@@ -1818,12 +1810,9 @@
 
   if (cursor > current_line && cursor[-1] == ' ') {
     // We are just after a space.  If we are in an argument, then we will
-    // continue
-    // parsing, but if we are between arguments, then we have to complete
-    // whatever the next
-    // element would be.
-    // We can distinguish the two cases because if we are in an argument (e.g.
-    // because the space is
+    // continue parsing, but if we are between arguments, then we have to
+    // complete whatever the next element would be. We can distinguish the two
+    // cases because if we are in an argument (e.g. because the space is
     // protected by a quote) then the space will also be in the parsed
     // argument...
 
@@ -1857,8 +1846,7 @@
     matches.InsertStringAtIndex(0, "");
   } else {
     // Now figure out if there is a common substring, and if so put that in
-    // element 0, otherwise
-    // put an empty string in element 0.
+    // element 0, otherwise put an empty string in element 0.
     std::string command_partial_str;
     if (cursor_index >= 0)
       command_partial_str =
@@ -1869,9 +1857,8 @@
     const size_t partial_name_len = command_partial_str.size();
     common_prefix.erase(0, partial_name_len);
 
-    // If we matched a unique single command, add a space...
-    // Only do this if the completer told us this was a complete word,
-    // however...
+    // If we matched a unique single command, add a space... Only do this if
+    // the completer told us this was a complete word, however...
     if (num_command_matches == 1 && word_complete) {
       char quote_char = parsed_line[cursor_index].quote;
       common_prefix =
@@ -1949,8 +1936,8 @@
   if (option_arg_vector_sp.get()) {
     if (wants_raw_input) {
       // We have a command that both has command options and takes raw input.
-      // Make *sure* it has a
-      // " -- " in the right place in the raw_input_string.
+      // Make *sure* it has a " -- " in the right place in the
+      // raw_input_string.
       size_t pos = raw_input_string.find(" -- ");
       if (pos == std::string::npos) {
         // None found; assume it goes at the beginning of the raw input string
@@ -2034,10 +2021,9 @@
   } else {
     result.SetStatus(eReturnStatusSuccessFinishNoResult);
     // This alias was not created with any options; nothing further needs to be
-    // done, unless it is a command that
-    // wants raw input, in which case we need to clear the rest of the data from
-    // cmd_args, since its in the raw
-    // input string.
+    // done, unless it is a command that wants raw input, in which case we need
+    // to clear the rest of the data from cmd_args, since its in the raw input
+    // string.
     if (wants_raw_input) {
       cmd_args.Clear();
       cmd_args.SetArguments(new_args.GetArgumentCount(),
@@ -2067,7 +2053,8 @@
       while (isdigit(cptr[0]))
         ++cptr;
 
-      // We've gotten to the end of the digits; are we at the end of the string?
+      // We've gotten to the end of the digits; are we at the end of the
+      // string?
       if (cptr[0] == '\0')
         position = atoi(start);
     }
@@ -2119,12 +2106,12 @@
       }
     }
   } else {
-    // If we aren't looking in the current working directory we are looking
-    // in the home directory. We will first see if there is an application
-    // specific ".lldbinit" file whose name is "~/.lldbinit" followed by a
-    // "-" and the name of the program. If this file doesn't exist, we fall
-    // back to just the "~/.lldbinit" file. We also obey any requests to not
-    // load the init files.
+    // If we aren't looking in the current working directory we are looking in
+    // the home directory. We will first see if there is an application
+    // specific ".lldbinit" file whose name is "~/.lldbinit" followed by a "-"
+    // and the name of the program. If this file doesn't exist, we fall back to
+    // just the "~/.lldbinit" file. We also obey any requests to not load the
+    // init files.
     llvm::SmallString<64> home_dir_path;
     llvm::sys::path::home_directory(home_dir_path);
     FileSpec profilePath(home_dir_path.c_str(), false);
@@ -2150,8 +2137,7 @@
   }
 
   // If the file exists, tell HandleCommand to 'source' it; this will do the
-  // actual broadcasting
-  // of the commands back to any appropriate listener (see
+  // actual broadcasting of the commands back to any appropriate listener (see
   // CommandObjectSource::Execute for more details).
 
   if (init_file.Exists()) {
@@ -2197,15 +2183,14 @@
   size_t num_lines = commands.GetSize();
 
   // If we are going to continue past a "continue" then we need to run the
-  // commands synchronously.
-  // Make sure you reset this value anywhere you return from the function.
+  // commands synchronously. Make sure you reset this value anywhere you return
+  // from the function.
 
   bool old_async_execution = m_debugger.GetAsyncExecution();
 
   // If we've been given an execution context, set it at the start, but don't
-  // keep resetting it or we will
-  // cause series of commands that change the context, then do an operation that
-  // relies on that context to fail.
+  // keep resetting it or we will cause series of commands that change the
+  // context, then do an operation that relies on that context to fail.
 
   if (override_context != nullptr)
     UpdateExecutionContext(override_context);
@@ -2230,9 +2215,8 @@
     // HandleCommand() since we updated our context already.
 
     // We might call into a regex or alias command, in which case the
-    // add_to_history will get lost.  This
-    // m_command_source_depth dingus is the way we turn off adding to the
-    // history in that case, so set it up here.
+    // add_to_history will get lost.  This m_command_source_depth dingus is the
+    // way we turn off adding to the history in that case, so set it up here.
     if (!options.GetAddToHistory())
       m_command_source_depth++;
     bool success =
@@ -2273,18 +2257,17 @@
     if (result.GetImmediateErrorStream())
       result.GetImmediateErrorStream()->Flush();
 
-    // N.B. Can't depend on DidChangeProcessState, because the state coming into
-    // the command execution
-    // could be running (for instance in Breakpoint Commands.
-    // So we check the return value to see if it is has running in it.
+    // N.B. Can't depend on DidChangeProcessState, because the state coming
+    // into the command execution could be running (for instance in Breakpoint
+    // Commands. So we check the return value to see if it is has running in
+    // it.
     if ((tmp_result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
         (tmp_result.GetStatus() == eReturnStatusSuccessContinuingResult)) {
       if (options.GetStopOnContinue()) {
         // If we caused the target to proceed, and we're going to stop in that
-        // case, set the
-        // status in our real result before returning.  This is an error if the
-        // continue was not the
-        // last command in the set of commands to be run.
+        // case, set the status in our real result before returning.  This is
+        // an error if the continue was not the last command in the set of
+        // commands to be run.
         if (idx != num_lines - 1)
           result.AppendErrorWithFormat(
               "Aborting reading of commands after command #%" PRIu64
@@ -2432,8 +2415,8 @@
                                          cmd_file_path.c_str());
       }
 
-      // Used for inheriting the right settings when "command source" might have
-      // nested "command source" commands
+      // Used for inheriting the right settings when "command source" might
+      // have nested "command source" commands
       lldb::StreamFileSP empty_stream_sp;
       m_command_source_flags.push_back(flags);
       IOHandlerSP io_handler_sp(new IOHandlerEditline(
@@ -2746,18 +2729,14 @@
   if (is_interactive == false) {
     // When we are not interactive, don't execute blank lines. This will happen
     // sourcing a commands file. We don't want blank lines to repeat the
-    // previous
-    // command and cause any errors to occur (like redefining an alias, get an
-    // error
-    // and stop parsing the commands file).
+    // previous command and cause any errors to occur (like redefining an
+    // alias, get an error and stop parsing the commands file).
     if (line.empty())
       return;
 
     // When using a non-interactive file handle (like when sourcing commands
-    // from a file)
-    // we need to echo the command out so we don't just see the command output
-    // and no
-    // command...
+    // from a file) we need to echo the command out so we don't just see the
+    // command output and no command...
     if (io_handler.GetFlags().Test(eHandleCommandFlagEchoCommand))
       io_handler.GetOutputStreamFile()->Printf("%s%s\n", io_handler.GetPrompt(),
                                                line.c_str());
@@ -2914,13 +2893,13 @@
 lldb::IOHandlerSP
 CommandInterpreter::GetIOHandler(bool force_create,
                                  CommandInterpreterRunOptions *options) {
-  // Always re-create the IOHandlerEditline in case the input
-  // changed. The old instance might have had a non-interactive
-  // input and now it does or vice versa.
+  // Always re-create the IOHandlerEditline in case the input changed. The old
+  // instance might have had a non-interactive input and now it does or vice
+  // versa.
   if (force_create || !m_command_io_handler_sp) {
-    // Always re-create the IOHandlerEditline in case the input
-    // changed. The old instance might have had a non-interactive
-    // input and now it does or vice versa.
+    // Always re-create the IOHandlerEditline in case the input changed. The
+    // old instance might have had a non-interactive input and now it does or
+    // vice versa.
     uint32_t flags = 0;
 
     if (options) {
@@ -2954,8 +2933,8 @@
 void CommandInterpreter::RunCommandInterpreter(
     bool auto_handle_events, bool spawn_thread,
     CommandInterpreterRunOptions &options) {
-  // Always re-create the command interpreter when we run it in case
-  // any file handles have changed.
+  // Always re-create the command interpreter when we run it in case any file
+  // handles have changed.
   bool force_create = true;
   m_debugger.PushIOHandler(GetIOHandler(force_create, &options));
   m_stopped_for_crash = false;
@@ -3023,8 +3002,8 @@
         CommandObject *sub_cmd_obj =
             cmd_obj->GetSubcommandObject(next_word.c_str());
         if (sub_cmd_obj) {
-          // The subcommand's name includes the parent command's name,
-          // so restart rather than append to the revised_command_line.
+          // The subcommand's name includes the parent command's name, so
+          // restart rather than append to the revised_command_line.
           llvm::StringRef sub_cmd_name = sub_cmd_obj->GetCommandName();
           actual_cmd_name_len = sub_cmd_name.size() + 1;
           revised_command_line.Clear();