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/24 02:00:33 UTC
[lucy-commits] svn commit: r1074002 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Method.pm src/CFCMethod.c
Author: marvin
Date: Thu Feb 24 01:00:33 2011
New Revision: 1074002
URL: http://svn.apache.org/viewvc?rev=1074002&view=rev
Log:
Port compatible() for CFCMethod from Perl to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
incubator/lucy/trunk/clownfish/src/CFCMethod.c
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1074002&r1=1074001&r2=1074002&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb 24 01:00:33 2011
@@ -574,6 +574,14 @@ DESTROY(self)
PPCODE:
CFCMethod_destroy(self);
+int
+compatible(self, other)
+ CFCMethod *self;
+ CFCMethod *other;
+CODE:
+ RETVAL = CFCMethod_compatible(self, other);
+OUTPUT: RETVAL
+
SV*
_various_method_syms(self, invoker)
CFCMethod *self;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm?rev=1074002&r1=1074001&r2=1074002&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm Thu Feb 24 01:00:33 2011
@@ -70,46 +70,6 @@ sub override {
$self->_set_novel(0);
}
-sub compatible {
- my ( $self, $other ) = @_;
- return 0 unless $self->get_macro_sym eq $other->get_macro_sym;
- return 0 if ( $self->public xor $other->public );
- my $param_list = $self->get_param_list;
- my $other_param_list = $other->get_param_list;
- my $arg_vars = $param_list->get_variables;
- my $other_vars = $other_param_list->get_variables;
- my $initial_vals = $param_list->get_initial_values;
- my $other_vals = $other_param_list->get_initial_values;
- return 0 unless @$arg_vars == @$other_vars;
- return 0 unless @$initial_vals == @$other_vals;
-
- # Validate initial values.
- for ( my $i = 1; $i <= $#$arg_vars; $i++ ) {
- return 0 unless $other_vars->[$i]->equals( $arg_vars->[$i] );
- my $val = $initial_vals->[$i];
- my $other_val = $other_vals->[$i];
- if ( defined $val ) {
- return 0 unless defined $other_val;
- return 0 unless $val eq $other_val;
- }
- else {
- return 0 if defined $other_val;
- }
- }
-
- # Weak validation of return type to allow covariant object return types.
- my $return_type = $self->get_return_type;
- my $other_return_type = $other->get_return_type;
- if ( $return_type->is_object ) {
- return 0 unless $return_type->similar($other_return_type);
- }
- else {
- return 0 unless $return_type->equals($other_return_type);
- }
-
- return 1;
-}
-
sub finalize {
my $self = shift;
my $finalized = $self->new(
Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.c?rev=1074002&r1=1074001&r2=1074002&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.c Thu Feb 24 01:00:33 2011
@@ -164,6 +164,54 @@ CFCMethod_destroy(CFCMethod *self)
CFCFunction_destroy((CFCFunction*)self);
}
+int
+CFCMethod_compatible(CFCMethod *self, CFCMethod *other)
+{
+ if (!other) { return false; }
+ if (strcmp(self->macro_sym, other->macro_sym)) { return false; }
+ int my_public = CFCSymbol_public((CFCSymbol*)self);
+ int other_public = CFCSymbol_public((CFCSymbol*)self);
+ if (!!my_public != !!other_public) { return false; }
+
+ // Check arguments and initial values.
+ CFCParamList *my_param_list = self->function.param_list;
+ CFCParamList *other_param_list = other->function.param_list;
+ CFCVariable **my_args = CFCParamList_get_variables(my_param_list);
+ CFCVariable **other_args = CFCParamList_get_variables(other_param_list);
+ const char **my_vals = CFCParamList_get_initial_values(my_param_list);
+ const char **other_vals = CFCParamList_get_initial_values(other_param_list);
+ size_t i;
+ for (i = 1; ; i++) { // start at 1, skipping self
+ if (!!my_args[i] != !!other_args[i]) { return false; }
+ if (!!my_vals[i] != !!other_vals[i]) { return false; }
+ if (my_vals[i]) {
+ if (strcmp(my_vals[i], other_vals[i])) { return false; }
+ }
+ if (my_args[i]) {
+ if (!CFCVariable_equals(my_args[i], other_args[i])) {
+ return false;
+ }
+ }
+ else {
+ break;
+ }
+ }
+
+ // Check return types.
+ CFCType *type = CFCFunction_get_return_type((CFCFunction*)self);
+ CFCType *other_type = CFCFunction_get_return_type((CFCFunction*)other);
+ if (CFCType_is_object(type)) {
+ // Weak validation to allow covariant object return types.
+ if (!CFCType_is_object(other_type)) { return false; }
+ if (!CFCType_similar(type, other_type)) { return false; }
+ }
+ else {
+ if (!CFCType_equals(type, other_type)) { return false; }
+ }
+
+ return true;
+}
+
size_t
CFCMethod_short_method_sym(CFCMethod *self, const char *invoker, char *buf,
size_t buf_size)