Make Obj_Get_Class_Name inert
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/b8aa6de6 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b8aa6de6 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b8aa6de6 Branch: refs/heads/master Commit: b8aa6de6fee1efefafc8f6dcd64f12cb0c795da7 Parents: 303da5f Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Wed May 27 17:47:31 2015 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Thu May 28 17:43:25 2015 +0200 ---------------------------------------------------------------------- compiler/src/CFCBindClass.c | 12 ++++++++++-- compiler/src/CFCPerl.c | 2 +- runtime/core/Clownfish/CharBuf.c | 2 +- runtime/core/Clownfish/Err.c | 6 +++--- runtime/core/Clownfish/Err.cfh | 2 +- runtime/core/Clownfish/Obj.c | 6 +++--- runtime/core/Clownfish/Obj.cfh | 4 ++-- runtime/core/Clownfish/Test/TestObj.c | 4 ++-- runtime/core/Clownfish/TestHarness/TestFormatter.c | 2 +- runtime/core/Clownfish/TestHarness/TestSuite.c | 2 +- runtime/perl/buildlib/Clownfish/Build/Binding.pm | 8 ++++++++ 11 files changed, 33 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/compiler/src/CFCBindClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c index 3033a81..661ff60 100644 --- a/compiler/src/CFCBindClass.c +++ b/compiler/src/CFCBindClass.c @@ -664,9 +664,16 @@ S_wrapper_defs(CFCBindClass *self) { "static CFISH_INLINE cfish_Class*\n" "%s%s_get_class(%s *self) {\n" " return cfish_Obj_get_class((cfish_Obj*)self);\n" + "}\n" + "\n" + "static CFISH_INLINE cfish_String*\n" + "%s%s_get_class_name(%s *self) {\n" + " return cfish_Obj_get_class_name((cfish_Obj*)self);\n" "}\n"; - return CFCUtil_sprintf(pattern, prefix, nickname, struct_sym); + return CFCUtil_sprintf(pattern, + prefix, nickname, struct_sym, + prefix, nickname, struct_sym); } // Define method invocation inline functions. @@ -769,7 +776,8 @@ S_short_names(CFCBindClass *self) { // Wrappers. if (strcmp(CFCClass_get_name(client), "Clownfish::Obj") != 0) { static const char *wrapped_funcs[] = { - "get_class" + "get_class", + "get_class_name" }; static int num_wrapped_funcs = sizeof(wrapped_funcs) / sizeof(wrapped_funcs[0]); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/compiler/src/CFCPerl.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c index 7916a5b..ecfb35e 100644 --- a/compiler/src/CFCPerl.c +++ b/compiler/src/CFCPerl.c @@ -610,7 +610,7 @@ S_write_callbacks_c(CFCPerl *self) { " LEAVE;\n" " if (!nullable && !retval) {\n" " CFISH_THROW(CFISH_ERR, \"%%o#%%s cannot return NULL\",\n" - " CFISH_Obj_Get_Class_Name((cfish_Obj*)vself),\n" + " cfish_Obj_get_class_name((cfish_Obj*)vself),\n" " meth_name);\n" " }\n" " return retval;\n" http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/CharBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/CharBuf.c b/runtime/core/Clownfish/CharBuf.c index b0ceb8b..089390f 100644 --- a/runtime/core/Clownfish/CharBuf.c +++ b/runtime/core/Clownfish/CharBuf.c @@ -352,7 +352,7 @@ CB_Mimic_IMP(CharBuf *self, Obj *other) { size = twin->size; } else { - THROW(ERR, "CharBuf can't mimic %o", Obj_Get_Class_Name(other)); + THROW(ERR, "CharBuf can't mimic %o", Obj_get_class_name(other)); return; // unreachable } SI_mimic_utf8(self, ptr, size); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/Err.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Err.c b/runtime/core/Clownfish/Err.c index 68c2365..dad6ae9 100644 --- a/runtime/core/Clownfish/Err.c +++ b/runtime/core/Clownfish/Err.c @@ -212,7 +212,7 @@ Err_downcast(Obj *obj, Class *klass, const char *file, int line, const char *func) { if (obj && !SI_obj_is_a(obj, klass)) { Err_throw_at(ERR, file, line, func, "Can't downcast from %o to %o", - Obj_Get_Class_Name(obj), Class_Get_Name(klass)); + Obj_get_class_name(obj), Class_Get_Name(klass)); } return obj; } @@ -226,14 +226,14 @@ Err_certify(Obj *obj, Class *klass, const char *file, int line, } else if (!SI_obj_is_a(obj, klass)) { Err_throw_at(ERR, file, line, func, "Can't downcast from %o to %o", - Obj_Get_Class_Name(obj), Class_Get_Name(klass)); + Obj_get_class_name(obj), Class_Get_Name(klass)); } return obj; } void Err_abstract_method_call(Obj *obj, Class *klass, const char *method_name) { - String *class_name = obj ? Obj_Get_Class_Name(obj) : Class_Get_Name(klass); + String *class_name = obj ? Obj_get_class_name(obj) : Class_Get_Name(klass); THROW(ERR, "Abstract method '%s' not defined by %o", method_name, class_name); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/Err.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Err.cfh b/runtime/core/Clownfish/Err.cfh index db56849..d863119 100644 --- a/runtime/core/Clownfish/Err.cfh +++ b/runtime/core/Clownfish/Err.cfh @@ -237,7 +237,7 @@ cfish_Err_abstract_class_check(cfish_Obj *obj, cfish_Class *klass) { cfish_Class *const my_class = (cfish_Class*)((cfish_Dummy*)obj)->klass; if (my_class == klass) { cfish_String *mess = CFISH_MAKE_MESS("%o is an abstract class", - CFISH_Obj_Get_Class_Name(obj)); + cfish_Obj_get_class_name(obj)); CFISH_DECREF_NN(obj); cfish_Err_throw_mess(CFISH_ERR, mess); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/Obj.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Obj.c b/runtime/core/Clownfish/Obj.c index d10d7d8..a1196f8 100644 --- a/runtime/core/Clownfish/Obj.c +++ b/runtime/core/Clownfish/Obj.c @@ -64,13 +64,13 @@ Obj_Equals_IMP(Obj *self, Obj *other) { String* Obj_To_String_IMP(Obj *self) { #if (CHY_SIZEOF_PTR == 4) - return Str_newf("%o@0x%x32", Obj_Get_Class_Name(self), self); + return Str_newf("%o@0x%x32", Obj_get_class_name(self), self); #elif (CHY_SIZEOF_PTR == 8) int64_t iaddress = CHY_PTR_TO_I64(self); uint64_t address = (uint64_t)iaddress; uint32_t address_hi = address >> 32; uint32_t address_lo = address & 0xFFFFFFFF; - return Str_newf("%o@0x%x32%x32", Obj_Get_Class_Name(self), address_hi, + return Str_newf("%o@0x%x32%x32", Obj_get_class_name(self), address_hi, address_lo); #else #error "Unexpected pointer size." @@ -83,7 +83,7 @@ Obj_get_class(Obj *self) { } String* -Obj_Get_Class_Name_IMP(Obj *self) { +Obj_get_class_name(Obj *self) { return Class_Get_Name(self->klass); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/Obj.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Obj.cfh b/runtime/core/Clownfish/Obj.cfh index b9d9fd4..7f4074b 100644 --- a/runtime/core/Clownfish/Obj.cfh +++ b/runtime/core/Clownfish/Obj.cfh @@ -70,8 +70,8 @@ public abstract class Clownfish::Obj { /** Return the name of the class that the object belongs to. */ - public String* - Get_Class_Name(Obj *self); + public inert String* + get_class_name(Obj *self); /** Indicate whether the object is a descendent of `ancestor`. */ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/Test/TestObj.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestObj.c b/runtime/core/Clownfish/Test/TestObj.c index cb3fa14..42c82fa 100644 --- a/runtime/core/Clownfish/Test/TestObj.c +++ b/runtime/core/Clownfish/Test/TestObj.c @@ -89,13 +89,13 @@ static void test_Is_A(TestBatchRunner *runner) { String *string = Str_new_from_trusted_utf8("", 0); Class *str_class = Str_get_class(string); - String *class_name = Str_Get_Class_Name(string); + String *class_name = Str_get_class_name(string); TEST_TRUE(runner, Str_Is_A(string, STRING), "String Is_A String."); TEST_TRUE(runner, Str_Is_A(string, OBJ), "String Is_A Obj."); TEST_TRUE(runner, str_class == STRING, "get_class"); TEST_TRUE(runner, Str_Equals(Class_Get_Name(STRING), (Obj*)class_name), - "Get_Class_Name"); + "get_class_name"); DECREF(string); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/TestHarness/TestFormatter.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/TestHarness/TestFormatter.c b/runtime/core/Clownfish/TestHarness/TestFormatter.c index 797ae84..ef3fd6b 100644 --- a/runtime/core/Clownfish/TestHarness/TestFormatter.c +++ b/runtime/core/Clownfish/TestHarness/TestFormatter.c @@ -76,7 +76,7 @@ TestFormatterCF_Batch_Prologue_IMP(TestFormatterCF *self, TestBatch *batch, uint32_t num_planned) { UNUSED_VAR(self); UNUSED_VAR(num_planned); - String *class_name = TestBatch_Get_Class_Name(batch); + String *class_name = TestBatch_get_class_name(batch); char *utf8 = Str_To_Utf8(class_name); printf("Running %s...\n", utf8); FREEMEM(utf8); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/core/Clownfish/TestHarness/TestSuite.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/TestHarness/TestSuite.c b/runtime/core/Clownfish/TestHarness/TestSuite.c index 856525b..078a317 100644 --- a/runtime/core/Clownfish/TestHarness/TestSuite.c +++ b/runtime/core/Clownfish/TestHarness/TestSuite.c @@ -67,7 +67,7 @@ TestSuite_Run_Batch_IMP(TestSuite *self, String *class_name, for (uint32_t i = 0; i < size; ++i) { TestBatch *batch = (TestBatch*)Vec_Fetch(self->batches, i); - if (Str_Equals(TestBatch_Get_Class_Name(batch), (Obj*)class_name)) { + if (Str_Equals(TestBatch_get_class_name(batch), (Obj*)class_name)) { TestBatchRunner *runner = TestBatchRunner_new(formatter); bool result = TestBatchRunner_Run_Batch(runner, batch); DECREF(runner); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b8aa6de6/runtime/perl/buildlib/Clownfish/Build/Binding.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index 14805bd..aa9ca76 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -494,6 +494,14 @@ CODE: RETVAL = (SV*)CFISH_Class_To_Host(klass); OUTPUT: RETVAL +SV* +get_class_name(self) + cfish_Obj *self +CODE: + cfish_String *class_name = cfish_Obj_get_class_name(self); + RETVAL = cfish_XSBind_str_to_sv(aTHX_ class_name); +OUTPUT: RETVAL + bool is_a(self, class_name) cfish_Obj *self;