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/03/04 01:16:02 UTC

[lucy-commits] svn commit: r1076898 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c src/CFCHierarchy.h

Author: marvin
Date: Fri Mar  4 00:16:02 2011
New Revision: 1076898

URL: http://svn.apache.org/viewvc?rev=1076898&view=rev
Log:
Port propagate_modified() from CFCHierarchy to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
    incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
    incubator/lucy/trunk/clownfish/src/CFCHierarchy.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1076898&r1=1076897&r2=1076898&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Mar  4 00:16:02 2011
@@ -725,6 +725,14 @@ _destroy(self)
 PPCODE:
     CFCHierarchy_destroy(self);
 
+int
+propagate_modified(self, ...)
+    CFCHierarchy *self;
+CODE:
+    int modified = items > 1 ? !!SvTRUE(ST(1)) : 0;
+    RETVAL = CFCHierarchy_propagate_modified(self, modified);
+OUTPUT: RETVAL
+
 void
 _add_tree(self, klass)
     CFCHierarchy *self;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1076898&r1=1076897&r2=1076898&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Fri Mar  4 00:16:02 2011
@@ -134,48 +134,6 @@ sub _parse_cf_files {
     }
 }
 
-sub propagate_modified {
-    my ( $self, $modified ) = @_;
-    # Seed the recursive write.
-    my $somebody_is_modified;
-    for my $tree ( @{ $self->_trees } ) {
-        next unless $self->_propagate_modified( $tree, $modified );
-        $somebody_is_modified = 1;
-    }
-    return $somebody_is_modified || $modified;
-}
-
-# Recursive helper function.
-sub _propagate_modified {
-    my ( $self, $class, $modified ) = @_;
-    my $file        = $self->_fetch_file( $class->get_source_class );
-    my $source_path = $file->cfh_path( $self->get_source );
-    my $h_path      = $file->h_path( $self->get_dest );
-
-    if ( !current( $source_path, $h_path ) ) {
-        $modified = 1;
-    }
-
-    if ($modified) {
-        $file->set_modified($modified);
-    }
-
-    # Proceed to the next generation.
-    my $somebody_is_modified = $modified;
-    for my $kid ( @{ $class->children } ) {
-        if ( $class->final ) {
-            confess(  "Attempt to inherit from final class "
-                    . $class->get_class_name . " by "
-                    . $kid->get_class_name );
-        }
-        if ( $self->_propagate_modified( $kid, $modified ) ) {
-            $somebody_is_modified = 1;
-        }
-    }
-
-    return $somebody_is_modified;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1076898&r1=1076897&r2=1076898&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Fri Mar  4 00:16:02 2011
@@ -19,11 +19,17 @@
 #include "perl.h"
 #include "XSUB.h"
 
+#ifndef true
+    #define true 1
+    #define false 0
+#endif
+
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCHierarchy.h"
 #include "CFCClass.h"
 #include "CFCFile.h"
+#include "CFCSymbol.h"
 #include "CFCUtil.h"
 
 struct CFCHierarchy {
@@ -36,6 +42,10 @@ struct CFCHierarchy {
     size_t num_files;
 };
 
+// Recursive helper function for CFCUtil_propagate_modified.
+int
+S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified);
+
 CFCHierarchy*
 CFCHierarchy_new(const char *source, const char *dest)
 {
@@ -76,6 +86,64 @@ CFCHierarchy_destroy(CFCHierarchy *self)
     CFCBase_destroy((CFCBase*)self);
 }
 
+int
+CFCHierarchy_propagate_modified(CFCHierarchy *self, int modified)
+{
+    // Seed the recursive write.
+    int somebody_is_modified = false;
+    size_t i;
+    for (i = 0; self->trees[i] != NULL; i++) {
+        CFCClass *tree = self->trees[i];
+        if (S_do_propagate_modified(self, tree, modified)) {
+            somebody_is_modified = true;
+        }
+    }
+    if (somebody_is_modified || modified) { 
+        return true; 
+    }
+    else {
+        return false;
+    }
+}
+
+int
+S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified)
+{
+    const char *source_class = CFCClass_get_source_class(klass);
+    CFCFile *file = CFCHierarchy_fetch_file(self, source_class);
+    size_t cfh_buf_size = CFCFile_path_buf_size(file, self->source);
+    char *source_path = (char*)MALLOCATE(cfh_buf_size);
+    CFCFile_cfh_path(file, source_path, cfh_buf_size, self->source);
+    size_t h_buf_size = CFCFile_path_buf_size(file, self->dest);
+    char *h_path = (char*)MALLOCATE(h_buf_size);
+    CFCFile_h_path(file, h_path, h_buf_size, self->dest);
+
+    if (!CFCUtil_current(source_path, h_path)) {
+        modified = true;
+    }
+    if (modified) {
+        CFCFile_set_modified(file, modified);
+    }
+
+    // Proceed to the next generation.
+    int somebody_is_modified = modified;
+    size_t i;
+    CFCClass **children = CFCClass_children(klass);
+    for (i = 0; children[i] != NULL; i++) {
+        CFCClass *kid = children[i];
+        if (CFCClass_final(klass)) {
+            CFCUtil_die("Attempt to inherit from final class '%s' by '%s'",
+                CFCSymbol_get_class_name((CFCSymbol*)klass),
+                CFCSymbol_get_class_name((CFCSymbol*)kid));
+        }
+        if (S_do_propagate_modified(self, kid, modified)) {
+            somebody_is_modified = 1;
+        }
+    }
+
+    return somebody_is_modified;
+}
+
 void
 CFCHierarchy_add_tree(CFCHierarchy *self, CFCClass *klass)
 {

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.h?rev=1076898&r1=1076897&r2=1076898&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Fri Mar  4 00:16:02 2011
@@ -34,6 +34,9 @@ CFCHierarchy_init(CFCHierarchy *self, co
 void
 CFCHierarchy_destroy(CFCHierarchy *self);
 
+int
+CFCHierarchy_propagate_modified(CFCHierarchy *self, int modified);
+
 void
 CFCHierarchy_add_tree(CFCHierarchy *self, struct CFCClass *klass);