Repository: lucy-clownfish
Updated Branches:
  refs/heads/master a32faa7c3 -> 706e3068b


Skip class from include dir if parcel was already processed

The parcel from the first source or include dir takes precedence.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/78ed1686
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/78ed1686
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/78ed1686

Branch: refs/heads/master
Commit: 78ed16860f94b8c5c6b0a0147a9e21d3364ac1f5
Parents: 963ee7f
Author: Nick Wellnhofer <[email protected]>
Authored: Fri Aug 1 13:47:46 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue Aug 5 11:56:01 2014 +0200

----------------------------------------------------------------------
 compiler/perl/t/502-clash.t | 21 +--------------------
 compiler/src/CFCClass.c     | 40 ++++++++++++++++++++++++----------------
 compiler/src/CFCClass.h     |  3 +++
 3 files changed, 28 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/78ed1686/compiler/perl/t/502-clash.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/502-clash.t b/compiler/perl/t/502-clash.t
index 4bb5a63..4cf870b 100644
--- a/compiler/perl/t/502-clash.t
+++ b/compiler/perl/t/502-clash.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5;
+use Test::More tests => 4;
 
 use Clownfish::CFC::Model::Hierarchy;
 use File::Spec::Functions qw( catdir catfile splitpath );
@@ -90,25 +90,6 @@ SKIP: {
 
     my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
 
-    $hierarchy->add_source_dir($foo_dir);
-    $hierarchy->add_include_dir($bar_dir);
-    $hierarchy->add_include_dir($base_dir);
-
-    eval { $hierarchy->build; };
-
-    like( $@, qr/Class .* from include dir .* parcel .* from source dir/,
-          "included class with source parcel" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
-SKIP: {
-    skip( 'Exceptions leak', 1 )
-        if $ENV{LUCY_VALGRIND};
-
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
-
     $hierarchy->add_source_dir($bar_dir);
     $hierarchy->add_include_dir($foo_dir);
     $hierarchy->add_include_dir($base_dir);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/78ed1686/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCClass.c b/compiler/src/CFCClass.c
index 7322e22..59ec8c3 100644
--- a/compiler/src/CFCClass.c
+++ b/compiler/src/CFCClass.c
@@ -184,25 +184,26 @@ CFCClass_do_create(CFCClass *self, struct CFCParcel 
*parcel,
     self->is_final    = !!is_final;
     self->is_inert    = !!is_inert;
 
-    if (file_spec && CFCFileSpec_included(file_spec)) {
-        if (!CFCParcel_included(parcel)) {
-            CFCUtil_die("Class %s from include dir found in parcel %s from"
-                        " source dir",
-                        class_name, CFCParcel_get_name(parcel));
-        }
-    }
-    else {
-        if (CFCParcel_included(parcel)) {
-            CFCUtil_die("Class %s from source dir found in parcel %s from"
-                        " include dir",
-                        class_name, CFCParcel_get_name(parcel));
-        }
+    if (!CFCClass_included(self) && CFCParcel_included(parcel)) {
+        CFCUtil_die("Class %s from source dir found in parcel %s from"
+                    " include dir",
+                    class_name, CFCParcel_get_name(parcel));
     }
 
-    // Store in registry.
-    S_register(self);
+    // Skip class if it's from an include dir and the parcel was already
+    // processed in another source or include dir.
+    const char *class_source_dir  = CFCClass_get_source_dir(self);
+    const char *parcel_source_dir = CFCParcel_get_source_dir(parcel);
+    if (!CFCClass_included(self)
+        || !class_source_dir
+        || !parcel_source_dir
+        || strcmp(class_source_dir, parcel_source_dir) == 0
+    ) {
+        // Store in registry.
+        S_register(self);
 
-    CFCParcel_add_struct_sym(parcel, self->struct_sym);
+        CFCParcel_add_struct_sym(parcel, self->struct_sym);
+    }
 
     return self;
 }
@@ -717,6 +718,13 @@ CFCClass_get_parent(CFCClass *self) {
 }
 
 const char*
+CFCClass_get_source_dir(CFCClass *self) {
+    return self->file_spec
+           ? CFCFileSpec_get_source_dir(self->file_spec)
+           : NULL;
+}
+
+const char*
 CFCClass_get_path_part(CFCClass *self) {
     return self->file_spec ? CFCFileSpec_get_path_part(self->file_spec) : NULL;
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/78ed1686/compiler/src/CFCClass.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCClass.h b/compiler/src/CFCClass.h
index 78eefd0..877a84a 100644
--- a/compiler/src/CFCClass.h
+++ b/compiler/src/CFCClass.h
@@ -202,6 +202,9 @@ CFCClass*
 CFCClass_get_parent(CFCClass *self);
 
 const char*
+CFCClass_get_source_dir(CFCClass *self);
+
+const char*
 CFCClass_get_path_part(CFCClass *self);
 
 int

Reply via email to