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/02/06 17:52:34 UTC

[lucy-commits] svn commit: r1067700 - in /incubator/lucy/trunk/clownfish: lib/Clownfish/Type/Arbitrary.pm lib/Clownfish/Type/Composite.pm lib/Clownfish/Type/Object.pm lib/Clownfish/Type/Primitive.pm lib/Clownfish/Type/VAList.pm src/CFCType.c t/100-type.t

Author: marvin
Date: Sun Feb  6 16:52:33 2011
New Revision: 1067700

URL: http://svn.apache.org/viewvc?rev=1067700&view=rev
Log:
Consolidate the functionality of most equals() methods for Clownfish::Type
subclasses within the parent class's equals() method.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm
    incubator/lucy/trunk/clownfish/src/CFCType.c
    incubator/lucy/trunk/clownfish/t/100-type.t

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm Sun Feb  6 16:52:33 2011
@@ -54,14 +54,6 @@ sub new {
     return $self;
 }
 
-sub equals {
-    my ( $self, $other ) = @_;
-    return 0 unless blessed($other);
-    return 0 unless $other->isa(__PACKAGE__);
-    return 0 unless $self->get_specifier eq $other->get_specifier;
-    return 1;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm Sun Feb  6 16:52:33 2011
@@ -71,11 +71,10 @@ sub _get_child    { $child{ +shift } }
 
 sub equals {
     my ( $self, $other ) = @_;
-    return 0 unless $self->get_indirection == $other->get_indirection;
     return 0 unless $self->_get_child->equals( $other->_get_child );
     return 0 if ( $self->get_array xor $other->get_array );
     return 0 if ( $self->get_array and $self->get_array ne $other->get_array );
-    return 1;
+    return $self->SUPER::equals($other);
 }
 
 1;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm Sun Feb  6 16:52:33 2011
@@ -107,8 +107,7 @@ sub similar {
 sub equals {
     my ( $self, $other ) = @_;
     return 0 unless $self->similar($other);
-    return 0 unless $self->get_specifier eq $other->get_specifier;
-    return 1;
+    return $self->SUPER::equals($other);
 }
 
 1;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm Sun Feb  6 16:52:33 2011
@@ -38,15 +38,6 @@ sub new {
     return $package->SUPER::new( %new_PARAMS, %args, primitive => 1 );
 }
 
-sub equals {
-    my ( $self, $other ) = @_;
-    return 0 unless blessed($other);
-    return 0 unless $other->isa(__PACKAGE__);
-    return 0 unless $self->get_specifier eq $other->get_specifier;
-    return 0 if ( $self->const xor $other->const );
-    return 1;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/VAList.pm Sun Feb  6 16:52:33 2011
@@ -34,13 +34,6 @@ sub new {
     );
 }
 
-sub equals {
-    my ( $self, $other ) = @_;
-    return 0 unless blessed($other);
-    return 0 unless $other->isa(__PACKAGE__);
-    return 1;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Sun Feb  6 16:52:33 2011
@@ -68,6 +68,21 @@ CFCType_destroy(CFCType *self)
 int
 CFCType_equals(CFCType *self, CFCType *other)
 {
+    if (   (CFCType_const(self)        ^ CFCType_const(other))
+        || (CFCType_nullable(self)     ^ CFCType_nullable(other))
+        || (CFCType_is_void(self)      ^ CFCType_is_void(other))
+        || (CFCType_is_object(self)    ^ CFCType_is_object(other))
+        || (CFCType_is_primitive(self) ^ CFCType_is_primitive(other))
+        || (CFCType_is_integer(self)   ^ CFCType_is_integer(other))
+        || (CFCType_is_floating(self)  ^ CFCType_is_floating(other))
+        || (CFCType_is_va_list(self)   ^ CFCType_is_va_list(other))
+        || (CFCType_is_arbitrary(self) ^ CFCType_is_arbitrary(other))
+        || (CFCType_is_composite(self) ^ CFCType_is_composite(other))
+    ) { 
+        return false; 
+    }
+    if (self->indirection != other->indirection) { return false; }
+    if (strcmp(self->specifier, other->specifier) != 0) { return false; }
     return true;
 }
 

Modified: incubator/lucy/trunk/clownfish/t/100-type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/t/100-type.t?rev=1067700&r1=1067699&r2=1067700&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/t/100-type.t (original)
+++ incubator/lucy/trunk/clownfish/t/100-type.t Sun Feb  6 16:52:33 2011
@@ -20,7 +20,7 @@ package MyType;
 use base qw( Clownfish::Type );
 
 package main;
-use Test::More tests => 12;
+use Test::More tests => 11;
 use Clownfish::Parcel;
 
 my $neato_parcel = Clownfish::Parcel->singleton( name => 'Neato' );
@@ -42,5 +42,3 @@ ok( !$type->is_void,        "is_void() f
 ok( !$type->is_composite,   "is_composite() false by default" );
 ok( !$type->is_string_type, "is_string_type() false by default" );
 
-ok( $type->equals( MyType->new ), "equals() depends solely on class" );
-