forked from OSchip/llvm-project
[lldb] (Semi-automatically) format .swig files
I've found my recent ventures into the swig land painful because of the strange way they are formatted. This patch attempts to alleviate future headaches by formatting these files into something resembling the normal llvm style. Unfortunately, completely formatting these files automatically does not work because clang format gets confused by swigs % syntax, so I have employed a hybrid approach where I formatted blocks of c++ code with clang-format and then manually massaged the code until it looked reasonable (and compiled). I don't expect these files to remain perfectly formatted (although, if one's editor is configured to configure the current line/block on request, one can get pretty good results by using it judiciously), but at least it will prevent the (mangled form of the) old lldb style being proliferated endlessly. Differential Revision: https://reviews.llvm.org/D115736
This commit is contained in:
parent
5b139a583d
commit
9d5e37ed8c
|
@ -1,27 +1,20 @@
|
||||||
template <typename SBClass>
|
template <typename SBClass> void PushSBClass(lua_State *L, SBClass *obj);
|
||||||
void
|
|
||||||
PushSBClass (lua_State* L, SBClass* obj);
|
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBFrame *frame_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBFrame* frame_sb)
|
|
||||||
{
|
|
||||||
SWIG_NewPointerObj(L, frame_sb, SWIGTYPE_p_lldb__SBFrame, 0);
|
SWIG_NewPointerObj(L, frame_sb, SWIGTYPE_p_lldb__SBFrame, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L,
|
||||||
PushSBClass (lua_State* L, lldb::SBBreakpointLocation* breakpoint_location_sb)
|
lldb::SBBreakpointLocation *breakpoint_location_sb) {
|
||||||
{
|
SWIG_NewPointerObj(L, breakpoint_location_sb,
|
||||||
SWIG_NewPointerObj(L, breakpoint_location_sb, SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
|
SWIGTYPE_p_lldb__SBBreakpointLocation, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBWatchpoint *watchpoint_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBWatchpoint* watchpoint_sb)
|
|
||||||
{
|
|
||||||
SWIG_NewPointerObj(L, watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0);
|
SWIG_NewPointerObj(L, watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void PushSBClass(lua_State *L, lldb::SBStructuredData *structured_data_sb) {
|
||||||
PushSBClass (lua_State* L, lldb::SBStructuredData* structured_data_sb)
|
SWIG_NewPointerObj(L, structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData,
|
||||||
{
|
0);
|
||||||
SWIG_NewPointerObj(L, structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData, 0);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,8 +307,7 @@ LLDB_NUMBER_TYPEMAP(enum SWIGTYPE);
|
||||||
if (lua_isnil(L, $input)) {
|
if (lua_isnil(L, $input)) {
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
$2 = 0;
|
$2 = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
$1 = (char *)luaL_checklstring(L, $input, (size_t *)&$2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,12 @@
|
||||||
%header %{
|
%header %{
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> void PushSBClass(lua_State * L, T * obj);
|
||||||
void
|
|
||||||
PushSBClass(lua_State* L, T* obj);
|
|
||||||
|
|
||||||
// This function is called from Lua::CallBreakpointCallback
|
// This function is called from Lua::CallBreakpointCallback
|
||||||
llvm::Expected<bool>
|
llvm::Expected<bool> lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
|
||||||
lldb_private::LLDBSwigLuaBreakpointCallbackFunction
|
lua_State * L, lldb::StackFrameSP stop_frame_sp,
|
||||||
(
|
|
||||||
lua_State *L,
|
|
||||||
lldb::StackFrameSP stop_frame_sp,
|
|
||||||
lldb::BreakpointLocationSP bp_loc_sp,
|
lldb::BreakpointLocationSP bp_loc_sp,
|
||||||
const StructuredDataImpl &extra_args_impl
|
const StructuredDataImpl &extra_args_impl) {
|
||||||
)
|
|
||||||
{
|
|
||||||
lldb::SBFrame sb_frame(stop_frame_sp);
|
lldb::SBFrame sb_frame(stop_frame_sp);
|
||||||
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
|
lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
|
||||||
int nargs = 2;
|
int nargs = 2;
|
||||||
|
@ -48,14 +41,8 @@ lldb_private::LLDBSwigLuaBreakpointCallbackFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is called from Lua::CallWatchpointCallback
|
// This function is called from Lua::CallWatchpointCallback
|
||||||
llvm::Expected<bool>
|
llvm::Expected<bool> lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
|
||||||
lldb_private::LLDBSwigLuaWatchpointCallbackFunction
|
lua_State * L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
|
||||||
(
|
|
||||||
lua_State *L,
|
|
||||||
lldb::StackFrameSP stop_frame_sp,
|
|
||||||
lldb::WatchpointSP wp_sp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
lldb::SBFrame sb_frame(stop_frame_sp);
|
lldb::SBFrame sb_frame(stop_frame_sp);
|
||||||
lldb::SBWatchpoint sb_wp(wp_sp);
|
lldb::SBWatchpoint sb_wp(wp_sp);
|
||||||
int nargs = 2;
|
int nargs = 2;
|
||||||
|
@ -82,8 +69,7 @@ lldb_private::LLDBSwigLuaWatchpointCallbackFunction
|
||||||
return stop;
|
return stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
|
||||||
LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
|
|
||||||
lua_State *L = (lua_State *)baton;
|
lua_State *L = (lua_State *)baton;
|
||||||
|
|
||||||
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
|
||||||
|
|
|
@ -41,11 +41,11 @@
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
PythonString s = list.GetItemAtIndex(i).AsType<PythonString>();
|
PythonString s = list.GetItemAtIndex(i).AsType<PythonString>();
|
||||||
if (!s.IsAllocated()) { $1 = 0; }
|
if (!s.IsAllocated()) {
|
||||||
|
$1 = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
} else {
|
||||||
{
|
|
||||||
$1 = (($input == Py_None) ? 1 : 0);
|
$1 = (($input == Py_None) ? 1 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@
|
||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
len = 0;
|
len = 0;
|
||||||
while ($1[len]) len++;
|
while ($1[len])
|
||||||
|
len++;
|
||||||
PythonList list(len);
|
PythonList list(len);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
list.SetItemAtIndex(i, PythonString($1[i]));
|
list.SetItemAtIndex(i, PythonString($1[i]));
|
||||||
|
@ -155,18 +156,15 @@
|
||||||
PythonString str(PyRefType::Borrowed, $input);
|
PythonString str(PyRefType::Borrowed, $input);
|
||||||
$1 = (char *)str.GetString().data();
|
$1 = (char *)str.GetString().data();
|
||||||
$2 = str.GetSize();
|
$2 = str.GetSize();
|
||||||
}
|
} else if (PythonByteArray::Check($input)) {
|
||||||
else if(PythonByteArray::Check($input)) {
|
|
||||||
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
||||||
$1 = (char *)bytearray.GetBytes().data();
|
$1 = (char *)bytearray.GetBytes().data();
|
||||||
$2 = bytearray.GetSize();
|
$2 = bytearray.GetSize();
|
||||||
}
|
} else if (PythonBytes::Check($input)) {
|
||||||
else if (PythonBytes::Check($input)) {
|
|
||||||
PythonBytes bytes(PyRefType::Borrowed, $input);
|
PythonBytes bytes(PyRefType::Borrowed, $input);
|
||||||
$1 = (char *)bytes.GetBytes().data();
|
$1 = (char *)bytes.GetBytes().data();
|
||||||
$2 = bytes.GetSize();
|
$2 = bytes.GetSize();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting a string");
|
PyErr_SetString(PyExc_ValueError, "Expecting a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -178,18 +176,15 @@
|
||||||
PythonString str(PyRefType::Borrowed, $input);
|
PythonString str(PyRefType::Borrowed, $input);
|
||||||
$1 = (void *)str.GetString().data();
|
$1 = (void *)str.GetString().data();
|
||||||
$2 = str.GetSize();
|
$2 = str.GetSize();
|
||||||
}
|
} else if (PythonByteArray::Check($input)) {
|
||||||
else if(PythonByteArray::Check($input)) {
|
|
||||||
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
PythonByteArray bytearray(PyRefType::Borrowed, $input);
|
||||||
$1 = (void *)bytearray.GetBytes().data();
|
$1 = (void *)bytearray.GetBytes().data();
|
||||||
$2 = bytearray.GetSize();
|
$2 = bytearray.GetSize();
|
||||||
}
|
} else if (PythonBytes::Check($input)) {
|
||||||
else if (PythonBytes::Check($input)) {
|
|
||||||
PythonBytes bytes(PyRefType::Borrowed, $input);
|
PythonBytes bytes(PyRefType::Borrowed, $input);
|
||||||
$1 = (void *)bytes.GetBytes().data();
|
$1 = (void *)bytes.GetBytes().data();
|
||||||
$2 = bytes.GetSize();
|
$2 = bytes.GetSize();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
|
PyErr_SetString(PyExc_ValueError, "Expecting a buffer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -250,19 +245,18 @@ template <> int32_t PyLongAsT<int32_t>(PyObject *obj) {
|
||||||
return static_cast<int32_t>(PyLong_AsLong(obj));
|
return static_cast<int32_t>(PyLong_AsLong(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T> bool SetNumberFromPyObject(T &number, PyObject *obj) {
|
||||||
bool SetNumberFromPyObject(T &number, PyObject *obj) {
|
|
||||||
if (PyInt_Check(obj))
|
if (PyInt_Check(obj))
|
||||||
number = static_cast<T>(PyInt_AsLong(obj));
|
number = static_cast<T>(PyInt_AsLong(obj));
|
||||||
else if (PyLong_Check(obj))
|
else if (PyLong_Check(obj))
|
||||||
number = PyLongAsT<T>(obj);
|
number = PyLongAsT<T>(obj);
|
||||||
else return false;
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
|
||||||
if (PyFloat_Check(obj)) {
|
if (PyFloat_Check(obj)) {
|
||||||
number = PyFloat_AsDouble(obj);
|
number = PyFloat_AsDouble(obj);
|
||||||
return true;
|
return true;
|
||||||
|
@ -338,12 +332,10 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
if (count >= $2)
|
if (count >= $2)
|
||||||
count = $2;
|
count = $2;
|
||||||
PyObject *list = PyList_New(count);
|
PyObject *list = PyList_New(count);
|
||||||
for (uint32_t j = 0; j < count; j++)
|
for (uint32_t j = 0; j < count; j++) {
|
||||||
{
|
|
||||||
PyObject *item = PyInt_FromLong($1[j]);
|
PyObject *item = PyInt_FromLong($1[j]);
|
||||||
int ok = PyList_SetItem(list, j, item);
|
int ok = PyList_SetItem(list, j, item);
|
||||||
if (ok != 0)
|
if (ok != 0) {
|
||||||
{
|
|
||||||
$result = Py_None;
|
$result = Py_None;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +350,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
|
|
||||||
// For Log::LogOutputCallback
|
// For Log::LogOutputCallback
|
||||||
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
%typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
|
||||||
if (!($input == Py_None || PyCallable_Check(reinterpret_cast<PyObject*>($input)))) {
|
if (!($input == Py_None ||
|
||||||
|
PyCallable_Check(reinterpret_cast<PyObject *>($input)))) {
|
||||||
PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
|
PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -398,7 +391,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFileForcingUseOfScriptingIOMethods());
|
auto sp = unwrapOrSetPythonException(
|
||||||
|
py_file.ConvertToFileForcingUseOfScriptingIOMethods());
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -410,7 +404,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFile(/*borrowed=*/true));
|
auto sp =
|
||||||
|
unwrapOrSetPythonException(py_file.ConvertToFile(/*borrowed=*/true));
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -422,7 +417,8 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
PyErr_SetString(PyExc_TypeError, "not a file");
|
PyErr_SetString(PyExc_TypeError, "not a file");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto sp = unwrapOrSetPythonException(py_file.ConvertToFileForcingUseOfScriptingIOMethods(/*borrowed=*/true));
|
auto sp = unwrapOrSetPythonException(
|
||||||
|
py_file.ConvertToFileForcingUseOfScriptingIOMethods(/*borrowed=*/true));
|
||||||
if (!sp)
|
if (!sp)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$1 = sp;
|
$1 = sp;
|
||||||
|
@ -446,21 +442,17 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
$result = pyfile.release();
|
$result = pyfile.release();
|
||||||
}
|
}
|
||||||
if (!$result)
|
if (!$result) {
|
||||||
{
|
|
||||||
$result = Py_None;
|
$result = Py_None;
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(in) (const char* string, int len) {
|
%typemap(in) (const char* string, int len) {
|
||||||
if ($input == Py_None)
|
if ($input == Py_None) {
|
||||||
{
|
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
$2 = 0;
|
$2 = 0;
|
||||||
}
|
} else if (PythonString::Check($input)) {
|
||||||
else if (PythonString::Check($input))
|
|
||||||
{
|
|
||||||
PythonString py_str(PyRefType::Borrowed, $input);
|
PythonString py_str(PyRefType::Borrowed, $input);
|
||||||
llvm::StringRef str = py_str.GetString();
|
llvm::StringRef str = py_str.GetString();
|
||||||
$1 = const_cast<char *>(str.data());
|
$1 = const_cast<char *>(str.data());
|
||||||
|
@ -474,9 +466,7 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
// releasing the string will not leak anything, since we
|
// releasing the string will not leak anything, since we
|
||||||
// created this as a borrowed reference.
|
// created this as a borrowed reference.
|
||||||
py_str.release();
|
py_str.release();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_TypeError, "not a string-like object");
|
PyErr_SetString(PyExc_TypeError, "not a string-like object");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +481,9 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
|
|
||||||
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
|
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
|
||||||
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
||||||
int res; Py_ssize_t size = 0; void *buf = 0;
|
int res;
|
||||||
|
Py_ssize_t size = 0;
|
||||||
|
void *buf = 0;
|
||||||
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_WRITABLE);
|
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_WRITABLE);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -506,7 +498,9 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
|
||||||
|
|
||||||
%define %pybuffer_binary(TYPEMAP, SIZE)
|
%define %pybuffer_binary(TYPEMAP, SIZE)
|
||||||
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
%typemap(in) (TYPEMAP, SIZE) (Py_buffer_RAII view) {
|
||||||
int res; Py_ssize_t size = 0; const void *buf = 0;
|
int res;
|
||||||
|
Py_ssize_t size = 0;
|
||||||
|
const void *buf = 0;
|
||||||
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_CONTIG_RO);
|
res = PyObject_GetBuffer($input, &view.buffer, PyBUF_CONTIG_RO);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue