You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/08/01 15:56:01 UTC

[7/8] git commit: Skip class from include dir if parcel was already processed

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/79246685
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/79246685
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/79246685

Branch: refs/heads/include_dir_fixes
Commit: 79246685bc3635b443053bdea1adf4d893786b4b
Parents: bec8dc3
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Aug 1 13:47:46 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Aug 1 15:49:09 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/79246685/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/79246685/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/79246685/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