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:56:01 UTC

[lucy-commits] svn commit: r1074012 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Method.pm src/CFCMethod.c src/CFCMethod.h

Author: marvin
Date: Thu Feb 24 01:56:00 2011
New Revision: 1074012

URL: http://svn.apache.org/viewvc?rev=1074012&view=rev
Log:
Finish porting CFCMethod 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
    incubator/lucy/trunk/clownfish/src/CFCMethod.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1074012&r1=1074011&r2=1074012&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb 24 01:56:00 2011
@@ -582,6 +582,22 @@ CODE:
     RETVAL = CFCMethod_compatible(self, other);
 OUTPUT: RETVAL
 
+void
+override(self, other)
+    CFCMethod *self;
+    CFCMethod *other;
+PPCODE:
+    CFCMethod_override(self, other);
+
+SV*
+finalize(self)
+    CFCMethod *self;
+CODE:
+    CFCMethod *finalized = CFCMethod_finalize(self);
+    RETVAL = newRV(CFCBase_get_perl_obj((CFCBase*)finalized));
+    CFCBase_decref((CFCBase*)finalized);
+OUTPUT: RETVAL
+
 SV*
 _various_method_syms(self, invoker)
     CFCMethod *self;
@@ -621,13 +637,11 @@ _set_or_get(self, ...)
     CFCMethod *self;
 ALIAS:
     get_macro_sym      = 2
-    _set_short_typedef = 3
     short_typedef      = 4
     full_typedef       = 6
     full_callback_sym  = 8
     full_override_sym  = 10
     abstract           = 12
-    _set_novel         = 13
     novel              = 14
     final              = 16
     self_type          = 18
@@ -639,9 +653,6 @@ PPCODE:
                 retval = newSVpvn(macro_sym, strlen(macro_sym));
             }
             break;
-        case 3:
-            CFCMethod_set_short_typedef(self, SvPV_nolen(ST(1)));
-            break;
         case 4: {
                 const char *short_typedef = CFCMethod_short_typedef(self);
                 retval = newSVpvn(short_typedef, strlen(short_typedef));
@@ -665,9 +676,6 @@ PPCODE:
         case 12:
             retval = newSViv(CFCMethod_abstract(self));
             break;
-        case 13:
-            CFCMethod_set_novel(self, !!SvIV(ST(1)));
-            break;
         case 14:
             retval = newSViv(CFCMethod_novel(self));
             break;

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm?rev=1074012&r1=1074011&r2=1074012&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm Thu Feb 24 01:56:00 2011
@@ -49,47 +49,6 @@ sub new {
     );
 }
 
-sub override {
-    my ( $self, $orig ) = @_;
-
-    # Check that the override attempt is legal.
-    if ( $orig->final ) {
-        my $orig_micro_sym = $orig->micro_sym;
-        my $orig_class     = $orig->get_class_name;
-        my $class_name     = $self->get_class_name;
-        confess(  "Attempt to override final method '$orig_micro_sym' "
-                . " from $orig_class by $class_name" );
-    }
-    if ( !$self->compatible($orig) ) {
-        my $func_name = $self->full_func_sym;
-        my $orig_func = $orig->full_func_sym;
-        confess("Non-matching signatures for $func_name and $orig_func");
-    }
-
-    # Mark the Method as no longer novel.
-    $self->_set_novel(0);
-}
-
-sub finalize {
-    my $self      = shift;
-    my $finalized = $self->new(
-        return_type => $self->get_return_type,
-        class_name  => $self->get_class_name,
-        class_cnick => $self->get_class_cnick,
-        param_list  => $self->get_param_list,
-        macro_sym   => $self->get_macro_sym,
-        docucomment => $self->get_docucomment,
-        parcel      => $self->get_parcel,
-        abstract    => $self->abstract,
-        final       => $self->final,
-        exposure    => $self->get_exposure,
-        final       => 1,
-    );
-    $finalized->_set_short_typedef( $self->short_typedef );
-    $finalized->_set_novel( $self->final );
-    return $finalized;
-}
-
 1;
 
 __END__

Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.c?rev=1074012&r1=1074011&r2=1074012&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.c Thu Feb 24 01:56:00 2011
@@ -46,6 +46,9 @@ struct CFCMethod {
     int is_novel;
 };
 
+static void
+S_update_typedefs(CFCMethod *self, const char *short_sym);
+
 CFCMethod*
 CFCMethod_new(CFCParcel *parcel, const char *exposure, const char *class_name,
               const char *class_cnick, const char *macro_sym, 
@@ -143,12 +146,8 @@ CFCMethod_init(CFCMethod *self, CFCParce
     // inheritance that it was overridden.
     self->is_novel = 1;
 
-    // Cache typedef.
-    const char *short_sym = CFCSymbol_short_sym((CFCSymbol*)self);
-    char *short_typedef = (char*)MALLOCATE(strlen(short_sym) + 3);
-    sprintf(short_typedef, "%s_t", short_sym);
-    CFCMethod_set_short_typedef(self, short_typedef);
-    FREEMEM(short_typedef);
+    // Cache typedefs.
+    S_update_typedefs(self, CFCSymbol_short_sym((CFCSymbol*)self));
 
     return self;
 }
@@ -212,6 +211,43 @@ CFCMethod_compatible(CFCMethod *self, CF
     return true;
 }
 
+void
+CFCMethod_override(CFCMethod *self, CFCMethod *orig)
+{
+    // Check that the override attempt is legal.
+    if (CFCMethod_final(orig)) {
+        const char *orig_class = CFCSymbol_get_class_name((CFCSymbol*)orig);
+        const char *my_class   = CFCSymbol_get_class_name((CFCSymbol*)self);
+        croak("Attempt to override final method '%s' from '%s' by '%s'",
+            orig->macro_sym, orig_class, my_class);
+    }
+    if (!CFCMethod_compatible(self, orig)) {
+        const char *func      = CFCFunction_full_func_sym((CFCFunction*)self);
+        const char *orig_func = CFCFunction_full_func_sym((CFCFunction*)orig);
+        croak("Non-matching signatures for %s and %s", func, orig_func);
+    }
+
+    // Mark the Method as no longer novel.
+    self->is_novel = false;
+}
+
+CFCMethod*
+CFCMethod_finalize(CFCMethod *self)
+{
+    CFCSymbol *self_sym = (CFCSymbol*)self;
+    CFCParcel *parcel = CFCSymbol_get_parcel(self_sym);
+    const char *exposure = CFCSymbol_get_exposure(self_sym);
+    const char *class_name = CFCSymbol_get_class_name(self_sym);
+    const char *class_cnick = CFCSymbol_get_class_cnick(self_sym);
+    CFCMethod *finalized = CFCMethod_new(parcel, exposure, class_name,
+        class_cnick, self->macro_sym, self->function.return_type,
+        self->function.param_list, self->function.docucomment, true,
+        self->is_abstract);
+    finalized->is_novel = self->is_final; // Is this right?
+    S_update_typedefs(finalized, CFCSymbol_short_sym((CFCSymbol*)self));
+    return finalized;
+}
+
 size_t
 CFCMethod_short_method_sym(CFCMethod *self, const char *invoker, char *buf, 
                            size_t buf_size)
@@ -260,18 +296,20 @@ CFCMethod_get_macro_sym(CFCMethod *self)
     return self->macro_sym;
 }
 
-void
-CFCMethod_set_short_typedef(CFCMethod *self, const char *short_typedef)
+static void
+S_update_typedefs(CFCMethod *self, const char *short_sym)
 {
     FREEMEM(self->short_typedef);
     FREEMEM(self->full_typedef);
-    if (short_typedef) {
-        self->short_typedef = CFCUtil_strdup(short_typedef);
+    if (short_sym) {
         const char *prefix = CFCSymbol_get_prefix((CFCSymbol*)self);
-        size_t amount = strlen(prefix) + strlen(short_typedef) + 1;
+        size_t amount = strlen(short_sym) + 3;
+        self->short_typedef = (char*)MALLOCATE(amount);
+        int check = sprintf(self->short_typedef, "%s_t", short_sym);
+        if (check < 0) { croak("sprintf failed"); }
+        amount += strlen(prefix);
         self->full_typedef = (char*)MALLOCATE(amount);
-        int check = sprintf(self->full_typedef, "%s%s", prefix,
-            short_typedef);
+        check = sprintf(self->full_typedef, "%s%s_t", prefix, short_sym);
         if (check < 0) { croak("sprintf failed"); }
     }
     else {
@@ -316,12 +354,6 @@ CFCMethod_abstract(CFCMethod *self)
     return self->is_abstract;
 }
 
-void
-CFCMethod_set_novel(CFCMethod *self, int is_novel)
-{
-    self->is_novel = !!is_novel;
-}
-
 int
 CFCMethod_novel(CFCMethod *self)
 {

Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.h?rev=1074012&r1=1074011&r2=1074012&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.h Thu Feb 24 01:56:00 2011
@@ -42,6 +42,15 @@ CFCMethod_init(CFCMethod *self, struct C
 void
 CFCMethod_destroy(CFCMethod *self);
 
+int
+CFCMethod_compatible(CFCMethod *self, CFCMethod *other);
+
+void
+CFCMethod_override(CFCMethod *self, CFCMethod *orig);
+
+CFCMethod*
+CFCMethod_finalize(CFCMethod *self);
+
 /** 
  * @return the number of bytes which the symbol would occupy.
  */
@@ -66,9 +75,6 @@ CFCMethod_full_offset_sym(CFCMethod *sel
 const char*
 CFCMethod_get_macro_sym(CFCMethod *self);
 
-void
-CFCMethod_set_short_typedef(CFCMethod *self, const char *short_typedef);
-
 const char*
 CFCMethod_short_typedef(CFCMethod *self);
 
@@ -87,9 +93,6 @@ CFCMethod_final(CFCMethod *self);
 int
 CFCMethod_abstract(CFCMethod *self);
 
-void
-CFCMethod_set_novel(CFCMethod *self, int is_novel);
-
 int
 CFCMethod_novel(CFCMethod *self);