mirror of
https://github.com/intel/llvm.git
synced 2026-01-18 16:50:51 +08:00
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
This commit is contained in:
@@ -19,12 +19,9 @@ using namespace lldb_private;
|
||||
|
||||
// A helper function for argument parsing.
|
||||
// Parses the initial part of the first argument using normal double quote
|
||||
// rules:
|
||||
// backslash escapes the double quote and itself. The parsed string is appended
|
||||
// to the second
|
||||
// argument. The function returns the unparsed portion of the string, starting
|
||||
// at the closing
|
||||
// quote.
|
||||
// rules: backslash escapes the double quote and itself. The parsed string is
|
||||
// appended to the second argument. The function returns the unparsed portion
|
||||
// of the string, starting at the closing quote.
|
||||
static llvm::StringRef ParseDoubleQuotes(llvm::StringRef quoted,
|
||||
std::string &result) {
|
||||
// Inside double quotes, '\' and '"' are special.
|
||||
@@ -49,8 +46,7 @@ static llvm::StringRef ParseDoubleQuotes(llvm::StringRef quoted,
|
||||
}
|
||||
|
||||
// If the character after the backslash is not a whitelisted escapable
|
||||
// character, we
|
||||
// leave the character sequence untouched.
|
||||
// character, we leave the character sequence untouched.
|
||||
if (strchr(k_escapable_characters, quoted.front()) == nullptr)
|
||||
result += '\\';
|
||||
|
||||
@@ -84,10 +80,10 @@ ParseSingleArgument(llvm::StringRef command) {
|
||||
// strings.
|
||||
std::string arg;
|
||||
|
||||
// Since we can have multiple quotes that form a single command
|
||||
// in a command like: "Hello "world'!' (which will make a single
|
||||
// argument "Hello world!") we remember the first quote character
|
||||
// we encounter and use that for the quote character.
|
||||
// Since we can have multiple quotes that form a single command in a command
|
||||
// like: "Hello "world'!' (which will make a single argument "Hello world!")
|
||||
// we remember the first quote character we encounter and use that for the
|
||||
// quote character.
|
||||
char first_quote_char = '\0';
|
||||
|
||||
bool arg_complete = false;
|
||||
@@ -110,8 +106,7 @@ ParseSingleArgument(llvm::StringRef command) {
|
||||
}
|
||||
|
||||
// If the character after the backslash is not a whitelisted escapable
|
||||
// character, we
|
||||
// leave the character sequence untouched.
|
||||
// character, we leave the character sequence untouched.
|
||||
if (strchr(" \t\\'\"`", command.front()) == nullptr)
|
||||
arg += '\\';
|
||||
|
||||
@@ -122,8 +117,8 @@ ParseSingleArgument(llvm::StringRef command) {
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
// We are not inside any quotes, we just found a space after an
|
||||
// argument. We are done.
|
||||
// We are not inside any quotes, we just found a space after an argument.
|
||||
// We are done.
|
||||
arg_complete = true;
|
||||
break;
|
||||
|
||||
@@ -138,8 +133,7 @@ ParseSingleArgument(llvm::StringRef command) {
|
||||
command = ParseDoubleQuotes(command, arg);
|
||||
else {
|
||||
// For single quotes, we simply skip ahead to the matching quote
|
||||
// character
|
||||
// (or the end of the string).
|
||||
// character (or the end of the string).
|
||||
size_t quoted = command.find(special);
|
||||
arg += command.substr(0, quoted);
|
||||
command = command.substr(quoted);
|
||||
@@ -274,9 +268,9 @@ char **Args::GetArgumentVector() {
|
||||
assert(!m_argv.empty());
|
||||
// TODO: functions like execve and posix_spawnp exhibit undefined behavior
|
||||
// when argv or envp is null. So the code below is actually wrong. However,
|
||||
// other code in LLDB depends on it being null. The code has been acting this
|
||||
// way for some time, so it makes sense to leave it this way until someone
|
||||
// has the time to come along and fix it.
|
||||
// other code in LLDB depends on it being null. The code has been acting
|
||||
// this way for some time, so it makes sense to leave it this way until
|
||||
// someone has the time to come along and fix it.
|
||||
return (m_argv.size() > 1) ? m_argv.data() : nullptr;
|
||||
}
|
||||
|
||||
@@ -555,17 +549,17 @@ void Args::EncodeEscapeSequences(const char *src, std::string &dst) {
|
||||
case '0':
|
||||
// 1 to 3 octal chars
|
||||
{
|
||||
// Make a string that can hold onto the initial zero char,
|
||||
// up to 3 octal digits, and a terminating NULL.
|
||||
// Make a string that can hold onto the initial zero char, up to 3
|
||||
// octal digits, and a terminating NULL.
|
||||
char oct_str[5] = {'\0', '\0', '\0', '\0', '\0'};
|
||||
|
||||
int i;
|
||||
for (i = 0; (p[i] >= '0' && p[i] <= '7') && i < 4; ++i)
|
||||
oct_str[i] = p[i];
|
||||
|
||||
// We don't want to consume the last octal character since
|
||||
// the main for loop will do this for us, so we advance p by
|
||||
// one less than i (even if i is zero)
|
||||
// We don't want to consume the last octal character since the main
|
||||
// for loop will do this for us, so we advance p by one less than i
|
||||
// (even if i is zero)
|
||||
p += i - 1;
|
||||
unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
|
||||
if (octal_value <= UINT8_MAX) {
|
||||
@@ -596,8 +590,8 @@ void Args::EncodeEscapeSequences(const char *src, std::string &dst) {
|
||||
break;
|
||||
|
||||
default:
|
||||
// Just desensitize any other character by just printing what
|
||||
// came after the '\'
|
||||
// Just desensitize any other character by just printing what came
|
||||
// after the '\'
|
||||
dst.append(1, *p);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user