lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [6/8] lucy-clownfish git commit: Move code to generate Perl callback declarations
Date Sat, 10 Jan 2015 17:31:22 GMT
Move code to generate Perl callback declarations

The original reason to have the code that generates callback declarations
in the CFCBind* classes was to allow reuse by other host languages. In
order to remove unneeded parameters for invalid callbacks, it's necessary
to move the code to the CFCPerl* classes.


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

Branch: refs/heads/master
Commit: c64e94dbcd5104136de247b7818d0c14fc172f87
Parents: cd8f180
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sun Jan 4 23:11:45 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Jan 5 00:30:22 2015 +0100

----------------------------------------------------------------------
 compiler/src/CFCBindClass.c  | 21 ----------
 compiler/src/CFCBindClass.h  |  5 ---
 compiler/src/CFCBindCore.c   | 65 -------------------------------
 compiler/src/CFCBindCore.h   |  6 ---
 compiler/src/CFCBindMethod.c | 16 --------
 compiler/src/CFCBindMethod.h |  5 ---
 compiler/src/CFCPerl.c       | 80 ++++++++++++++++++++++++++++++++++++---
 compiler/src/CFCPerlMethod.c | 16 ++++++++
 compiler/src/CFCPerlMethod.h |  5 +++
 9 files changed, 96 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index 4900111..2de2bd3 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -562,27 +562,6 @@ CFCBindClass_spec_def(CFCBindClass *self) {
     return code;
 }
 
-// Declare host callbacks.
-char*
-CFCBindClass_callback_decs(CFCBindClass *self) {
-    CFCClass   *client        = self->client;
-    CFCMethod **fresh_methods = CFCClass_fresh_methods(client);
-    char       *cb_decs       = CFCUtil_strdup("");
-
-    for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
-        CFCMethod *method = fresh_methods[meth_num];
-
-        // Declare callback.
-        if (CFCMethod_novel(method) && !CFCMethod_final(method)) {
-            char *cb_dec = CFCBindMeth_callback_dec(method);
-            cb_decs = CFCUtil_cat(cb_decs, cb_dec, "\n", NULL);
-            FREEMEM(cb_dec);
-        }
-    }
-
-    return cb_decs;
-}
-
 // Declare typedefs for every method, to ease casting.
 static char*
 S_method_typedefs(CFCBindClass *self) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindClass.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.h b/compiler/src/CFCBindClass.h
index 7dd915a..c915c65 100644
--- a/compiler/src/CFCBindClass.h
+++ b/compiler/src/CFCBindClass.h
@@ -59,11 +59,6 @@ CFCBindClass_to_c_data(CFCBindClass *self);
 char*
 CFCBindClass_spec_def(CFCBindClass *self);
 
-/* Return the declarations of the host callbacks of this class.
- */
-char*
-CFCBindClass_callback_decs(CFCBindClass *self);
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index c6adf01..2bf6119 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -493,71 +493,6 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
     FREEMEM(file_content);
 }
 
-/* Write the "callbacks.h" header file, which contains declarations of host
- * callbacks.
- */
-void
-CFCBindCore_write_callbacks_h(CFCBindCore *self) {
-    CFCHierarchy  *hierarchy   = self->hierarchy;
-    CFCClass     **ordered     = CFCHierarchy_ordered_classes(hierarchy);
-    char          *includes    = CFCUtil_strdup("");
-    char          *all_cb_decs = CFCUtil_strdup("");
-
-    for (int i = 0; ordered[i] != NULL; i++) {
-        CFCClass *klass = ordered[i];
-
-        const char *include_h = CFCClass_include_h(klass);
-        includes = CFCUtil_cat(includes, "#include \"", include_h, "\"\n",
-                               NULL);
-
-        if (!CFCClass_included(klass)) {
-            CFCBindClass *class_binding = CFCBindClass_new(klass);
-            char *cb_decs = CFCBindClass_callback_decs(class_binding);
-            all_cb_decs = CFCUtil_cat(all_cb_decs, cb_decs, NULL);
-            FREEMEM(cb_decs);
-            CFCBase_decref((CFCBase*)class_binding);
-        }
-    }
-
-    FREEMEM(ordered);
-
-    const char pattern[] =
-        "%s\n"
-        "#ifndef CFCCALLBACKS_H\n"
-        "#define CFCCALLBACKS_H 1\n"
-        "\n"
-        "#ifdef __cplusplus\n"
-        "extern \"C\" {\n"
-        "#endif\n"
-        "\n"
-        "%s"
-        "\n"
-        "%s"
-        "\n"
-        "#ifdef __cplusplus\n"
-        "}\n"
-        "#endif\n"
-        "\n"
-        "#endif /* CFCCALLBACKS_H */\n"
-        "\n"
-        "%s\n"
-        "\n";
-    char *file_content
-        = CFCUtil_sprintf(pattern, self->c_header, includes, all_cb_decs,
-                          self->c_footer);
-
-    // Unlink then write file.
-    const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
-    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "callbacks.h", inc_dest);
-    remove(filepath);
-    CFCUtil_write_file(filepath, file_content, strlen(file_content));
-    FREEMEM(filepath);
-
-    FREEMEM(includes);
-    FREEMEM(all_cb_decs);
-    FREEMEM(file_content);
-}
-
 /* Write the "cfish_platform.h" header file, which contains platform-specific
  * definitions.
  */

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindCore.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.h b/compiler/src/CFCBindCore.h
index f6389d7..04392ef 100644
--- a/compiler/src/CFCBindCore.h
+++ b/compiler/src/CFCBindCore.h
@@ -57,12 +57,6 @@ CFCBindCore_destroy(CFCBindCore *self);
 int
 CFCBindCore_write_all_modified(CFCBindCore *self, int modified);
 
-/** Write the "callbacks.h" header file, which contains declarations of host
- * callbacks.
- */
-void
-CFCBindCore_write_callbacks_h(CFCBindCore *self);
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.c b/compiler/src/CFCBindMethod.c
index 0aec672..e907332 100644
--- a/compiler/src/CFCBindMethod.c
+++ b/compiler/src/CFCBindMethod.c
@@ -223,22 +223,6 @@ CFCBindMeth_abstract_method_def(CFCMethod *method) {
 }
 
 char*
-CFCBindMeth_callback_dec(CFCMethod *method) {
-    CFCType *return_type = CFCMethod_get_return_type(method);
-    const char *ret_type_str = CFCType_to_c(return_type);
-    const char *override_sym = CFCMethod_full_override_sym(method);
-    const char *params = CFCParamList_to_c(CFCMethod_get_param_list(method));
-
-    char pattern[] =
-        "%s\n"
-        "%s(%s);\n";
-    char *callback_dec
-        = CFCUtil_sprintf(pattern, ret_type_str, override_sym, params);
-
-    return callback_dec;
-}
-
-char*
 CFCBindMeth_imp_declaration(CFCMethod *method) {
     CFCType      *return_type    = CFCMethod_get_return_type(method);
     CFCParamList *param_list     = CFCMethod_get_param_list(method);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCBindMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.h b/compiler/src/CFCBindMethod.h
index 2f837cb..624a958 100644
--- a/compiler/src/CFCBindMethod.h
+++ b/compiler/src/CFCBindMethod.h
@@ -71,11 +71,6 @@ CFCBindMeth_inherited_spec_def(struct CFCMethod *method,
 char*
 CFCBindMeth_abstract_method_def(struct CFCMethod *method);
 
-/** Return C code declaring a callback to the Host for this method.
- */
-char*
-CFCBindMeth_callback_dec(struct CFCMethod *method);
-
 /** Return C code declaring the function which implements a method.
  */
 char*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index deefc1a..ca0af64 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -54,6 +54,9 @@ static void
 S_replace_double_colons(char *text, char replacement);
 
 static void
+S_write_callbacks_h(CFCPerl *self);
+
+static void
 S_write_callbacks_c(CFCPerl *self);
 
 static const CFCMeta CFCPERL_META = {
@@ -503,14 +506,81 @@ CFCPerl_write_bindings(CFCPerl *self) {
 
 void
 CFCPerl_write_callbacks(CFCPerl *self) {
-    CFCBindCore *core_binding
-        = CFCBindCore_new(self->hierarchy, self->header, self->footer);
-    CFCBindCore_write_callbacks_h(core_binding);
-    CFCBase_decref((CFCBase*)core_binding);
-
+    S_write_callbacks_h(self);
     S_write_callbacks_c(self);
 }
 
+/* Write the "callbacks.h" header file, which contains declarations of host
+ * callbacks.
+ */
+static void
+S_write_callbacks_h(CFCPerl *self) {
+    CFCHierarchy  *hierarchy = self->hierarchy;
+    CFCClass     **ordered   = CFCHierarchy_ordered_classes(hierarchy);
+    char          *includes  = CFCUtil_strdup("");
+    char          *cb_decs   = CFCUtil_strdup("");
+
+    for (int i = 0; ordered[i] != NULL; i++) {
+        CFCClass *klass = ordered[i];
+
+        const char *include_h = CFCClass_include_h(klass);
+        includes = CFCUtil_cat(includes, "#include \"", include_h, "\"\n",
+                               NULL);
+
+        if (CFCClass_included(klass)) { continue; }
+
+        CFCMethod **fresh_methods = CFCClass_fresh_methods(klass);
+        for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) {
+            CFCMethod *method = fresh_methods[meth_num];
+
+            // Declare callback.
+            if (CFCMethod_novel(method) && !CFCMethod_final(method)) {
+                char *cb_dec = CFCPerlMethod_callback_dec(method);
+                cb_decs = CFCUtil_cat(cb_decs, cb_dec, "\n", NULL);
+                FREEMEM(cb_dec);
+            }
+        }
+    }
+
+    FREEMEM(ordered);
+
+    const char pattern[] =
+        "%s\n"
+        "#ifndef CFCCALLBACKS_H\n"
+        "#define CFCCALLBACKS_H 1\n"
+        "\n"
+        "#ifdef __cplusplus\n"
+        "extern \"C\" {\n"
+        "#endif\n"
+        "\n"
+        "%s"
+        "\n"
+        "%s"
+        "\n"
+        "#ifdef __cplusplus\n"
+        "}\n"
+        "#endif\n"
+        "\n"
+        "#endif /* CFCCALLBACKS_H */\n"
+        "\n"
+        "%s\n"
+        "\n";
+    char *file_content
+        = CFCUtil_sprintf(pattern, self->c_header, includes, cb_decs,
+                          self->c_footer);
+
+    // Unlink then write file.
+    const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
+    char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "callbacks.h", inc_dest);
+    remove(filepath);
+    CFCUtil_write_file(filepath, file_content, strlen(file_content));
+    FREEMEM(filepath);
+
+    FREEMEM(includes);
+    FREEMEM(cb_decs);
+    FREEMEM(file_content);
+}
+
 static void
 S_write_callbacks_c(CFCPerl *self) {
     CFCClass **ordered = CFCHierarchy_ordered_classes(self->hierarchy);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 0dd7a98..e39878c 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -441,6 +441,22 @@ S_xsub_def_positional_args(CFCPerlMethod *self) {
 }
 
 char*
+CFCPerlMethod_callback_dec(CFCMethod *method) {
+    CFCType *return_type = CFCMethod_get_return_type(method);
+    const char *ret_type_str = CFCType_to_c(return_type);
+    const char *override_sym = CFCMethod_full_override_sym(method);
+    const char *params = CFCParamList_to_c(CFCMethod_get_param_list(method));
+
+    char pattern[] =
+        "%s\n"
+        "%s(%s);\n";
+    char *callback_dec
+        = CFCUtil_sprintf(pattern, ret_type_str, override_sym, params);
+
+    return callback_dec;
+}
+
+char*
 CFCPerlMethod_callback_def(CFCMethod *method) {
     // Return a callback wrapper that throws an error if there are no
     // bindings for a method.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c64e94db/compiler/src/CFCPerlMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.h b/compiler/src/CFCPerlMethod.h
index ee85efe..a0fbd83 100644
--- a/compiler/src/CFCPerlMethod.h
+++ b/compiler/src/CFCPerlMethod.h
@@ -62,6 +62,11 @@ CFCPerlMethod_perl_name(struct CFCMethod *method);
 char*
 CFCPerlMethod_xsub_def(CFCPerlMethod *self);
 
+/** Return C code declaring a callback to the Host for this method.
+ */
+char*
+CFCPerlMethod_callback_dec(struct CFCMethod *method);
+
 /** Return C code implementing a callback to Perl for this method.  This code
  * is run when a Perl subclass has overridden a method in a Clownfish base
  * class.


Mime
View raw message