You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/10/30 03:50:32 UTC

[lucy-commits] svn commit: r1195095 - in /incubator/lucy/trunk: clownfish/lib/Clownfish.xs clownfish/lib/Clownfish/Binding/Perl/Class.pm clownfish/lib/Clownfish/Binding/Perl/Pod.pm clownfish/src/CFCPerlPod.c clownfish/src/CFCPerlPod.h perl/lib/Lucy/Index/Indexer.pm

Author: marvin
Date: Sun Oct 30 02:50:32 2011
New Revision: 1195095

URL: http://svn.apache.org/viewvc?rev=1195095&view=rev
Log:
Port generation of POD for constructors to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Class.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Pod.pm
    incubator/lucy/trunk/clownfish/src/CFCPerlPod.c
    incubator/lucy/trunk/clownfish/src/CFCPerlPod.h
    incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Sun Oct 30 02:50:32 2011
@@ -2064,6 +2064,20 @@ PPCODE:
     const char *pod = SvPOK(pod_sv) ? SvPVutf8_nolen(pod_sv) : NULL;
     CFCPerlPod_add_method(self, name, pod);
 
+void
+_add_constructor(self, name_sv, pod_sv, func_sv, sample_sv)
+    CFCPerlPod *self;
+    SV *name_sv;
+    SV *pod_sv;
+    SV *func_sv;
+    SV *sample_sv;
+PPCODE:
+    const char *name   = SvPOK(name_sv)   ? SvPVutf8_nolen(name_sv)   : NULL;
+    const char *pod    = SvPOK(pod_sv)    ? SvPVutf8_nolen(pod_sv)    : NULL;
+    const char *func   = SvPOK(func_sv)   ? SvPVutf8_nolen(func_sv)   : NULL;
+    const char *sample = SvPOK(sample_sv) ? SvPVutf8_nolen(sample_sv) : NULL;
+    CFCPerlPod_add_constructor(self, name, pod, func, sample);
+
 SV*
 methods_pod(self, klass)
     CFCPerlPod *self;
@@ -2073,6 +2087,15 @@ CODE:
     RETVAL = S_sv_eat_c_string(methods_pod);
 OUTPUT: RETVAL
 
+SV*
+constructors_pod(self, klass)
+    CFCPerlPod *self;
+    CFCClass   *klass;
+CODE:
+    char *constructors_pod = CFCPerlPod_constructors_pod(self, klass);
+    RETVAL = S_sv_eat_c_string(constructors_pod);
+OUTPUT: RETVAL
+
 void
 _set_or_get(self, ...)
     CFCPerlPod *self;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Class.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Class.pm?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Class.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Class.pm Sun Oct 30 02:50:32 2011
@@ -184,29 +184,7 @@ sub create_pod {
     }
 
     # Create CONSTRUCTORS.
-    my $constructor_pod = "";
-    my $constructors = $pod_args->{constructors} || [];
-    if ( defined $pod_args->{constructor} ) {
-        push @$constructors, $pod_args->{constructor};
-    }
-    if (@$constructors) {
-        $constructor_pod = "=head1 CONSTRUCTORS\n\n";
-        for my $spec (@$constructors) {
-            if ( !ref $spec ) {
-                $constructor_pod .= $pod_spec->_perlify_doc_text($spec);
-            }
-            else {
-                my $func_name   = $spec->{func} || 'init';
-                my $init_func   = $class->function($func_name);
-                my $ctor_name   = $spec->{name} || 'new';
-                my $code_sample = $spec->{sample};
-                my $sub_pod
-                    = $pod_spec->_gen_subroutine_pod( $init_func, $ctor_name,
-                    $class, $code_sample, $class_name, 1 );
-                $constructor_pod .= $pod_spec->_perlify_doc_text($sub_pod);
-            }
-        }
-    }
+    my $constructor_pod = $pod_spec->constructors_pod($class);
 
     # Create METHODS, possibly including an ABSTRACT METHODS section.
     my $methods_pod = $pod_spec->methods_pod($class);

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Pod.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Pod.pm?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Pod.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Perl/Pod.pm Sun Oct 30 02:50:32 2011
@@ -32,18 +32,24 @@ our %new_PARAMS = (
 sub new {
     my ( $either, %args ) = @_;
     verify_args( \%new_PARAMS, %args ) or confess $@;
-    my $synopsis    = $args{synopsis}    || '';
-    my $description = $args{description} || '';
-    my $methods     = $args{methods}     || [];
+    my $synopsis     = $args{synopsis}     || '';
+    my $description  = $args{description}  || '';
+    my $methods      = $args{methods}      || [];
+    my $constructors = $args{constructors} || [];
+    push @$constructors, $args{constructor} if $args{constructor};
     my $self = _new( $synopsis, $description );
+
     for (@$methods) {
-        if (ref($_)) {
+        if ( ref($_) ) {
             _add_method( $self, $_->{name}, $_->{pod} );
         }
         else {
-            _add_method( $self, $_, undef);
+            _add_method( $self, $_, undef );
         }
     }
+    for my $con (@$constructors) {
+        _add_constructor( $self, @{$con}{qw( name pod func sample )} );
+    }
     return $self;
 }
 

Modified: incubator/lucy/trunk/clownfish/src/CFCPerlPod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlPod.c?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlPod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlPod.c Sun Oct 30 02:50:32 2011
@@ -35,6 +35,8 @@
 
 typedef struct NamePod {
     char *name;
+    char *func;
+    char *sample;
     char *pod;
 } NamePod;
 
@@ -44,6 +46,8 @@ struct CFCPerlPod {
     char    *description;
     NamePod *methods;
     size_t   num_methods;
+    NamePod *constructors;
+    size_t   num_constructors;
 };
 
 CFCPerlPod*
@@ -57,10 +61,12 @@ CFCPerlPod_new(const char *synopsis, con
 CFCPerlPod*
 CFCPerlPod_init(CFCPerlPod *self, const char *synopsis,
                 const char *description) {
-    self->synopsis    = CFCUtil_strdup(synopsis ? synopsis : "");
-    self->description = CFCUtil_strdup(description ? description : "");
-    self->methods     = NULL;
-    self->num_methods = 0;
+    self->synopsis         = CFCUtil_strdup(synopsis ? synopsis : "");
+    self->description      = CFCUtil_strdup(description ? description : "");
+    self->methods          = NULL;
+    self->constructors     = NULL;
+    self->num_methods      = 0;
+    self->num_constructors = 0;
     return self;
 }
 
@@ -71,6 +77,8 @@ CFCPerlPod_destroy(CFCPerlPod *self) {
     for (size_t i = 0; i < self->num_methods; i++) {
         FREEMEM(self->methods[i].name);
         FREEMEM(self->methods[i].pod);
+        FREEMEM(self->methods[i].func);
+        FREEMEM(self->methods[i].sample);
     }
     FREEMEM(self->methods);
     CFCBase_destroy((CFCBase*)self);
@@ -83,8 +91,24 @@ CFCPerlPod_add_method(CFCPerlPod *self, 
     size_t size = self->num_methods * sizeof(NamePod);
     self->methods = (NamePod*)REALLOCATE(self->methods, size);
     NamePod *slot = &self->methods[self->num_methods - 1];
-    slot->name = CFCUtil_strdup(name);
-    slot->pod  = pod ? CFCUtil_strdup(pod) : NULL;
+    slot->name   = CFCUtil_strdup(name);
+    slot->pod    = pod ? CFCUtil_strdup(pod) : NULL;
+    slot->func   = NULL;
+    slot->sample = NULL;
+}
+
+void
+CFCPerlPod_add_constructor(CFCPerlPod *self, const char *name,
+                           const char *pod, const char *func,
+                           const char *sample) {
+    self->num_constructors++;
+    size_t size = self->num_constructors * sizeof(NamePod);
+    self->constructors = (NamePod*)REALLOCATE(self->constructors, size);
+    NamePod *slot = &self->constructors[self->num_constructors - 1];
+    slot->name   = CFCUtil_strdup(name ? name : "new");
+    slot->pod    = pod ? CFCUtil_strdup(pod) : NULL;
+    slot->func   = CFCUtil_strdup(func ? func : "init");
+    slot->sample = CFCUtil_strdup(sample ? sample : "");
 }
 
 const char*
@@ -143,6 +167,35 @@ CFCPerlPod_methods_pod(CFCPerlPod *self,
     return pod;
 }
 
+// Create CONSTRUCTORS.
+char*
+CFCPerlPod_constructors_pod(CFCPerlPod *self, CFCClass *klass) {
+    if (!self->num_constructors) {
+        return CFCUtil_strdup("");
+    }
+    const char *class_name = CFCClass_get_class_name(klass);
+    char *pod = CFCUtil_strdup("=head1 CONSTRUCTORS\n\n");
+    for (size_t i = 0; i < self->num_constructors; i++) {
+        NamePod slot = self->constructors[i];
+        if (slot.pod) {
+            char *perlified = CFCPerlPod_perlify_doc_text(self, slot.pod);
+            pod = CFCUtil_cat(pod, perlified, NULL);
+            FREEMEM(perlified);
+        }
+        else {
+            CFCFunction *init_func = CFCClass_function(klass, slot.func);
+            char *sub_pod
+                = CFCPerlPod_gen_subroutine_pod(self, init_func, slot.name, klass,
+                                                slot.sample, class_name, true);
+            char *perlified = CFCPerlPod_perlify_doc_text(self, sub_pod);
+            pod = CFCUtil_cat(pod, perlified, NULL);
+            FREEMEM(sub_pod);
+            FREEMEM(perlified);
+        }
+    }
+    return pod;
+}
+
 static char*
 S_global_replace(const char *string, const char *match,
                  const char *replacement) {

Modified: incubator/lucy/trunk/clownfish/src/CFCPerlPod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCPerlPod.h?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCPerlPod.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCPerlPod.h Sun Oct 30 02:50:32 2011
@@ -41,9 +41,17 @@ CFCPerlPod_destroy(CFCPerlPod *self);
 void
 CFCPerlPod_add_method(CFCPerlPod *self, const char *name, const char *pod);
 
+void
+CFCPerlPod_add_constructor(CFCPerlPod *self, const char *name,
+                           const char *pod, const char *func,
+                           const char *sample);
+
 char*
 CFCPerlPod_methods_pod(CFCPerlPod *self, struct CFCClass *klass);
 
+char*
+CFCPerlPod_constructors_pod(CFCPerlPod *self, struct CFCClass *klass);
+
 const char*
 CFCPerlPod_get_synopsis(CFCPerlPod *self);
 

Modified: incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm?rev=1195095&r1=1195094&r2=1195095&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Index/Indexer.pm Sun Oct 30 02:50:32 2011
@@ -202,7 +202,7 @@ Clownfish::Binding::Perl::Class->registe
                 )
         ],
         synopsis     => $synopsis,
-        constructors => [$constructor],
+        constructors => [ { pod => $constructor } ],
     },
 );