Port CFCCHtml changes to CFCCMan
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/043989fc Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/043989fc Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/043989fc Branch: refs/heads/markdown_v2 Commit: 043989fc0a935923f9db749cd034e72c2dc0000b Parents: c584c76 Author: Nick Wellnhofer <[email protected]> Authored: Mon Dec 8 16:18:56 2014 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Mon Dec 8 16:18:56 2014 +0100 ---------------------------------------------------------------------- compiler/src/CFCCMan.c | 149 +++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/043989fc/compiler/src/CFCCMan.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCCMan.c b/compiler/src/CFCCMan.c index 632cb2e..b9a05f0 100644 --- a/compiler/src/CFCCMan.c +++ b/compiler/src/CFCCMan.c @@ -54,14 +54,13 @@ static char* S_man_create_methods(CFCClass *klass); static char* -S_man_create_inherited_methods(CFCClass *klass); +S_man_create_fresh_methods(CFCClass *klass, CFCClass *ancestor); static char* -S_man_create_func(CFCClass *klass, CFCFunction *func, const char *short_sym, - const char *full_sym); +S_man_create_func(CFCClass *klass, CFCFunction *func, const char *full_sym); static char* -S_man_create_param_list(CFCFunction *func, const char *full_sym); +S_man_create_param_list(CFCClass *klass, CFCFunction *func); static char* S_man_create_inheritance(CFCClass *klass); @@ -180,13 +179,13 @@ S_man_create_functions(CFCClass *klass) { result = CFCUtil_cat(result, ".SH FUNCTIONS\n", NULL); } - const char *micro_sym = CFCFunction_micro_sym(func); - const char *full_func_sym = CFCFunction_full_func_sym(func); + const char *micro_sym = CFCFunction_micro_sym(func); + result = CFCUtil_cat(result, ".TP\n.B ", micro_sym, "\n", NULL); - char *redman = S_man_create_func(klass, func, micro_sym, - full_func_sym); - result = CFCUtil_cat(result, redman, NULL); - FREEMEM(redman); + const char *full_func_sym = CFCFunction_full_func_sym(func); + char *function_man = S_man_create_func(klass, func, full_func_sym); + result = CFCUtil_cat(result, function_man, NULL); + FREEMEM(function_man); } return result; @@ -194,53 +193,31 @@ S_man_create_functions(CFCClass *klass) { static char* S_man_create_methods(CFCClass *klass) { - CFCMethod **fresh_methods = CFCClass_fresh_methods(klass); - char *methods_man = CFCUtil_strdup(""); - char *novel_man = CFCUtil_strdup(""); - char *result; - - for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) { - CFCMethod *method = fresh_methods[meth_num]; - if (!CFCMethod_public(method) || !CFCMethod_novel(method)) { - continue; + char *methods_man = CFCUtil_strdup(""); + char *result; + + for (CFCClass *ancestor = klass; + ancestor; + ancestor = CFCClass_get_parent(ancestor) + ) { + const char *class_name = CFCClass_get_class_name(ancestor); + // Exclude methods inherited from Clownfish::Obj + if (ancestor != klass && strcmp(class_name, "Clownfish::Obj") == 0) { + break; } - const char *macro_sym = CFCMethod_get_macro_sym(method); - char *full_method_sym = CFCMethod_full_method_sym(method, NULL); - char *method_man = S_man_create_func(klass, (CFCFunction*)method, - macro_sym, full_method_sym); - - if (CFCMethod_abstract(method)) { - if (methods_man[0] == '\0') { - methods_man = CFCUtil_cat(methods_man, - ".SS Abstract methods\n", NULL); + char *fresh_man = S_man_create_fresh_methods(klass, ancestor); + if (fresh_man[0] != '\0') { + if (ancestor == klass) { + methods_man = CFCUtil_cat(methods_man, fresh_man, NULL); } - methods_man = CFCUtil_cat(methods_man, method_man, NULL); - } - else { - if (novel_man[0] == '\0') { - novel_man = CFCUtil_cat(novel_man, - ".SS Novel methods\n", NULL); + else { + methods_man + = CFCUtil_cat(methods_man, ".SS Methods inherited from ", + class_name, "\n", fresh_man, NULL); } - novel_man = CFCUtil_cat(novel_man, method_man, NULL); } - - FREEMEM(method_man); - FREEMEM(full_method_sym); - } - - methods_man = CFCUtil_cat(methods_man, novel_man, NULL); - - // Add methods from parent classes excluding Clownfish::Obj - CFCClass *parent = CFCClass_get_parent(klass); - while (parent) { - if (strcmp(CFCClass_get_class_name(parent), "Clownfish::Obj") == 0) { - break; - } - char *inherited_man = S_man_create_inherited_methods(parent); - methods_man = CFCUtil_cat(methods_man, inherited_man, NULL); - FREEMEM(inherited_man); - parent = CFCClass_get_parent(parent); + FREEMEM(fresh_man); } if (methods_man[0] == '\0') { @@ -251,42 +228,48 @@ S_man_create_methods(CFCClass *klass) { } FREEMEM(methods_man); - FREEMEM(novel_man); return result; } static char* -S_man_create_inherited_methods(CFCClass *klass) { - CFCMethod **fresh_methods = CFCClass_fresh_methods(klass); - char *result = CFCUtil_strdup(""); +S_man_create_fresh_methods(CFCClass *klass, CFCClass *ancestor) { + CFCMethod **fresh_methods = CFCClass_fresh_methods(ancestor); + const char *ancestor_name = CFCClass_get_class_name(ancestor); + char *result = CFCUtil_strdup(""); for (int meth_num = 0; fresh_methods[meth_num] != NULL; meth_num++) { - CFCMethod *method = fresh_methods[meth_num]; - if (!CFCMethod_public(method) || !CFCMethod_novel(method)) { + CFCMethod *ancestor_method = fresh_methods[meth_num]; + if (!CFCMethod_public(ancestor_method)) { continue; } - if (result[0] == '\0') { - result = CFCUtil_cat(result, ".SS Methods inherited from ", - CFCClass_get_class_name(klass), "\n", NULL); + const char *macro_sym = CFCMethod_get_macro_sym(ancestor_method); + CFCMethod *method = CFCClass_method(klass, macro_sym); + const char *class_name = CFCMethod_get_class_name(method); + if (strcmp(class_name, ancestor_name) != 0) { + // Overridden by a subclass. + continue; } - const char *macro_sym = CFCMethod_get_macro_sym(method); - char *full_method_sym = CFCMethod_full_method_sym(method, NULL); + result = CFCUtil_cat(result, ".TP\n.BR ", macro_sym, NULL); + if (CFCMethod_abstract(method)) { + result = CFCUtil_cat(result, " \" (abstract)\"", NULL); + } + result = CFCUtil_cat(result, "\n", NULL); + + char *full_sym = CFCMethod_full_method_sym(method, klass); char *method_man = S_man_create_func(klass, (CFCFunction*)method, - macro_sym, full_method_sym); + full_sym); result = CFCUtil_cat(result, method_man, NULL); - FREEMEM(method_man); - FREEMEM(full_method_sym); + FREEMEM(full_sym); } return result; } static char* -S_man_create_func(CFCClass *klass, CFCFunction *func, const char *short_sym, - const char *full_sym) { +S_man_create_func(CFCClass *klass, CFCFunction *func, const char *full_sym) { CFCType *return_type = CFCFunction_get_return_type(func); const char *return_type_c = CFCType_to_c(return_type); const char *incremented = ""; @@ -295,19 +278,17 @@ S_man_create_func(CFCClass *klass, CFCFunction *func, const char *short_sym, incremented = " // incremented"; } - char *param_list = S_man_create_param_list(func, full_sym); + char *param_list = S_man_create_param_list(klass, func); const char *pattern = - ".TP\n" - ".B %s\n" ".nf\n" ".fam C\n" "%s%s\n" - "%s" + ".BR %s %s\n" ".fam\n" ".fi\n"; - char *result = CFCUtil_sprintf(pattern, short_sym, return_type_c, - incremented, param_list); + char *result = CFCUtil_sprintf(pattern, return_type_c, incremented, + full_sym, param_list); FREEMEM(param_list); @@ -361,21 +342,31 @@ S_man_create_func(CFCClass *klass, CFCFunction *func, const char *short_sym, } static char* -S_man_create_param_list(CFCFunction *func, const char *full_sym) { +S_man_create_param_list(CFCClass *klass, CFCFunction *func) { CFCParamList *param_list = CFCFunction_get_param_list(func); CFCVariable **variables = CFCParamList_get_variables(param_list); if (!variables[0]) { - return CFCUtil_sprintf(".BR %s (void);\n", full_sym); + return CFCUtil_strdup("(void);"); } - char *result = CFCUtil_sprintf(".BR %s (", full_sym); + const char *cfc_class = CFCBase_get_cfc_class((CFCBase*)func); + int is_method = strcmp(cfc_class, "Clownfish::CFC::Model::Method") == 0; + char *result = CFCUtil_strdup("("); for (int i = 0; variables[i]; ++i) { CFCVariable *variable = variables[i]; CFCType *type = CFCVariable_get_type(variable); - const char *type_c = CFCType_to_c(type); const char *name = CFCVariable_micro_sym(variable); + char *type_c; + + if (is_method && i == 0) { + const char *struct_sym = CFCClass_full_struct_sym(klass); + type_c = CFCUtil_sprintf("%s*", struct_sym); + } + else { + type_c = CFCUtil_strdup(CFCType_to_c(type)); + } result = CFCUtil_cat(result, "\n.RB \" ", type_c, " \" ", name, NULL); @@ -392,7 +383,7 @@ S_man_create_param_list(CFCFunction *func, const char *full_sym) { } } - result = CFCUtil_cat(result, "\n);\n", NULL); + result = CFCUtil_cat(result, "\n);", NULL); return result; }
