Python: Option to generate flat class methods
This commit is contained in:
parent
a6eae77dd5
commit
484e5316f2
3 changed files with 14 additions and 9 deletions
|
|
@ -957,6 +957,7 @@ swig -python -help
|
||||||
<tr><td>-doxygen </td><td>Convert C++ doxygen comments to pydoc comments in proxy classes</td></tr>
|
<tr><td>-doxygen </td><td>Convert C++ doxygen comments to pydoc comments in proxy classes</td></tr>
|
||||||
<tr><td>-extranative </td><td>Return extra native wrappers for C++ std containers wherever possible</td></tr>
|
<tr><td>-extranative </td><td>Return extra native wrappers for C++ std containers wherever possible</td></tr>
|
||||||
<tr><td>-fastproxy </td><td>Use fast proxy mechanism for member methods</td></tr>
|
<tr><td>-fastproxy </td><td>Use fast proxy mechanism for member methods</td></tr>
|
||||||
|
<tr><td>-flatstaticmethod </td><td>Generate Foo_bar for static method Foo::bar</td></tr>
|
||||||
<tr><td>-globals <name> </td><td>Set <name> used to access C global variable (default: 'cvar')</td></tr>
|
<tr><td>-globals <name> </td><td>Set <name> used to access C global variable (default: 'cvar')</td></tr>
|
||||||
<tr><td>-interface <mod></td><td>Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')</td></tr>
|
<tr><td>-interface <mod></td><td>Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')</td></tr>
|
||||||
<tr><td>-keyword </td><td>Use keyword arguments</td></tr>
|
<tr><td>-keyword </td><td>Use keyword arguments</td></tr>
|
||||||
|
|
@ -1616,16 +1617,15 @@ In Python, the static member can be accessed in three different ways:
|
||||||
|
|
||||||
<div class="targetlang">
|
<div class="targetlang">
|
||||||
<pre>
|
<pre>
|
||||||
>>> example.Spam_foo() # Spam::foo()
|
|
||||||
>>> s = example.Spam()
|
>>> s = example.Spam()
|
||||||
>>> s.foo() # Spam::foo() via an instance
|
>>> s.foo() # Spam::foo() via an instance
|
||||||
>>> example.Spam.foo() # Spam::foo() using Python-2.2 and later
|
>>> example.Spam.foo() # Spam::foo() using class method
|
||||||
|
>>> example.Spam_foo() # Spam::foo() "flattened" name
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The first two methods of access are supported in all versions of Python. The
|
The last technique is only available when using the <tt>-flatstaticmethod</tt> option.
|
||||||
last technique is only available in Python-2.2 and later versions.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ LIBS = -L.
|
||||||
VALGRIND_OPT += --suppressions=pythonswig.supp
|
VALGRIND_OPT += --suppressions=pythonswig.supp
|
||||||
|
|
||||||
# Custom tests - tests with additional commandline options
|
# Custom tests - tests with additional commandline options
|
||||||
#python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
|
python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod
|
||||||
|
|
||||||
# Rules for the different types of tests
|
# Rules for the different types of tests
|
||||||
%.cpptest:
|
%.cpptest:
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ static int castmode = 0;
|
||||||
static int extranative = 0;
|
static int extranative = 0;
|
||||||
static int nortti = 0;
|
static int nortti = 0;
|
||||||
static int relativeimport = 0;
|
static int relativeimport = 0;
|
||||||
|
static int flat_static_method = 0;
|
||||||
|
|
||||||
/* flags for the make_autodoc function */
|
/* flags for the make_autodoc function */
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -118,6 +119,7 @@ Python Options (available with -python)\n\
|
||||||
-doxygen - Convert C++ doxygen comments to pydoc comments in proxy classes\n\
|
-doxygen - Convert C++ doxygen comments to pydoc comments in proxy classes\n\
|
||||||
-extranative - Return extra native wrappers for C++ std containers wherever possible\n\
|
-extranative - Return extra native wrappers for C++ std containers wherever possible\n\
|
||||||
-fastproxy - Use fast proxy mechanism for member methods\n\
|
-fastproxy - Use fast proxy mechanism for member methods\n\
|
||||||
|
-flatstaticmethod - Generate Foo_bar for static method Foo::bar\n\
|
||||||
-globals <name> - Set <name> used to access C global variable (default: 'cvar')\n\
|
-globals <name> - Set <name> used to access C global variable (default: 'cvar')\n\
|
||||||
-interface <mod>- Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')\n\
|
-interface <mod>- Set low-level C/C++ module name to <mod> (default: module name prefixed by '_')\n\
|
||||||
-keyword - Use keyword arguments\n";
|
-keyword - Use keyword arguments\n";
|
||||||
|
|
@ -373,6 +375,9 @@ public:
|
||||||
} else if (strcmp(argv[i], "-extranative") == 0) {
|
} else if (strcmp(argv[i], "-extranative") == 0) {
|
||||||
extranative = 1;
|
extranative = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i], "-flatstaticmethod") == 0) {
|
||||||
|
flat_static_method = 1;
|
||||||
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i], "-noh") == 0) {
|
} else if (strcmp(argv[i], "-noh") == 0) {
|
||||||
no_header_file = 1;
|
no_header_file = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
|
@ -2636,11 +2641,11 @@ public:
|
||||||
Printv(f->code, "}\n", NIL);
|
Printv(f->code, "}\n", NIL);
|
||||||
Wrapper_print(f, f_wrappers);
|
Wrapper_print(f, f_wrappers);
|
||||||
Node *p = Getattr(n, "sym:previousSibling");
|
Node *p = Getattr(n, "sym:previousSibling");
|
||||||
if (!builtin_self)
|
if (!builtin_self && (flat_static_method || !in_class || !builtin))
|
||||||
add_method(symname, wname, 0, p);
|
add_method(symname, wname, 0, p);
|
||||||
|
|
||||||
/* Create a shadow for this function (if enabled and not in a member function) */
|
/* Create a shadow for this function (if enabled and not in a member function) */
|
||||||
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
|
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (flat_static_method || !in_class)) {
|
||||||
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, symname, 0);
|
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, symname, 0);
|
||||||
}
|
}
|
||||||
DelWrapper(f);
|
DelWrapper(f);
|
||||||
|
|
@ -3309,11 +3314,11 @@ public:
|
||||||
|
|
||||||
/* Now register the function with the interpreter. */
|
/* Now register the function with the interpreter. */
|
||||||
if (!Getattr(n, "sym:overloaded")) {
|
if (!Getattr(n, "sym:overloaded")) {
|
||||||
if (!builtin_self)
|
if (!builtin_self && (flat_static_method || !in_class || !builtin))
|
||||||
add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
|
add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
|
||||||
|
|
||||||
/* Create a shadow for this function (if enabled and not in a member function) */
|
/* Create a shadow for this function (if enabled and not in a member function) */
|
||||||
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
|
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (flat_static_method || !in_class)) {
|
||||||
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
|
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue