Numerous autodoc fixes for Python
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12735 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
50425dc95e
commit
3243cbaad4
7 changed files with 471 additions and 161 deletions
|
|
@ -1,9 +1,9 @@
|
|||
%module(docstring="hello") python_autodoc
|
||||
%module(docstring="hello") autodoc
|
||||
|
||||
%feature("autodoc");
|
||||
|
||||
// especial typemap and its docs
|
||||
%typemap(in) (int c, int d) "$1 =0; $2 = 0;";
|
||||
// special typemap and its docs
|
||||
%typemap(in) (int c, int d) "$1 = 0; $2 = 0;";
|
||||
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
|
||||
|
||||
// testing for different documentation levels
|
||||
|
|
@ -12,7 +12,22 @@
|
|||
%feature("autodoc","2") A::func2; // extended
|
||||
%feature("autodoc","3") A::func3; // extended + types
|
||||
|
||||
%feature("autodoc","just a string") A::func; // names
|
||||
%feature("autodoc","0") A::func0default; // names
|
||||
%feature("autodoc","1") A::func1default; // names + types
|
||||
%feature("autodoc","2") A::func2default; // extended
|
||||
%feature("autodoc","3") A::func3default; // extended + types
|
||||
|
||||
%feature("autodoc","0") A::func0static; // names
|
||||
%feature("autodoc","1") A::func1static; // names + types
|
||||
%feature("autodoc","2") A::func2static; // extended
|
||||
%feature("autodoc","3") A::func3static; // extended + types
|
||||
|
||||
%feature("autodoc","0") A::variable_a; // names
|
||||
%feature("autodoc","1") A::variable_b; // names + types
|
||||
%feature("autodoc","2") A::variable_c; // extended
|
||||
%feature("autodoc","3") A::variable_d; // extended + types
|
||||
|
||||
%feature("autodoc","just a string") A::funk; // names
|
||||
|
||||
%inline {
|
||||
|
||||
|
|
@ -20,36 +35,29 @@
|
|||
hi, hello
|
||||
};
|
||||
|
||||
struct A
|
||||
{
|
||||
A(int a, short b, Hola h)
|
||||
{
|
||||
}
|
||||
struct A {
|
||||
A(int a, short b, Hola h) {}
|
||||
int funk(int a) { return a; }
|
||||
|
||||
int func(int a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
int func0(short, int c, int d) { return c; }
|
||||
int func1(short, int c, int d) { return c; }
|
||||
int func2(short, int c, int d) { return c; }
|
||||
int func3(short, int c, int d) { return c; }
|
||||
|
||||
int func0(int c, int d)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
int func1(int c, int d)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
int func0default(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
int func1default(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
int func2default(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
int func3default(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
|
||||
int func2(A* c, double d = 2)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
static int func0static(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
static int func1static(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
static int func2static(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
static int func3static(A *e, short, int c, int d, double f = 2) { return 0; }
|
||||
|
||||
int func3(A* c, double d = 2)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
int variable_a;
|
||||
int variable_b;
|
||||
int variable_c;
|
||||
int variable_d;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -62,34 +70,66 @@
|
|||
%typemap(doc) int a "a: special comment for parameter a";
|
||||
%typemap(doc) int b "b: another special comment for parameter b";
|
||||
|
||||
%callback(1) func_cb;
|
||||
%feature("autodoc","0") C::C(int a, int b, Hola h); // names
|
||||
%feature("autodoc","1") D::D(int a, int b, Hola h); // names + types
|
||||
%feature("autodoc","2") E::E(int a, int b, Hola h); // extended
|
||||
%feature("autodoc","3") F::F(int a, int b, Hola h); // extended + types
|
||||
|
||||
%inline {
|
||||
|
||||
struct B
|
||||
{
|
||||
B(int a, int b, Hola h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int func(int c, int d)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
struct B {
|
||||
B(int a, int b, Hola h) {}
|
||||
int funk(int c, int d) { return c; }
|
||||
};
|
||||
|
||||
int func(int c, int d) {
|
||||
return c;
|
||||
}
|
||||
struct C {
|
||||
C(int a, int b, Hola h) {}
|
||||
};
|
||||
struct D {
|
||||
D(int a, int b, Hola h) {}
|
||||
};
|
||||
struct E {
|
||||
E(int a, int b, Hola h) {}
|
||||
};
|
||||
struct F {
|
||||
F(int a, int b, Hola h) {}
|
||||
};
|
||||
|
||||
int funcio(int *INOUT) {
|
||||
int funk(A *e, short, int c, int d) { return c; }
|
||||
int funkdefaults(A *e, short, int c, int d, double f = 2) { return c; }
|
||||
}
|
||||
|
||||
%include <typemaps.i>
|
||||
%inline %{
|
||||
int func_input(int *INPUT) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int func_cb(int c, int d) {
|
||||
return c;
|
||||
int func_output(int *OUTPUT) {
|
||||
*OUTPUT = 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int func_inout(int *INOUT) {
|
||||
*INOUT += 1;
|
||||
return 1;
|
||||
}
|
||||
%}
|
||||
|
||||
%callback(1) func_cb;
|
||||
|
||||
%inline {
|
||||
int func_cb(int c, int d) { return c; }
|
||||
}
|
||||
|
||||
// Bug 3310528
|
||||
%feature("autodoc","1") banana; // names + types
|
||||
%inline %{
|
||||
typedef struct tagS {
|
||||
int a;
|
||||
char b;
|
||||
} S;
|
||||
|
||||
typedef int Integer;
|
||||
|
||||
void banana(S *a, const struct tagS *b, int c, Integer d) {}
|
||||
%}
|
||||
|
||||
|
|
|
|||
176
Examples/test-suite/python/autodoc_runme.py
Normal file
176
Examples/test-suite/python/autodoc_runme.py
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
from autodoc import *
|
||||
|
||||
def check(got, expected):
|
||||
if expected != got:
|
||||
raise RuntimeError("\n" + "Expected: [" + expected + "]\n" + "Got : [" + got + "]")
|
||||
|
||||
check(A.__doc__, "Proxy of C++ A class")
|
||||
check(A.funk.__doc__, "just a string")
|
||||
check(A.func0.__doc__, "func0(self, arg2, hello) -> int")
|
||||
check(A.func1.__doc__, "func1(A self, short arg2, Tuple hello) -> int")
|
||||
check(A.func2.__doc__, "\n"
|
||||
" func2(self, arg2, hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
check(A.func3.__doc__, "\n"
|
||||
" func3(A self, short arg2, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
|
||||
check(A.func0default.__doc__, "\n"
|
||||
" func0default(self, e, arg3, hello, f=2) -> int\n"
|
||||
" func0default(self, e, arg3, hello) -> int\n"
|
||||
" "
|
||||
)
|
||||
check(A.func1default.__doc__, "\n"
|
||||
" func1default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
||||
" func1default(A self, A e, short arg3, Tuple hello) -> int\n"
|
||||
" "
|
||||
)
|
||||
check(A.func2default.__doc__, "\n"
|
||||
" func2default(self, e, arg3, hello, f=2) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"\n"
|
||||
" func2default(self, e, arg3, hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
check(A.func3default.__doc__, "\n"
|
||||
" func3default(A self, A e, short arg3, Tuple hello, double f=2) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"\n"
|
||||
" func3default(A self, A e, short arg3, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg3: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
|
||||
check(A.func0static.__doc__, "\n"
|
||||
" func0static(e, arg2, hello, f=2) -> int\n"
|
||||
" func0static(e, arg2, hello) -> int\n"
|
||||
" "
|
||||
)
|
||||
check(A.func1static.__doc__, "\n"
|
||||
" func1static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
||||
" func1static(A e, short arg2, Tuple hello) -> int\n"
|
||||
" "
|
||||
)
|
||||
check(A.func2static.__doc__, "\n"
|
||||
" func2static(e, arg2, hello, f=2) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"\n"
|
||||
" func2static(e, arg2, hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
check(A.func3static.__doc__, "\n"
|
||||
" func3static(A e, short arg2, Tuple hello, double f=2) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
" f: double\n"
|
||||
"\n"
|
||||
" func3static(A e, short arg2, Tuple hello) -> int\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" e: A *\n"
|
||||
" arg2: short\n"
|
||||
" hello: int tuple[2]\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
|
||||
check(A.variable_a.__doc__, "A_variable_a_get(self) -> int")
|
||||
check(A.variable_b.__doc__, "A_variable_b_get(A self) -> int")
|
||||
check(A.variable_c.__doc__, "\n"
|
||||
"A_variable_c_get(self) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" self: A *\n"
|
||||
"\n"
|
||||
)
|
||||
check(A.variable_d.__doc__, "\n"
|
||||
"A_variable_d_get(A self) -> int\n"
|
||||
"\n"
|
||||
"Parameters:\n"
|
||||
" self: A *\n"
|
||||
"\n"
|
||||
)
|
||||
|
||||
check(B.__doc__, "Proxy of C++ B class")
|
||||
check(C.__init__.__doc__, "__init__(self, a, b, h) -> C")
|
||||
check(D.__init__.__doc__, "__init__(D self, int a, int b, Hola h) -> D")
|
||||
check(E.__init__.__doc__, "\n"
|
||||
" __init__(self, a, b, h) -> E\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" a: special comment for parameter a\n"
|
||||
" b: another special comment for parameter b\n"
|
||||
" h: enum Hola\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
check(F.__init__.__doc__, "\n"
|
||||
" __init__(F self, int a, int b, Hola h) -> F\n"
|
||||
"\n"
|
||||
" Parameters:\n"
|
||||
" a: special comment for parameter a\n"
|
||||
" b: another special comment for parameter b\n"
|
||||
" h: enum Hola\n"
|
||||
"\n"
|
||||
" "
|
||||
)
|
||||
|
||||
check(B.funk.__doc__, "funk(B self, int c, int d) -> int")
|
||||
check(funk.__doc__, "funk(A e, short arg2, int c, int d) -> int")
|
||||
check(funkdefaults.__doc__, "\n"
|
||||
" funkdefaults(A e, short arg2, int c, int d, double f=2) -> int\n"
|
||||
" funkdefaults(A e, short arg2, int c, int d) -> int\n"
|
||||
" "
|
||||
)
|
||||
|
||||
check(func_input.__doc__, "func_input(int * INPUT) -> int")
|
||||
check(func_output.__doc__, "func_output() -> int")
|
||||
check(func_inout.__doc__, "func_inout(int * INOUT) -> int")
|
||||
check(banana.__doc__, "banana(S a, S b, int c, Integer d)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue