Separate test whether to create method bindings

Move the code that checks whether bindings for a method should be
generated to a separate function.


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

Branch: refs/heads/master
Commit: 2ba718badd7f3e8851b86a562f0c79111d88efe2
Parents: 3b924b5
Author: Nick Wellnhofer <[email protected]>
Authored: Thu Jul 31 14:04:20 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Mon Sep 1 13:30:04 2014 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerlClass.c  |  7 ++-----
 compiler/src/CFCPerlMethod.c | 12 ++++++++++++
 compiler/src/CFCPerlMethod.h |  5 +++++
 3 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba718ba/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index 1fb2b7c..14af20a 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -239,16 +239,13 @@ CFCPerlClass_method_bindings(CFCClass *klass) {
     for (size_t i = 0; fresh_methods[i] != NULL; i++) {
         CFCMethod *method = fresh_methods[i];
 
-        // Skip private methods.
-        if (CFCSymbol_private((CFCSymbol*)method)) { continue; }
-
         // Skip methods which have been explicitly excluded.
         if (CFCMethod_excluded_from_host(method)) {
             continue;
         }
 
-        // Skip methods with types which cannot be mapped automatically.
-        if (!CFCPerlSub_can_be_bound((CFCFunction*)method)) {
+        // Skip methods that shouldn't be bound.
+        if (!CFCPerlMethod_can_be_bound(method)) {
             continue;
         }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba718ba/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 2aad102..5efca7b 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -23,6 +23,7 @@
 #include "CFCPerlMethod.h"
 #include "CFCUtil.h"
 #include "CFCClass.h"
+#include "CFCFunction.h"
 #include "CFCMethod.h"
 #include "CFCSymbol.h"
 #include "CFCType.h"
@@ -134,6 +135,17 @@ CFCPerlMethod_destroy(CFCPerlMethod *self) {
     CFCPerlSub_destroy((CFCPerlSub*)self);
 }
 
+int
+CFCPerlMethod_can_be_bound(CFCMethod *method) {
+    /*
+     * Check for
+     * - private methods
+     * - methods with types which cannot be mapped automatically
+     */
+    return !CFCSymbol_private((CFCSymbol*)method)
+           && CFCPerlSub_can_be_bound((CFCFunction*)method);
+}
+
 char*
 CFCPerlMethod_perl_name(CFCMethod *method) {
     // See if the user wants the method to have a specific alias.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2ba718ba/compiler/src/CFCPerlMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.h b/compiler/src/CFCPerlMethod.h
index be441c4..ee85efe 100644
--- a/compiler/src/CFCPerlMethod.h
+++ b/compiler/src/CFCPerlMethod.h
@@ -46,6 +46,11 @@ CFCPerlMethod_init(CFCPerlMethod *self, struct CFCMethod 
*method);
 void
 CFCPerlMethod_destroy(CFCPerlMethod *self);
 
+/** Test whether bindings should be generated for a method.
+  */
+int
+CFCPerlMethod_can_be_bound(struct CFCMethod *method);
+
 /**
  * Create the Perl name of the method.
  */

Reply via email to