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/06/23 22:02:56 UTC

[lucy-commits] svn commit: r1139051 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs lib/Clownfish/Binding/Core/Class.pm src/CFCBindClass.c src/CFCBindClass.h

Author: marvin
Date: Thu Jun 23 20:02:56 2011
New Revision: 1139051

URL: http://svn.apache.org/viewvc?rev=1139051&view=rev
Log:
Port struct definition generation for Clownfish::Binding::Core::Class to C.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm
    incubator/lucy/trunk/clownfish/src/CFCBindClass.c
    incubator/lucy/trunk/clownfish/src/CFCBindClass.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1139051&r1=1139050&r2=1139051&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Jun 23 20:02:56 2011
@@ -1799,4 +1799,10 @@ PPCODE:
     END_SET_OR_GET_SWITCH
 }
 
+SV*
+_struct_definition(self)
+    CFCBindClass *self;
+CODE:
+    RETVAL = S_sv_eat_c_string(CFCBindClass_struct_definition(self));
+OUTPUT: RETVAL
 

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm?rev=1139051&r1=1139050&r2=1139051&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/Class.pm Thu Jun 23 20:02:56 2011
@@ -96,19 +96,6 @@ $vt_type $vt = {
 END_VTABLE
 }
 
-# Create the definition for the instantiable object struct.
-sub _struct_definition {
-    my $self                = shift;
-    my $struct_sym          = $self->_get_client->full_struct_sym;
-    my $member_declarations = join( "\n    ",
-        map { $_->local_declaration } @{ $self->_get_client->member_vars } );
-    return <<END_STRUCT
-struct $struct_sym {
-    $member_declarations
-};
-END_STRUCT
-}
-
 sub to_c_header {
     my $self          = shift;
     my $client        = $self->_get_client;

Modified: incubator/lucy/trunk/clownfish/src/CFCBindClass.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindClass.c?rev=1139051&r1=1139050&r2=1139051&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindClass.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindClass.c Thu Jun 23 20:02:56 2011
@@ -71,6 +71,33 @@ CFCBindClass_destroy(CFCBindClass *self)
     CFCBase_destroy((CFCBase*)self);
 }
 
+// Create the definition for the instantiable object struct.
+char*
+CFCBindClass_struct_definition(CFCBindClass *self) {
+    const char *struct_sym = CFCClass_full_struct_sym(self->client);
+    CFCVariable **member_vars = CFCClass_member_vars(self->client);
+    char *member_decs = CFCUtil_strdup("");
+    
+    for (int i = 0; member_vars[i] != NULL; i++) {
+        const char *member_dec = CFCVariable_local_declaration(member_vars[i]);
+        size_t needed = strlen(member_decs) + strlen(member_dec) + 10;
+        member_decs = (char*)REALLOCATE(member_decs, needed);
+        strcat(member_decs, "\n    ");
+        strcat(member_decs, member_dec);
+    }
+
+    char pattern[] = "struct %s {%s\n};\n";
+    size_t size = sizeof(pattern)
+                  + strlen(struct_sym)
+                  + strlen(member_decs)
+                  + 10;
+    char *struct_def = (char*)MALLOCATE(size);
+    sprintf(struct_def, pattern, struct_sym, member_decs);
+
+    FREEMEM(member_decs);
+    return struct_def;
+}
+
 CFCClass*
 CFCBindClass_get_client(CFCBindClass *self) {
     return self->client;

Modified: incubator/lucy/trunk/clownfish/src/CFCBindClass.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCBindClass.h?rev=1139051&r1=1139050&r2=1139051&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCBindClass.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCBindClass.h Thu Jun 23 20:02:56 2011
@@ -34,6 +34,9 @@ CFCBindClass_init(struct CFCBindClass *s
 void
 CFCBindClass_destroy(CFCBindClass *self);
 
+char*
+CFCBindClass_struct_definition(CFCBindClass *self);
+
 struct CFCClass*
 CFCBindClass_get_client(struct CFCBindClass *self);