lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] git commit: Add --parcel option to cfc
Date Mon, 31 Mar 2014 12:13:28 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 64ae37ff5 -> 63de94b6a


Add --parcel option to cfc

The --parcel option can be used by non-Clownfish projects to add parcels
to the list of prerequisites. Example:

    cfc --include=PREFIX/share/clownfish/include --parcel=Lucy


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

Branch: refs/heads/master
Commit: 63de94b6a99c8a68405fb035f428296916e432ef
Parents: 64ae37f
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Mar 31 14:07:59 2014 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Mar 31 14:07:59 2014 +0200

----------------------------------------------------------------------
 compiler/c/cfc.c                | 19 +++++++++++++++----
 compiler/src/CFCHierarchy.c     | 35 ++++++++++++++++++++++++++++++++---
 compiler/src/CFCHierarchy.h     |  5 +++++
 compiler/src/CFCTestHierarchy.c | 31 ++++++++++++++++++++++++++++++-
 4 files changed, 82 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/63de94b6/compiler/c/cfc.c
----------------------------------------------------------------------
diff --git a/compiler/c/cfc.c b/compiler/c/cfc.c
index df5e9bd..ae8828f 100644
--- a/compiler/c/cfc.c
+++ b/compiler/c/cfc.c
@@ -41,6 +41,8 @@ struct CFCArgs {
     char **source_dirs;
     int    num_include_dirs;
     char **include_dirs;
+    int    num_parcels;
+    char **parcels;
     char  *header_filename;
     char  *footer_filename;
 };
@@ -99,10 +101,9 @@ S_parse_arguments(int argc, char **argv, CFCArgs *args) {
     int i;
 
     memset(args, 0, sizeof(CFCArgs));
-    args->source_dirs     = (char **)MALLOCATE(sizeof(char *));
-    args->source_dirs[0]  = NULL;
-    args->include_dirs    = (char **)MALLOCATE(sizeof(char *));
-    args->include_dirs[0] = NULL;
+    args->source_dirs  = (char**)CALLOCATE(1, sizeof(char*));
+    args->include_dirs = (char**)CALLOCATE(1, sizeof(char*));
+    args->parcels      = (char**)CALLOCATE(1, sizeof(char*));
 
     for (i = 1; i < argc; i++) {
         char *arg = argv[i];
@@ -128,6 +129,12 @@ S_parse_arguments(int argc, char **argv, CFCArgs *args) {
            ) {
             continue;
         }
+        if (S_parse_string_array_argument(arg, "--parcel",
+                                          &args->num_parcels,
+                                          &args->parcels)
+           ) {
+            continue;
+        }
 
         fprintf(stderr, "Invalid argument '%s'\n", arg);
         exit(EXIT_FAILURE);
@@ -206,6 +213,10 @@ main(int argc, char **argv) {
         CFCHierarchy_add_include_dir(hierarchy, "/usr/" SYS_INCLUDE_DIR);
     }
 
+    for (i = 0; args.parcels[i]; ++i) {
+        CFCHierarchy_add_prereq(hierarchy, args.parcels[i]);
+    }
+
     CFCHierarchy_build(hierarchy);
 
     if (args.header_filename) {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/63de94b6/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index ca7dba5..dddb121 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -45,6 +45,8 @@ struct CFCHierarchy {
     char **sources;
     size_t num_includes;
     char **includes;
+    size_t num_prereqs;
+    char **prereqs;
     char *dest;
     char *inc_dest;
     char *src_dest;
@@ -67,7 +69,7 @@ static void
 S_parse_parcel_files(const char *path, void *context);
 
 static void
-S_check_prereqs(void);
+S_check_prereqs(CFCHierarchy *self);
 
 static void
 S_do_make_path(const char *path);
@@ -112,6 +114,8 @@ CFCHierarchy_init(CFCHierarchy *self, const char *dest) {
     self->num_sources  = 0;
     self->includes     = (char**)CALLOCATE(1, sizeof(char*));
     self->num_includes = 0;
+    self->prereqs      = (char**)CALLOCATE(1, sizeof(char*));
+    self->num_prereqs  = 0;
     self->dest         = CFCUtil_strdup(dest);
     self->trees        = (CFCClass**)CALLOCATE(1, sizeof(CFCClass*));
     self->num_trees    = 0;
@@ -148,11 +152,15 @@ CFCHierarchy_destroy(CFCHierarchy *self) {
     for (size_t i = 0; self->includes[i] != NULL; i++) {
         FREEMEM(self->includes[i]);
     }
+    for (size_t i = 0; self->prereqs[i] != NULL; i++) {
+        FREEMEM(self->prereqs[i]);
+    }
     FREEMEM(self->trees);
     FREEMEM(self->files);
     FREEMEM(self->classes);
     FREEMEM(self->sources);
     FREEMEM(self->includes);
+    FREEMEM(self->prereqs);
     FREEMEM(self->dest);
     FREEMEM(self->inc_dest);
     FREEMEM(self->src_dest);
@@ -191,6 +199,16 @@ CFCHierarchy_add_include_dir(CFCHierarchy *self, const char *include_dir)
{
 }
 
 void
+CFCHierarchy_add_prereq(CFCHierarchy *self, const char *parcel) {
+    size_t n = self->num_prereqs;
+    size_t size = (n + 2) * sizeof(char*);
+    self->prereqs      = (char**)REALLOCATE(self->prereqs, size);
+    self->prereqs[n]   = CFCUtil_strdup(parcel);
+    self->prereqs[n+1] = NULL;
+    self->num_prereqs  = n + 1;
+}
+
+void
 CFCHierarchy_build(CFCHierarchy *self) {
     // Read .cfp files.
     CFCParseParcelFilesContext context;
@@ -203,7 +221,7 @@ CFCHierarchy_build(CFCHierarchy *self) {
         CFCUtil_walk(self->includes[i], S_parse_parcel_files, &context);
     }
 
-    S_check_prereqs();
+    S_check_prereqs(self);
 
     // Read .cfh files.
     for (size_t i = 0; self->sources[i] != NULL; i++) {
@@ -261,7 +279,7 @@ S_parse_parcel_files(const char *path, void *arg) {
 }
 
 static void
-S_check_prereqs() {
+S_check_prereqs(CFCHierarchy *self) {
     CFCParcel **parcels = CFCParcel_all_parcels();
 
     for (int i = 0; parcels[i]; ++i) {
@@ -270,6 +288,17 @@ S_check_prereqs() {
             CFCParcel_check_prereqs(parcel);
         }
     }
+
+    for (int i = 0; self->prereqs[i]; ++i) {
+        const char *prereq = self->prereqs[i];
+        CFCParcel *parcel = CFCParcel_fetch(prereq);
+        if (parcel == NULL) {
+            CFCUtil_die("Prerequisite parcel '%s' not found", prereq);
+        }
+        else {
+            CFCParcel_check_prereqs(parcel);
+        }
+    }
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/63de94b6/compiler/src/CFCHierarchy.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.h b/compiler/src/CFCHierarchy.h
index 06d1e57..ed9df25 100644
--- a/compiler/src/CFCHierarchy.h
+++ b/compiler/src/CFCHierarchy.h
@@ -57,6 +57,11 @@ CFCHierarchy_add_source_dir(CFCHierarchy *self, const char *source_dir);
 void
 CFCHierarchy_add_include_dir(CFCHierarchy *self, const char *include_dir);
 
+/** Add parcel to the list of required parcel.
+ */
+void
+CFCHierarchy_add_prereq(CFCHierarchy *self, const char *parcel);
+
 /** Parse every Clownfish header file which can be found under any of the
  * source and include directories, building up the object hierarchy.
  */

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/63de94b6/compiler/src/CFCTestHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestHierarchy.c b/compiler/src/CFCTestHierarchy.c
index 8941fe2..ff5fde9 100644
--- a/compiler/src/CFCTestHierarchy.c
+++ b/compiler/src/CFCTestHierarchy.c
@@ -53,7 +53,7 @@ S_run_include_tests(CFCTest *test);
 
 const CFCTestBatch CFCTEST_BATCH_HIERARCHY = {
     "Clownfish::CFC::Model::Hierarchy",
-    39,
+    44,
     S_run_tests
 };
 
@@ -229,6 +229,35 @@ S_run_include_tests(CFCTest *test) {
         CFCParcel_reap_singletons();
     }
 
+    {
+        CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
+        CFCHierarchy_add_include_dir(hierarchy, T_CFBASE);
+        CFCHierarchy_add_include_dir(hierarchy, T_CFEXT);
+        CFCHierarchy_add_prereq(hierarchy, "AnimalExtension");
+
+        CFCHierarchy_build(hierarchy);
+
+        CFCParcel *animal = CFCParcel_fetch("Animal");
+        OK(test, animal != NULL, "parcel Animal registered");
+        OK(test, CFCParcel_required(animal), "parcel Animal required");
+        CFCParcel *animal_ext = CFCParcel_fetch("AnimalExtension");
+        OK(test, animal_ext != NULL, "parcel AnimalExtension registered");
+        OK(test, CFCParcel_required(animal_ext),
+           "parcel AnimalExtension required");
+
+        CFCClass **classes = CFCHierarchy_ordered_classes(hierarchy);
+        int num_classes = 0;
+        while (classes[num_classes]) {
+            ++num_classes;
+        }
+        INT_EQ(test, num_classes, 5, "class count");
+
+        FREEMEM(classes);
+        CFCBase_decref((CFCBase*)hierarchy);
+        CFCClass_clear_registry();
+        CFCParcel_reap_singletons();
+    }
+
     rmdir(T_CFDEST_INCLUDE);
     rmdir(T_CFDEST_SOURCE);
     rmdir(T_CFDEST);


Mime
View raw message