lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [01/34] git commit: refs/heads/master - Hack in IVARS.
Date Wed, 17 Jul 2013 14:12:21 GMT
Updated Branches:
  refs/heads/master 6f661d5d2 -> adacb96f4


Hack in IVARS.

Create FooIVARS struct which is typedef'd to Foo and a Foo_IVARS inline
function which simply performs a cast.


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

Branch: refs/heads/master
Commit: 59bd0cd783781c6b603ce6f59fc7ad0fc0bf5cb3
Parents: 6f661d5
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Wed Jun 26 16:34:01 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Jul 16 15:48:58 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindClass.c | 30 +++++++++++++++++++++++++++++-
 clownfish/compiler/src/CFCClass.c     | 16 ++++++++++++++++
 clownfish/compiler/src/CFCClass.h     |  6 ++++++
 3 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/59bd0cd7/clownfish/compiler/src/CFCBindClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindClass.c b/clownfish/compiler/src/CFCBindClass.c
index 2cd5efd..a1b3ac6 100644
--- a/clownfish/compiler/src/CFCBindClass.c
+++ b/clownfish/compiler/src/CFCBindClass.c
@@ -152,11 +152,37 @@ S_to_c_header_inert(CFCBindClass *self) {
 }
 
 static char*
+S_ivars_hack(CFCBindClass *self) {
+    const char *full_struct = CFCClass_full_struct_sym(self->client);
+    const char *full_ivars  = CFCClass_full_ivars_name(self->client);
+    const char *short_ivars = CFCClass_short_ivars_name(self->client);
+    const char *prefix      = CFCClass_get_PREFIX(self->client);
+    const char *class_cnick = CFCClass_get_cnick(self->client);
+    char pattern[] =
+        "typedef struct %s %s;\n"
+        "static CHY_INLINE %s*\n"
+        "%s%s_IVARS(%s *self) {\n"
+        "   return (%s*)self;\n"
+        "}\n"
+        "#ifdef %sUSE_SHORT_NAMES\n"
+        "  #define %s %s\n"
+        "  #define %s_IVARS %s%s_IVARS\n"
+        "#endif\n";
+    char *content
+        = CFCUtil_sprintf(pattern, full_struct, full_ivars, full_ivars, prefix,
+                          class_cnick, full_struct, full_ivars, prefix,
+                          short_ivars, full_ivars, class_cnick, prefix,
+                          class_cnick);
+    return content;
+}
+
+static char*
 S_to_c_header_dynamic(CFCBindClass *self) {
     const char *privacy_symbol  = CFCClass_privacy_symbol(self->client);
     const char *vt_var          = CFCClass_full_vtable_var(self->client);
     const char *prefix          = CFCClass_get_prefix(self->client);
     const char *PREFIX          = CFCClass_get_PREFIX(self->client);
+    char *ivars                 = S_ivars_hack(self);
     char *struct_def            = S_struct_definition(self);
     char *parent_include        = S_parent_include(self);
     char *sub_declarations      = S_sub_declarations(self);
@@ -178,6 +204,7 @@ S_to_c_header_dynamic(CFCBindClass *self) {
         "\n"
         "#ifdef %s\n"
         "%s\n"
+        "%s\n"
         "#endif /* %s */\n"
         "\n"
         "/* Declare this class's inert variables.\n"
@@ -214,10 +241,11 @@ S_to_c_header_dynamic(CFCBindClass *self) {
         "\n";
     char *content
         = CFCUtil_sprintf(pattern, prefix, parent_include, privacy_symbol,
-                          struct_def, privacy_symbol, inert_var_defs,
+                          ivars, struct_def, privacy_symbol, inert_var_defs,
                           sub_declarations, method_typedefs, method_defs,
                           PREFIX, vt_var, short_names);
 
+    FREEMEM(ivars);
     FREEMEM(struct_def);
     FREEMEM(parent_include);
     FREEMEM(sub_declarations);

http://git-wip-us.apache.org/repos/asf/lucy/blob/59bd0cd7/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c b/clownfish/compiler/src/CFCClass.c
index 9c90f68..790fd72 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -77,6 +77,8 @@ struct CFCClass {
     int is_inert;
     char *struct_sym;
     char *full_struct_sym;
+    char *ivars_name;
+    char *full_ivars_name;
     char *short_vtable_var;
     char *full_vtable_var;
     char *privacy_symbol;
@@ -174,6 +176,8 @@ CFCClass_do_create(CFCClass *self, struct CFCParcel *parcel,
     }
     self->short_vtable_var[struct_sym_len] = '\0';
     self->full_struct_sym = CFCUtil_sprintf("%s%s", prefix, self->struct_sym);
+    self->ivars_name      = CFCUtil_sprintf("%sIVARS", self->struct_sym);
+    self->full_ivars_name = CFCUtil_sprintf("%sIVARS", self->full_struct_sym);
     size_t full_struct_sym_len = strlen(self->full_struct_sym);
     self->full_vtable_var = (char*)MALLOCATE(full_struct_sym_len + 1);
     for (i = 0; self->full_struct_sym[i] != '\0'; i++) {
@@ -250,6 +254,8 @@ CFCClass_destroy(CFCClass *self) {
     FREEMEM(self->autocode);
     FREEMEM(self->parent_class_name);
     FREEMEM(self->struct_sym);
+    FREEMEM(self->ivars_name);
+    FREEMEM(self->full_ivars_name);
     FREEMEM(self->short_vtable_var);
     FREEMEM(self->full_struct_sym);
     FREEMEM(self->full_vtable_var);
@@ -823,6 +829,16 @@ CFCClass_full_struct_sym(CFCClass *self) {
 }
 
 const char*
+CFCClass_short_ivars_name(CFCClass *self) {
+    return self->ivars_name;
+}
+
+const char*
+CFCClass_full_ivars_name(CFCClass *self) {
+    return self->full_ivars_name;
+}
+
+const char*
 CFCClass_short_vtable_var(CFCClass *self) {
     return self->short_vtable_var;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/59bd0cd7/clownfish/compiler/src/CFCClass.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.h b/clownfish/compiler/src/CFCClass.h
index cb484d8..d45e883 100644
--- a/clownfish/compiler/src/CFCClass.h
+++ b/clownfish/compiler/src/CFCClass.h
@@ -246,6 +246,12 @@ CFCClass_get_struct_sym(CFCClass *self);
 const char*
 CFCClass_full_struct_sym(CFCClass *self);
 
+const char*
+CFCClass_short_ivars_name(CFCClass *self);
+
+const char*
+CFCClass_full_ivars_name(CFCClass *self);
+
 /** The short name of the global VTable object for this class.
  */
 const char*


Mime
View raw message