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 2013/07/01 20:48:06 UTC

[lucy-commits] [1/4] git commit: refs/heads/master - Check for class/parcel include mismatch

Updated Branches:
  refs/heads/master acc7158f6 -> 146a6860d


Check for class/parcel include mismatch


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

Branch: refs/heads/master
Commit: 23857d20c5cc5c06ef6a6d2a44feb9ce1ab32331
Parents: acc7158
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Jul 1 00:39:44 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Jul 1 20:41:24 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/c/t/cfbase/Animal.cfh        |  19 +++
 clownfish/compiler/c/t/cfbase/Animal.cfp        |   4 +
 clownfish/compiler/c/t/cfbase/Animal/Dog.cfh    |  28 ++++
 clownfish/compiler/c/t/cfbase/Animal/Util.cfh   |  23 ++++
 .../compiler/c/t/cfext/Animal/Rottweiler.cfh    |   2 +-
 .../compiler/c/t/cfext/AnimalExtension.cfp      |   5 +
 clownfish/compiler/c/t/cfsource/Animal.cfh      |  19 ---
 clownfish/compiler/c/t/cfsource/Animal.cfp      |   4 -
 clownfish/compiler/c/t/cfsource/Animal/Dog.cfh  |  28 ----
 clownfish/compiler/c/t/cfsource/Animal/Util.cfh |  23 ----
 clownfish/compiler/perl/t/403-parcel.t          |   2 +-
 clownfish/compiler/perl/t/500-hierarchy.t       |   8 +-
 clownfish/compiler/perl/t/501-include_dir.t     |  98 +++-----------
 clownfish/compiler/perl/t/502-clash.t           | 129 +++++++++++++++++++
 clownfish/compiler/perl/t/cfbase/Animal.cfh     |  19 +++
 clownfish/compiler/perl/t/cfbase/Animal.cfp     |   4 +
 clownfish/compiler/perl/t/cfbase/Animal/Dog.cfh |  28 ++++
 .../compiler/perl/t/cfbase/Animal/Util.cfh      |  23 ++++
 clownfish/compiler/perl/t/cfclash/bar/Bar.cfh   |  25 ++++
 clownfish/compiler/perl/t/cfclash/bar/Bar.cfp   |   4 +
 clownfish/compiler/perl/t/cfclash/bar/Baz.cfh   |  25 ++++
 clownfish/compiler/perl/t/cfclash/foo/Foo.cfh   |  25 ++++
 clownfish/compiler/perl/t/cfclash/foo/Foo.cfp   |   4 +
 .../compiler/perl/t/cfext/Animal/Rottweiler.cfh |   2 +-
 .../compiler/perl/t/cfext/AnimalExtension.cfp   |   5 +
 clownfish/compiler/perl/t/cfsource/Animal.cfh   |  19 ---
 clownfish/compiler/perl/t/cfsource/Animal.cfp   |   4 -
 .../compiler/perl/t/cfsource/Animal/Dog.cfh     |  28 ----
 .../compiler/perl/t/cfsource/Animal/Util.cfh    |  23 ----
 clownfish/compiler/src/CFCClass.c               |  15 ++-
 clownfish/compiler/src/CFCTestHierarchy.c       |  14 +-
 clownfish/compiler/src/CFCTestParcel.c          |   2 +-
 32 files changed, 417 insertions(+), 244 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfbase/Animal.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfbase/Animal.cfh b/clownfish/compiler/c/t/cfbase/Animal.cfh
new file mode 100644
index 0000000..a4d689a
--- /dev/null
+++ b/clownfish/compiler/c/t/cfbase/Animal.cfh
@@ -0,0 +1,19 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+abstract class Animal { }

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfbase/Animal.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfbase/Animal.cfp b/clownfish/compiler/c/t/cfbase/Animal.cfp
new file mode 100644
index 0000000..e2b5ab5
--- /dev/null
+++ b/clownfish/compiler/c/t/cfbase/Animal.cfp
@@ -0,0 +1,4 @@
+{
+    "name": "Animal",
+    "version": "v0.1.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfbase/Animal/Dog.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfbase/Animal/Dog.cfh b/clownfish/compiler/c/t/cfbase/Animal/Dog.cfh
new file mode 100644
index 0000000..6d54baa
--- /dev/null
+++ b/clownfish/compiler/c/t/cfbase/Animal/Dog.cfh
@@ -0,0 +1,28 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+class Animal::Dog inherits Animal {
+    public inert incremented Dog*
+    new();
+
+    public inert Dog*
+    init(Dog *self);
+
+    public void
+    Bark(Dog *self);
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfbase/Animal/Util.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfbase/Animal/Util.cfh b/clownfish/compiler/c/t/cfbase/Animal/Util.cfh
new file mode 100644
index 0000000..f5688a5
--- /dev/null
+++ b/clownfish/compiler/c/t/cfbase/Animal/Util.cfh
@@ -0,0 +1,23 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+inert class Animal::Util {
+    inert void
+    groom(Animal *animal);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfext/Animal/Rottweiler.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfext/Animal/Rottweiler.cfh b/clownfish/compiler/c/t/cfext/Animal/Rottweiler.cfh
index 8de5e24..9e78b58 100644
--- a/clownfish/compiler/c/t/cfext/Animal/Rottweiler.cfh
+++ b/clownfish/compiler/c/t/cfext/Animal/Rottweiler.cfh
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-parcel Animal;
+parcel AnimalExtension;
 
 class Animal::Rottweiler inherits Animal::Dog {
     public inert incremented Rottweiler*

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfext/AnimalExtension.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfext/AnimalExtension.cfp b/clownfish/compiler/c/t/cfext/AnimalExtension.cfp
new file mode 100644
index 0000000..76f31d3
--- /dev/null
+++ b/clownfish/compiler/c/t/cfext/AnimalExtension.cfp
@@ -0,0 +1,5 @@
+{
+    "name": "AnimalExtension",
+    "nickname": "AniExt",
+    "version": "v0.1.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfsource/Animal.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfsource/Animal.cfh b/clownfish/compiler/c/t/cfsource/Animal.cfh
deleted file mode 100644
index a4d689a..0000000
--- a/clownfish/compiler/c/t/cfsource/Animal.cfh
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-abstract class Animal { }

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfsource/Animal.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfsource/Animal.cfp b/clownfish/compiler/c/t/cfsource/Animal.cfp
deleted file mode 100644
index e2b5ab5..0000000
--- a/clownfish/compiler/c/t/cfsource/Animal.cfp
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "name": "Animal",
-    "version": "v0.1.0"
-}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfsource/Animal/Dog.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfsource/Animal/Dog.cfh b/clownfish/compiler/c/t/cfsource/Animal/Dog.cfh
deleted file mode 100644
index 6d54baa..0000000
--- a/clownfish/compiler/c/t/cfsource/Animal/Dog.cfh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-class Animal::Dog inherits Animal {
-    public inert incremented Dog*
-    new();
-
-    public inert Dog*
-    init(Dog *self);
-
-    public void
-    Bark(Dog *self);
-}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/c/t/cfsource/Animal/Util.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/c/t/cfsource/Animal/Util.cfh b/clownfish/compiler/c/t/cfsource/Animal/Util.cfh
deleted file mode 100644
index f5688a5..0000000
--- a/clownfish/compiler/c/t/cfsource/Animal/Util.cfh
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-inert class Animal::Util {
-    inert void
-    groom(Animal *animal);
-}
-

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/403-parcel.t b/clownfish/compiler/perl/t/403-parcel.t
index 462f7c3..de887fd 100644
--- a/clownfish/compiler/perl/t/403-parcel.t
+++ b/clownfish/compiler/perl/t/403-parcel.t
@@ -66,7 +66,7 @@ isa_ok(
 
 isa_ok(
     Clownfish::CFC::Model::Parcel->new_from_file(
-        path => catfile(qw( t cfsource Animal.cfp )),
+        path => catfile(qw( t cfbase Animal.cfp )),
     ),
     "Clownfish::CFC::Model::Parcel",
     "new_from_file"

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/500-hierarchy.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/500-hierarchy.t b/clownfish/compiler/perl/t/500-hierarchy.t
index 0f7f82e..4866731 100644
--- a/clownfish/compiler/perl/t/500-hierarchy.t
+++ b/clownfish/compiler/perl/t/500-hierarchy.t
@@ -24,7 +24,7 @@ use File::Spec::Functions qw( catdir catfile splitpath );
 use Fcntl;
 use File::Path qw( rmtree mkpath );
 
-my $source = catdir(qw( t cfsource ));
+my $base_dir = catdir(qw( t cfbase ));
 my %args = (
     dest => catdir(qw( t cfdest )),
 );
@@ -48,8 +48,8 @@ is( $hierarchy->get_include_dest, $inc_dest, "get_include_dest" );
 my $src_dest = catfile( $args{dest}, "source" );
 is( $hierarchy->get_source_dest, $src_dest, "get_source_dest" );
 
-$hierarchy->add_source_dir($source);
-is_deeply( $hierarchy->get_source_dirs, [ $source ], "get_source_dirs" );
+$hierarchy->add_source_dir($base_dir);
+is_deeply( $hierarchy->get_source_dirs, [ $base_dir ], "get_source_dirs" );
 
 $hierarchy->build;
 
@@ -89,7 +89,7 @@ for my $file (@files) {
         or die "utime failed for '$h_path': $!";
 }
 
-my $path_to_animal_cf = $animal->cfh_path( $source );
+my $path_to_animal_cf = $animal->cfh_path( $base_dir );
 utime( undef, undef, $path_to_animal_cf )
     or die "utime for '$path_to_animal_cf' failed";    # touch
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/501-include_dir.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/501-include_dir.t b/clownfish/compiler/perl/t/501-include_dir.t
index 45e5060..00b735c 100644
--- a/clownfish/compiler/perl/t/501-include_dir.t
+++ b/clownfish/compiler/perl/t/501-include_dir.t
@@ -16,31 +16,27 @@
 use strict;
 use warnings;
 
-use Test::More tests => 25;
+use Test::More tests => 21;
 
 use Clownfish::CFC::Model::Hierarchy;
-use Clownfish::CFC::Util qw( a_isa_b );
 use File::Spec::Functions qw( catdir catfile splitpath );
-use Fcntl;
 use File::Path qw( rmtree );
 
-my $source = catdir(qw( t cfsource ));
-my $ext    = catdir(qw( t cfext ));
-my $dest   = catdir(qw( t cfdest ));
-
-my $class_clash = catdir(qw( t cfclash class ));
-my $file_clash  = catdir(qw( t cfclash file ));
+my $base_dir = catdir(qw( t cfbase ));
+my $ext_dir  = catdir(qw( t cfext ));
+my $dest_dir = catdir(qw( t cfdest ));
 
 # One source, one include
 
 {
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
 
-    $hierarchy->add_source_dir($ext);
-    is_deeply( $hierarchy->get_source_dirs, [ $ext ], "get_source_dirs" );
+    $hierarchy->add_source_dir($ext_dir);
+    is_deeply( $hierarchy->get_source_dirs, [ $ext_dir ], "get_source_dirs" );
 
-    $hierarchy->add_include_dir($source);
-    is_deeply( $hierarchy->get_include_dirs, [ $source ], "get_include_dirs" );
+    $hierarchy->add_include_dir($base_dir);
+    is_deeply( $hierarchy->get_include_dirs, [ $base_dir ],
+               "get_include_dirs" );
 
     $hierarchy->build;
 
@@ -48,7 +44,8 @@ my $file_clash  = catdir(qw( t cfclash file ));
     is( scalar @$classes, 4, "all classes" );
     my $num_included = 0;
     for my $class (@$classes) {
-        die "not a Class" unless isa_ok( $class, "Clownfish::CFC::Model::Class" );
+        die "not a Class"
+            unless isa_ok( $class, "Clownfish::CFC::Model::Class" );
 
         my $expect;
 
@@ -75,11 +72,12 @@ my $file_clash  = catdir(qw( t cfclash file ));
 # Two sources
 
 {
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
 
-    $hierarchy->add_source_dir($source);
-    $hierarchy->add_source_dir($ext);
-    is_deeply( $hierarchy->get_source_dirs, [ $source, $ext ], "get_source_dirs" );
+    $hierarchy->add_source_dir($base_dir);
+    $hierarchy->add_source_dir($ext_dir);
+    is_deeply( $hierarchy->get_source_dirs, [ $base_dir, $ext_dir ],
+               "get_source_dirs" );
     is_deeply( $hierarchy->get_include_dirs, [], "get_include_dirs" );
 
     $hierarchy->build;
@@ -99,66 +97,6 @@ my $file_clash  = catdir(qw( t cfclash file ));
     Clownfish::CFC::Model::Parcel->reap_singletons();
 }
 
-# Name clashes
-
-{
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
-
-    $hierarchy->add_source_dir($source);
-    $hierarchy->add_source_dir($class_clash);
-
-    eval { $hierarchy->build; };
-
-    like( $@, qr/Conflict with existing class Animal::Dog/, "source/source class name clash" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
-{
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
-
-    $hierarchy->add_source_dir($source);
-    $hierarchy->add_source_dir($file_clash);
-
-    eval { $hierarchy->build; };
-
-    my $filename = catfile(qw( Animal Dog.cfh ));
-    like( $@, qr/File \Q$filename\E already registered/, "source/source filename clash" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
-{
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
-
-    $hierarchy->add_source_dir($source);
-    $hierarchy->add_include_dir($class_clash);
-
-    eval { $hierarchy->build; };
-
-    like( $@, qr/Conflict with existing class Animal::Dog/, "source/include class name clash" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
-{
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest);
-
-    $hierarchy->add_source_dir($source);
-    $hierarchy->add_include_dir($file_clash);
-
-    $hierarchy->build;
-
-    my $classes = $hierarchy->ordered_classes;
-    is( scalar @$classes, 3, "source/include filename clash" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
 # Clean up.
-rmtree($dest);
+rmtree($dest_dir);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/502-clash.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/502-clash.t b/clownfish/compiler/perl/t/502-clash.t
new file mode 100644
index 0000000..b095c34
--- /dev/null
+++ b/clownfish/compiler/perl/t/502-clash.t
@@ -0,0 +1,129 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+use Clownfish::CFC::Model::Hierarchy;
+use File::Spec::Functions qw( catdir catfile splitpath );
+use File::Path qw( rmtree );
+
+my $base_dir        = catdir(qw( t cfbase ));
+my $ext_dir         = catdir(qw( t cfext ));
+my $dest_dir        = catdir(qw( t cfdest ));
+my $class_clash_dir = catdir(qw( t cfclash class ));
+my $file_clash_dir  = catdir(qw( t cfclash file ));
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($base_dir);
+    $hierarchy->add_source_dir($class_clash_dir);
+
+    eval { $hierarchy->build; };
+
+    like( $@, qr/Conflict with existing class Animal::Dog/,
+          "source/source class name clash" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($base_dir);
+    $hierarchy->add_source_dir($file_clash_dir);
+
+    eval { $hierarchy->build; };
+
+    my $filename = catfile(qw( Animal Dog.cfh ));
+    like( $@, qr/File \Q$filename\E already registered/,
+          "source/source filename clash" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($base_dir);
+    $hierarchy->add_include_dir($class_clash_dir);
+
+    eval { $hierarchy->build; };
+
+    like( $@, qr/Class .* from include dir .* parcel .* from source dir/,
+          "source/include class name clash" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($base_dir);
+    $hierarchy->add_include_dir($file_clash_dir);
+
+    $hierarchy->build;
+
+    my $classes = $hierarchy->ordered_classes;
+    is( scalar @$classes, 3, "source/include filename clash" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+
+# Parcel/class include mismatch
+
+my $foo_dir = catdir(qw( t cfclash foo ));
+my $bar_dir = catdir(qw( t cfclash bar ));
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($foo_dir);
+    $hierarchy->add_include_dir($bar_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();
+}
+
+{
+    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
+
+    $hierarchy->add_source_dir($bar_dir);
+    $hierarchy->add_include_dir($foo_dir);
+
+    eval { $hierarchy->build; };
+
+    like( $@, qr/Class .* from source dir .* parcel .* from include dir/,
+          "source class with included parcel" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+    Clownfish::CFC::Model::Parcel->reap_singletons();
+}
+
+# Clean up.
+rmtree($dest_dir);
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfbase/Animal.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfbase/Animal.cfh b/clownfish/compiler/perl/t/cfbase/Animal.cfh
new file mode 100644
index 0000000..a4d689a
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfbase/Animal.cfh
@@ -0,0 +1,19 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+abstract class Animal { }

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfbase/Animal.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfbase/Animal.cfp b/clownfish/compiler/perl/t/cfbase/Animal.cfp
new file mode 100644
index 0000000..e2b5ab5
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfbase/Animal.cfp
@@ -0,0 +1,4 @@
+{
+    "name": "Animal",
+    "version": "v0.1.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfbase/Animal/Dog.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfbase/Animal/Dog.cfh b/clownfish/compiler/perl/t/cfbase/Animal/Dog.cfh
new file mode 100644
index 0000000..6d54baa
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfbase/Animal/Dog.cfh
@@ -0,0 +1,28 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+class Animal::Dog inherits Animal {
+    public inert incremented Dog*
+    new();
+
+    public inert Dog*
+    init(Dog *self);
+
+    public void
+    Bark(Dog *self);
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfbase/Animal/Util.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfbase/Animal/Util.cfh b/clownfish/compiler/perl/t/cfbase/Animal/Util.cfh
new file mode 100644
index 0000000..f5688a5
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfbase/Animal/Util.cfh
@@ -0,0 +1,23 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Animal;
+
+inert class Animal::Util {
+    inert void
+    groom(Animal *animal);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfclash/bar/Bar.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/bar/Bar.cfh b/clownfish/compiler/perl/t/cfclash/bar/Bar.cfh
new file mode 100644
index 0000000..89e798e
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/bar/Bar.cfh
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Bar;
+
+public class Bar inherits Clownfish::Obj {
+    int var;
+
+    public void
+    Method(Bar *self);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfclash/bar/Bar.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/bar/Bar.cfp b/clownfish/compiler/perl/t/cfclash/bar/Bar.cfp
new file mode 100644
index 0000000..e5868f6
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/bar/Bar.cfp
@@ -0,0 +1,4 @@
+{
+    "name": "Bar",
+    "version": "v1.0.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfclash/bar/Baz.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/bar/Baz.cfh b/clownfish/compiler/perl/t/cfclash/bar/Baz.cfh
new file mode 100644
index 0000000..00e4033
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/bar/Baz.cfh
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Foo;
+
+public class Baz inherits Clownfish::Obj {
+    int var;
+
+    public void
+    Method(Baz *self);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfclash/foo/Foo.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/foo/Foo.cfh b/clownfish/compiler/perl/t/cfclash/foo/Foo.cfh
new file mode 100644
index 0000000..b770d8a
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/foo/Foo.cfh
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel Foo;
+
+public class Foo inherits Clownfish::Obj {
+    int var;
+
+    public void
+    Method(Foo *self);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfclash/foo/Foo.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/foo/Foo.cfp b/clownfish/compiler/perl/t/cfclash/foo/Foo.cfp
new file mode 100644
index 0000000..2995169
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/foo/Foo.cfp
@@ -0,0 +1,4 @@
+{
+    "name": "Foo",
+    "version": "v1.0.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfext/Animal/Rottweiler.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfext/Animal/Rottweiler.cfh b/clownfish/compiler/perl/t/cfext/Animal/Rottweiler.cfh
index 8de5e24..9e78b58 100644
--- a/clownfish/compiler/perl/t/cfext/Animal/Rottweiler.cfh
+++ b/clownfish/compiler/perl/t/cfext/Animal/Rottweiler.cfh
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-parcel Animal;
+parcel AnimalExtension;
 
 class Animal::Rottweiler inherits Animal::Dog {
     public inert incremented Rottweiler*

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfext/AnimalExtension.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfext/AnimalExtension.cfp b/clownfish/compiler/perl/t/cfext/AnimalExtension.cfp
new file mode 100644
index 0000000..76f31d3
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfext/AnimalExtension.cfp
@@ -0,0 +1,5 @@
+{
+    "name": "AnimalExtension",
+    "nickname": "AniExt",
+    "version": "v0.1.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfsource/Animal.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfsource/Animal.cfh b/clownfish/compiler/perl/t/cfsource/Animal.cfh
deleted file mode 100644
index a4d689a..0000000
--- a/clownfish/compiler/perl/t/cfsource/Animal.cfh
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-abstract class Animal { }

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfsource/Animal.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfsource/Animal.cfp b/clownfish/compiler/perl/t/cfsource/Animal.cfp
deleted file mode 100644
index e2b5ab5..0000000
--- a/clownfish/compiler/perl/t/cfsource/Animal.cfp
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "name": "Animal",
-    "version": "v0.1.0"
-}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfsource/Animal/Dog.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfsource/Animal/Dog.cfh b/clownfish/compiler/perl/t/cfsource/Animal/Dog.cfh
deleted file mode 100644
index 6d54baa..0000000
--- a/clownfish/compiler/perl/t/cfsource/Animal/Dog.cfh
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-class Animal::Dog inherits Animal {
-    public inert incremented Dog*
-    new();
-
-    public inert Dog*
-    init(Dog *self);
-
-    public void
-    Bark(Dog *self);
-}

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/perl/t/cfsource/Animal/Util.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfsource/Animal/Util.cfh b/clownfish/compiler/perl/t/cfsource/Animal/Util.cfh
deleted file mode 100644
index f5688a5..0000000
--- a/clownfish/compiler/perl/t/cfsource/Animal/Util.cfh
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Animal;
-
-inert class Animal::Util {
-    inert void
-    groom(Animal *animal);
-}
-

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c b/clownfish/compiler/src/CFCClass.c
index ffa326b..0eda731 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -188,7 +188,20 @@ CFCClass_do_create(CFCClass *self, struct CFCParcel *parcel,
     self->is_final    = !!is_final;
     self->is_inert    = !!is_inert;
 
-    // TODO: Check that file_spec->is_included matches parcel->is_included.
+    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));
+        }
+    }
 
     // Store in registry.
     S_register(self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/src/CFCTestHierarchy.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestHierarchy.c b/clownfish/compiler/src/CFCTestHierarchy.c
index 7516146..c84c836 100644
--- a/clownfish/compiler/src/CFCTestHierarchy.c
+++ b/clownfish/compiler/src/CFCTestHierarchy.c
@@ -36,7 +36,7 @@
 #include "CFCTest.h"
 #include "CFCUtil.h"
 
-#define T_CFSOURCE        "t" CHY_DIR_SEP "cfsource"
+#define T_CFBASE          "t" CHY_DIR_SEP "cfbase"
 #define T_CFEXT           "t" CHY_DIR_SEP "cfext"
 #define T_CFDEST          "t" CHY_DIR_SEP "cfdest"
 #define T_CFDEST_INCLUDE  T_CFDEST CHY_DIR_SEP "include"
@@ -72,9 +72,9 @@ S_run_basic_tests(CFCTest *test) {
     STR_EQ(test, CFCHierarchy_get_source_dest(hierarchy), T_CFDEST_SOURCE,
            "get_source_dest");
 
-    CFCHierarchy_add_source_dir(hierarchy, T_CFSOURCE);
+    CFCHierarchy_add_source_dir(hierarchy, T_CFBASE);
     const char **source_dirs = CFCHierarchy_get_source_dirs(hierarchy);
-    STR_EQ(test, source_dirs[0], T_CFSOURCE, "source_dirs[0]");
+    STR_EQ(test, source_dirs[0], T_CFBASE, "source_dirs[0]");
     OK(test, source_dirs[1] == NULL, "source_dirs[1]");
 
     CFCHierarchy_build(hierarchy);
@@ -135,7 +135,7 @@ S_run_basic_tests(CFCTest *test) {
         CFCTest_set_file_times(h_path, past_time);
     }
 
-    char *cfh_path = CFCFile_cfh_path(animal, T_CFSOURCE);
+    char *cfh_path = CFCFile_cfh_path(animal, T_CFBASE);
     CFCTest_set_file_times(cfh_path, now);
     FREEMEM(cfh_path);
 
@@ -165,9 +165,9 @@ S_run_include_tests(CFCTest *test) {
     {
         CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
         CFCHierarchy_add_source_dir(hierarchy, T_CFEXT);
-        CFCHierarchy_add_include_dir(hierarchy, T_CFSOURCE);
+        CFCHierarchy_add_include_dir(hierarchy, T_CFBASE);
         const char **include_dirs = CFCHierarchy_get_include_dirs(hierarchy);
-        STR_EQ(test, include_dirs[0], T_CFSOURCE, "include_dirs[0]");
+        STR_EQ(test, include_dirs[0], T_CFBASE, "include_dirs[0]");
         OK(test, include_dirs[1] == NULL, "include_dirs[1]");
 
         CFCHierarchy_build(hierarchy);
@@ -201,7 +201,7 @@ S_run_include_tests(CFCTest *test) {
 
     {
         CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
-        CFCHierarchy_add_source_dir(hierarchy, T_CFSOURCE);
+        CFCHierarchy_add_source_dir(hierarchy, T_CFBASE);
         CFCHierarchy_add_source_dir(hierarchy, T_CFEXT);
 
         CFCHierarchy_build(hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy/blob/23857d20/clownfish/compiler/src/CFCTestParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestParcel.c b/clownfish/compiler/src/CFCTestParcel.c
index 9c63f18..d91a271 100644
--- a/clownfish/compiler/src/CFCTestParcel.c
+++ b/clownfish/compiler/src/CFCTestParcel.c
@@ -65,7 +65,7 @@ S_run_tests(CFCTest *test) {
     }
 
     {
-        const char *path = "t" CHY_DIR_SEP "cfsource" CHY_DIR_SEP "Animal.cfp";
+        const char *path = "t" CHY_DIR_SEP "cfbase" CHY_DIR_SEP "Animal.cfp";
         CFCParcel *parcel = CFCParcel_new_from_file(path, false);
         OK(test, parcel != NULL, "new_from_file");
         CFCBase_decref((CFCBase*)parcel);


[lucy-commits] [4/4] git commit: refs/heads/master - Check for class name and nickname clashes

Posted by nw...@apache.org.
Check for class name and nickname clashes


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

Branch: refs/heads/master
Commit: 25b290f56009dc942583085a921dbf4d76b5eb36
Parents: 2198b8b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Jul 1 02:36:29 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Jul 1 20:41:33 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/t/105-object_type.t     |   7 +-
 clownfish/compiler/perl/t/401-class.t           |  26 ++++-
 clownfish/compiler/perl/t/404-file.t            | 102 ++++++++++---------
 clownfish/compiler/perl/t/502-clash.t           |  24 +----
 clownfish/compiler/perl/t/600-parser.t          |   2 +-
 .../perl/t/cfclash/class/Animal/DogClash.cfh    |   4 +-
 .../perl/t/cfclash/class/AnimalExtension.cfp    |   5 +
 clownfish/compiler/src/CFCClass.c               |  38 +++++--
 clownfish/compiler/src/CFCTestFile.c            |   5 +-
 clownfish/compiler/src/CFCTestParser.c          |   2 +-
 clownfish/compiler/src/CFCTestType.c            |   4 +-
 11 files changed, 126 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/105-object_type.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/105-object_type.t b/clownfish/compiler/perl/t/105-object_type.t
index 2298f91..d20d01f 100644
--- a/clownfish/compiler/perl/t/105-object_type.t
+++ b/clownfish/compiler/perl/t/105-object_type.t
@@ -86,7 +86,7 @@ ok( !$foo_type->equals($bar_type), "different specifier spoils equals" );
 
 my $foreign_foo_class = Clownfish::CFC::Model::Class->create(
     parcel     => 'Foreign',
-    class_name => 'Foo',
+    class_name => 'Foreign::Foo',
 );
 my $foreign_foo = Clownfish::CFC::Model::Type->new_object(
     specifier => 'Foo',
@@ -117,14 +117,11 @@ ok( !$foo_type->equals($decremented_foo),
     "different decremented spoils equals"
 );
 
-my $foo_class = Clownfish::CFC::Model::Class->create(
-    class_name => 'Foo',
-);
 my $const_foo = Clownfish::CFC::Model::Type->new_object(
     specifier => 'Foo',
     const     => 1,
 );
-$const_foo->resolve([ $foo_class ]);
+$const_foo->resolve(\@classes);
 ok( !$foo_type->equals($const_foo), "different const spoils equals" );
 like( $const_foo->to_c, qr/const/, "const included in C representation" );
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/401-class.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/401-class.t b/clownfish/compiler/perl/t/401-class.t
index d611440..5e37cc3 100644
--- a/clownfish/compiler/perl/t/401-class.t
+++ b/clownfish/compiler/perl/t/401-class.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 52;
+use Test::More tests => 54;
 use Clownfish::CFC::Model::Class;
 use Clownfish::CFC::Parser;
 
@@ -49,15 +49,33 @@ my $foo = Clownfish::CFC::Model::Class->create(%foo_create_args);
 $foo->add_function($tread_water);
 $foo->add_member_var($thing);
 $foo->add_inert_var($widget);
-eval { Clownfish::CFC::Model::Class->create(%foo_create_args) };
-like( $@, qr/conflict/i,
-    "Can't call create for the same class more than once" );
 my $should_be_foo = Clownfish::CFC::Model::Class->fetch_singleton(
     parcel     => 'Neato',
     class_name => 'Foo',
 );
 is( $$foo, $$should_be_foo, "fetch_singleton" );
 
+eval { Clownfish::CFC::Model::Class->create(%foo_create_args) };
+like( $@, qr/two classes with name/i,
+      "Can't call create for the same class more than once" );
+eval {
+    Clownfish::CFC::Model::Class->create(
+        parcel     => 'Neato',
+        class_name => 'Other::Foo',
+    );
+};
+like( $@, qr/class name conflict/i,
+      "Can't create classes wth the same final component" );
+eval {
+    Clownfish::CFC::Model::Class->create(
+        parcel     => 'Neato',
+        class_name => 'Bar',
+        cnick      => 'Foo',
+    );
+};
+like( $@, qr/class nickname conflict/i,
+      "Can't create classes wth the same nickname" );
+
 my $foo_jr = Clownfish::CFC::Model::Class->create(
     parcel            => 'Neato',
     class_name        => 'Foo::FooJr',

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/404-file.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/404-file.t b/clownfish/compiler/perl/t/404-file.t
index 8f8a700..11668c4 100644
--- a/clownfish/compiler/perl/t/404-file.t
+++ b/clownfish/compiler/perl/t/404-file.t
@@ -40,50 +40,60 @@ my $file_spec = Clownfish::CFC::Model::FileSpec->new(
     source_dir  => '.',
     path_part   => $path_part,
 );
-my $file
-    = $parser->_parse_file( "$parcel_declaration\n$class_content\n$c_block",
-    $file_spec );
-
-is( $file->get_source_dir, ".", "get_source_dir" );
-is( $file->get_path_part, $path_part, "get_path_part" );
-ok( !$file->included, "included" );
-
-my $guard_name = $file->guard_name;
-is( $guard_name, "H_STUFF_THING", "guard_name" );
-like( $file->guard_start, qr/$guard_name/, "guard_start" );
-like( $file->guard_close, qr/$guard_name/,
-    "guard_close includes guard_name" );
-
-ok( !$file->get_modified, "modified false at start" );
-$file->set_modified(1);
-ok( $file->get_modified, "set_modified, get_modified" );
-
-my $path_sep = $^O =~ /^mswin/i ? '\\' : '/';
-my $path_to_stuff_thing = join( $path_sep, qw( path to Stuff Thing ) );
-is( $file->cfh_path('path/to'), "$path_to_stuff_thing.cfh", "cfh_path" );
-is( $file->c_path('path/to'),   "$path_to_stuff_thing.c",   "c_path" );
-is( $file->h_path('path/to'),   "$path_to_stuff_thing.h",   "h_path" );
-
-my $classes = $file->classes;
-is( scalar @$classes, 3, "classes() filters blocks" );
-my $class = $classes->[0];
-my ( $foo, $bar ) = @{ $class->member_vars };
-$foo->resolve_type($classes);
-$bar->resolve_type($classes);
-is( $foo->get_type->get_specifier,
-    'stuff_Foo', 'file production picked up parcel def' );
-is( $bar->get_type->get_specifier, 'stuff_Bar', 'parcel def is sticky' );
-
-my $blocks = $file->blocks;
-is( scalar @$blocks, 5, "all five blocks" );
-isa_ok( $blocks->[0], "Clownfish::CFC::Model::Parcel" );
-isa_ok( $blocks->[1], "Clownfish::CFC::Model::Class" );
-isa_ok( $blocks->[2], "Clownfish::CFC::Model::Class" );
-isa_ok( $blocks->[3], "Clownfish::CFC::Model::Class" );
-isa_ok( $blocks->[4], "Clownfish::CFC::Model::CBlock" );
-
-$file = $parser->_parse_file( $class_content, $file_spec );
-($class) = @{ $file->classes };
-( $foo, $bar ) = @{ $class->member_vars };
-is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
+
+{
+    my $file
+        = $parser->_parse_file( "$parcel_declaration\n$class_content\n$c_block",
+        $file_spec );
+
+    is( $file->get_source_dir, ".", "get_source_dir" );
+    is( $file->get_path_part, $path_part, "get_path_part" );
+    ok( !$file->included, "included" );
+
+    my $guard_name = $file->guard_name;
+    is( $guard_name, "H_STUFF_THING", "guard_name" );
+    like( $file->guard_start, qr/$guard_name/, "guard_start" );
+    like( $file->guard_close, qr/$guard_name/,
+        "guard_close includes guard_name" );
+
+    ok( !$file->get_modified, "modified false at start" );
+    $file->set_modified(1);
+    ok( $file->get_modified, "set_modified, get_modified" );
+
+    my $path_sep = $^O =~ /^mswin/i ? '\\' : '/';
+    my $path_to_stuff_thing = join( $path_sep, qw( path to Stuff Thing ) );
+    is( $file->cfh_path('path/to'), "$path_to_stuff_thing.cfh", "cfh_path" );
+    is( $file->c_path('path/to'),   "$path_to_stuff_thing.c",   "c_path" );
+    is( $file->h_path('path/to'),   "$path_to_stuff_thing.h",   "h_path" );
+
+    my $classes = $file->classes;
+    is( scalar @$classes, 3, "classes() filters blocks" );
+    my $class = $classes->[0];
+    my ( $foo, $bar ) = @{ $class->member_vars };
+    $foo->resolve_type($classes);
+    $bar->resolve_type($classes);
+    is( $foo->get_type->get_specifier,
+        'stuff_Foo', 'file production picked up parcel def' );
+    is( $bar->get_type->get_specifier, 'stuff_Bar', 'parcel def is sticky' );
+
+    my $blocks = $file->blocks;
+    is( scalar @$blocks, 5, "all five blocks" );
+    isa_ok( $blocks->[0], "Clownfish::CFC::Model::Parcel" );
+    isa_ok( $blocks->[1], "Clownfish::CFC::Model::Class" );
+    isa_ok( $blocks->[2], "Clownfish::CFC::Model::Class" );
+    isa_ok( $blocks->[3], "Clownfish::CFC::Model::Class" );
+    isa_ok( $blocks->[4], "Clownfish::CFC::Model::CBlock" );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+}
+
+{
+    my $file = $parser->_parse_file( $class_content, $file_spec );
+    my ($class) = @{ $file->classes };
+    my ( $foo, $bar ) = @{ $class->member_vars };
+    is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
+
+    Clownfish::CFC::Model::Class->_clear_registry();
+}
+
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/502-clash.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/502-clash.t b/clownfish/compiler/perl/t/502-clash.t
index b095c34..85df4d0 100644
--- a/clownfish/compiler/perl/t/502-clash.t
+++ b/clownfish/compiler/perl/t/502-clash.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 5;
 
 use Clownfish::CFC::Model::Hierarchy;
 use File::Spec::Functions qw( catdir catfile splitpath );
@@ -32,21 +32,6 @@ my $file_clash_dir  = catdir(qw( t cfclash file ));
     my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
 
     $hierarchy->add_source_dir($base_dir);
-    $hierarchy->add_source_dir($class_clash_dir);
-
-    eval { $hierarchy->build; };
-
-    like( $@, qr/Conflict with existing class Animal::Dog/,
-          "source/source class name clash" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-    Clownfish::CFC::Model::Parcel->reap_singletons();
-}
-
-{
-    my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
-
-    $hierarchy->add_source_dir($base_dir);
     $hierarchy->add_source_dir($file_clash_dir);
 
     eval { $hierarchy->build; };
@@ -62,13 +47,12 @@ my $file_clash_dir  = catdir(qw( t cfclash file ));
 {
     my $hierarchy = Clownfish::CFC::Model::Hierarchy->new(dest => $dest_dir);
 
-    $hierarchy->add_source_dir($base_dir);
-    $hierarchy->add_include_dir($class_clash_dir);
+    $hierarchy->add_source_dir($class_clash_dir);
+    $hierarchy->add_include_dir($base_dir);
 
     eval { $hierarchy->build; };
 
-    like( $@, qr/Class .* from include dir .* parcel .* from source dir/,
-          "source/include class name clash" );
+    like( $@, qr/Two classes with name/, "source/include class name clash" );
 
     Clownfish::CFC::Model::Class->_clear_registry();
     Clownfish::CFC::Model::Parcel->reap_singletons();

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/600-parser.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/600-parser.t b/clownfish/compiler/perl/t/600-parser.t
index 5ac2269..6d9f297 100644
--- a/clownfish/compiler/perl/t/600-parser.t
+++ b/clownfish/compiler/perl/t/600-parser.t
@@ -156,7 +156,7 @@ SKIP: {
 
 is( $parser->parse(qq|class Foodie$_ cnick $_ { }|)->get_cnick,
     $_, "cnick: $_" )
-    for (qw( Foo FF ));
+    for (qw( Food FF ));
 
 SKIP: {
     skip( "Can't recover from bad cnick under flex/lemon parser", 3 );

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/cfclash/class/Animal/DogClash.cfh
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/class/Animal/DogClash.cfh b/clownfish/compiler/perl/t/cfclash/class/Animal/DogClash.cfh
index 6d54baa..3eba020 100644
--- a/clownfish/compiler/perl/t/cfclash/class/Animal/DogClash.cfh
+++ b/clownfish/compiler/perl/t/cfclash/class/Animal/DogClash.cfh
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-parcel Animal;
+parcel AnimalExtension;
 
-class Animal::Dog inherits Animal {
+class Animal::Dog inherits Clownfish::Obj {
     public inert incremented Dog*
     new();
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/perl/t/cfclash/class/AnimalExtension.cfp
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/cfclash/class/AnimalExtension.cfp b/clownfish/compiler/perl/t/cfclash/class/AnimalExtension.cfp
new file mode 100644
index 0000000..76f31d3
--- /dev/null
+++ b/clownfish/compiler/perl/t/cfclash/class/AnimalExtension.cfp
@@ -0,0 +1,5 @@
+{
+    "name": "AnimalExtension",
+    "nickname": "AniExt",
+    "version": "v0.1.0"
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c b/clownfish/compiler/src/CFCClass.c
index a84c5f6..2476071 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -254,10 +254,6 @@ CFCClass_destroy(CFCClass *self) {
 
 static void
 S_register(CFCClass *self) {
-    /*
-     * TODO: Verify that there isn't a class with the same class_name in
-     * another parcel. Verify that cnick is unique within this parcel.
-     */
     if (registry_size == registry_cap) {
         size_t new_cap = registry_cap + 10;
         registry = (CFCClassRegEntry*)REALLOCATE(
@@ -269,15 +265,35 @@ S_register(CFCClass *self) {
         }
         registry_cap = new_cap;
     }
-    CFCParcel *parcel = CFCClass_get_parcel(self);
+
+    CFCParcel  *parcel     = CFCClass_get_parcel(self);
+    const char *prefix     = CFCParcel_get_prefix(parcel);
     const char *class_name = CFCClass_get_class_name(self);
-    CFCClass *existing = CFCClass_fetch_singleton(parcel, class_name);
-    const char *key = self->full_struct_sym;
-    if (existing) {
-        CFCBase_decref((CFCBase*)self);
-        CFCUtil_die("Conflict with existing class %s",
-                    CFCClass_get_class_name(existing));
+    const char *cnick      = CFCClass_get_cnick(self);
+    const char *key        = self->full_struct_sym;
+
+    for (size_t i = 0; i < registry_size; i++) {
+        CFCClass   *other            = registry[i].klass;
+        CFCParcel  *other_parcel     = CFCClass_get_parcel(other);
+        const char *other_prefix     = CFCParcel_get_prefix(other_parcel);
+        const char *other_class_name = CFCClass_get_class_name(other);
+        const char *other_cnick      = CFCClass_get_cnick(other);
+
+        if (strcmp(class_name, other_class_name) == 0) {
+            CFCUtil_die("Two classes with name %s", class_name);
+        }
+        if (strcmp(registry[i].key, key) == 0) {
+            CFCUtil_die("Class name conflict between %s and %s",
+                        class_name, other_class_name);
+        }
+        if (strcmp(prefix, other_prefix) == 0
+            && strcmp(cnick, other_cnick) == 0
+           ) {
+            CFCUtil_die("Class nickname conflict between %s and %s",
+                        class_name, other_class_name);
+        }
     }
+
     registry[registry_size].key   = CFCUtil_strdup(key);
     registry[registry_size].klass = (CFCClass*)CFCBase_incref((CFCBase*)self);
     registry_size++;

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/src/CFCTestFile.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestFile.c b/clownfish/compiler/src/CFCTestFile.c
index f62b919..ad1cd5c 100644
--- a/clownfish/compiler/src/CFCTestFile.c
+++ b/clownfish/compiler/src/CFCTestFile.c
@@ -119,6 +119,8 @@ S_run_tests(CFCTest *test) {
         OK(test, blocks[5] == NULL, "blocks[5]");
 
         CFCBase_decref((CFCBase*)file);
+
+        CFCClass_clear_registry();
     }
 
     {
@@ -135,12 +137,13 @@ S_run_tests(CFCTest *test) {
                "file production resets parcel");
 
         CFCBase_decref((CFCBase*)file);
+
+        CFCClass_clear_registry();
     }
 
     CFCBase_decref((CFCBase*)file_spec);
     CFCBase_decref((CFCBase*)parser);
 
-    CFCClass_clear_registry();
     CFCParcel_reap_singletons();
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/src/CFCTestParser.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestParser.c b/clownfish/compiler/src/CFCTestParser.c
index 04c39e7..ca8ad2c 100644
--- a/clownfish/compiler/src/CFCTestParser.c
+++ b/clownfish/compiler/src/CFCTestParser.c
@@ -293,7 +293,7 @@ S_run_tests(CFCTest *test) {
     }
 
     {
-        static const char *const cnicks[2] =  { "Foo", "FF" };
+        static const char *const cnicks[2] =  { "Food", "FF" };
         for (int i = 0; i < 2; ++i) {
             const char *cnick = cnicks[i];
             char *class_string

http://git-wip-us.apache.org/repos/asf/lucy/blob/25b290f5/clownfish/compiler/src/CFCTestType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestType.c b/clownfish/compiler/src/CFCTestType.c
index d1d9b08..af85017 100644
--- a/clownfish/compiler/src/CFCTestType.c
+++ b/clownfish/compiler/src/CFCTestType.c
@@ -354,8 +354,8 @@ S_run_object_tests(CFCTest *test) {
         CFCParcel *foreign_parcel
             = CFCParcel_new("Foreign", NULL, NULL, false);
         CFCClass *foreign_foo_class
-            = CFCClass_create(foreign_parcel, NULL, "Foo", NULL, NULL, NULL,
-                              NULL, NULL, false, false);
+            = CFCClass_create(foreign_parcel, NULL, "Foreign::Foo", NULL, NULL,
+                              NULL, NULL, NULL, false, false);
         CFCClass *foreign_class_list[2] = { foreign_foo_class, NULL };
         CFCType *foreign_foo = CFCType_new_object(0, foreign_parcel, "Foo", 1);
         CFCType_resolve(foreign_foo, foreign_class_list);


[lucy-commits] [2/4] git commit: refs/heads/master - Use class name to check for fresh symbols

Posted by nw...@apache.org.
Use class name to check for fresh symbols

Checking by cnick isn't safe with multiple parcels.


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

Branch: refs/heads/master
Commit: 2198b8b091906c6ac92d9b806468d4a1bbdf58dd
Parents: 23857d2
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Jul 1 00:52:31 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Jul 1 20:41:33 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCClass.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/2198b8b0/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c b/clownfish/compiler/src/CFCClass.c
index 0eda731..a84c5f6 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -467,12 +467,11 @@ CFCClass_method(CFCClass *self, const char *sym) {
 
 CFCMethod*
 CFCClass_fresh_method(CFCClass *self, const char *sym) {
-    // TODO: Comparing classes by cnick isn't safe with multiple parcels.
     CFCMethod *method = CFCClass_method(self, sym);
     if (method) {
-        const char *cnick = CFCClass_get_cnick(self);
-        const char *meth_cnick = CFCMethod_get_class_cnick(method);
-        if (strcmp(cnick, meth_cnick) == 0) {
+        const char *class_name = CFCClass_get_class_name(self);
+        const char *meth_class_name = CFCMethod_get_class_name(method);
+        if (strcmp(class_name, meth_class_name) == 0) {
             return method;
         }
     }
@@ -655,8 +654,7 @@ CFCClass_tree_to_ladder(CFCClass *self) {
 
 static CFCSymbol**
 S_fresh_syms(CFCClass *self, CFCSymbol **syms) {
-    // TODO: Comparing classes by cnick isn't safe with multiple parcels.
-    const char *cnick = CFCClass_get_cnick(self);
+    const char *class_name = CFCClass_get_class_name(self);
     size_t count = 0;
     while (syms[count] != NULL) { count++; }
     size_t amount = (count + 1) * sizeof(CFCSymbol*);
@@ -664,8 +662,8 @@ S_fresh_syms(CFCClass *self, CFCSymbol **syms) {
     size_t num_fresh = 0;
     for (size_t i = 0; i < count; i++) {
         CFCSymbol *sym = syms[i];
-        const char *sym_cnick = CFCSymbol_get_class_cnick(sym);
-        if (strcmp(sym_cnick, cnick) == 0) {
+        const char *sym_class_name = CFCSymbol_get_class_name(sym);
+        if (strcmp(sym_class_name, class_name) == 0) {
             fresh[num_fresh++] = sym;
         }
     }


[lucy-commits] [3/4] git commit: refs/heads/master - Check that parcel nickname is unique

Posted by nw...@apache.org.
Check that parcel nickname is unique


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

Branch: refs/heads/master
Commit: 146a6860d31b52bfcef6ce9f9747e7596a7e7085
Parents: 25b290f
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Jul 1 03:01:03 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Jul 1 20:41:33 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/t/403-parcel.t | 15 ++++++++++++++-
 clownfish/compiler/src/CFCParcel.c     | 17 ++++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/146a6860/clownfish/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/403-parcel.t b/clownfish/compiler/perl/t/403-parcel.t
index de887fd..c311987 100644
--- a/clownfish/compiler/perl/t/403-parcel.t
+++ b/clownfish/compiler/perl/t/403-parcel.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 18;
 use File::Spec::Functions qw( catfile );
 
 BEGIN { use_ok('Clownfish::CFC::Model::Parcel') }
@@ -26,6 +26,19 @@ isa_ok( $foo, "Clownfish::CFC::Model::Parcel", "new" );
 ok( !$foo->included, "not included" );
 $foo->register;
 
+my $same_name = Clownfish::CFC::Model::Parcel->new( name => "Foo" );
+eval { $same_name->register; };
+like( $@, qr/parcel .* already registered/i,
+      "can't register two parcels with the same name" );
+
+my $same_nick = Clownfish::CFC::Model::Parcel->new(
+    name  => "OtherFoo",
+    cnick => "Foo",
+);
+eval { $same_nick->register; };
+like( $@, qr/parcel with nickname .* already registered/i,
+      "can't register two parcels with the same nickname" );
+
 my $included_foo = Clownfish::CFC::Model::Parcel->new(
     name        => "IncludedFoo",
     is_included => 1,

http://git-wip-us.apache.org/repos/asf/lucy/blob/146a6860/clownfish/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.c b/clownfish/compiler/src/CFCParcel.c
index 6e72f2e..bb6eb56 100644
--- a/clownfish/compiler/src/CFCParcel.c
+++ b/clownfish/compiler/src/CFCParcel.c
@@ -94,10 +94,20 @@ CFCParcel_fetch(const char *name) {
 
 void
 CFCParcel_register(CFCParcel *self) {
-    CFCParcel *existing = CFCParcel_fetch(self->name);
-    if (existing) {
-        CFCUtil_die("Parcel '%s' already registered", self->name);
+    const char *name  = self->name;
+    const char *cnick = self->cnick;
+
+    for (size_t i = 0; i < num_registered ; i++) {
+        CFCParcel *other = registry[i];
+
+        if (strcmp(other->name, name) == 0) {
+            CFCUtil_die("Parcel '%s' already registered", name);
+        }
+        if (strcmp(other->cnick, cnick) == 0) {
+            CFCUtil_die("Parcel with nickname '%s' already registered", cnick);
+        }
     }
+
     if (!num_registered) {
         // Init default parcel as first.
         registry = (CFCParcel**)CALLOCATE(3, sizeof(CFCParcel*));
@@ -105,6 +115,7 @@ CFCParcel_register(CFCParcel *self) {
         registry[0] = (CFCParcel*)CFCBase_incref((CFCBase*)def);
         num_registered++;
     }
+
     size_t size = (num_registered + 2) * sizeof(CFCParcel*);
     registry = (CFCParcel**)REALLOCATE(registry, size);
     registry[num_registered++] = (CFCParcel*)CFCBase_incref((CFCBase*)self);