better documented autodoc levels
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6318 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
776f15623e
commit
9455a03257
2 changed files with 91 additions and 18 deletions
|
|
@ -1,11 +1,19 @@
|
||||||
%module autodoc
|
%module autodoc
|
||||||
|
|
||||||
%feature("autodoc","extended");
|
%feature("autodoc");
|
||||||
|
|
||||||
// especial typemap and its docs
|
// especial typemap and its docs
|
||||||
%typemap(in) (int c, int d) "$1 =0; $2 = 0;";
|
%typemap(in) (int c, int d) "$1 =0; $2 = 0;";
|
||||||
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
|
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
|
||||||
|
|
||||||
|
// testing for different documentation levels
|
||||||
|
%feature("autodoc","0") A::func0; // names
|
||||||
|
%feature("autodoc","1") A::func1; // names + types
|
||||||
|
%feature("autodoc","2") A::func2; // extended
|
||||||
|
%feature("autodoc","3") A::func3; // extended + types
|
||||||
|
|
||||||
|
%feature("autodoc","just a string") A::func; // names
|
||||||
|
|
||||||
%inline {
|
%inline {
|
||||||
|
|
||||||
enum Hola {
|
enum Hola {
|
||||||
|
|
@ -17,18 +25,31 @@
|
||||||
A(int a, short b, Hola h)
|
A(int a, short b, Hola h)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int func1(int c, int d)
|
int func(int a)
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
int func0(int c, int d)
|
||||||
{
|
{
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int func1(int c, int d)
|
||||||
|
{
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
int func2(A* c, double d = 2)
|
int func2(A* c, double d = 2)
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int func3(A* c, double d = 2)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ static int in_class = 0;
|
||||||
static int classic = 0;
|
static int classic = 0;
|
||||||
static int modern = 0;
|
static int modern = 0;
|
||||||
static int apply = 0;
|
static int apply = 0;
|
||||||
static int new_repr = 0;
|
static int new_repr = 1;
|
||||||
|
|
||||||
/* C++ Support + Shadow Classes */
|
/* C++ Support + Shadow Classes */
|
||||||
|
|
||||||
|
|
@ -71,6 +71,7 @@ Python Options (available with -python)\n\
|
||||||
-modern - Use modern python features only, without compatibility code\n\
|
-modern - Use modern python features only, without compatibility code\n\
|
||||||
-apply - Use apply() in proxy classes\n\
|
-apply - Use apply() in proxy classes\n\
|
||||||
-new_repr - Use more informative version of __repr__ in proxy classes\n\
|
-new_repr - Use more informative version of __repr__ in proxy classes\n\
|
||||||
|
-old_repr - Use shorter version of __repr__ in proxy classes\n\
|
||||||
-noexcept - No automatic exception handling\n\
|
-noexcept - No automatic exception handling\n\
|
||||||
-noproxy - Don't generate proxy classes \n\n";
|
-noproxy - Don't generate proxy classes \n\n";
|
||||||
|
|
||||||
|
|
@ -118,6 +119,9 @@ public:
|
||||||
} else if (strcmp(argv[i],"-new_repr") == 0) {
|
} else if (strcmp(argv[i],"-new_repr") == 0) {
|
||||||
new_repr = 1;
|
new_repr = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i],"-old_repr") == 0) {
|
||||||
|
new_repr = 0;
|
||||||
|
Swig_mark_arg(i);
|
||||||
} else if ((strcmp(argv[i],"-noproxy") == 0)) {
|
} else if ((strcmp(argv[i],"-noproxy") == 0)) {
|
||||||
shadow = 0;
|
shadow = 0;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
|
@ -462,15 +466,51 @@ public:
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum autodoc_l {
|
||||||
|
NO_AUTODOC = -2, // no autodoc
|
||||||
|
STRING_AUTODOC = -1, // use provided string
|
||||||
|
NAMES_AUTODOC = 0, // only parameter names
|
||||||
|
TYPES_AUTODOC = 1, // parameter names and types
|
||||||
|
EXTEND_AUTODOC = 2, // extended documentation and parameter names
|
||||||
|
EXTEND_TYPES_AUTODOC = 3 // extended documentation and parameter types + names
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Autodoc Levels:
|
||||||
|
-2
|
||||||
|
-1
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
*/
|
||||||
|
autodoc_l autodoc_level(String *autodoc) {
|
||||||
|
autodoc_l dlevel = NO_AUTODOC;
|
||||||
|
if (autodoc) {
|
||||||
|
char *c = Char(autodoc);
|
||||||
|
if (c && isdigit(c[0])) {
|
||||||
|
dlevel = (autodoc_l) atoi(c);
|
||||||
|
} else {
|
||||||
|
if (strcmp(c,"extended")== 0) {
|
||||||
|
dlevel = EXTEND_AUTODOC;
|
||||||
|
} else {
|
||||||
|
dlevel = STRING_AUTODOC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dlevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int functionHandler(Node *n) {
|
int functionHandler(Node *n) {
|
||||||
if (checkAttribute(n,"feature:python:callback","1")) {
|
if (checkAttribute(n,"feature:python:callback","1")) {
|
||||||
Setattr(n,"feature:callback","%s_cb_ptr");
|
Setattr(n,"feature:callback","%s_cb_ptr");
|
||||||
if (checkAttribute(n,"feature:autodoc","extended")) {
|
autodoc_l dlevel = autodoc_level(Getattr(n, "feature:autodoc"));
|
||||||
|
if (dlevel != NO_AUTODOC && dlevel > TYPES_AUTODOC) {
|
||||||
Setattr(n,"feature:autodoc","1");
|
Setattr(n,"feature:autodoc","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Language::functionHandler(n);
|
return Language::functionHandler(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -626,20 +666,29 @@ public:
|
||||||
while (n) {
|
while (n) {
|
||||||
bool showTypes = false;
|
bool showTypes = false;
|
||||||
bool skipAuto = false;
|
bool skipAuto = false;
|
||||||
|
String *autodoc = Getattr(n,"feature:autodoc");
|
||||||
// check how should the parameters be rendered?
|
autodoc_l dlevel = autodoc_level(autodoc);
|
||||||
String* autodoc = Getattr(n, "feature:autodoc");
|
switch (dlevel) {
|
||||||
if (Strcmp(autodoc, "0") == 0)
|
case NO_AUTODOC:
|
||||||
|
break;
|
||||||
|
case NAMES_AUTODOC:
|
||||||
showTypes = false;
|
showTypes = false;
|
||||||
else if (Strcmp(autodoc, "1") == 0)
|
break;
|
||||||
|
case TYPES_AUTODOC:
|
||||||
showTypes = true;
|
showTypes = true;
|
||||||
else if (Strcmp(autodoc, "extended") == 0) {
|
break;
|
||||||
|
case EXTEND_AUTODOC:
|
||||||
extended = 1;
|
extended = 1;
|
||||||
showTypes = false;
|
showTypes = false;
|
||||||
} else {
|
break;
|
||||||
// if not "0" or "1" then autodoc is already the string that should be used
|
case EXTEND_TYPES_AUTODOC:
|
||||||
|
extended = 1;
|
||||||
|
showTypes = true;
|
||||||
|
break;
|
||||||
|
case STRING_AUTODOC:
|
||||||
Printf(doc, "%s", autodoc);
|
Printf(doc, "%s", autodoc);
|
||||||
skipAuto = true;
|
skipAuto = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipAuto) {
|
if (!skipAuto) {
|
||||||
|
|
@ -664,9 +713,12 @@ public:
|
||||||
|
|
||||||
switch ( ad_type ) {
|
switch ( ad_type ) {
|
||||||
case AUTODOC_CLASS:
|
case AUTODOC_CLASS:
|
||||||
Printf(doc, "Automatic wrap of C/C++ '%s' type", class_name);
|
if (CPlusPlus) {
|
||||||
break;
|
Printf(doc, "Proxy of C++ %s class", class_name);
|
||||||
|
} else {
|
||||||
|
Printf(doc, "Proxy of C %s struct", class_name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case AUTODOC_CTOR:
|
case AUTODOC_CTOR:
|
||||||
if ( Strcmp(class_name, symname) == 0) {
|
if ( Strcmp(class_name, symname) == 0) {
|
||||||
String* paramList = make_autodocParmList(n, showTypes);
|
String* paramList = make_autodocParmList(n, showTypes);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue