X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6977316f8d12a8d78f5774dbbe7cea4a45d98443..ad3fca675f77c2903cafd096bbda8baa2e7689ff:/wxPython/SWIG/swig.python-docstring.patch diff --git a/wxPython/SWIG/swig.python-docstring.patch b/wxPython/SWIG/swig.python-docstring.patch index 808f6897b0..d542fe69aa 100644 --- a/wxPython/SWIG/swig.python-docstring.patch +++ b/wxPython/SWIG/swig.python-docstring.patch @@ -1,39 +1,118 @@ Index: Source/Modules/python.cxx =================================================================== -RCS file: /cvsroot/SWIG/Source/Modules/python.cxx,v -retrieving revision 1.28 -diff -u -4 -r1.28 python.cxx ---- Source/Modules/python.cxx 18 Nov 2003 20:19:15 -0000 1.28 -+++ Source/Modules/python.cxx 27 Nov 2003 00:52:28 -0000 -@@ -67,8 +67,19 @@ - -new_repr - Use more informative version of __repr__ in proxy classes\n\ - -noexcept - No automatic exception handling\n\ - -noproxy - Don't generate proxy classes \n\n"; +RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v +retrieving revision 1.40 +diff -u -4 -r1.40 python.cxx +--- Source/Modules/python.cxx 24 Jan 2004 00:25:31 -0000 1.40 ++++ Source/Modules/python.cxx 2 Jun 2004 01:38:46 -0000 +@@ -19,8 +19,9 @@ + + static String *const_code = 0; + static String *shadow_methods = 0; + static String *module = 0; ++static String *package = 0; + static String *mainmodule = 0; + static String *interface = 0; + static String *global_name = 0; + static int shadow = 1; +@@ -50,8 +51,18 @@ + static int have_constructor; + static int have_repr; + static String *real_classname; -+ +/* flags for the make_autodoc function */ +enum autodoc_t { + AUTODOC_CLASS, + AUTODOC_CTOR, + AUTODOC_DTOR, + AUTODOC_STATICFUNC, -+ AUTODOC_FUNC ++ AUTODOC_FUNC, ++ AUTODOC_METHOD +}; + + static const char *usage = (char *)"\ + Python Options (available with -python)\n\ + -ldflags - Print runtime libraries to link with\n\ + -globals - Set used to access C global variable [default: 'cvar']\n\ +@@ -146,19 +157,22 @@ + * + * use %module(directors="1") modulename at the start of the + * interface file to enable director generation. + */ ++ String* mod_docstring = NULL; + { +- Node *module = Getattr(n, "module"); +- if (module) { +- Node *options = Getattr(module, "options"); ++ Node *mod = Getattr(n, "module"); ++ if (mod) { ++ Node *options = Getattr(mod, "options"); + if (options) { + if (Getattr(options, "directors")) { + allow_directors(); + } + if (Getattr(options, "dirprot")) { + allow_dirprot(); + } ++ mod_docstring = Getattr(options, "docstring"); ++ package = Getattr(options, "package"); + } + } + } + +@@ -258,8 +272,13 @@ + Printv(f_shadow, + "# This file is compatible with both classic and new-style classes.\n", + NIL); + } + - class PYTHON : public Language { - public: ++ if (mod_docstring && Len(mod_docstring)) { ++ Printv(f_shadow, "\n\"\"\"\n", mod_docstring, "\n\"\"\"\n", NIL); ++ Delete(mod_docstring); mod_docstring = NULL; ++ } + + Printf(f_shadow,"\nimport %s\n\n", module); - /* ------------------------------------------------------------ -@@ -414,17 +425,23 @@ + if (! modern) { +@@ -382,9 +401,28 @@ + virtual int importDirective(Node *n) { + if (shadow) { + String *modname = Getattr(n,"module"); + if (modname) { +- Printf(f_shadow,"import %s\n", modname); ++ Printf(f_shadow,"import "); ++ ++ // Find the module node for this imported module. It should be the ++ // first child but search just in case. ++ Node* mod = firstChild(n); ++ while (mod && Strcmp(nodeType(mod), "module") != 0) ++ mod = nextSibling(mod); ++ ++ // Is the imported module in another package? (IOW, does it use the ++ // %module(package="name") option and it's different than the package ++ // of this module.) ++ Node *options = Getattr(mod, "options"); ++ if (options && Getattr(options, "package")) { ++ String* pkg = Getattr(options, "package"); ++ if (!package || Strcmp(pkg, package) != 0) ++ Printf(f_shadow, "%s.", Getattr(options, "package")); ++ } ++ ++ // finally, output the name of the imported module ++ Printf(f_shadow, "%s\n", modname); + } + } + return Language::importDirective(n); + } +@@ -417,17 +455,25 @@ * functions. * ------------------------------------------------------------ */ void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { - if ( ! have_addtofunc(n) ) { - /* If there is no addtofunc directive then just assign from the extension module */ -+ if ( ! have_addtofunc(n) && ! have_docstring(n) ) { -+ /* If there is no addtofunc or docstring directive then just assign from the extension module */ ++ if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n) ) { ++ /* If there is no pythonappend or docstring directive then just assign from the extension module */ Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL); } else { /* Otherwise make a wrapper function to insert the code into */ @@ -43,9 +122,11 @@ diff -u -4 -r1.28 python.cxx - Printv(f_dest, tab4, "return val\n", NIL); + if ( have_docstring(n) ) + Printv(f_dest, tab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); -+ if ( have_addtofunc(n) ) { ++ if ( have_pythonprepend(n) ) ++ Printv(f_dest, tab4, pythonprepend(n), "\n", NIL); ++ if ( have_pythonappend(n) ) { + Printv(f_dest, tab4, "val = ", funcCallHelper(name, kw), "\n", NIL); -+ Printv(f_dest, tab4, addtofunc(n), "\n", NIL); ++ Printv(f_dest, tab4, pythonappend(n), "\n", NIL); + Printv(f_dest, tab4, "return val\n", NIL); + } else { + Printv(f_dest, tab4, "return ", funcCallHelper(name, kw), "\n", NIL); @@ -54,11 +135,13 @@ diff -u -4 -r1.28 python.cxx } -@@ -438,8 +455,246 @@ +@@ -441,24 +487,303 @@ } /* ------------------------------------------------------------ +- * have_addtofunc() +- * Check if there is a %addtofunc directive and it has text + * have_docstring() + * Check if there is a docstring directive and it has text, + * or there is an autodoc flag set @@ -98,14 +181,6 @@ diff -u -4 -r1.28 python.cxx + have_auto = (autodoc != NULL && Len(autodoc) > 0); + } + -+// if ( have_auto && have_ds ) -+// doc = NewStringf("%s%s\n\n%s%s", triple_double, autodoc, str, triple_double); -+// else if ( !have_auto && have_ds ) -+// doc = NewStringf("%s%s%s", triple_double, str, triple_double); -+// else -+// doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); -+ -+ + // If there is more than one line then make docstrings like this: + // + // """ @@ -201,27 +276,37 @@ diff -u -4 -r1.28 python.cxx + if (Strcmp(type, "void") == 0) + type = NULL; + else { -+ type = SwigType_base(type); -+ Node* lookup = Swig_symbol_clookup(type, 0); -+ if (lookup) -+ type = Getattr(lookup, "sym:name"); ++ SwigType* qt = SwigType_typedef_resolve_all(type); ++ if (SwigType_isenum(qt)) ++ type = NewString("int"); ++ else { ++ type = SwigType_base(type); ++ Node* lookup = Swig_symbol_clookup(type, 0); ++ if (lookup) ++ type = Getattr(lookup, "sym:name"); ++ } + } + } + + switch ( ad_type ) { + case AUTODOC_CTOR: -+ if ( Strcmp(class_name, symname) == 0) -+ Printf(doc, "__init__(%s) -> %s", make_autodocParmList(n, showTypes), class_name); ++ if ( Strcmp(class_name, symname) == 0) { ++ String* paramList = make_autodocParmList(n, showTypes); ++ if (Len(paramList)) ++ Printf(doc, "__init__(self, %s) -> %s", paramList, class_name); ++ else ++ Printf(doc, "__init__(self) -> %s", class_name); ++ } + else + Printf(doc, "%s(%s) -> %s", symname, make_autodocParmList(n, showTypes), class_name); + break; + + case AUTODOC_DTOR: -+ Printf(doc, "__del__()"); ++ Printf(doc, "__del__(self)"); + break; + + case AUTODOC_STATICFUNC: -+ Printf(doc, "%s.%s(%s)", class_name, symname, make_autodocParmList(n, showTypes)); ++ Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); + if (type) Printf(doc, " -> %s", type); + break; + @@ -229,6 +314,15 @@ diff -u -4 -r1.28 python.cxx + Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); + if (type) Printf(doc, " -> %s", type); + break; ++ ++ case AUTODOC_METHOD: ++ String* paramList = make_autodocParmList(n, showTypes); ++ if (Len(paramList)) ++ Printf(doc, "%s(self, %s)", symname, paramList); ++ else ++ Printf(doc, "%s(self)", symname); ++ if (type) Printf(doc, " -> %s", type); ++ break; + } + } + @@ -269,9 +363,14 @@ diff -u -4 -r1.28 python.cxx + // Do the param type too? + if (showTypes) { + SwigType* type = SwigType_base(Getattr(p, "type")); -+ lookup = Swig_symbol_clookup(type, 0); -+ if (lookup) -+ type = Getattr(lookup, "sym:name"); ++ SwigType* qt = SwigType_typedef_resolve_all(type); ++ if (SwigType_isenum(qt)) ++ type = NewString("int"); ++ else { ++ lookup = Swig_symbol_clookup(type, 0); ++ if (lookup) ++ type = Getattr(lookup, "sym:name"); ++ } + Printf(doc, "%s ", type); + } + @@ -297,11 +396,78 @@ diff -u -4 -r1.28 python.cxx + + + /* ------------------------------------------------------------ - * have_addtofunc() - * Check if there is a %addtofunc directive and it has text ++ * have_pythonprepend() ++ * Check if there is a %pythonprepend directive and it has text ++ * ------------------------------------------------------------ */ ++ ++ bool have_pythonprepend(Node *n) { ++ String* str = Getattr(n, "feature:pythonprepend"); ++ return (str != NULL && Len(str) > 0); ++ } ++ ++ /* ------------------------------------------------------------ ++ * pythonprepend() ++ * Get the %pythonprepend code, stripping off {} if neccessary ++ * ------------------------------------------------------------ */ ++ ++ String *pythonprepend(Node *n) { ++ String* str = Getattr(n, "feature:pythonprepend"); ++ char* t = Char(str); ++ if (*t == '{') { ++ Delitem(str ,0); ++ Delitem(str,DOH_END); ++ } ++ return str; ++ } ++ ++ /* ------------------------------------------------------------ ++ * have_pythonappend() ++ * Check if there is a %pythonappend directive and it has text * ------------------------------------------------------------ */ -@@ -1660,9 +1915,11 @@ +- bool have_addtofunc(Node *n) { +- String* str = Getattr(n, "feature:addtofunc"); ++ bool have_pythonappend(Node *n) { ++ String* str = Getattr(n, "feature:pythonappend"); + return (str != NULL && Len(str) > 0); + } + + /* ------------------------------------------------------------ +- * addtofunc() +- * Get the %addtofunc code, stripping off {} if neccessary ++ * pythonappend() ++ * Get the %pythonappend code, stripping off {} if neccessary + * ------------------------------------------------------------ */ + +- String *addtofunc(Node *n) { +- String* str = Getattr(n, "feature:addtofunc"); ++ String *pythonappend(Node *n) { ++ String* str = Getattr(n, "feature:pythonappend"); + char* t = Char(str); + if (*t == '{') { + Delitem(str ,0); + Delitem(str,DOH_END); +@@ -1657,9 +1982,18 @@ + mod = Getattr(n,"module"); + if (mod) { + String *modname = Getattr(mod,"name"); + if (Strcmp(modname,mainmodule) != 0) { +- importname = NewStringf("%s.%s", modname, Getattr(n,"sym:name")); ++ // check if the module has a package option ++ String* pkg = NULL; ++ Node *options = Getattr(mod, "options"); ++ if (options && Getattr(options, "package")) ++ pkg = Getattr(options, "package"); ++ ++ if (!package || Strcmp(pkg, package) != 0) ++ importname = NewStringf("%s.%s.%s", pkg, modname, Getattr(n,"sym:name")); ++ else ++ importname = NewStringf("%s.%s", modname, Getattr(n,"sym:name")); + } else { + importname = NewString(Getattr(n,"sym:name")); + } + Setattr(n,"python:proxy",importname); +@@ -1731,9 +2065,11 @@ Printf(f_shadow, modern ? "(object)" : "(_object)"); } } @@ -314,7 +480,7 @@ diff -u -4 -r1.28 python.cxx Printv(f_shadow,tab4,"__swig_setmethods__ = {}\n",NIL); if (Len(base_class)) { Printf(f_shadow,"%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n",tab4,base_class); -@@ -1795,16 +2052,22 @@ +@@ -1866,16 +2202,24 @@ Delete(pyaction); Printv(f_shadow,pycode,"\n",NIL); } else { @@ -326,16 +492,18 @@ diff -u -4 -r1.28 python.cxx - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); - Printv(f_shadow, tab8, "return val\n", NIL); + Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):", NIL); -+ if ( ! have_addtofunc(n) && ! have_docstring(n)) { ++ if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n)) { + Printv(f_shadow, " return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); } else { - Printv(f_shadow, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); + Printv(f_shadow, "\n", NIL); + if ( have_docstring(n) ) -+ Printv(f_shadow, tab8, docstring(n, AUTODOC_FUNC, tab8), "\n", NIL); -+ if ( have_addtofunc(n) ) { ++ Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); ++ if ( have_pythonprepend(n) ) ++ Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); ++ if ( have_pythonappend(n) ) { + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); -+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); ++ Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n\n", NIL); @@ -344,13 +512,13 @@ diff -u -4 -r1.28 python.cxx } } -@@ -1819,14 +2082,20 @@ +@@ -1890,14 +2234,22 @@ virtual int staticmemberfunctionHandler(Node *n) { String *symname = Getattr(n,"sym:name"); Language::staticmemberfunctionHandler(n); if (shadow) { - if ( !classic && have_addtofunc(n) ) { -+ if ( !classic && (have_addtofunc(n) || have_docstring(n)) ) { ++ if ( !classic && (have_pythonprepend(n) || have_pythonappend(n) || have_docstring(n)) ) { int kw = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0; Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); - Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); @@ -358,9 +526,11 @@ diff -u -4 -r1.28 python.cxx - Printv(f_shadow, tab8, "return val\n", NIL); + if ( have_docstring(n) ) + Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); -+ if ( have_addtofunc(n) ) { ++ if ( have_pythonprepend(n) ) ++ Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); ++ if ( have_pythonappend(n) ) { + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); -+ Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); ++ Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n\n", NIL); @@ -369,53 +539,70 @@ diff -u -4 -r1.28 python.cxx " = staticmethod(", symname, ")\n", NIL); if (!modern) { -@@ -1911,8 +2180,10 @@ +@@ -1982,8 +2334,12 @@ } Printv(f_shadow, tab4, "def __init__(self, *args", (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); + if ( have_docstring(n) ) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); ++ if ( have_pythonprepend(n) ) ++ Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, pass_self, NIL); if (!modern) { Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ", funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL); -@@ -1926,9 +2197,9 @@ +@@ -1996,10 +2352,10 @@ + Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL); Printv(f_shadow, tab8, "self.thisown = 1\n", NIL); Printv(f_shadow, tab8, "del newobj.thisown\n", NIL); } - if ( have_addtofunc(n) ) +- if ( have_addtofunc(n) ) - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); -+ Printv(f_shadow, tab8, addtofunc(n), "\n\n", NIL); ++ if ( have_pythonappend(n) ) ++ Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL); Delete(pass_self); } have_constructor = 1; } else { -@@ -1944,8 +2215,10 @@ +@@ -2015,13 +2371,17 @@ } else { Printv(f_shadow_stubs, "\ndef ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); + if ( have_docstring(n) ) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); ++ if ( have_pythonprepend(n) ) ++ Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL); Printv(f_shadow_stubs, tab4, "val = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); - if ( have_addtofunc(n) ) -@@ -1977,13 +2250,15 @@ +- if ( have_addtofunc(n) ) +- Printv(f_shadow_stubs, tab4, addtofunc(n), "\n", NIL); ++ if ( have_pythonappend(n) ) ++ Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + } + } + } +@@ -2048,13 +2408,18 @@ Delete(pyaction); Printv(f_shadow,pycode,"\n", NIL); } else { Printv(f_shadow, tab4, "def __del__(self, destroy=", module, ".", Swig_name_destroy(symname), "):\n", NIL); +- if ( have_addtofunc(n) ) +- Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); + if ( have_docstring(n) ) + Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); - if ( have_addtofunc(n) ) - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); ++ if ( have_pythonprepend(n) ) ++ Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, tab8, "try:\n", NIL); - Printv(f_shadow, tab4, tab8, "if self.thisown: destroy(self)\n", NIL); -- Printv(f_shadow, tab8, "except: pass\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL); -+ Printv(f_shadow, tab8, "except: pass\n\n", NIL); + Printv(f_shadow, tab8, "except: pass\n", NIL); ++ if ( have_pythonappend(n) ) ++ Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); ++ Printv(f_shadow, "\n", NIL); } } return SWIG_OK;