Repository: lucy-clownfish
Updated Branches:
  refs/heads/ivars_fixes [created] d33f60130


Make sure that ivars typedef is a complete type

If all ancestors of an object are in the same parcel, use object struct
for ivars typedef.


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

Branch: refs/heads/ivars_fixes
Commit: 74cd3e0e00deeabd617e4734fe42a87c70b0e871
Parents: 4e8f130
Author: Nick Wellnhofer <[email protected]>
Authored: Fri Jul 25 18:00:49 2014 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat Jul 26 15:33:59 2014 +0200

----------------------------------------------------------------------
 compiler/src/CFCBindClass.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/74cd3e0e/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindClass.c b/compiler/src/CFCBindClass.c
index ebeb07d..3714d28 100644
--- a/compiler/src/CFCBindClass.c
+++ b/compiler/src/CFCBindClass.c
@@ -155,6 +155,22 @@ S_ivars_func(CFCBindClass *self) {
     const char *short_struct = CFCClass_short_ivars_struct(client);
     const char *full_offset  = CFCClass_full_ivars_offset(client);
     const char *PREFIX       = CFCClass_get_PREFIX(client);
+    const char *ivars_or_not = NULL;
+
+    // Try to find first ancestor from a different parcel.
+    CFCParcel *parcel = CFCClass_get_parcel(client);
+    CFCClass *ancestor = CFCClass_get_parent(client);
+    while (ancestor && CFCClass_get_parcel(ancestor) == parcel) {
+        ancestor = CFCClass_get_parent(ancestor);
+    }
+    // Use full struct or ivars struct for typedef.
+    if (!ancestor) {
+        ivars_or_not = CFCClass_full_struct_sym(client);
+    }
+    else {
+        ivars_or_not = full_struct;
+    }
+
     char pattern[] =
         "extern size_t %s;\n"
         "typedef struct %s %s;\n"
@@ -169,7 +185,7 @@ S_ivars_func(CFCBindClass *self) {
         "#endif\n";
     char *content = CFCUtil_sprintf(pattern,
                                     full_offset,
-                                    full_struct, full_struct,
+                                    ivars_or_not, full_struct,
                                     full_struct,
                                     full_func, full_type,
                                     full_offset,
@@ -454,7 +470,6 @@ CFCBindClass_spec_def(CFCBindClass *self) {
     CFCClass   *parent       = CFCClass_get_parent(client);
     const char *class_name   = CFCClass_get_class_name(client);
     const char *class_var    = CFCClass_full_class_var(client);
-    const char *struct_sym   = CFCClass_full_struct_sym(client);
     const char *ivars_struct = CFCClass_full_ivars_struct(client);
     const char *prefix       = CFCClass_get_prefix(client);
 
@@ -502,8 +517,6 @@ CFCBindClass_spec_def(CFCBindClass *self) {
                                                 class_var)
                               : CFCUtil_strdup("NULL");
 
-    const char *ivars_or_not = strcmp(prefix, "cfish_") == 0
-                               ? struct_sym : ivars_struct;
     const char *ivars_offset_name = CFCClass_full_ivars_offset(client);
 
     char pattern[] =
@@ -522,7 +535,7 @@ CFCBindClass_spec_def(CFCBindClass *self) {
         "    }";
     char *code
         = CFCUtil_sprintf(pattern, class_var, parent_ref, class_name,
-                          ivars_or_not, ivars_offset_name, num_novel,
+                          ivars_struct, ivars_offset_name, num_novel,
                           num_overridden, num_inherited, novel_ms_var,
                           overridden_ms_var, inherited_ms_var);
 

Reply via email to