Run make beautify on python.cxx to fix code style to match style on szager-builtin branch

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12514 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-03-03 19:33:25 +00:00
commit 084a3c7205

View file

@ -166,11 +166,9 @@ public:
director_multiple_inheritance = 1; director_multiple_inheritance = 1;
director_language = 1; director_language = 1;
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Thread Implementation * Thread Implementation
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
int threads_enable(Node *n) const { int threads_enable(Node *n) const {
return threads && !GetFlagAttr(n, "feature:nothread"); return threads && !GetFlagAttr(n, "feature:nothread");
} }
@ -435,7 +433,7 @@ public:
} }
} }
} /* for */ }
if (py3) { if (py3) {
/* force disable features that not compatible with Python 3.x */ /* force disable features that not compatible with Python 3.x */
@ -702,8 +700,7 @@ public:
Printv(f_shadow, "\nfrom sys import version_info\n", NULL); Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
if(fastproxy) if (fastproxy) {
{
Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL); Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module); Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(f_shadow, "else:\n", NULL); Printv(f_shadow, "else:\n", NULL);
@ -788,8 +785,7 @@ public:
// "import types\n", // "import types\n",
"try:\n", "try:\n",
// " _object = types.ObjectType\n", // " _object = types.ObjectType\n",
" _object = object\n", " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
" _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
// "del types\n", // "del types\n",
"\n\n", NIL); "\n\n", NIL);
} }
@ -905,9 +901,8 @@ public:
* This wrapper is used to implement -fastproxy, * This wrapper is used to implement -fastproxy,
* as a replacement of new.instancemethod in Python 3. * as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
int add_pyinstancemethod_new() int add_pyinstancemethod_new() {
{ String *name = NewString("SWIG_PyInstanceMethod_New");
String* name = NewString("SWIG_PyInstanceMethod_New");
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name); Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name);
Delete(name); Delete(name);
return 0; return 0;
@ -1156,7 +1151,7 @@ public:
String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0); String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0);
// Use C parameter name unless it is a duplicate or an empty parameter name // Use C parameter name unless it is a duplicate or an empty parameter name
int count = 0; int count = 0;
if ( SwigType_isvarargs(Getattr(p, "type")) ) { if (SwigType_isvarargs(Getattr(p, "type"))) {
return NewString("*args"); return NewString("*args");
} }
while (plist) { while (plist) {
@ -1176,7 +1171,7 @@ public:
* func_annotation: Function annotation support * func_annotation: Function annotation support
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String *make_autodocParmList(Node *n, bool showTypes, bool calling=false, bool func_annotation=false) { String *make_autodocParmList(Node *n, bool showTypes, bool calling = false, bool func_annotation = false) {
String *doc = NewString(""); String *doc = NewString("");
@ -1191,7 +1186,7 @@ public:
int arg_num = 0; int arg_num = 0;
const int maxwidth = 50; const int maxwidth = 50;
if(calling) if (calling)
func_annotation = false; func_annotation = false;
if (pdocs) if (pdocs)
@ -1200,7 +1195,7 @@ public:
Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("in", plist, 0);
Swig_typemap_attach_parms("doc", plist, 0); Swig_typemap_attach_parms("doc", plist, 0);
if (Strcmp(ParmList_protostr(plist), "void")==0) { if (Strcmp(ParmList_protostr(plist), "void") == 0) {
//No parameters actually //No parameters actually
return doc; return doc;
} }
@ -1269,14 +1264,13 @@ public:
pdocs = NewString("Parameters:\n"); pdocs = NewString("Parameters:\n");
Printf(pdocs, " %s\n", pdoc); Printf(pdocs, " %s\n", pdoc);
} }
// Write the function annoation // Write the function annoation
if (func_annotation) if (func_annotation)
Printf(doc, " : '%s'", type); Printf(doc, " : '%s'", type);
// Write default value // Write default value
if (value && !calling) { if (value && !calling) {
String* pv = pyvalue(value, Getattr(p, "type")); String *pv = pyvalue(value, Getattr(p, "type"));
if (pv) if (pv)
value = pv; value = pv;
else { else {
@ -1414,7 +1408,6 @@ public:
Printv(doc, "\n", pdocs, NULL); Printv(doc, "\n", pdocs, NULL);
} }
} }
// if it's overloaded then get the next decl and loop around again // if it's overloaded then get the next decl and loop around again
n = Getattr(n, "sym:nextSibling"); n = Getattr(n, "sym:nextSibling");
if (n) if (n)
@ -1429,22 +1422,21 @@ public:
* Check if string v can be a Python value literal, * Check if string v can be a Python value literal,
* (eg. number or string), or translate it to a Python literal. * (eg. number or string), or translate it to a Python literal.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* pyvalue(String *v, SwigType *t) String *pyvalue(String *v, SwigType *t) {
{ if (v && Len(v) > 0) {
if (v && Len(v)>0) {
char fc = (Char(v))[0]; char fc = (Char(v))[0];
if (('0'<=fc && fc<='9') || '\''==fc || '"'==fc) { if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) {
/* number or string (or maybe NULL pointer)*/ /* number or string (or maybe NULL pointer) */
if (SwigType_ispointer(t) && Strcmp(v, "0")==0) if (SwigType_ispointer(t) && Strcmp(v, "0") == 0)
return NewString("None"); return NewString("None");
else else
return v; return v;
} }
if (Strcmp(v, "true")==0 || Strcmp(v, "FALSE")==0) if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("True"); return NewString("True");
if (Strcmp(v, "false")==0 || Strcmp(v, "FALSE")==0) if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False"); return NewString("False");
if (Strcmp(v, "NULL")==0) if (Strcmp(v, "NULL") == 0)
return NewString("None"); return NewString("None");
} }
return 0; return 0;
@ -1455,8 +1447,7 @@ public:
* (So we can generate proper parameter list with default * (So we can generate proper parameter list with default
* values..) * values..)
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
bool is_primitive_defaultargs(Node *n) bool is_primitive_defaultargs(Node *n) {
{
ParmList *plist = CopyParmList(Getattr(n, "parms")); ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p; Parm *p;
Parm *pnext; Parm *pnext;
@ -1487,8 +1478,7 @@ public:
* siblings generated due to the original function have * siblings generated due to the original function have
* default arguments. * default arguments.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
bool is_real_overloaded(Node *n) bool is_real_overloaded(Node *n) {
{
Node *h = Getattr(n, "sym:overloaded"); Node *h = Getattr(n, "sym:overloaded");
Node *i; Node *i;
if (!h) if (!h)
@ -1513,20 +1503,17 @@ public:
* Generate parameter list for Python functions or methods, * Generate parameter list for Python functions or methods,
* reuse make_autodocParmList() to do so. * reuse make_autodocParmList() to do so.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) String *make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) {
{
/* Get the original function for a defaultargs copy, /* Get the original function for a defaultargs copy,
* see default_arguments() in parser.y. */ * see default_arguments() in parser.y. */
Node *nn = Getattr(n, "defaultargs"); Node *nn = Getattr(n, "defaultargs");
if (nn) n = nn; if (nn)
n = nn;
/* For overloaded function, just use *args */ /* For overloaded function, just use *args */
if (is_real_overloaded(n) || if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) {
GetFlag(n, "feature:compactdefaultargs") ||
!is_primitive_defaultargs(n))
{
String *parms = NewString(""); String *parms = NewString("");
if(in_class) if (in_class)
Printf(parms, "self, "); Printf(parms, "self, ");
Printf(parms, "*args"); Printf(parms, "*args");
if (kw) if (kw)
@ -1538,10 +1525,9 @@ public:
String *params = NewString(""); String *params = NewString("");
String *_params = make_autodocParmList(n, false, is_calling, funcanno); String *_params = make_autodocParmList(n, false, is_calling, funcanno);
if (in_class) if (in_class) {
{
Printf(params, "self"); Printf(params, "self");
if(Len(_params) > 0) if (Len(_params) > 0)
Printf(params, ", "); Printf(params, ", ");
} }
@ -1620,15 +1606,14 @@ public:
* Helper function for constructing the function annotation * Helper function for constructing the function annotation
* of the returning type, return a empty string for Python 2.x * of the returning type, return a empty string for Python 2.x
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* returnTypeAnnotation(Node *n) String *returnTypeAnnotation(Node *n) {
{ String *ret = 0;
String *ret=0;
Parm *p = Getattr(n, "parms"); Parm *p = Getattr(n, "parms");
String *tm; String *tm;
/* Try to guess the returning type by argout typemap, /* Try to guess the returning type by argout typemap,
* however the result may not accurate. */ * however the result may not accurate. */
while (p) { while (p) {
if ((tm=Getattr(p, "tmap:argout:match_type"))) { if ((tm = Getattr(p, "tmap:argout:match_type"))) {
tm = SwigType_str(tm, 0); tm = SwigType_str(tm, 0);
if (ret) if (ret)
Printv(ret, ", ", tm, NULL); Printv(ret, ", ", tm, NULL);
@ -1643,7 +1628,8 @@ public:
* the function prototype. */ * the function prototype. */
if (!ret) { if (!ret) {
ret = Getattr(n, "type"); ret = Getattr(n, "type");
if (ret) ret = SwigType_str(ret, 0); if (ret)
ret = SwigType_str(ret, 0);
} }
return (ret && py3) ? NewStringf(" -> \"%s\" ", ret) return (ret && py3) ? NewStringf(" -> \"%s\" ", ret)
: NewString(""); : NewString("");
@ -1993,7 +1979,7 @@ public:
if (Len(pn)) { if (Len(pn)) {
String *tmp = 0; String *tmp = 0;
String *name = pn; String *name = pn;
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
name = tmp = Swig_name_make(p, 0, pn, 0, 0); name = tmp = Swig_name_make(p, 0, pn, 0, 0);
} }
Printf(kwargs, "(char *) \"%s\",", name); Printf(kwargs, "(char *) \"%s\",", name);
@ -2026,7 +2012,7 @@ public:
if (Getattr(p, "tmap:in:implicitconv")) { if (Getattr(p, "tmap:in:implicitconv")) {
const char *convflag = "0"; const char *convflag = "0";
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type"); SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype)); convflag = get_implicitconv_flag(classLookup(ptype));
} }
@ -2128,7 +2114,7 @@ public:
if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) { if (Getattr(p, "tmap:freearg:implicitconv")) {
const char *convflag = "0"; const char *convflag = "0";
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type"); SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype)); convflag = get_implicitconv_flag(classLookup(ptype));
} }
@ -2205,11 +2191,11 @@ public:
if (allow_thread) { if (allow_thread) {
String *preaction = NewString(""); String *preaction = NewString("");
thread_begin_allow(n, preaction); thread_begin_allow(n, preaction);
Setattr(n,"wrap:preaction", preaction); Setattr(n, "wrap:preaction", preaction);
String *postaction = NewString(""); String *postaction = NewString("");
thread_end_allow(n, postaction); thread_end_allow(n, postaction);
Setattr(n,"wrap:postaction", postaction); Setattr(n, "wrap:postaction", postaction);
} }
} }
@ -2867,7 +2853,8 @@ public:
if (!bname || ignore) { if (!bname || ignore) {
if (!bname && !ignore) { if (!bname && !ignore) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
"Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n",
SwigType_namestr(Getattr(b.item, "name")));
} }
b = Next(b); b = Next(b);
continue; continue;
@ -2897,7 +2884,7 @@ public:
if (!classic) { if (!classic) {
Printf(f_shadow, modern ? "(object)" : "(_object)"); Printf(f_shadow, modern ? "(object)" : "(_object)");
} }
if (GetFlag(n, "feature:exceptionclass") ) { if (GetFlag(n, "feature:exceptionclass")) {
Printf(f_shadow, "(Exception)"); Printf(f_shadow, "(Exception)");
} }
} }
@ -2980,8 +2967,7 @@ public:
} }
Printv(f_wrappers, Printv(f_wrappers,
" SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " return SWIG_Py_Void();\n", "}\n\n", NIL);
" return SWIG_Py_Void();\n", "}\n\n", NIL);
String *cname = NewStringf("%s_swigregister", class_name); String *cname = NewStringf("%s_swigregister", class_name);
add_method(cname, cname, 0); add_method(cname, cname, 0);
Delete(smart); Delete(smart);
@ -2990,7 +2976,8 @@ public:
Delete(realct); Delete(realct);
} }
if (!have_constructor) { if (!have_constructor) {
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
(Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
} else if (fastinit) { } else if (fastinit) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
@ -3032,7 +3019,8 @@ public:
List *shadow_list = Getattr(n, "shadow_methods"); List *shadow_list = Getattr(n, "shadow_methods");
for (int i = 0; i < Len(shadow_list); ++i) { for (int i = 0; i < Len(shadow_list); ++i) {
String *symname = Getitem(shadow_list, i); String *symname = Getitem(shadow_list, i);
Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname),
class_name);
} }
} }
Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
@ -3111,7 +3099,7 @@ public:
Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
} }
} else { } else {
Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
Printv(f_shadow, "\n", NIL); Printv(f_shadow, "\n", NIL);
if (have_docstring(n)) if (have_docstring(n))
Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
@ -3180,10 +3168,12 @@ public:
} else { } else {
if (!modern) { if (!modern) {
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n",
NIL);
} }
if (!classic) { if (!classic) {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
")\n", NIL);
} }
} }
} }