From 7d570676f550f8fbfc553ad5fa26680e97cfbd6e Mon Sep 17 00:00:00 2001 From: Gonzalo Garramuno Date: Thu, 3 May 2007 09:56:28 +0000 Subject: [PATCH] Better autodocs. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9760 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 6 +-- Lib/ruby/rubyrun.swg | 6 --- Lib/ruby/rubystdautodoc.swg | 1 + Source/Modules/ruby.cxx | 79 +++++++++++++++++++++++++++---------- 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 5b1ff6327..5f65e92ce 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,9 +4,8 @@ Version 1.3.32 (in progress) 05/03/2007: gga [Ruby] Fixed Ruby documentation to use the proper css styles for - each section. - Added autodoc section to document the features supported by - Ruby in documenting its modules. + each section. Added autodoc section to Ruby's docs to + document the features supported by Ruby in documenting its modules. 05/03/2007: gga [Ruby] @@ -18,6 +17,7 @@ Version 1.3.32 (in progress) Improved autodoc generation. Added autodoc .swg files to Ruby library for easily adding documentation to common Ruby methods and STL methods. + Fixed autodoc documenting of getters and setters and module. Made test suite always generate autodocs. 05/03/2007: gga diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index 39e30a281..9848e4a3a 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -64,9 +64,6 @@ #ifdef __cplusplus extern "C" { -#if 0 -} /* cc-mode */ -#endif #endif typedef struct { @@ -398,8 +395,5 @@ SWIG_Ruby_SetModule(swig_module_info *pointer) } #ifdef __cplusplus -#if 0 -{ /* cc-mode */ -#endif } #endif diff --git a/Lib/ruby/rubystdautodoc.swg b/Lib/ruby/rubystdautodoc.swg index a0e2b86bd..ad70f7f8b 100644 --- a/Lib/ruby/rubystdautodoc.swg +++ b/Lib/ruby/rubystdautodoc.swg @@ -34,3 +34,4 @@ AUTODOC(push_front, "Add an element at the beginning of the $class"); AUTODOC(push_back, "Add an element at the end of the $class"); AUTODOC(pop_front, "Remove and return element at the beginning of the $class"); AUTODOC(pop_back, "Remove and return an element at the end of the $class"); +AUTODOC(clear, "Clear $class contents"); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 59867542c..fc38733e2 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -120,7 +120,9 @@ enum autodoc_t { AUTODOC_DTOR, AUTODOC_STATICFUNC, AUTODOC_FUNC, - AUTODOC_METHOD + AUTODOC_METHOD, + AUTODOC_GETTER, + AUTODOC_SETTER }; static const char *usage = "\ @@ -542,8 +544,12 @@ private: case AUTODOC_FUNC: case AUTODOC_METHOD: + case AUTODOC_GETTER: Printf(doc, " Document-method: %s\n\n", symname); break; + case AUTODOC_SETTER: + Printf(doc, " Document-method: %s=\n\n", symname); + break; } } @@ -555,6 +561,7 @@ private: case AUTODOC_STATICFUNC: case AUTODOC_FUNC: case AUTODOC_METHOD: + case AUTODOC_GETTER: { String *paramList = make_autodocParmList(n, showTypes); if (Len(paramList)) @@ -565,6 +572,12 @@ private: Printf(doc, " -> %s", type); break; } + case AUTODOC_SETTER: + { + Printf(doc, " %s=(x)", symname); + if (type) Printf(doc, " -> %s", type); + break; + } default: break; } @@ -605,15 +618,25 @@ private: case AUTODOC_STATICFUNC: case AUTODOC_FUNC: case AUTODOC_METHOD: - if (counter == 0) Printf(doc, " call-seq:\n"); - String *paramList = make_autodocParmList(n, showTypes); - if (Len(paramList)) - Printf(doc, " %s(%s)", symname, paramList); - else - Printf(doc, " %s", symname); - if (type) - Printf(doc, " -> %s", type); - break; + case AUTODOC_GETTER: + { + if (counter == 0) Printf(doc, " call-seq:\n"); + String *paramList = make_autodocParmList(n, showTypes); + if (Len(paramList)) + Printf(doc, " %s(%s)", symname, paramList); + else + Printf(doc, " %s", symname); + if (type) + Printf(doc, " -> %s", type); + break; + } + case AUTODOC_SETTER: + { + Printf(doc, " call-seq:\n"); + Printf(doc, " %s=(x)", symname); + if (type) Printf(doc, " -> %s", type); + break; + } } } @@ -627,24 +650,25 @@ private: if (!skipAuto) { switch (ad_type) { case AUTODOC_CLASS: + case AUTODOC_DTOR: break; case AUTODOC_CTOR: Printf(doc, "Class constructor.\n"); break; - - case AUTODOC_DTOR: - break; - case AUTODOC_STATICFUNC: - Printf(doc, "A static function.\n"); + Printf(doc, "A class method.\n"); break; - case AUTODOC_FUNC: - Printf(doc, "A function.\n"); + Printf(doc, "A module function.\n"); break; - case AUTODOC_METHOD: - Printf(doc, "A method.\n"); + Printf(doc, "An instance method.\n"); + break; + case AUTODOC_GETTER: + Printf(doc, "Get value of attribute.\n"); + break; + case AUTODOC_SETTER: + Printf(doc, "Set new value for attribute.\n"); break; } } @@ -1012,6 +1036,8 @@ public: Printf(f_header, "static VALUE %s;\n", modvar); /* Start generating the initialization function */ + String* docs = docstring(n, AUTODOC_CLASS); + Printf(f_init, "/*\n%s\n*/", docs ); Printv(f_init, "\n", "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", "SWIGEXPORT void Init_", feature, "(void) {\n", "size_t i;\n", "\n", NIL); Printv(f_init, tab4, "VALUE parent = Qnil;\n", NIL); @@ -1955,10 +1981,11 @@ public: * --------------------------------------------------------------------- */ virtual int variableWrapper(Node *n) { - String* docs = docstring(n, AUTODOC_METHOD); + String* docs = docstring(n, AUTODOC_GETTER); Printf(f_wrappers, "%s", docs); Delete(docs); + char *name = GetChar(n, "name"); char *iname = GetChar(n, "sym:name"); SwigType *t = Getattr(n, "type"); @@ -2001,6 +2028,10 @@ public: setfname = NewString("NULL"); } else { /* create setter */ + String* docs = docstring(n, AUTODOC_SETTER); + Printf(f_wrappers, "%s", docs); + Delete(docs); + String *setname = Swig_name_set(iname); setfname = Swig_name_wrapper(setname); Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL); @@ -2563,10 +2594,16 @@ public: * -------------------------------------------------------------------- */ virtual int membervariableHandler(Node *n) { - String* docs = docstring(n, AUTODOC_METHOD); + String* docs = docstring(n, AUTODOC_GETTER); Printf(f_wrappers, "%s", docs); Delete(docs); + if (is_assignable(n)) { + String* docs = docstring(n, AUTODOC_SETTER); + Printf(f_wrappers, "%s", docs); + Delete(docs); + } + current = MEMBER_VAR; Language::membervariableHandler(n); current = NO_CPP;