diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2015-05-16 19:24:03 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2015-05-16 19:45:48 +0100 |
commit | 0e4d8f70ee19ebd651ca6de43197beffb324c495 (patch) | |
tree | 5dbfb8dd626f488aba9e3740f7abc568c91c7cc7 | |
parent | fa69c2a96033287e5e97e2630aae9352dc29ccb2 (diff) | |
download | swig-0e4d8f70ee19ebd651ca6de43197beffb324c495.tar.gz |
Doxygen code cosmetic style corrections
Formatting changes and a few variable and function name changes.
-rw-r--r-- | Source/CParse/cscanner.c | 2 | ||||
-rw-r--r-- | Source/CParse/parser.y | 116 | ||||
-rw-r--r-- | Source/Modules/java.cxx | 116 | ||||
-rw-r--r-- | Source/Modules/lang.cxx | 9 | ||||
-rw-r--r-- | Source/Modules/python.cxx | 21 | ||||
-rw-r--r-- | Source/Modules/swigmod.h | 2 | ||||
-rw-r--r-- | Source/Swig/misc.c | 2 |
7 files changed, 140 insertions, 128 deletions
diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 619bc6215..5dce570a7 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -925,7 +925,7 @@ int yylex(void) { case POUND: return yylex(); case SWIG_TOKEN_COMMENT: - return yylex(); + return yylex(); default: return (l); } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index d36717cca..1bd1fab21 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -60,57 +60,61 @@ static int template_reduce = 0; static int cparse_externc = 0; int ignore_nested_classes = 0; int kwargs_supported = 0; + /* ----------------------------------------------------------------------------- * Doxygen Comment Globals and Assist Functions * ----------------------------------------------------------------------------- */ + static String *currentDeclComment = NULL; /* Comment of C/C++ declaration. */ static Node *previousNode = NULL; /* Pointer to the previous node (for post comments) */ static Node *currentNode = NULL; /* Pointer to the current node (for post comments) */ -int isStructuralDoxygen(String *s){ - static const char* const structuralTags[] = { - "addtogroup", - "callgraph", - "callergraph", - "category", - "def", - "defgroup", - "dir", - "example", - "file", - "headerfile", - "internal", - "mainpage", - "name", - "nosubgrouping", - "overload", - "package", - "page", - "protocol", - "relates", - "relatesalso", - "showinitializer", - "weakgroup", - }; - - unsigned n; - char *slashPointer = Strchr(s, '\\'); - char *atPointer = Strchr(s,'@'); - if (slashPointer == NULL && atPointer == NULL) return 0; - else if( slashPointer == NULL) slashPointer = atPointer; - - slashPointer++; /* skip backslash or at sign */ - - for (n = 0; n < sizeof(structuralTags)/sizeof(structuralTags[0]); n++) { - const size_t len = strlen(structuralTags[n]); - if (strncmp(slashPointer, structuralTags[n], len) == 0) { - /* Take care to avoid false positives with prefixes of other tags. */ - if (slashPointer[len] == '\0' || isspace(slashPointer[len])) - return 1; - } - } +int is_structural_doxygen(String *s) { + static const char* const structuralTags[] = { + "addtogroup", + "callgraph", + "callergraph", + "category", + "def", + "defgroup", + "dir", + "example", + "file", + "headerfile", + "internal", + "mainpage", + "name", + "nosubgrouping", + "overload", + "package", + "page", + "protocol", + "relates", + "relatesalso", + "showinitializer", + "weakgroup" + }; + + unsigned int i; + char *slashPointer = Strchr(s, '\\'); + char *atPointer = Strchr(s,'@'); + if (slashPointer == NULL && atPointer == NULL) + return 0; + else if (slashPointer == NULL) + slashPointer = atPointer; + + slashPointer++; /* skip backslash or at sign */ + + for (i = 0; i < sizeof(structuralTags) / sizeof(structuralTags[0]); i++) { + const size_t len = strlen(structuralTags[i]); + if (strncmp(slashPointer, structuralTags[i], len) == 0) { + /* Take care to avoid false positives with prefixes of other tags. */ + if (slashPointer[len] == '\0' || isspace(slashPointer[len])) + return 1; + } + } - return 0; + return 0; } /* ----------------------------------------------------------------------------- @@ -220,16 +224,16 @@ static void set_comment(Node *n, String *comment) { if (!n || !comment) return; - if (Getattr(n, "doxygen")) + if (Getattr(n, "doxygen")) { Append(Getattr(n, "doxygen"), comment); - else { + } else { Setattr(n, "doxygen", comment); /* This is the first comment, populate it with @params, if any */ p = Getattr(n, "parms"); while (p) { if (Getattr(p, "doxygen")) Printv(comment, "\n@param ", Getattr(p, "name"), Getattr(p, "doxygen"), NIL); - p=nextSibling(p); + p = nextSibling(p); } } @@ -1598,8 +1602,8 @@ program : interface { 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) */ if (currentDeclComment != NULL) { - set_comment($2, currentDeclComment); - currentDeclComment = NULL; + set_comment($2, currentDeclComment); + currentDeclComment = NULL; } appendChild($1,$2); $$ = $1; @@ -1611,7 +1615,7 @@ interface : interface declaration { | interface doxygen_post_comment { Node *node = lastChild($1); if (node) { - set_comment(node, $2); + set_comment(node, $2); } $$ = $1; } @@ -3476,7 +3480,7 @@ doxygen_comment_item : DOXYGENSTRING { DohReplace($1, "*/", "", 0); /* Throw out all structural comments */ - if (isStructuralDoxygen($1)) { + if (is_structural_doxygen($1)) { Delete($1); $1 = 0; } @@ -4891,7 +4895,11 @@ rawparms : parm ptail { set_nextSibling($1,$2); $$ = $1; } - | empty { $$ = 0; previousNode = currentNode; currentNode=0; } + | empty { + $$ = 0; + previousNode = currentNode; + currentNode=0; + } ; ptail : COMMA parm ptail { @@ -6082,7 +6090,11 @@ edecl : identifier { $$ = $1; set_comment($1, $2); } - | empty { $$ = 0; previousNode = currentNode; currentNode = 0; } + | empty { + $$ = 0; + previousNode = currentNode; + currentNode = 0; + } ; etype : expr { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 72a1007fc..cff00eaf4 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -47,8 +47,8 @@ class JAVA:public Language { bool global_variable_flag; // Flag for when wrapping a global variable bool old_variable_names; // Flag for old style variable names in the intermediary class bool member_func_flag; // flag set when wrapping a member function - bool doxygen; //flag for converting found doxygen to javadoc - bool comment_creation_chatter; //flag for getting information about where comments were created in java.cxx + bool doxygen; // Flag for converting found doxygen to javadoc + bool comment_creation_chatter;// Flag for adding debug information about where comments were created String *imclass_name; // intermediary class name String *module_class_name; // module class name @@ -80,7 +80,7 @@ class JAVA:public Language { String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code String *imclass_directors; // Intermediate class director code String *destructor_call; //C++ destructor call if any - String *structuralComments; + String *structual_comments; String *destructor_throws_clause; //C++ destructor throws clause if any // Director method stuff: @@ -155,7 +155,7 @@ public: imclass_cppcasts_code(NULL), imclass_directors(NULL), destructor_call(NULL), - structuralComments(NULL), + structual_comments(NULL), destructor_throws_clause(NULL), dmethods_seq(NULL), dmethods_table(NULL), @@ -171,7 +171,7 @@ public: } ~JAVA() { - delete doxygenTranslator; + delete doxygen_translator; } /* ----------------------------------------------------------------------------- @@ -319,7 +319,7 @@ public: } if (doxygen) - doxygenTranslator = new JavaDocConverter(doxygen_translator_flags); + doxygen_translator = new JavaDocConverter(doxygen_translator_flags); // Add a symbol to the parser for conditional compilation Preprocessor_define("SWIGJAVA 1", 0); @@ -441,7 +441,7 @@ public: imclass_imports = NewString(""); imclass_cppcasts_code = NewString(""); imclass_directors = NewString(""); - structuralComments = NewString(""); + structual_comments = NewString(""); upcasts_code = NewString(""); dmethods_seq = NewList(); dmethods_table = NewHash(); @@ -580,19 +580,18 @@ public: // Start writing out the module class file emitBanner(f_module); - //Add any structural comments to the top - if(doxygen && structuralComments){ - Printf(f_module, "%s", structuralComments); - } + // Add any structural comments to the top + if (doxygen && structual_comments) + Printf(f_module, "%s", structual_comments); if (package) Printf(f_module, "package %s;\n", package); if (module_imports) Printf(f_module, "%s\n", module_imports); - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(f_module, "/* This was generated from top() */"); Printv(f_module, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -728,8 +727,8 @@ public: module_imports = NULL; Delete(module_class_modifiers); module_class_modifiers = NULL; - Delete(structuralComments); - structuralComments = NULL; + Delete(structual_comments); + structual_comments = NULL; Delete(imclass_imports); imclass_imports = NULL; Delete(imclass_cppcasts_code); @@ -1275,16 +1274,15 @@ public: EnumFeature enum_feature = decodeEnumFeature(n); String *typemap_lookup_type = Getattr(n, "name"); - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) { + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) { Printf(enum_code, "/* This was generated from enumvalueDeclaration() */"); } Printv(enum_code, Char(doxygen_comments), NIL); Delete(doxygen_comments); } - if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum @@ -1307,13 +1305,12 @@ public: Replaceall(enum_code, "$static ", ""); Delete(scope); } else { - //translate and write javadoc comment for the enum itself if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment for the enum itself if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(constants_code, "/* This was generated from enumDeclaration() */"); - Printf(constants_code, "/* Comment for enum %s */\n", - Getattr(n, "unnamedinstance") ? "" : symname); + Printf(constants_code, "/* Comment for enum %s */\n", Getattr(n, "unnamedinstance") ? "" : symname); Printf(constants_code, Char(doxygen_comments)); Printf(constants_code, "\n"); Delete(doxygen_comments); @@ -1378,10 +1375,10 @@ public: Printv(f_enum, typemapLookup(n, "javaimports", typemap_lookup_type, WARN_NONE), // Import statements "\n\n", NIL); - //translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(f_enum, "/* This was generated from enumDeclaration() */"); Printv(f_enum, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -1481,10 +1478,10 @@ public: if (!addSymbol(symname, n, scope)) return SWIG_ERROR; - //translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(enum_code, "/* This was generated from enumvalueDeclaration() */"); Printv(enum_code, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -1493,7 +1490,6 @@ public: if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) { // Wrap (non-anonymous) C/C++ enum with a proper Java enum // Emit the enum item. - Printf(enum_code, " %s", symname); if (Getattr(n, "enumvalue")) { String *value = enumValue(n); @@ -1549,15 +1545,16 @@ public: /* ----------------------------------------------------------------------- * doxygenComment() + * * Simply translates the doxygen comment and places it into the appropriate * file * ------------------------------------------------------------------------ */ virtual int doxygenComment(Node *n){ - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) - Printf(structuralComments, "/* This was generated from doxygenComment() */"); - Printv(structuralComments, Char(doxygen_comments), NIL); + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) + Printf(structual_comments, "/* This was generated from doxygenComment() */"); + Printv(structual_comments, Char(doxygen_comments), NIL); Delete(doxygen_comments); } return SWIG_OK; @@ -1565,6 +1562,7 @@ public: /* ----------------------------------------------------------------------- * constantWrapper() + * * Used for wrapping constants - #define or %constant. * Also for inline initialised const static primitive type member variables (short, int, double, enums etc). * Java static final variables are generated for these. @@ -1583,10 +1581,10 @@ public: String *constants_code = NewString(""); Swig_save("constantWrapper", n, "value", NIL); - //translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(constants_code, "/* This was generated from constantWrapper() */"); Printv(constants_code, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -1899,10 +1897,10 @@ public: // Pure Java interfaces const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE); - //translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(proxy_class_def, "/* This was generated from emitProxyClassDefAndCPPCasts() */"); Printv(proxy_class_def, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -2365,9 +2363,9 @@ public: 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 - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); if(comment_creation_chatter) Printf(function_code, "/* This was generated from proxyclassfunctionhandler() */"); Printv(function_code, Char(doxygen_comments), NIL); @@ -2596,10 +2594,10 @@ public: tm = Getattr(n, "tmap:jtype"); // typemaps were attached earlier to the node Printf(im_return_type, "%s", tm); - //translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(function_code, "/* This was generated from constructionhandler() */"); Printv(function_code, Char(doxygen_comments), NIL); Delete(doxygen_comments); @@ -2866,10 +2864,10 @@ public: String *pre_code = NewString(""); String *post_code = NewString(""); - // translate and write javadoc comment if flagged - if (doxygen && doxygenTranslator->hasDocumentation(n)){ - String *doxygen_comments=doxygenTranslator->getDocumentation(n); - if(comment_creation_chatter) + // Translate and write javadoc comment if flagged + if (doxygen && doxygen_translator->hasDocumentation(n)) { + String *doxygen_comments = doxygen_translator->getDocumentation(n); + if (comment_creation_chatter) Printf(function_code, "/* This was generated from moduleClassFunctionHandler() */"); Printv(function_code, doxygen_comments, NIL); Delete(doxygen_comments); diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 7f92ffead..eb068d1bf 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -139,8 +139,7 @@ int Dispatcher::emit_one(Node *n) { ret = namespaceDeclaration(n); } else if (strcmp(tag, "template") == 0) { ret = templateDeclaration(n); - } - else if (strcmp(tag, "doxycomm") == 0) { + } else if (strcmp(tag, "doxycomm") == 0) { ret = doxygenComment(n); } else if (strcmp(tag, "lambda") == 0) { ret = lambdaDeclaration(n); @@ -310,7 +309,7 @@ int Dispatcher::usingDeclaration(Node *n) { int Dispatcher::namespaceDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::doxygenComment(Node *n){ +int Dispatcher::doxygenComment(Node *n) { return defaultHandler(n); } @@ -340,8 +339,7 @@ directors(0) { director_language = 0; assert(!this_); this_ = this; - - doxygenTranslator = NULL; + doxygen_translator = NULL; } Language::~Language() { @@ -2972,6 +2970,7 @@ int Language::usingDeclaration(Node *n) { /* ---------------------------------------------------------------------- * Language::doxygenComment() * ---------------------------------------------------------------------- */ + int Language::doxygenComment(Node *n){ String *comment = Getattr(n, "comment"); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 036e58082..bbd40d1b7 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -263,7 +263,7 @@ public: } ~PYTHON() { - delete doxygenTranslator; + delete doxygen_translator; } /* ------------------------------------------------------------ @@ -565,7 +565,7 @@ public: } if (doxygen) - doxygenTranslator = new PyDocConverter(doxygen_translator_flags); + doxygen_translator = new PyDocConverter(doxygen_translator_flags); if (!global_name) global_name = NewString("cvar"); @@ -1488,12 +1488,13 @@ public: String *str = Getattr(n, "feature:docstring"); return ((str && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) - || (doxygen && doxygenTranslator->hasDocumentation(n)) + || (doxygen && doxygen_translator->hasDocumentation(n)) ); } /* ------------------------------------------------------------ * 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 @@ -1502,6 +1503,7 @@ public: * 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) { String *docstr = Getattr(n, "feature:docstring"); if (docstr && Len(docstr)) { @@ -1514,14 +1516,14 @@ public: } 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 (docstr && Len(docstr)) { Append(autodoc, "\n"); Append(autodoc, docstr); } - String* tmp = autodoc; + String *tmp = autodoc; autodoc = docstr; docstr = tmp; } @@ -1532,8 +1534,8 @@ public: if (!docstr || !Len(docstr)) { if (doxygen) { docstr = Getattr(n, "python:docstring"); - if (!docstr && doxygenTranslator->hasDocumentation(n)) { - docstr = doxygenTranslator->getDocumentation(n); + if (!docstr && doxygen_translator->hasDocumentation(n)) { + docstr = doxygen_translator->getDocumentation(n); // Avoid rebuilding it again the next time: notice that we can't do // this for the combined doc string as autodoc part of it depends on @@ -1588,8 +1590,7 @@ public: * source code (but without quotes around it). * ------------------------------------------------------------ */ - String *cdocstring(Node *n, autodoc_t ad_type) - { + String *cdocstring(Node *n, autodoc_t ad_type) { String *ds = build_combined_docstring(n, ad_type); Replaceall(ds, "\\", "\\\\"); Replaceall(ds, "\"", "\\\""); @@ -4200,7 +4201,7 @@ public: Printf(f_shadow, ":\n"); - // write docstrings if requested + // Write docstrings if requested if (have_docstring(n)) { String *str = docstring(n, AUTODOC_CLASS); if (str && Len(str)) diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h index 09f0460df..c0c7caf4d 100644 --- a/Source/Modules/swigmod.h +++ b/Source/Modules/swigmod.h @@ -354,7 +354,7 @@ protected: int director_language; /* Used to translate Doxygen comments to target documentation format */ - class DoxygenTranslator *doxygenTranslator; + class DoxygenTranslator *doxygen_translator; private: Hash *symtabs; /* symbol tables */ diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index d41a7c12d..a9616d4d6 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1385,9 +1385,11 @@ String *Swig_pcre_version(void) { /* ------------------------------------------------------------ * Swig_is_generated_overload() + * * Check if the function is an automatically generated * overload created because a method has default parameters. * ------------------------------------------------------------ */ + int Swig_is_generated_overload(Node *n) { Node *base_method = Getattr(n, "sym:overloaded"); Node *default_args = Getattr(n, "defaultargs"); |