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:
@@ -123,21 +123,20 @@ PythonObject::ResolveNameWithDictionary(llvm::StringRef name,
|
||||
}
|
||||
|
||||
PythonObject PythonObject::ResolveName(llvm::StringRef name) const {
|
||||
// Resolve the name in the context of the specified object. If,
|
||||
// for example, `this` refers to a PyModule, then this will look for
|
||||
// `name` in this module. If `this` refers to a PyType, then it will
|
||||
// resolve `name` as an attribute of that type. If `this` refers to
|
||||
// an instance of an object, then it will resolve `name` as the value
|
||||
// of the specified field.
|
||||
// Resolve the name in the context of the specified object. If, for example,
|
||||
// `this` refers to a PyModule, then this will look for `name` in this
|
||||
// module. If `this` refers to a PyType, then it will resolve `name` as an
|
||||
// attribute of that type. If `this` refers to an instance of an object,
|
||||
// then it will resolve `name` as the value of the specified field.
|
||||
//
|
||||
// This function handles dotted names so that, for example, if `m_py_obj`
|
||||
// refers to the `sys` module, and `name` == "path.append", then it
|
||||
// will find the function `sys.path.append`.
|
||||
// refers to the `sys` module, and `name` == "path.append", then it will find
|
||||
// the function `sys.path.append`.
|
||||
|
||||
size_t dot_pos = name.find_first_of('.');
|
||||
if (dot_pos == llvm::StringRef::npos) {
|
||||
// No dots in the name, we should be able to find the value immediately
|
||||
// as an attribute of `m_py_obj`.
|
||||
// No dots in the name, we should be able to find the value immediately as
|
||||
// an attribute of `m_py_obj`.
|
||||
return GetAttributeValue(name);
|
||||
}
|
||||
|
||||
@@ -230,8 +229,8 @@ bool PythonBytes::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonBytes::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonBytes::Check(py_obj)) {
|
||||
@@ -240,8 +239,7 @@ void PythonBytes::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -303,8 +301,8 @@ bool PythonByteArray::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonByteArray::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonByteArray::Check(py_obj)) {
|
||||
@@ -313,8 +311,7 @@ void PythonByteArray::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -378,8 +375,8 @@ bool PythonString::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonString::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonString::Check(py_obj)) {
|
||||
@@ -394,8 +391,7 @@ void PythonString::Reset(PyRefType type, PyObject *py_obj) {
|
||||
result.Reset(PyRefType::Owned, PyUnicode_AsUTF8String(result.get()));
|
||||
#endif
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -466,8 +462,8 @@ bool PythonInteger::Check(PyObject *py_obj) {
|
||||
return false;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
// Python 3 does not have PyInt_Check. There is only one type of
|
||||
// integral value, long.
|
||||
// Python 3 does not have PyInt_Check. There is only one type of integral
|
||||
// value, long.
|
||||
return PyLong_Check(py_obj);
|
||||
#else
|
||||
return PyLong_Check(py_obj) || PyInt_Check(py_obj);
|
||||
@@ -475,8 +471,8 @@ bool PythonInteger::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonInteger::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonInteger::Check(py_obj)) {
|
||||
@@ -485,13 +481,13 @@ void PythonInteger::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
// Always store this as a PyLong, which makes interoperability between
|
||||
// Python 2.x and Python 3.x easier. This is only necessary in 2.x,
|
||||
// since 3.x doesn't even have a PyInt.
|
||||
// Always store this as a PyLong, which makes interoperability between Python
|
||||
// 2.x and Python 3.x easier. This is only necessary in 2.x, since 3.x
|
||||
// doesn't even have a PyInt.
|
||||
if (PyInt_Check(py_obj)) {
|
||||
// Since we converted the original object to a different type, the new
|
||||
// object is an owned object regardless of the ownership semantics requested
|
||||
// by the user.
|
||||
// object is an owned object regardless of the ownership semantics
|
||||
// requested by the user.
|
||||
result.Reset(PyRefType::Owned, PyLong_FromLongLong(PyInt_AsLong(py_obj)));
|
||||
}
|
||||
#endif
|
||||
@@ -500,8 +496,7 @@ void PythonInteger::Reset(PyRefType type, PyObject *py_obj) {
|
||||
"Couldn't get a PyLong from this PyObject");
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -513,10 +508,9 @@ int64_t PythonInteger::GetInteger() const {
|
||||
int overflow = 0;
|
||||
int64_t result = PyLong_AsLongLongAndOverflow(m_py_obj, &overflow);
|
||||
if (overflow != 0) {
|
||||
// We got an integer that overflows, like 18446744072853913392L
|
||||
// we can't use PyLong_AsLongLong() as it will return
|
||||
// 0xffffffffffffffff. If we use the unsigned long long
|
||||
// it will work as expected.
|
||||
// We got an integer that overflows, like 18446744072853913392L we can't
|
||||
// use PyLong_AsLongLong() as it will return 0xffffffffffffffff. If we
|
||||
// use the unsigned long long it will work as expected.
|
||||
const uint64_t uval = PyLong_AsUnsignedLongLong(m_py_obj);
|
||||
result = static_cast<int64_t>(uval);
|
||||
}
|
||||
@@ -563,8 +557,8 @@ bool PythonList::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonList::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonList::Check(py_obj)) {
|
||||
@@ -573,8 +567,7 @@ void PythonList::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -668,8 +661,8 @@ bool PythonTuple::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonTuple::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonTuple::Check(py_obj)) {
|
||||
@@ -678,8 +671,7 @@ void PythonTuple::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -741,8 +733,8 @@ bool PythonDictionary::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonDictionary::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonDictionary::Check(py_obj)) {
|
||||
@@ -751,8 +743,7 @@ void PythonDictionary::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -833,8 +824,8 @@ bool PythonModule::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonModule::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonModule::Check(py_obj)) {
|
||||
@@ -843,8 +834,7 @@ void PythonModule::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -871,8 +861,8 @@ bool PythonCallable::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonCallable::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonCallable::Check(py_obj)) {
|
||||
@@ -881,8 +871,7 @@ void PythonCallable::Reset(PyRefType type, PyObject *py_obj) {
|
||||
}
|
||||
|
||||
// Calling PythonObject::Reset(const PythonObject&) will lead to stack
|
||||
// overflow since it calls
|
||||
// back into the virtual implementation.
|
||||
// overflow since it calls back into the virtual implementation.
|
||||
PythonObject::Reset(PyRefType::Borrowed, result.get());
|
||||
}
|
||||
|
||||
@@ -963,9 +952,9 @@ bool PythonFile::Check(PyObject *py_obj) {
|
||||
#else
|
||||
// In Python 3, there is no `PyFile_Check`, and in fact PyFile is not even a
|
||||
// first-class object type anymore. `PyFile_FromFd` is just a thin wrapper
|
||||
// over `io.open()`, which returns some object derived from `io.IOBase`.
|
||||
// As a result, the only way to detect a file in Python 3 is to check whether
|
||||
// it inherits from `io.IOBase`. Since it is possible for non-files to also
|
||||
// over `io.open()`, which returns some object derived from `io.IOBase`. As a
|
||||
// result, the only way to detect a file in Python 3 is to check whether it
|
||||
// inherits from `io.IOBase`. Since it is possible for non-files to also
|
||||
// inherit from `io.IOBase`, we additionally verify that it has the `fileno`
|
||||
// attribute, which should guarantee that it is backed by the file system.
|
||||
PythonObject io_module(PyRefType::Owned, PyImport_ImportModule("io"));
|
||||
@@ -985,8 +974,8 @@ bool PythonFile::Check(PyObject *py_obj) {
|
||||
}
|
||||
|
||||
void PythonFile::Reset(PyRefType type, PyObject *py_obj) {
|
||||
// Grab the desired reference type so that if we end up rejecting
|
||||
// `py_obj` it still gets decremented if necessary.
|
||||
// Grab the desired reference type so that if we end up rejecting `py_obj` it
|
||||
// still gets decremented if necessary.
|
||||
PythonObject result(type, py_obj);
|
||||
|
||||
if (!PythonFile::Check(py_obj)) {
|
||||
|
||||
Reference in New Issue
Block a user