lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [04/11] git commit: refs/heads/master - Change naming for method implementations.
Date Mon, 12 Aug 2013 20:51:42 GMT
Change naming for method implementations.

Change the naming conventions for the functions which implement
clownfish methods, adding a suffix "_IMP" rather than relying on
case changes.

Before: prefix_Foo_do_stuff
After:  Prefix_Foo_Do_Stuff_IMP

This change should make it harder to confuse the method invocation
(static inline) function with the (concrete) function which implements
the method for a specific class.

The old naming style is temporarily preserved as an pound-define alias
until all existing classes can be transitioned.


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

Branch: refs/heads/master
Commit: 052cf9c350ae190d9416bbc258678ed565bdcbcb
Parents: 5eaf066
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Aug 5 18:18:23 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Mon Aug 12 13:40:47 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindClass.c  | 18 ++++++++++++-----
 clownfish/compiler/src/CFCBindMethod.c | 24 ++++++++++++++++------
 clownfish/compiler/src/CFCBindMethod.h |  5 +++++
 clownfish/compiler/src/CFCMethod.c     | 31 ++++++++++++++++++++++++-----
 clownfish/compiler/src/CFCMethod.h     | 10 ++++++++--
 5 files changed, 70 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/052cf9c3/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c
index e5c068b..51f9162 100644
--- a/clownfish/compiler/src/CFCBindClass.c
+++ b/clownfish/compiler/src/CFCBindClass.c
@@ -597,11 +597,15 @@ S_sub_declarations(CFCBindClass *self) {
     }
     for (int i = 0; fresh_methods[i] != NULL; i++) {
         CFCMethod *method = fresh_methods[i];
-        char *dec = CFCBindFunc_func_declaration((CFCFunction*)method);
+        char *dec = CFCBindMeth_imp_declaration(method);
         if (CFCMethod_final(method)) {
             declarations = CFCUtil_cat(declarations, PREFIX, "VISIBLE ", NULL);
         }
         declarations = CFCUtil_cat(declarations, dec, "\n\n", NULL);
+        const char *func  = CFCMethod_imp_func(method);
+        const char *alias = CFCMethod_imp_func_alias(method);
+        declarations = CFCUtil_cat(declarations, "#define ", alias, " ", func,
+                                   "\n", NULL);
         FREEMEM(dec);
     }
     FREEMEM(fresh_methods);
@@ -679,10 +683,14 @@ S_short_names(CFCBindClass *self) {
             CFCMethod *meth = fresh_methods[i];
 
             // Implementing functions.
-            const char *short_func = CFCMethod_short_implementing_func_sym(meth);
-            const char *full_func  = CFCMethod_implementing_func_sym(meth);
-            short_names = CFCUtil_cat(short_names, "  #define ", short_func,
-                                      " ", full_func, "\n", NULL);
+            const char *short_imp  = CFCMethod_short_imp_func(meth);
+            const char *full_imp   = CFCMethod_imp_func(meth);
+            short_names = CFCUtil_cat(short_names, "  #define ", short_imp,
+                                      " ", full_imp, "\n", NULL);
+            const char *short_alias = CFCMethod_short_imp_func_alias(meth);
+            const char *full_alias  = CFCMethod_imp_func_alias(meth);
+            short_names = CFCUtil_cat(short_names, "  #define ", short_alias,
+                                      " ", full_alias, "\n", NULL);
         }
         FREEMEM(fresh_methods);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/052cf9c3/clownfish/compiler/src/CFCBindMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindMethod.c b/clownfish/compiler/src/CFCBindMethod.c
index 7ef11e1..e6ac41f 100644
--- a/clownfish/compiler/src/CFCBindMethod.c
+++ b/clownfish/compiler/src/CFCBindMethod.c
@@ -63,7 +63,7 @@ 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_implementing_func_sym(method);
+    const char *full_func_sym = CFCMethod_imp_func(method);
     const char *arg_names 
         = CFCParamList_name_list(CFCMethod_get_param_list(method));
 
@@ -148,7 +148,7 @@ CFCBindMeth_typedef_dec(struct CFCMethod *method, CFCClass *klass) {
 char*
 CFCBindMeth_novel_spec_def(CFCMethod *method) {
     const char *macro_sym = CFCMethod_get_macro_sym(method);
-    const char *impl_sym  = CFCMethod_implementing_func_sym(method);
+    const char *imp_func  = CFCMethod_imp_func(method);
 
     const char *full_override_sym = "NULL";
     if (!CFCMethod_final(method)) {
@@ -165,7 +165,7 @@ CFCBindMeth_novel_spec_def(CFCMethod *method) {
         "        (cfish_method_t)%s /* callback_func */\n"
         "    }";
     char *def
-        = CFCUtil_sprintf(pattern, full_offset_sym, macro_sym, impl_sym,
+        = CFCUtil_sprintf(pattern, full_offset_sym, macro_sym, imp_func,
                           full_override_sym);
 
     FREEMEM(full_offset_sym);
@@ -174,7 +174,7 @@ CFCBindMeth_novel_spec_def(CFCMethod *method) {
 
 char*
 CFCBindMeth_overridden_spec_def(CFCMethod *method, CFCClass *klass) {
-    const char *impl_sym  = CFCMethod_implementing_func_sym(method);
+    const char *imp_func  = CFCMethod_imp_func(method);
 
     char *full_offset_sym = CFCMethod_full_offset_sym(method, NULL);
 
@@ -189,7 +189,7 @@ CFCBindMeth_overridden_spec_def(CFCMethod *method, CFCClass *klass) {
         "    }";
     char *def
         = CFCUtil_sprintf(pattern, full_offset_sym, parent_offset_sym,
-                          impl_sym);
+                          imp_func);
 
     FREEMEM(full_offset_sym);
     FREEMEM(parent_offset_sym);
@@ -249,7 +249,7 @@ char*
 CFCBindMeth_abstract_method_def(CFCMethod *method) {
     CFCParamList *param_list = CFCMethod_get_param_list(method);
     const char *params = CFCParamList_to_c(param_list);
-    const char *full_func_sym = CFCMethod_implementing_func_sym(method);
+    const char *full_func_sym = CFCMethod_imp_func(method);
     const char *vtable_var
         = CFCType_get_vtable_var(CFCMethod_self_type(method));
     CFCType    *return_type  = CFCMethod_get_return_type(method);
@@ -292,3 +292,15 @@ CFCBindMeth_callback_dec(CFCMethod *method) {
     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);
+    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 *buf = CFCUtil_sprintf("%s\n%s(%s);", ret_type_str,
+                                full_imp_sym, param_list_str);
+    return buf;
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/052cf9c3/clownfish/compiler/src/CFCBindMethod.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindMethod.h b/clownfish/compiler/src/CFCBindMethod.h
index 9f2f256..45bbb31 100644
--- a/clownfish/compiler/src/CFCBindMethod.h
+++ b/clownfish/compiler/src/CFCBindMethod.h
@@ -76,6 +76,11 @@ CFCBindMeth_abstract_method_def(struct CFCMethod *method);
 char*
 CFCBindMeth_callback_dec(struct CFCMethod *method);
 
+/** Return C code declaring the function which implements a method.
+ */
+char*
+CFCBindMeth_imp_declaration(struct CFCMethod *method);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy/blob/052cf9c3/clownfish/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.c b/clownfish/compiler/src/CFCMethod.c
index 9710209..fbd46b5 100644
--- a/clownfish/compiler/src/CFCMethod.c
+++ b/clownfish/compiler/src/CFCMethod.c
@@ -39,6 +39,8 @@ struct CFCMethod {
     char *macro_sym;
     char *full_override_sym;
     char *host_alias;
+    char *short_imp_func;
+    char *imp_func;
     int is_final;
     int is_abstract;
     int is_novel;
@@ -132,6 +134,13 @@ 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_cnick(self),
+                          self->macro_sym);
+    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;
@@ -149,6 +158,8 @@ CFCMethod_destroy(CFCMethod *self) {
     FREEMEM(self->macro_sym);
     FREEMEM(self->full_override_sym);
     FREEMEM(self->host_alias);
+    FREEMEM(self->short_imp_func);
+    FREEMEM(self->imp_func);
     CFCFunction_destroy((CFCFunction*)self);
 }
 
@@ -208,8 +219,8 @@ CFCMethod_override(CFCMethod *self, CFCMethod *orig) {
                     orig->macro_sym, orig_class, my_class);
     }
     if (!CFCMethod_compatible(self, orig)) {
-        const char *func      = CFCMethod_implementing_func_sym(self);
-        const char *orig_func = CFCMethod_implementing_func_sym(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);
     }
 
@@ -336,7 +347,7 @@ CFCMethod_full_typedef(CFCMethod *self, CFCClass *invoker) {
 const char*
 CFCMethod_full_override_sym(CFCMethod *self) {
     if (!self->full_override_sym) {
-        const char *full_func_sym = CFCMethod_implementing_func_sym(self);
+        const char *full_func_sym = CFCMethod_imp_func_alias(self);
         self->full_override_sym
             = CFCUtil_sprintf("%s_OVERRIDE", full_func_sym);
     }
@@ -410,12 +421,22 @@ CFCMethod_get_param_list(CFCMethod *self) {
 }
 
 const char*
-CFCMethod_implementing_func_sym(CFCMethod *self) {
+CFCMethod_imp_func_alias(CFCMethod *self) {
     return CFCFunction_full_func_sym((CFCFunction*)self);
 }
 
 const char*
-CFCMethod_short_implementing_func_sym(CFCMethod *self) {
+CFCMethod_short_imp_func_alias(CFCMethod *self) {
     return CFCFunction_short_func_sym((CFCFunction*)self);
 }
 
+const char*
+CFCMethod_imp_func(CFCMethod *self) {
+    return self->imp_func;
+}
+
+const char*
+CFCMethod_short_imp_func(CFCMethod *self) {
+    return self->short_imp_func;
+}
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/052cf9c3/clownfish/compiler/src/CFCMethod.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCMethod.h b/clownfish/compiler/src/CFCMethod.h
index 2835d55..931580c 100644
--- a/clownfish/compiler/src/CFCMethod.h
+++ b/clownfish/compiler/src/CFCMethod.h
@@ -228,10 +228,16 @@ struct CFCParamList*
 CFCMethod_get_param_list(CFCMethod *self);
 
 const char*
-CFCMethod_implementing_func_sym(CFCMethod *self);
+CFCMethod_imp_func_alias(CFCMethod *self);
 
 const char*
-CFCMethod_short_implementing_func_sym(CFCMethod *self);
+CFCMethod_short_imp_func_alias(CFCMethod *self);
+
+const char*
+CFCMethod_imp_func(CFCMethod *self);
+
+const char*
+CFCMethod_short_imp_func(CFCMethod *self);
 
 #ifdef __cplusplus
 }


Mime
View raw message