Code formatting fixes in doxygen code

This commit is contained in:
William S Fulton 2018-05-19 20:52:39 +01:00
commit 73c585b994
4 changed files with 109 additions and 111 deletions

View file

@ -53,50 +53,52 @@ static int rename_active = 0;
/* Doxygen comments scanning */ /* Doxygen comments scanning */
int scan_doxygen_comments = 0; int scan_doxygen_comments = 0;
int isStructuralDoxygen(String *s){ int isStructuralDoxygen(String *s) {
static const char* const structuralTags[] = { static const char* const structuralTags[] = {
"addtogroup", "addtogroup",
"callgraph", "callgraph",
"callergraph", "callergraph",
"category", "category",
"def", "def",
"defgroup", "defgroup",
"dir", "dir",
"example", "example",
"file", "file",
"headerfile", "headerfile",
"internal", "internal",
"mainpage", "mainpage",
"name", "name",
"nosubgrouping", "nosubgrouping",
"overload", "overload",
"package", "package",
"page", "page",
"protocol", "protocol",
"relates", "relates",
"relatesalso", "relatesalso",
"showinitializer", "showinitializer",
"weakgroup", "weakgroup",
}; };
unsigned n; unsigned n;
char *slashPointer = Strchr(s, '\\'); char *slashPointer = Strchr(s, '\\');
char *atPointer = Strchr(s,'@'); char *atPointer = Strchr(s,'@');
if (slashPointer == NULL && atPointer == NULL) return 0; if (slashPointer == NULL && atPointer == NULL)
else if( slashPointer == NULL) slashPointer = atPointer; return 0;
else if(slashPointer == NULL)
slashPointer = atPointer;
slashPointer++; /* skip backslash or at sign */ slashPointer++; /* skip backslash or at sign */
for (n = 0; n < sizeof(structuralTags)/sizeof(structuralTags[0]); n++) { for (n = 0; n < sizeof(structuralTags)/sizeof(structuralTags[0]); n++) {
const size_t len = strlen(structuralTags[n]); const size_t len = strlen(structuralTags[n]);
if (strncmp(slashPointer, structuralTags[n], len) == 0) { if (strncmp(slashPointer, structuralTags[n], len) == 0) {
/* Take care to avoid false positives with prefixes of other tags. */ /* Take care to avoid false positives with prefixes of other tags. */
if (slashPointer[len] == '\0' || isspace(slashPointer[len])) if (slashPointer[len] == '\0' || isspace(slashPointer[len]))
return 1; return 1;
} }
} }
return 0; return 0;
} }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
@ -427,7 +429,7 @@ static int yylook(void) {
do { do {
String *cmt = Scanner_text(scan); String *cmt = Scanner_text(scan);
char *loc = Char(cmt); char *loc = Char(cmt);
if ((strncmp(loc,"/*@SWIG",7) == 0) && (loc[Len(cmt)-3] == '@')) { if ((strncmp(loc, "/*@SWIG", 7) == 0) && (loc[Len(cmt)-3] == '@')) {
Scanner_locator(scan, cmt); Scanner_locator(scan, cmt);
} }
if (scan_doxygen_comments) { /* else just skip this node, to avoid crashes in parser module*/ if (scan_doxygen_comments) { /* else just skip this node, to avoid crashes in parser module*/
@ -437,9 +439,7 @@ static int yylook(void) {
if (Len(cmt) > 3 && loc[0] == '/' && if (Len(cmt) > 3 && loc[0] == '/' &&
((loc[1] == '/' && ((loc[2] == '/' && loc[3] != '/') || loc[2] == '!')) || ((loc[1] == '/' && ((loc[2] == '/' && loc[3] != '/') || loc[2] == '!')) ||
(loc[1] == '*' && ((loc[2] == '*' && loc[3] != '*') || loc[2] == '!')))) { (loc[1] == '*' && ((loc[2] == '*' && loc[3] != '*') || loc[2] == '!')))) {
comment_kind_t this_comment = loc[3] == '<' ? DOX_COMMENT_POST comment_kind_t this_comment = loc[3] == '<' ? DOX_COMMENT_POST : DOX_COMMENT_PRE;
: DOX_COMMENT_PRE;
if (existing_comment != DOX_COMMENT_NONE && this_comment != existing_comment) { if (existing_comment != DOX_COMMENT_NONE && this_comment != existing_comment) {
/* We can't concatenate together Doxygen pre- and post-comments. */ /* We can't concatenate together Doxygen pre- and post-comments. */
break; break;

View file

@ -1723,8 +1723,8 @@ program : interface {
interface : interface declaration { interface : interface declaration {
/* add declaration to end of linked list (the declaration isn't always a single declaration, sometimes it is a linked list itself) */ /* add declaration to end of linked list (the declaration isn't always a single declaration, sometimes it is a linked list itself) */
if (currentDeclComment != NULL) { if (currentDeclComment != NULL) {
set_comment($2, currentDeclComment); set_comment($2, currentDeclComment);
currentDeclComment = NULL; currentDeclComment = NULL;
} }
appendChild($1,$2); appendChild($1,$2);
$$ = $1; $$ = $1;
@ -1736,7 +1736,7 @@ interface : interface declaration {
| interface DOXYGENPOSTSTRING { | interface DOXYGENPOSTSTRING {
Node *node = lastChild($1); Node *node = lastChild($1);
if (node) { if (node) {
set_comment(node, $2); set_comment(node, $2);
} }
$$ = $1; $$ = $1;
} }
@ -5048,7 +5048,11 @@ rawparms : parm ptail {
set_nextSibling($1,$2); set_nextSibling($1,$2);
$$ = $1; $$ = $1;
} }
| empty { $$ = 0; previousNode = currentNode; currentNode=0; } | empty {
$$ = 0;
previousNode = currentNode;
currentNode=0;
}
; ;
ptail : COMMA parm ptail { ptail : COMMA parm ptail {
@ -5057,7 +5061,7 @@ ptail : COMMA parm ptail {
} }
| COMMA DOXYGENPOSTSTRING parm ptail { | COMMA DOXYGENPOSTSTRING parm ptail {
set_comment(previousNode, $2); set_comment(previousNode, $2);
set_nextSibling($3,$4); set_nextSibling($3, $4);
$$ = $3; $$ = $3;
} }
| empty { $$ = 0; } | empty { $$ = 0; }

View file

@ -591,9 +591,9 @@ public:
if (module_imports) if (module_imports)
Printf(f_module, "%s\n", module_imports); Printf(f_module, "%s\n", module_imports);
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(f_module, "/* This was generated from top() */"); Printf(f_module, "/* This was generated from top() */");
Printv(f_module, Char(doxygen_comments), NIL); Printv(f_module, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -1274,16 +1274,15 @@ public:
EnumFeature enum_feature = decodeEnumFeature(n); EnumFeature enum_feature = decodeEnumFeature(n);
String *typemap_lookup_type = Getattr(n, "name"); String *typemap_lookup_type = Getattr(n, "name");
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) { if (comment_creation_chatter) {
Printf(enum_code, "/* This was generated from enumDeclaration() */"); Printf(enum_code, "/* This was generated from enumDeclaration() */");
} }
Printv(enum_code, Char(doxygen_comments), NIL); Printv(enum_code, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
} }
if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) {
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum
@ -1306,18 +1305,16 @@ public:
Replaceall(enum_code, "$static ", ""); Replaceall(enum_code, "$static ", "");
Delete(scope); Delete(scope);
} else { } else {
//translate and write javadoc comment for the enum itself if flagged // Translate and write javadoc comment for the enum itself if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(constants_code, "/* This was generated from enumDeclaration() */"); Printf(constants_code, "/* This was generated from enumDeclaration() */");
Printf(constants_code, "/* Comment for enum %s */\n", Printf(constants_code, "/* Comment for enum %s */\n", Getattr(n, "unnamedinstance") ? "" : symname);
Getattr(n, "unnamedinstance") ? "" : symname);
Printf(constants_code, Char(doxygen_comments)); Printf(constants_code, Char(doxygen_comments));
Printf(constants_code, "\n"); Printf(constants_code, "\n");
Delete(doxygen_comments); Delete(doxygen_comments);
} } else if (symname && !Getattr(n, "unnamedinstance"))
else if (symname && !Getattr(n, "unnamedinstance"))
Printf(constants_code, " // %s \n", symname); Printf(constants_code, " // %s \n", symname);
} }
@ -1472,10 +1469,10 @@ public:
if (!addSymbol(symname, n, scope)) if (!addSymbol(symname, n, scope))
return SWIG_ERROR; return SWIG_ERROR;
//translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(enum_code, "/* This was generated from enumvalueDeclaration() */"); Printf(enum_code, "/* This was generated from enumvalueDeclaration() */");
Printv(enum_code, Char(doxygen_comments), NIL); Printv(enum_code, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -1557,13 +1554,12 @@ public:
String *tm; String *tm;
String *return_type = NewString(""); String *return_type = NewString("");
String *constants_code = NewString(""); String *constants_code = NewString("");
Swig_save("constantWrapper", n, "value", NIL); Swig_save("constantWrapper", n, "value", NIL);
//translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(constants_code, "/* This was generated from constantWrapper() */"); Printf(constants_code, "/* This was generated from constantWrapper() */");
Printv(constants_code, Char(doxygen_comments), NIL); Printv(constants_code, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -2009,10 +2005,10 @@ public:
// Pure Java interfaces // Pure Java interfaces
const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
//translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(proxy_class_def, "/* This was generated from emitProxyClassDefAndCPPCasts() */"); Printf(proxy_class_def, "/* This was generated from emitProxyClassDefAndCPPCasts() */");
Printv(proxy_class_def, Char(doxygen_comments), NIL); Printv(proxy_class_def, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -2021,7 +2017,6 @@ public:
if (*Char(interface_list) && *Char(pure_interfaces)) if (*Char(interface_list) && *Char(pure_interfaces))
Append(interface_list, ", "); Append(interface_list, ", ");
Append(interface_list, pure_interfaces); Append(interface_list, pure_interfaces);
// Start writing the proxy class // Start writing the proxy class
if (!has_outerclass) // Import statements if (!has_outerclass) // Import statements
Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE),"\n", NIL); Printv(proxy_class_def, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE),"\n", NIL);
@ -2507,10 +2502,10 @@ public:
setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) == 0); setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(getNSpace(), Swig_name_member(0, getClassPrefix(), variable_name))) == 0);
} }
//translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(function_code, "/* This was generated from proxyclassfunctionhandler() */"); Printf(function_code, "/* This was generated from proxyclassfunctionhandler() */");
Printv(function_code, Char(doxygen_comments), NIL); Printv(function_code, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -2751,10 +2746,10 @@ public:
tm = Getattr(n, "tmap:jtype"); // typemaps were attached earlier to the node tm = Getattr(n, "tmap:jtype"); // typemaps were attached earlier to the node
Printf(im_return_type, "%s", tm); Printf(im_return_type, "%s", tm);
//translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(function_code, "/* This was generated from constructionhandler() */"); Printf(function_code, "/* This was generated from constructionhandler() */");
Printv(function_code, Char(doxygen_comments), NIL); Printv(function_code, Char(doxygen_comments), NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -3025,10 +3020,10 @@ public:
String *pre_code = NewString(""); String *pre_code = NewString("");
String *post_code = NewString(""); String *post_code = NewString("");
// translate and write javadoc comment if flagged // Translate and write javadoc comment if flagged
if (doxygen && doxygenTranslator->hasDocumentation(n)){ if (doxygen && doxygenTranslator->hasDocumentation(n)) {
String *doxygen_comments=doxygenTranslator->getDocumentation(n); String *doxygen_comments = doxygenTranslator->getDocumentation(n);
if(comment_creation_chatter) if (comment_creation_chatter)
Printf(function_code, "/* This was generated from moduleClassFunctionHandler() */"); Printf(function_code, "/* This was generated from moduleClassFunctionHandler() */");
Printv(function_code, doxygen_comments, NIL); Printv(function_code, doxygen_comments, NIL);
Delete(doxygen_comments); Delete(doxygen_comments);
@ -3514,7 +3509,6 @@ public:
const String *pure_baseclass = typemapLookup(n, "javabase", type, WARN_NONE); const String *pure_baseclass = typemapLookup(n, "javabase", type, WARN_NONE);
const String *pure_interfaces = typemapLookup(n, "javainterfaces", type, WARN_NONE); const String *pure_interfaces = typemapLookup(n, "javainterfaces", type, WARN_NONE);
// Emit the class // Emit the class
Printv(swigtype, typemapLookup(n, "javaimports", type, WARN_NONE), // Import statements Printv(swigtype, typemapLookup(n, "javaimports", type, WARN_NONE), // Import statements
"\n", typemapLookup(n, "javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers "\n", typemapLookup(n, "javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
@ -4993,4 +4987,3 @@ Java Options (available with -java)\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\ -oldvarnames - Old intermediary method names for variable wrappers\n\
-package <name> - Set name of the Java package to <name>\n\ -package <name> - Set name of the Java package to <name>\n\
\n"; \n";

View file

@ -1688,14 +1688,16 @@ public:
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* build_combined_docstring() * build_combined_docstring()
* Build the full docstring which may be a combination of the
* explicit docstring and autodoc string or, if none of them
* is specified, obtained by translating Doxygen comment to
* Python.
* *
* Return new string to be deleted by caller (never NIL but * Build the full docstring which may be a combination of the
* may be empty if there is no docstring). * explicit docstring and autodoc string or, if none of them
* is specified, obtained by translating Doxygen comment to
* Python.
*
* Return new string to be deleted by caller (never NIL but
* may be empty if there is no docstring).
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "") { String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "") {
String *docstr = Getattr(n, "feature:docstring"); String *docstr = Getattr(n, "feature:docstring");
if (docstr && Len(docstr)) { if (docstr && Len(docstr)) {
@ -1708,14 +1710,14 @@ public:
} }
if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) { if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) {
String* autodoc = make_autodoc(n, ad_type); String *autodoc = make_autodoc(n, ad_type);
if (autodoc && Len(autodoc) > 0) { if (autodoc && Len(autodoc) > 0) {
if (docstr && Len(docstr)) { if (docstr && Len(docstr)) {
Append(autodoc, "\n"); Append(autodoc, "\n");
Append(autodoc, docstr); Append(autodoc, docstr);
} }
String* tmp = autodoc; String *tmp = autodoc;
autodoc = docstr; autodoc = docstr;
docstr = tmp; docstr = tmp;
} }
@ -1751,8 +1753,7 @@ public:
// """ // """
// //
// otherwise, put it all on a single line // otherwise, put it all on a single line
if (Strchr(docstr, '\n')) if (Strchr(docstr, '\n')) {
{
String *tmp = NewString(""); String *tmp = NewString("");
Append(tmp, "\n"); Append(tmp, "\n");
Append(tmp, indent_docstring(docstr, indent)); Append(tmp, indent_docstring(docstr, indent));
@ -3728,7 +3729,7 @@ public:
} }
if (f_s) { if (f_s) {
if(needs_swigconstant(n)) { if (needs_swigconstant(n)) {
Printv(f_s, "\n",NIL); Printv(f_s, "\n",NIL);
Printv(f_s, module, ".", iname, "_swigconstant(",module,")\n", NIL); Printv(f_s, module, ".", iname, "_swigconstant(",module,")\n", NIL);
} }