Don't cache names of implementing functions

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

Branch: refs/heads/master
Commit: 8847fbfd7e8711b50edb6dba097827b411044869
Parents: 5cb2872
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Jul 26 22:47:28 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Thu May 7 21:13:59 2015 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.xs | 12 +++++++-----
 compiler/src/CFCBindClass.c        | 12 +++++++-----
 compiler/src/CFCBindMethod.c       | 31 +++++++++++++++++++------------
 compiler/src/CFCBindMethod.h       |  7 ++++---
 compiler/src/CFCGoMethod.c         |  2 +-
 compiler/src/CFCMethod.c           | 33 ++++++++++++---------------------
 compiler/src/CFCMethod.h           |  8 ++++----
 7 files changed, 54 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs 
b/compiler/perl/lib/Clownfish/CFC.xs
index e636aa7..b87cc0b 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -1961,12 +1961,13 @@ OUTPUT: RETVAL
 MODULE = Clownfish::CFC  PACKAGE = Clownfish::CFC::Binding::Core::Method
 
 SV*
-abstract_method_def(unused, meth)
-    SV *unused;
+abstract_method_def(unused, meth, klass)
+    SV        *unused;
     CFCMethod *meth;
+    CFCClass  *klass;
 CODE:
     CHY_UNUSED_VAR(unused);
-    RETVAL = S_sv_eat_c_string(CFCBindMeth_abstract_method_def(meth));
+    RETVAL = S_sv_eat_c_string(CFCBindMeth_abstract_method_def(meth, klass));
 OUTPUT: RETVAL
 
 SV*
@@ -1978,10 +1979,11 @@ CODE:
 OUTPUT: RETVAL
 
 SV*
-_novel_spec_def(meth)
+_novel_spec_def(meth, klass)
     CFCMethod *meth;
+    CFCClass  *klass;
 CODE:
-    RETVAL = S_sv_eat_c_string(CFCBindMeth_novel_spec_def(meth));
+    RETVAL = S_sv_eat_c_string(CFCBindMeth_novel_spec_def(meth, klass));
 OUTPUT: RETVAL
 
 SV*

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index 0c9e18c..6faf67d 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -300,7 +300,7 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
 
         // Create a default implementation for abstract methods.
         if (is_fresh && CFCMethod_abstract(method)) {
-            char *method_def = CFCBindMeth_abstract_method_def(method);
+            char *method_def = CFCBindMeth_abstract_method_def(method, client);
             method_defs = CFCUtil_cat(method_defs, method_def, "\n", NULL);
             FREEMEM(method_def);
         }
@@ -320,7 +320,7 @@ CFCBindClass_to_c_data(CFCBindClass *self) {
             else {
                 novel_ms_var = CFCUtil_cat(novel_ms_var, ",\n", NULL);
             }
-            char *ms_def = CFCBindMeth_novel_spec_def(method);
+            char *ms_def = CFCBindMeth_novel_spec_def(method, client);
             novel_ms_var = CFCUtil_cat(novel_ms_var, ms_def, NULL);
             FREEMEM(ms_def);
         }
@@ -616,7 +616,7 @@ S_sub_declarations(CFCBindClass *self) {
     }
     for (int i = 0; fresh_methods[i] != NULL; i++) {
         CFCMethod *method = fresh_methods[i];
-        char *dec = CFCBindMeth_imp_declaration(method);
+        char *dec = CFCBindMeth_imp_declaration(method, self->client);
         if (CFCMethod_final(method)) {
             declarations = CFCUtil_cat(declarations, PREFIX, "VISIBLE ", NULL);
         }
@@ -743,10 +743,12 @@ S_short_names(CFCBindClass *self) {
             CFCMethod *meth = fresh_methods[i];
 
             // Implementing functions.
-            const char *short_imp  = CFCMethod_short_imp_func(meth);
-            const char *full_imp   = CFCMethod_imp_func(meth);
+            char *short_imp = CFCMethod_short_imp_func(meth, client);
+            char *full_imp  = CFCMethod_imp_func(meth, client);
             short_names = CFCUtil_cat(short_names, "  #define ", short_imp,
                                       " ", full_imp, "\n", NULL);
+            FREEMEM(short_imp);
+            FREEMEM(full_imp);
         }
 
         CFCMethod  **methods = CFCClass_methods(client);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.c b/compiler/src/CFCBindMethod.c
index 1ea5ec5..a205861 100644
--- a/compiler/src/CFCBindMethod.c
+++ b/compiler/src/CFCBindMethod.c
@@ -49,10 +49,10 @@ CFCBindMeth_method_def(CFCMethod *method, CFCClass *klass) {
 static char*
 S_final_method_def(CFCMethod *method, CFCClass *klass) {
     const char *self_type = CFCType_to_c(CFCMethod_self_type(method));
-    const char *full_func_sym = CFCMethod_imp_func(method);
     const char *arg_names 
         = CFCParamList_name_list(CFCMethod_get_param_list(method));
 
+    char *full_func_sym   = CFCMethod_imp_func(method, klass);
     char *full_meth_sym   = CFCMethod_full_method_sym(method, klass);
     char *full_offset_sym = CFCMethod_full_offset_sym(method, klass);
 
@@ -66,6 +66,7 @@ S_final_method_def(CFCMethod *method, CFCClass *klass) {
 
     FREEMEM(full_offset_sym);
     FREEMEM(full_meth_sym);
+    FREEMEM(full_func_sym);
     return method_def;
 }
 
@@ -135,16 +136,16 @@ CFCBindMeth_typedef_dec(struct CFCMethod *method, 
CFCClass *klass) {
 }
 
 char*
-CFCBindMeth_novel_spec_def(CFCMethod *method) {
+CFCBindMeth_novel_spec_def(CFCMethod *method, CFCClass *klass) {
     const char *meth_name = CFCMethod_get_name(method);
-    const char *imp_func  = CFCMethod_imp_func(method);
 
     const char *full_override_sym = "NULL";
     if (!CFCMethod_final(method)) {
         full_override_sym = CFCMethod_full_override_sym(method);
     }
 
-    char *full_offset_sym = CFCMethod_full_offset_sym(method, NULL);
+    char *imp_func        = CFCMethod_imp_func(method, klass);
+    char *full_offset_sym = CFCMethod_full_offset_sym(method, klass);
 
     char pattern[] =
         "    {\n"
@@ -158,14 +159,14 @@ CFCBindMeth_novel_spec_def(CFCMethod *method) {
                           full_override_sym);
 
     FREEMEM(full_offset_sym);
+    FREEMEM(imp_func);
     return def;
 }
 
 char*
 CFCBindMeth_overridden_spec_def(CFCMethod *method, CFCClass *klass) {
-    const char *imp_func  = CFCMethod_imp_func(method);
-
-    char *full_offset_sym = CFCMethod_full_offset_sym(method, NULL);
+    char *imp_func        = CFCMethod_imp_func(method, klass);
+    char *full_offset_sym = CFCMethod_full_offset_sym(method, klass);
 
     CFCClass *parent = CFCClass_get_parent(klass);
     char *parent_offset_sym = CFCMethod_full_offset_sym(method, parent);
@@ -180,8 +181,9 @@ CFCBindMeth_overridden_spec_def(CFCMethod *method, CFCClass 
*klass) {
         = CFCUtil_sprintf(pattern, full_offset_sym, parent_offset_sym,
                           imp_func);
 
-    FREEMEM(full_offset_sym);
     FREEMEM(parent_offset_sym);
+    FREEMEM(full_offset_sym);
+    FREEMEM(imp_func);
     return def;
 }
 
@@ -205,11 +207,10 @@ CFCBindMeth_inherited_spec_def(CFCMethod *method, 
CFCClass *klass) {
 }
 
 char*
-CFCBindMeth_abstract_method_def(CFCMethod *method) {
+CFCBindMeth_abstract_method_def(CFCMethod *method, CFCClass *klass) {
     CFCType    *ret_type      = CFCMethod_get_return_type(method);
     const char *ret_type_str  = CFCType_to_c(ret_type);
     CFCType    *type          = CFCMethod_self_type(method);
-    const char *full_func_sym = CFCMethod_imp_func(method);
     const char *class_var     = CFCType_get_class_var(type);
     const char *meth_name     = CFCMethod_get_name(method);
     CFCParamList *param_list  = CFCMethod_get_param_list(method);
@@ -234,6 +235,8 @@ CFCBindMeth_abstract_method_def(CFCMethod *method) {
                                       ret_type_str);
     }
 
+    char *full_func_sym = CFCMethod_imp_func(method, klass);
+
     char pattern[] =
         "%s\n"
         "%s(%s) {\n"
@@ -247,18 +250,22 @@ CFCBindMeth_abstract_method_def(CFCMethod *method) {
                           unreachable);
 
     FREEMEM(unused);
+    FREEMEM(full_func_sym);
     return abstract_def;
 }
 
 char*
-CFCBindMeth_imp_declaration(CFCMethod *method) {
+CFCBindMeth_imp_declaration(CFCMethod *method, CFCClass *klass) {
     CFCType      *return_type    = CFCMethod_get_return_type(method);
     CFCParamList *param_list     = CFCMethod_get_param_list(method);
     const char   *ret_type_str   = CFCType_to_c(return_type);
-    const char   *full_imp_sym   = CFCMethod_imp_func(method);
     const char   *param_list_str = CFCParamList_to_c(param_list);
+
+    char *full_imp_sym = CFCMethod_imp_func(method, klass);
     char *buf = CFCUtil_sprintf("%s\n%s(%s);", ret_type_str,
                                 full_imp_sym, param_list_str);
+
+    FREEMEM(full_imp_sym);
     return buf;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCBindMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindMethod.h b/compiler/src/CFCBindMethod.h
index 624a958..3bc16ab 100644
--- a/compiler/src/CFCBindMethod.h
+++ b/compiler/src/CFCBindMethod.h
@@ -48,7 +48,7 @@ CFCBindMeth_typedef_dec(struct CFCMethod *method, struct 
CFCClass *klass);
  * is used during Class initialization.
  */
 char*
-CFCBindMeth_novel_spec_def(struct CFCMethod *method);
+CFCBindMeth_novel_spec_def(struct CFCMethod *method, struct CFCClass *klass);
 
 /** Return C code defining the MethSpec object for an overridden method,
  * which is used during Class initialization.
@@ -69,12 +69,13 @@ CFCBindMeth_inherited_spec_def(struct CFCMethod *method,
  * "abstract" in a Clownfish header file.
  */
 char*
-CFCBindMeth_abstract_method_def(struct CFCMethod *method);
+CFCBindMeth_abstract_method_def(struct CFCMethod *method,
+                                struct CFCClass *klass);
 
 /** Return C code declaring the function which implements a method.
  */
 char*
-CFCBindMeth_imp_declaration(struct CFCMethod *method);
+CFCBindMeth_imp_declaration(struct CFCMethod *method, struct CFCClass *klass);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCGoMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCGoMethod.c b/compiler/src/CFCGoMethod.c
index 37f7bdd..87f062e 100644
--- a/compiler/src/CFCGoMethod.c
+++ b/compiler/src/CFCGoMethod.c
@@ -191,7 +191,7 @@ CFCGoMethod_func_def(CFCGoMethod *self, CFCClass *invoker) {
                                             param_list, ret_type, true);
     char *cfunc;
     if (CFCMethod_novel(self->method) && CFCMethod_final(self->method)) {
-        cfunc = CFCUtil_strdup(CFCMethod_imp_func(self->method));
+        cfunc = CFCUtil_strdup(CFCMethod_imp_func(self->method, invoker));
     }
     else {
         cfunc = CFCMethod_full_method_sym(novel_method, NULL);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCMethod.c b/compiler/src/CFCMethod.c
index ad9d945..ff1f4f6 100644
--- a/compiler/src/CFCMethod.c
+++ b/compiler/src/CFCMethod.c
@@ -39,8 +39,6 @@ struct CFCMethod {
     CFCMethod *novel_method;
     char *full_override_sym;
     char *host_alias;
-    char *short_imp_func;
-    char *imp_func;
     int is_final;
     int is_abstract;
     int is_novel;
@@ -129,13 +127,6 @@ CFCMethod_init(CFCMethod *self, CFCParcel *parcel, const 
char *exposure,
     self->is_abstract       = is_abstract;
     self->is_excluded       = false;
 
-    // Derive name of implementing function.
-    self->short_imp_func
-        = CFCUtil_sprintf("%s_%s_IMP", CFCMethod_get_class_nickname(self),
-                          name);
-    self->imp_func = CFCUtil_sprintf("%s%s", CFCMethod_get_PREFIX(self),
-                                     self->short_imp_func);
-
     // Assume that this method is novel until we discover when applying
     // inheritance that it overrides another.
     self->is_novel = true;
@@ -153,8 +144,6 @@ CFCMethod_destroy(CFCMethod *self) {
     CFCBase_decref((CFCBase*)self->novel_method);
     FREEMEM(self->full_override_sym);
     FREEMEM(self->host_alias);
-    FREEMEM(self->short_imp_func);
-    FREEMEM(self->imp_func);
     CFCCallable_destroy((CFCCallable*)self);
 }
 
@@ -225,9 +214,11 @@ CFCMethod_override(CFCMethod *self, CFCMethod *orig) {
                     orig_name, orig_class, my_class);
     }
     if (!CFCMethod_compatible(self, orig)) {
-        const char *func      = CFCMethod_imp_func(self);
-        const char *orig_func = CFCMethod_imp_func(orig);
-        CFCUtil_die("Non-matching signatures for %s and %s", func, orig_func);
+        const char *orig_name  = CFCMethod_get_name(orig);
+        const char *orig_class = CFCMethod_get_class_name(orig);
+        const char *my_class   = CFCMethod_get_class_name(self);
+        CFCUtil_die("Non-matching signatures for method '%s' in '%s' and '%s'",
+                    orig_name, orig_class, my_class);
     }
 
     // Mark the Method as no longer novel.
@@ -444,7 +435,7 @@ CFCMethod_get_class_name(CFCMethod *self) {
 
 const char*
 CFCMethod_get_class_nickname(CFCMethod *self) {
-    return CFCSymbol_get_class_nickname((CFCSymbol*)self);
+    return CFCSymbol_get_class_nickname((CFCSymbol*)self);;
 }
 
 int
@@ -462,13 +453,13 @@ CFCMethod_get_param_list(CFCMethod *self) {
     return self->callable.param_list;
 }
 
-const char*
-CFCMethod_imp_func(CFCMethod *self) {
-    return self->imp_func;
+char*
+CFCMethod_imp_func(CFCMethod *self, CFCClass *klass) {
+    return S_full_method_sym(self, klass, "_IMP");
 }
 
-const char*
-CFCMethod_short_imp_func(CFCMethod *self) {
-    return self->short_imp_func;
+char*
+CFCMethod_short_imp_func(CFCMethod *self, CFCClass *klass) {
+    return S_short_method_sym(self, klass, "_IMP");
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8847fbfd/compiler/src/CFCMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCMethod.h b/compiler/src/CFCMethod.h
index 7cbee5e..e57eb5c 100644
--- a/compiler/src/CFCMethod.h
+++ b/compiler/src/CFCMethod.h
@@ -238,11 +238,11 @@ CFCMethod_get_return_type(CFCMethod *self);
 struct CFCParamList*
 CFCMethod_get_param_list(CFCMethod *self);
 
-const char*
-CFCMethod_imp_func(CFCMethod *self);
+char*
+CFCMethod_imp_func(CFCMethod *self, struct CFCClass *klass);
 
-const char*
-CFCMethod_short_imp_func(CFCMethod *self);
+char*
+CFCMethod_short_imp_func(CFCMethod *self, struct CFCClass *klass);
 
 #ifdef __cplusplus
 }

Reply via email to