You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/05/26 17:35:36 UTC

[lucy-commits] [8/9] git commit: refs/heads/separate-clownfish-wip1 - Intra-parcel dependencies

Intra-parcel dependencies

Parcels depend on other parcels if:

* A class extends a class from another parcel.
* A class uses types from another parcel.

This commit makes CFC track these dependencies.

TODO: Perl bindings


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

Branch: refs/heads/separate-clownfish-wip1
Commit: 13149c82a91dd4781fd0e59efb4b7b85792fb465
Parents: 041145b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun May 26 13:09:14 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun May 26 17:19:42 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/src/CFCClass.c  |    5 ++
 clownfish/compiler/src/CFCParcel.c |   77 +++++++++++++++++++++++++++++++
 clownfish/compiler/src/CFCParcel.h |   22 +++++++++
 clownfish/compiler/src/CFCType.c   |   24 +++++++++-
 4 files changed, 126 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/13149c82/clownfish/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCClass.c b/clownfish/compiler/src/CFCClass.c
index 0567ca4..e2cb2cc 100644
--- a/clownfish/compiler/src/CFCClass.c
+++ b/clownfish/compiler/src/CFCClass.c
@@ -323,6 +323,11 @@ CFCClass_add_child(CFCClass *self, CFCClass *child) {
     self->children[self->num_kids - 1]
         = (CFCClass*)CFCBase_incref((CFCBase*)child);
     self->children[self->num_kids] = NULL;
+
+    // Add parcel dependency.
+    CFCParcel *parcel       = CFCClass_get_parcel(self);
+    CFCParcel *child_parcel = CFCClass_get_parcel(child);
+    CFCParcel_add_extended_parcel(child_parcel, parcel);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/13149c82/clownfish/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.c b/clownfish/compiler/src/CFCParcel.c
index f628f66..7387524 100644
--- a/clownfish/compiler/src/CFCParcel.c
+++ b/clownfish/compiler/src/CFCParcel.c
@@ -38,6 +38,10 @@ struct CFCParcel {
     char *Prefix;
     char *PREFIX;
     int is_included;
+    CFCParcel **dependent_parcels;
+    size_t num_dependent_parcels;
+    CFCParcel **extended_parcels;
+    size_t num_extended_parcels;
 };
 
 static CFCParcel *default_parcel = NULL;
@@ -216,6 +220,12 @@ CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
     // Set is_included.
     self->is_included = is_included;
 
+    // Initialize dependencies.
+    self->dependent_parcels = (CFCParcel**)CALLOCATE(1, sizeof(CFCParcel*));
+    self->num_dependent_parcels = 0;
+    self->extended_parcels = (CFCParcel**)CALLOCATE(1, sizeof(CFCParcel*));
+    self->num_extended_parcels = 0;
+
     return self;
 }
 
@@ -304,6 +314,14 @@ CFCParcel_destroy(CFCParcel *self) {
     FREEMEM(self->prefix);
     FREEMEM(self->Prefix);
     FREEMEM(self->PREFIX);
+    for (size_t i = 0; self->dependent_parcels[i]; ++i) {
+        CFCBase_decref((CFCBase*)self->dependent_parcels[i]);
+    }
+    FREEMEM(self->dependent_parcels);
+    for (size_t i = 0; self->extended_parcels[i]; ++i) {
+        CFCBase_decref((CFCBase*)self->extended_parcels[i]);
+    }
+    FREEMEM(self->extended_parcels);
     CFCBase_destroy((CFCBase*)self);
 }
 
@@ -361,6 +379,65 @@ CFCParcel_included(CFCParcel *self) {
     return self->is_included;
 }
 
+void
+CFCParcel_add_dependent_parcel(CFCParcel *self, CFCParcel *dependent) {
+    const char *prefix     = CFCParcel_get_prefix(self);
+    const char *dep_prefix = CFCParcel_get_prefix(dependent);
+
+    if (strcmp(prefix, dep_prefix) == 0) { return; }
+
+    for (size_t i = 0; self->dependent_parcels[i]; ++i) {
+        const char *other_prefix
+            = CFCParcel_get_prefix(self->dependent_parcels[i]);
+        if (strcmp(other_prefix, dep_prefix) == 0) { return; }
+    }
+
+    size_t num_parcels = self->num_dependent_parcels;
+    self->dependent_parcels
+        = (CFCParcel**)REALLOCATE(self->dependent_parcels,
+                                  (num_parcels + 2) * sizeof(CFCParcel*));
+    self->dependent_parcels[num_parcels]
+        = (CFCParcel*)CFCBase_incref((CFCBase*)dependent);
+    self->dependent_parcels[num_parcels+1] = NULL;
+    self->num_dependent_parcels = num_parcels + 1;
+}
+
+void
+CFCParcel_add_extended_parcel(CFCParcel *self, CFCParcel *extended) {
+    const char *prefix     = CFCParcel_get_prefix(self);
+    const char *ext_prefix = CFCParcel_get_prefix(extended);
+
+    if (strcmp(prefix, ext_prefix) == 0) { return; }
+
+    for (size_t i = 0; self->extended_parcels[i]; ++i) {
+        const char *other_prefix
+            = CFCParcel_get_prefix(self->extended_parcels[i]);
+        if (strcmp(other_prefix, ext_prefix) == 0) { return; }
+    }
+
+    size_t num_parcels = self->num_extended_parcels;
+    self->extended_parcels
+        = (CFCParcel**)REALLOCATE(self->extended_parcels,
+                                  (num_parcels + 2) * sizeof(CFCParcel*));
+    self->extended_parcels[num_parcels]
+        = (CFCParcel*)CFCBase_incref((CFCBase*)extended);
+    self->extended_parcels[num_parcels+1] = NULL;
+    self->num_extended_parcels = num_parcels + 1;
+
+    // Add to dependent parcels.
+    CFCParcel_add_dependent_parcel(self, extended);
+}
+
+CFCParcel**
+CFCParcel_dependent_parcels(CFCParcel *self) {
+    return self->dependent_parcels;
+}
+
+CFCParcel**
+CFCParcel_extended_parcels(CFCParcel *self) {
+    return self->extended_parcels;
+}
+
 /*****************************************************************************
  * The hack JSON parser coded up below is only meant to parse Clownfish parcel
  * file content.  It is limited in its capabilities because so little is legal

http://git-wip-us.apache.org/repos/asf/lucy/blob/13149c82/clownfish/compiler/src/CFCParcel.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.h b/clownfish/compiler/src/CFCParcel.h
index e77e5a8..f8a58d2 100644
--- a/clownfish/compiler/src/CFCParcel.h
+++ b/clownfish/compiler/src/CFCParcel.h
@@ -115,6 +115,28 @@ CFCParcel_get_PREFIX(CFCParcel *self);
 int
 CFCParcel_included(CFCParcel *self);
 
+/** Add another Parcel that the Parcel depends on.
+ */
+void
+CFCParcel_add_dependent_parcel(CFCParcel *self, CFCParcel *dependent);
+
+/** Add another Parcel containing superclasses that subclasses in the Parcel
+ * extend. Also adds the other Parcel to the Parcel's dependencies.
+ */
+void
+CFCParcel_add_extended_parcel(CFCParcel *self, CFCParcel *extended);
+
+/** Return a NULL-terminated array of all Parcels that the Parcel depends on.
+ */
+CFCParcel**
+CFCParcel_dependent_parcels(CFCParcel *self);
+
+/** Return a NULL-terminated array of all Parcels containing superclasses that
+ * subclasses in the Parcel extend.
+ */
+CFCParcel**
+CFCParcel_extended_parcels(CFCParcel *self);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/lucy/blob/13149c82/clownfish/compiler/src/CFCType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCType.c b/clownfish/compiler/src/CFCType.c
index 0494f93..d0b68ec 100644
--- a/clownfish/compiler/src/CFCType.c
+++ b/clownfish/compiler/src/CFCType.c
@@ -325,11 +325,11 @@ CFCType_resolve(CFCType *self, CFCClass **classes) {
         return;
     }
 
+    CFCClass *klass = NULL;
+
     if (isupper(self->specifier[0])) {
         // Try to find class from class list.
         const char *specifier = self->specifier;
-        CFCClass   *klass     = NULL;
-
         for (size_t i = 0; classes[i]; ++i) {
             CFCClass   *maybe_class = classes[i];
             const char *struct_sym  = CFCClass_get_struct_sym(maybe_class);
@@ -356,6 +356,26 @@ CFCType_resolve(CFCType *self, CFCClass **classes) {
         FREEMEM(self->specifier);
         self->specifier = CFCUtil_strdup(full_specifier);
     }
+    else {
+        // Try to find class from class list.
+        const char *specifier = self->specifier;
+        for (size_t i = 0; classes[i]; ++i) {
+            CFCClass *maybe_class = classes[i];
+            const char *full_struct_sym
+                = CFCClass_full_struct_sym(maybe_class);
+
+            if (strcmp(specifier, full_struct_sym) == 0) {
+                klass = maybe_class;
+                break;
+            }
+        }
+    }
+
+    // Add parcel dependency.
+    if (klass) {
+        CFCParcel *class_parcel = CFCClass_get_parcel(klass);
+        CFCParcel_add_dependent_parcel(self->parcel, class_parcel);
+    }
 
     // Cache C representation.
     char c_string[MAX_SPECIFIER_LEN + 10];