Rdoc on SWIG-generated files

I run rdoc on a SWIG-generated file and it grabs the module, module methods, and classes, but it fails to document the methods inside classes.

Perhaps this is because the rb_define_method calls are inside a special MACRO block, e.g.:

SWIGEXPORT(void) Init_ladspa(void) {
     int i;

     SWIG_InitRuntime();
     mLADSPA = rb_define_module("LADSPA");

     for (i = 0; swig_types_initial[i]; i++) {
         swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
         SWIG_define_class(swig_types[i]);
     }

     cLADSPA_Descriptor.klass = rb_define_class_under(mLADSPA, "LADSPA_Descriptor", rb_cObject);
     SWIG_TypeClientData(SWIGTYPE_p_LADSPA_Descriptor, (void *) &cLADSPA_Descriptor);
     rb_define_alloc_func(cLADSPA_Descriptor.klass, _wrap_LADSPA_Descriptor_allocate);
     rb_define_method(cLADSPA_Descriptor.klass, "initialize", _wrap_new_LADSPA_Descriptor, -1);

/* etc. */
}

Is there a workaround to this? Would it be hard to convince rdoc to grok it? How do people generally document their SWIG-generated code?

It wouldn't be hard: it's just a question of updating the regexps to recognize the different forms of definitions. Right now I'm pretty bogged down with the new Pickaxe, but if someone wanted to generate a patch I'd gladly apply it.

Cheers

Dave

···

On Jul 23, 2004, at 15:56, Hans Fugal wrote:

I run rdoc on a SWIG-generated file and it grabs the module, module methods, and classes, but it fails to document the methods inside classes.
....
Is there a workaround to this? Would it be hard to convince rdoc to grok it? How do people generally document their SWIG-generated code?

Dave Thomas wrote:

It wouldn't be hard: it's just a question of updating the regexps to recognize the different forms of definitions. Right now I'm pretty bogged down with the new Pickaxe, but if someone wanted to generate a patch I'd gladly apply it.

The problem is those pesky .klass things:

     cLADSPA_Descriptor.klass = rb_define_class_under(mLADSPA, "LADSPA_Descriptor", rb_cObject);
     rb_define_alloc_func(cLADSPA_Descriptor.klass, _wrap_LADSPA_Descriptor_allocate);

Index: rdoc/parsers/parse_c.rb

···

===================================================================
RCS file: /cvsroot/rdoc/rdoc/rdoc/parsers/parse_c.rb,v
retrieving revision 1.9
diff -u -r1.9 parse_c.rb
--- rdoc/parsers/parse_c.rb 5 Oct 2003 17:49:07 -0000 1.9
+++ rdoc/parsers/parse_c.rb 24 Jul 2004 13:08:40 -0000
@@ -196,7 +196,7 @@
          handle_class_module(var_name, "module", class_name, nil, in_module)
        end

- @body.scan(/(\w+)\s* = \s*rb_define_class
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class
                  \(
                     \s*"(\w+)",
                     \s*(\w+)\s*
@@ -206,7 +206,7 @@
          handle_class_module(var_name, "class", class_name, parent, nil)
        end

- @body.scan(/(\w+)\s* = \s*rb_define_class_under
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under
                  \(
                     \s*(\w+),
                     \s*"(\w+)",
@@ -221,7 +221,7 @@

      def do_methods
- @body.scan(/rb_define_(singleton_method|method|module_function)\(\s*(\w+)
,
+ @body.scan(/rb_define_(singleton_method|method|module_function)\(\s*([\w\.
]+),
                                 \s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
                                 \s*(-?\w+)\s*\)/xm) do

I don't know if there are other places where a similar thing should be done, or if you'd prefer a different regex (maybe one that would handle -> as well, like [-\w\.>] or perhaps [^\s=,])