From fc8f93d387674d00e668075b129123fe27a0dfd6 Mon Sep 17 00:00:00 2001 From: Marvin Humphrey Date: Mon, 30 Sep 2013 11:52:32 -0700 Subject: [PATCH 1/2] Fix the invocant type on method typedefs. Method typedefs, like method invocation inline functions, are defined for each class in the inheritance chain. Prior to this fix, the "self" type in the typedef was the type of the last concrete implementor rather than the type of the invocant. --- clownfish/compiler/src/CFCBindMethod.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/clownfish/compiler/src/CFCBindMethod.c b/clownfish/compiler/src/CFCBindMethod.c index c60cc988c..0a2f7c953 100644 --- a/clownfish/compiler/src/CFCBindMethod.c +++ b/clownfish/compiler/src/CFCBindMethod.c @@ -88,8 +88,6 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) { CFCParamList *param_list = CFCMethod_get_param_list(method); const char *PREFIX = CFCClass_get_PREFIX(klass); const char *invoker_struct = CFCClass_full_struct_sym(klass); - const char *common_struct - = CFCType_get_specifier(CFCMethod_self_type(method)); char *full_meth_sym = CFCMethod_full_method_sym(method, klass); char *full_offset_sym = CFCMethod_full_offset_sym(method, klass); @@ -125,7 +123,7 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) { = CFCUtil_sprintf(pattern, PREFIX, full_offset_sym, ret_type_str, full_meth_sym, invoker_struct, params_minus_invoker, full_typedef, full_typedef, full_offset_sym, - maybe_return, common_struct, + maybe_return, invoker_struct, arg_names_minus_invoker); FREEMEM(full_offset_sym); @@ -136,11 +134,17 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) { char* CFCBindMeth_typedef_dec(struct CFCMethod *method, CFCClass *klass) { - const char *params = CFCParamList_to_c(CFCMethod_get_param_list(method)); + const char *params_minus_invoker + = CFCParamList_to_c(CFCMethod_get_param_list(method)); + while (*params_minus_invoker && *params_minus_invoker != ',') { + params_minus_invoker++; + } + const char *self_struct = CFCClass_full_struct_sym(klass); const char *ret_type = CFCType_to_c(CFCMethod_get_return_type(method)); char *full_typedef = CFCMethod_full_typedef(method, klass); - char *buf = CFCUtil_sprintf("typedef %s\n(*%s)(%s);\n", ret_type, - full_typedef, params); + char *buf = CFCUtil_sprintf("typedef %s\n(*%s)(%s *self%s);\n", ret_type, + full_typedef, self_struct, + params_minus_invoker); FREEMEM(full_typedef); return buf; } From dd3c85b1dd09b297c0fa013dab22d51a3cff3661 Mon Sep 17 00:00:00 2001 From: Marvin Humphrey Date: Mon, 30 Sep 2013 11:56:50 -0700 Subject: [PATCH 2/2] Remove un-const-ing from method invocation funcs. Method invocation functions have been casting away const-ness by accepting `const prefix_Foo *self` as the invocant but then invoking the retrieved function pointer with `self` cast to `(prefix_Foo*)`. This was necessary to avoid warnings from "const CharBuf" immutable strings -- but now our String type is immutable without requiring `const`, allowing us to improve type safety by removing the cast. --- clownfish/compiler/src/CFCBindMethod.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clownfish/compiler/src/CFCBindMethod.c b/clownfish/compiler/src/CFCBindMethod.c index 0a2f7c953..3448e4418 100644 --- a/clownfish/compiler/src/CFCBindMethod.c +++ b/clownfish/compiler/src/CFCBindMethod.c @@ -115,16 +115,15 @@ S_virtual_method_def(CFCMethod *method, CFCClass *klass) { const char pattern[] = "extern %sVISIBLE size_t %s;\n" "static CFISH_INLINE %s\n" - "%s(const %s *self%s) {\n" + "%s(%s *self%s) {\n" " const %s method = (%s)cfish_obj_method(self, %s);\n" - " %smethod((%s*)self%s);\n" + " %smethod(self%s);\n" "}\n"; char *method_def = CFCUtil_sprintf(pattern, PREFIX, full_offset_sym, ret_type_str, full_meth_sym, invoker_struct, params_minus_invoker, full_typedef, full_typedef, full_offset_sym, - maybe_return, invoker_struct, - arg_names_minus_invoker); + maybe_return, arg_names_minus_invoker); FREEMEM(full_offset_sym); FREEMEM(full_meth_sym);