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");
} }
@ -430,16 +428,16 @@ public:
fputs(usage2, stdout); fputs(usage2, stdout);
fputs(usage3, stdout); fputs(usage3, stdout);
} else if (strcmp(argv[i], "-py3") == 0) { } else if (strcmp(argv[i], "-py3") == 0) {
py3 = 1; py3 = 1;
Swig_mark_arg(i); Swig_mark_arg(i);
} }
} }
} /* 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 */
classic = 0; classic = 0;
} }
if (cppcast) { if (cppcast) {
@ -702,12 +700,11 @@ 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); Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
} }
/* Import the C-extension module. This should be a relative import, /* Import the C-extension module. This should be a relative import,
* since the shadow module may also have been imported by a relative * since the shadow module may also have been imported by a relative
@ -781,17 +778,16 @@ public:
tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
if (!classic) { if (!classic) {
/* Usage of types.ObjectType is deprecated. /* Usage of types.ObjectType is deprecated.
* But don't sure wether this would broken old Python? * But don't sure wether this would broken old Python?
*/ */
Printv(f_shadow, Printv(f_shadow,
// "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);
} }
} }
if (modern) { if (modern) {
@ -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;
@ -944,9 +939,9 @@ public:
Printf(import, "_%s\n", modname); Printf(import, "_%s\n", modname);
if (!Strstr(f_shadow_imports, import)) { if (!Strstr(f_shadow_imports, import)) {
if (pkg && (!package || Strcmp(pkg, package) != 0)) { if (pkg && (!package || Strcmp(pkg, package) != 0)) {
Printf(f_shadow, "import %s.%s\n", pkg, modname); Printf(f_shadow, "import %s.%s\n", pkg, modname);
} else { } else {
Printf(f_shadow, "import %s\n", modname); Printf(f_shadow, "import %s\n", modname);
} }
Printv(f_shadow_imports, import, NULL); Printv(f_shadow_imports, import, NULL);
} }
@ -965,12 +960,12 @@ public:
* module. Using proper argument and calling style for * module. Using proper argument and calling style for
* given node n. * given node n.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String *funcCall(String *name, String *parms) { String *funcCall(String *name, String *parms) {
String *str = NewString(""); String *str = NewString("");
Printv(str, module, ".", name, "(", parms, ")", NIL); Printv(str, module, ".", name, "(", parms, ")", NIL);
return str; return str;
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
@ -1139,7 +1134,7 @@ public:
return doc; return doc;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* makeParameterName() * makeParameterName()
* Note: the generated name should consist with that in kwnames[] * Note: the generated name should consist with that in kwnames[]
* *
@ -1156,12 +1151,12 @@ 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) {
if ((Cmp(pn, Getattr(plist, "name")) == 0)) if ((Cmp(pn, Getattr(plist, "name")) == 0))
count++; count++;
plist = nextSibling(plist); plist = nextSibling(plist);
} }
arg = (!pn || !Len(pn) || (count > 1)) ? NewStringf("arg%d", arg_num) : Copy(pn); arg = (!pn || !Len(pn) || (count > 1)) ? NewStringf("arg%d", arg_num) : Copy(pn);
@ -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;
} }
@ -1210,9 +1205,9 @@ public:
String *tm = Getattr(p, "tmap:in"); String *tm = Getattr(p, "tmap:in");
if (tm) { if (tm) {
pnext = Getattr(p, "tmap:in:next"); pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) { if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue; continue;
} }
} else { } else {
pnext = nextSibling(p); pnext = nextSibling(p);
} }
@ -1256,34 +1251,33 @@ public:
type = SwigType_base(type); type = SwigType_base(type);
lookup = Swig_symbol_clookup(type, 0); lookup = Swig_symbol_clookup(type, 0);
if (lookup) if (lookup)
type = Getattr(lookup, "sym:name"); type = Getattr(lookup, "sym:name");
// Do the param type too? // Do the param type too?
if (showTypes) if (showTypes)
Printf(doc, "%s ", type); Printf(doc, "%s ", type);
Append(doc, name); Append(doc, name);
if (pdoc) { if (pdoc) {
if (!pdocs) if (!pdocs)
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 {
lookup = Swig_symbol_clookup(value, 0); lookup = Swig_symbol_clookup(value, 0);
if (lookup) { if (lookup) {
value = Getattr(lookup, "sym:name"); value = Getattr(lookup, "sym:name");
} }
} }
Printf(doc, " = %s", value); Printf(doc, " = %s", value);
} }
@ -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,23 +1422,22 @@ 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;
@ -1465,17 +1456,17 @@ public:
for (p = plist; p; p = pnext) { for (p = plist; p; p = pnext) {
String *tm = Getattr(p, "tmap:in"); String *tm = Getattr(p, "tmap:in");
if (tm) { if (tm) {
pnext = Getattr(p, "tmap:in:next"); pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) { if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue; continue;
} }
} else { } else {
pnext = nextSibling(p); pnext = nextSibling(p);
} }
String *type = Getattr(p, "type"); String *type = Getattr(p, "type");
String *value = Getattr(p, "value"); String *value = Getattr(p, "value");
if (!pyvalue(value, type)) if (!pyvalue(value, type))
return false; return false;
} }
return true; return true;
} }
@ -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)
@ -1498,9 +1488,9 @@ public:
while (i) { while (i) {
Node *nn = Getattr(i, "defaultargs"); Node *nn = Getattr(i, "defaultargs");
if (nn != h) { if (nn != h) {
/* Check if overloaded function has defaultargs and /* Check if overloaded function has defaultargs and
* pointed to the first overloaded. */ * pointed to the first overloaded. */
return true; return true;
} }
i = Getattr(i, "sym:nextSibling"); i = Getattr(i, "sym:nextSibling");
} }
@ -1513,24 +1503,21 @@ 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)
Printf(parms, ", **kwargs"); Printf(parms, ", **kwargs");
return parms; return parms;
} }
@ -1538,11 +1525,10 @@ 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, ", ");
} }
Printv(params, _params, NULL); Printv(params, _params, NULL);
@ -1620,21 +1606,20 @@ 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);
else else
ret = tm; ret = tm;
p = Getattr(p, "tmap:argout:next"); p = Getattr(p, "tmap:argout:next");
} else { } else {
p = nextSibling(p); p = nextSibling(p);
} }
@ -1643,10 +1628,11 @@ 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("");
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
@ -1670,7 +1656,7 @@ public:
Printv(f_dest, pythoncode(pythonappend(n), " "), "\n", NIL); Printv(f_dest, pythoncode(pythonappend(n), " "), "\n", NIL);
Printv(f_dest, " return val\n", NIL); Printv(f_dest, " return val\n", NIL);
} else { } else {
Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL); Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL);
} }
if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) {
@ -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);
} }
} }
@ -2863,12 +2849,13 @@ public:
b = First(baselist); b = First(baselist);
while (b.item) { while (b.item) {
String *bname = Getattr(b.item, "python:proxy"); String *bname = Getattr(b.item, "python:proxy");
bool ignore = GetFlag(b.item, "feature:ignore") ? true : false; bool ignore = GetFlag(b.item, "feature:ignore") ? true : false;
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;
} }
@ -2883,10 +2870,10 @@ public:
/* dealing with abstract base class */ /* dealing with abstract base class */
String *abcs = Getattr(n, "feature:python:abc"); String *abcs = Getattr(n, "feature:python:abc");
if (py3 && abcs) { if (py3 && abcs) {
if (Len(base_class)) { if (Len(base_class)) {
Putc(',', base_class); Putc(',', base_class);
} }
Printv(base_class, abcs, NIL); Printv(base_class, abcs, NIL);
} }
Printv(f_shadow, "class ", class_name, NIL); Printv(f_shadow, "class ", class_name, NIL);
@ -2897,9 +2884,9 @@ 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)");
} }
} }
Printf(f_shadow, ":\n"); Printf(f_shadow, ":\n");
if (have_docstring(n)) { if (have_docstring(n)) {
@ -2950,22 +2937,22 @@ public:
if (shadow) { if (shadow) {
/* Generate a class registration function */ /* Generate a class registration function */
{ {
String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers) String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
SwigType *smart = 0; SwigType *smart = 0;
if (smartptr) { if (smartptr) {
SwigType *cpt = Swig_cparse_type(smartptr); SwigType *cpt = Swig_cparse_type(smartptr);
if (cpt) { if (cpt) {
smart = SwigType_typedef_resolve_all(cpt); smart = SwigType_typedef_resolve_all(cpt);
Delete(cpt); Delete(cpt);
} else { } else {
// TODO: report line number of where the feature comes from // TODO: report line number of where the feature comes from
Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname); Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname);
} }
} }
SwigType *ct = Copy(smart ? smart : real_classname); SwigType *ct = Copy(smart ? smart : real_classname);
SwigType_add_pointer(ct); SwigType_add_pointer(ct);
SwigType *realct = Copy(real_classname); SwigType *realct = Copy(real_classname);
SwigType_add_pointer(realct); SwigType_add_pointer(realct);
SwigType_remember(realct); SwigType_remember(realct);
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
Printv(f_wrappers, " PyObject *obj;\n", NIL); Printv(f_wrappers, " PyObject *obj;\n", NIL);
@ -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);
@ -3103,15 +3091,15 @@ public:
Delete(pycode); Delete(pycode);
fproxy = 0; fproxy = 0;
} else { } else {
String *parms = make_pyParmList(n, true, false, allow_kwargs); String *parms = make_pyParmList(n, true, false, allow_kwargs);
String *callParms = make_pyParmList(n, true, true, allow_kwargs); String *callParms = make_pyParmList(n, true, true, allow_kwargs);
if (!have_addtofunc(n)) { if (!have_addtofunc(n)) {
if (!fastproxy || olddefs) { if (!fastproxy || olddefs) {
Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL); Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
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);
@ -3158,8 +3146,8 @@ public:
if (shadow) { if (shadow) {
if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw); String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw); String *callParms = make_pyParmList(n, false, true, kw);
Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
if (have_docstring(n)) if (have_docstring(n))
Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, 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);
} }
} }
} }
@ -3243,7 +3233,7 @@ public:
Delete(cname); Delete(cname);
} }
if (!have_constructor && handled_as_init) { if (!have_constructor && handled_as_init) {
if (Getattr(n, "feature:shadow")) { if (Getattr(n, "feature:shadow")) {
String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname)); String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
@ -3259,16 +3249,16 @@ public:
assert(rclassname); assert(rclassname);
String *parms = make_pyParmList(n, true, false, allow_kwargs); String *parms = make_pyParmList(n, true, false, allow_kwargs);
/* Pass 'self' only if using director */ /* Pass 'self' only if using director */
String *callParms = make_pyParmList(n, false, true, allow_kwargs); String *callParms = make_pyParmList(n, false, true, allow_kwargs);
if (use_director) { if (use_director) {
Insert(callParms, 0, "_self, "); Insert(callParms, 0, "_self, ");
Printv(pass_self, tab8, NIL); Printv(pass_self, tab8, NIL);
Printf(pass_self, "if self.__class__ == %s:\n", classname); Printf(pass_self, "if self.__class__ == %s:\n", classname);
//Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL);
Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL); Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL);
} }
Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL); Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL);
@ -3301,8 +3291,8 @@ public:
Printv(f_shadow_stubs, pycode, "\n", NIL); Printv(f_shadow_stubs, pycode, "\n", NIL);
Delete(pycode); Delete(pycode);
} else { } else {
String *parms = make_pyParmList(n, false, false, allow_kwargs); String *parms = make_pyParmList(n, false, false, allow_kwargs);
String *callParms = make_pyParmList(n, false, true, allow_kwargs); String *callParms = make_pyParmList(n, false, true, allow_kwargs);
Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL); Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
if (have_docstring(n)) if (have_docstring(n))
@ -3430,10 +3420,10 @@ public:
String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
String *getname = Swig_name_get(NSPACE_TODO, mname); String *getname = Swig_name_get(NSPACE_TODO, mname);
String *wrapgetname = Swig_name_wrapper(getname); String *wrapgetname = Swig_name_wrapper(getname);
String *vargetname = NewStringf("Swig_var_%s", getname); String *vargetname = NewStringf("Swig_var_%s", getname);
String *setname = Swig_name_set(NSPACE_TODO, mname); String *setname = Swig_name_set(NSPACE_TODO, mname);
String *wrapsetname = Swig_name_wrapper(setname); String *wrapsetname = Swig_name_wrapper(setname);
String *varsetname = NewStringf("Swig_var_%s", setname); String *varsetname = NewStringf("Swig_var_%s", setname);
Wrapper *f = NewWrapper(); Wrapper *f = NewWrapper();
Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);