Author: nwellnhof
Date: Thu Mar 22 18:46:18 2012
New Revision: 1303973

URL: http://svn.apache.org/viewvc?rev=1303973&view=rev
Log:
Add support for multiple Clownfish source directories

Modified:
    
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.pm
    
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.xs
    
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/t/500-hierarchy.t
    incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.c
    incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.h
    incubator/lucy/branches/LUCY-215-cf-extensions/perl/buildlib/Lucy/Build.pm

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.pm
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.pm?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.pm
 (original)
+++ 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.pm
 Thu Mar 22 18:46:18 2012
@@ -239,7 +239,7 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
         my ( $either, %args ) = @_;
         confess "no subclassing allowed" unless $either eq __PACKAGE__;
         verify_args( \%new_PARAMS, %args ) or confess $@;
-        return _new( @args{qw( source dest )} );
+        return _new( @args{qw( dest )} );
     }
 }
 

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.xs
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.xs?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.xs
 (original)
+++ 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/lib/Clownfish/CFC.xs
 Thu Mar 22 18:46:18 2012
@@ -689,16 +689,34 @@ PPCODE:
 MODULE = Clownfish::CFC   PACKAGE = Clownfish::CFC::Model::Hierarchy
 
 SV*
-_new(source, dest)
-    const char *source;
+_new(dest)
     const char *dest;
 CODE:
-    CFCHierarchy *self = CFCHierarchy_new(source, dest);
+    CFCHierarchy *self = CFCHierarchy_new(dest);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
 
 void
+add_source_dir(self, source_dir)
+    CFCHierarchy *self;
+    const char *source_dir;
+PPCODE:
+    CFCHierarchy_add_source_dir(self, source_dir);
+
+void
+get_source_dirs(self)
+    CFCHierarchy *self;
+PPCODE:
+    size_t n = CFCHierarchy_get_num_source_dirs(self);
+    size_t i;
+    EXTEND(SP, n);
+    for (i = 0; i < n; ++i) {
+        const char *value = CFCHierarchy_get_source_dir(self, i);
+        PUSHs(sv_2mortal(newSVpv(value, strlen(value))));
+    }
+
+void
 build(self)
     CFCHierarchy *self;
 PPCODE:
@@ -716,18 +734,12 @@ void
 _set_or_get(self, ...)
     CFCHierarchy *self;
 ALIAS:
-    get_source        = 2
     get_dest          = 4
     files             = 8
     ordered_classes   = 10
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
-        case 2: {
-                const char *value = CFCHierarchy_get_source(self);
-                retval = newSVpv(value, strlen(value));
-            }
-            break;
         case 4: {
                 const char *value = CFCHierarchy_get_dest(self);
                 retval = newSVpv(value, strlen(value));

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/t/500-hierarchy.t
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/t/500-hierarchy.t?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/t/500-hierarchy.t 
(original)
+++ 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/perl/t/500-hierarchy.t 
Thu Mar 22 18:46:18 2012
@@ -24,8 +24,8 @@ use File::Spec::Functions qw( catfile sp
 use Fcntl;
 use File::Path qw( rmtree mkpath );
 
+my $source = 't/cfsource';
 my %args = (
-    source => 't/cfsource',
     dest   => 't/cfdest',
 );
 
@@ -40,8 +40,10 @@ like( $@, qr/extra_arg/, "Extra arg kill
 
 my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(%args);
 isa_ok( $hierarchy, "Clownfish::CFC::Model::Hierarchy" );
-is( $hierarchy->get_source, $args{source}, "get_source" );
-is( $hierarchy->get_dest,   $args{dest},   "get_dest" );
+is( $hierarchy->get_dest, $args{dest}, "get_dest" );
+
+$hierarchy->add_source_dir($source);
+is_deeply( [ $hierarchy->get_source_dirs ], [ $source ], "get_source_dirs" );
 
 $hierarchy->build;
 
@@ -81,7 +83,7 @@ for my $file (@files) {
         or die "utime failed for '$h_path': $!";
 }
 
-my $path_to_animal_cf = $animal->cfh_path( $args{source} );
+my $path_to_animal_cf = $animal->cfh_path( $source );
 utime( undef, undef, $path_to_animal_cf )
     or die "utime for '$path_to_animal_cf' failed";    # touch
 

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.c
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.c?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.c 
(original)
+++ incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.c 
Thu Mar 22 18:46:18 2012
@@ -37,7 +37,8 @@
 
 struct CFCHierarchy {
     CFCBase base;
-    char *source;
+    size_t num_sources;
+    char **sources;
     char *dest;
     CFCParser *parser;
     CFCClass **trees;
@@ -75,17 +76,18 @@ const static CFCMeta CFCHIERARCHY_META =
 };
 
 CFCHierarchy*
-CFCHierarchy_new(const char *source, const char *dest) {
+CFCHierarchy_new(const char *dest) {
     CFCHierarchy *self = (CFCHierarchy*)CFCBase_allocate(&CFCHIERARCHY_META);
-    return CFCHierarchy_init(self, source, dest);
+    return CFCHierarchy_init(self, dest);
 }
 
 CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest) {
-    if (!source || !strlen(source) || !dest || !strlen(dest)) {
-        CFCUtil_die("Both 'source' and 'dest' are required");
+CFCHierarchy_init(CFCHierarchy *self, const char *dest) {
+    if (!dest || !strlen(dest)) {
+        CFCUtil_die("'dest' is required");
     }
-    self->source       = CFCUtil_strdup(source);
+    self->sources      = (char**)CALLOCATE(1, sizeof(char*));
+    self->num_sources  = 0;
     self->dest         = CFCUtil_strdup(dest);
     self->trees        = (CFCClass**)CALLOCATE(1, sizeof(CFCClass*));
     self->num_trees    = 0;
@@ -107,18 +109,32 @@ CFCHierarchy_destroy(CFCHierarchy *self)
     for (size_t i = 0; self->files[i] != NULL; i++) {
         CFCBase_decref((CFCBase*)self->files[i]);
     }
+    for (size_t i = 0; self->sources[i] != NULL; i++) {
+        FREEMEM(self->sources[i]);
+    }
     FREEMEM(self->trees);
     FREEMEM(self->files);
     FREEMEM(self->classes);
-    FREEMEM(self->source);
+    FREEMEM(self->sources);
     FREEMEM(self->dest);
     CFCBase_decref((CFCBase*)self->parser);
     CFCBase_destroy((CFCBase*)self);
 }
 
 void
+CFCHierarchy_add_source_dir(CFCHierarchy *self, const char *source) {
+    size_t n = self->num_sources;
+    self->sources      = (char**)REALLOCATE(self->sources, n + 2);
+    self->sources[n]   = CFCUtil_strdup(source);
+    self->sources[n+1] = NULL;
+    self->num_sources  = n + 1;
+}
+
+void
 CFCHierarchy_build(CFCHierarchy *self) {
-    S_parse_cf_files(self, self->source);
+    for (size_t i = 0; self->sources[i] != NULL; i++) {
+        S_parse_cf_files(self, self->sources[i]);
+    }
     S_connect_classes(self);
     for (size_t i = 0; self->trees[i] != NULL; i++) {
         CFCClass_grow_tree(self->trees[i]);
@@ -409,8 +425,13 @@ CFCHierarchy_files(CFCHierarchy *self) {
 }
 
 const char*
-CFCHierarchy_get_source(CFCHierarchy *self) {
-    return self->source;
+CFCHierarchy_get_source_dir(CFCHierarchy *self, size_t i) {
+    return i < self->num_sources ? self->sources[i] : NULL;
+}
+
+size_t
+CFCHierarchy_get_num_source_dirs(CFCHierarchy *self) {
+    return self->num_sources;
 }
 
 const char*

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.h
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.h?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.h 
(original)
+++ incubator/lucy/branches/LUCY-215-cf-extensions/clownfish/src/CFCHierarchy.h 
Thu Mar 22 18:46:18 2012
@@ -40,14 +40,19 @@ struct CFCFile;
  * @param dest The directory where the autogenerated files will be written.
  */
 CFCHierarchy*
-CFCHierarchy_new(const char *source, const char *dest);
+CFCHierarchy_new(const char *dest);
 
 CFCHierarchy*
-CFCHierarchy_init(CFCHierarchy *self, const char *source, const char *dest);
+CFCHierarchy_init(CFCHierarchy *self, const char *dest);
 
 void
 CFCHierarchy_destroy(CFCHierarchy *self);
 
+/** Add path C<source_dir> to source directories.
+ */
+void
+CFCHierarchy_add_source_dir(CFCHierarchy *self, const char *source_dir);
+
 /** Parse every Clownfish header file which can be found under C<source>,
  * building up the object hierarchy.
  */
@@ -72,7 +77,10 @@ struct CFCFile**
 CFCHierarchy_files(CFCHierarchy *self);
 
 const char*
-CFCHierarchy_get_source(CFCHierarchy *self);
+CFCHierarchy_get_source_dir(CFCHierarchy *self, size_t i);
+
+size_t
+CFCHierarchy_get_num_source_dirs(CFCHierarchy *self);
 
 const char*
 CFCHierarchy_get_dest(CFCHierarchy *self);

Modified: 
incubator/lucy/branches/LUCY-215-cf-extensions/perl/buildlib/Lucy/Build.pm
URL: 
http://svn.apache.org/viewvc/incubator/lucy/branches/LUCY-215-cf-extensions/perl/buildlib/Lucy/Build.pm?rev=1303973&r1=1303972&r2=1303973&view=diff
==============================================================================
--- incubator/lucy/branches/LUCY-215-cf-extensions/perl/buildlib/Lucy/Build.pm 
(original)
+++ incubator/lucy/branches/LUCY-215-cf-extensions/perl/buildlib/Lucy/Build.pm 
Thu Mar 22 18:46:18 2012
@@ -228,9 +228,9 @@ sub _compile_clownfish {
 
     # Compile Clownfish.
     my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(
-        source => $CORE_SOURCE_DIR,
         dest   => $AUTOGEN_DIR,
     );
+    $hierarchy->add_source_dir($CORE_SOURCE_DIR);
     $hierarchy->build;
 
     # Process all __BINDING__ blocks.


Reply via email to