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 2014/08/05 12:21:38 UTC
[4/8] git commit: Find .cfp files using S_find_files
Find .cfp files using S_find_files
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/881bf241
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/881bf241
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/881bf241
Branch: refs/heads/master
Commit: 881bf241397bf1e710d28c05b8513660e0f2656d
Parents: 28a012d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Aug 1 13:47:46 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 5 11:56:01 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCHierarchy.c | 116 +++++++++++++++++++--------------------
1 file changed, 57 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/881bf241/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index 190c01d..672b7c1 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -66,22 +66,23 @@ typedef struct CFCFindFilesContext {
size_t num_paths;
} CFCFindFilesContext;
-typedef struct CFCParseParcelFilesContext {
- int is_included;
-} CFCParseParcelFilesContext;
+static void
+S_do_make_path(const char *path);
-// CFCUtil_walk() callback which parses .cfp files.
static void
-S_parse_parcel_files(const char *path, void *context);
+S_parse_parcel_files(const char *source_dir, int is_included);
static void
S_check_prereqs(CFCHierarchy *self);
static void
-S_do_make_path(const char *path);
+S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included);
static void
-S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included);
+S_find_files(const char *path, void *arg);
+
+static void
+S_free_find_files_context(CFCFindFilesContext *context);
static void
S_connect_classes(CFCHierarchy *self);
@@ -217,24 +218,21 @@ CFCHierarchy_add_prereq(CFCHierarchy *self, const char *parcel) {
void
CFCHierarchy_build(CFCHierarchy *self) {
// Read .cfp files.
- CFCParseParcelFilesContext context;
- context.is_included = false;
for (size_t i = 0; self->sources[i] != NULL; i++) {
- CFCUtil_walk(self->sources[i], S_parse_parcel_files, &context);
+ S_parse_parcel_files(self->sources[i], false);
}
- context.is_included = true;
for (size_t i = 0; self->includes[i] != NULL; i++) {
- CFCUtil_walk(self->includes[i], S_parse_parcel_files, &context);
+ S_parse_parcel_files(self->includes[i], true);
}
S_check_prereqs(self);
// Read .cfh files.
for (size_t i = 0; self->sources[i] != NULL; i++) {
- S_parse_cf_files(self, self->sources[i], 0);
+ S_parse_cf_files(self, self->sources[i], false);
}
for (size_t i = 0; self->includes[i] != NULL; i++) {
- S_parse_cf_files(self, self->includes[i], 1);
+ S_parse_cf_files(self, self->includes[i], true);
}
for (int i = 0; self->classes[i] != NULL; i++) {
@@ -248,24 +246,22 @@ CFCHierarchy_build(CFCHierarchy *self) {
}
static void
-S_parse_parcel_files(const char *path, void *arg) {
- CFCParseParcelFilesContext *context = (CFCParseParcelFilesContext*)arg;
-
- // Ignore hidden files.
- if (strstr(path, CHY_DIR_SEP ".") != NULL) {
- return;
- }
+S_parse_parcel_files(const char *source_dir, int is_included) {
+ CFCFindFilesContext context;
+ context.ext = ".cfp";
+ context.paths = (char**)CALLOCATE(1, sizeof(char*));
+ context.num_paths = 0;
+ CFCUtil_walk(source_dir, S_find_files, &context);
// Parse .cfp files and register the parcels they define.
- size_t path_len = strlen(path);
- if (path_len > 4 && (strcmp((path + path_len - 4), ".cfp") == 0)) {
- CFCParcel *parcel = CFCParcel_new_from_file(path,
- context->is_included);
+ for (int i = 0; context.paths[i] != NULL; i++) {
+ const char *path = context.paths[i];
+ CFCParcel *parcel = CFCParcel_new_from_file(path, is_included);
const char *name = CFCParcel_get_name(parcel);
CFCParcel *existing = CFCParcel_fetch(name);
if (existing) {
if (!CFCParcel_equals(parcel, existing)) {
- if (context->is_included && !CFCParcel_included(existing)) {
+ if (is_included && !CFCParcel_included(existing)) {
// Allow clash between source and include dirs.
CFCUtil_warn("Warning: Parcel %s from source dir takes "
"precedence over parcel from include dir",
@@ -282,6 +278,8 @@ S_parse_parcel_files(const char *path, void *arg) {
}
CFCBase_decref((CFCBase*)parcel);
}
+
+ S_free_find_files_context(&context);
}
static void
@@ -308,39 +306,6 @@ S_check_prereqs(CFCHierarchy *self) {
}
static void
-S_find_files(const char *path, void *arg) {
- // Ignore updirs and hidden files.
- if (strstr(path, CHY_DIR_SEP ".") != NULL) {
- return;
- }
-
- CFCFindFilesContext *context = (CFCFindFilesContext*)arg;
- const char *ext = context->ext;
- size_t path_len = strlen(path);
- size_t ext_len = strlen(ext);
-
- if (path_len > ext_len && (strcmp(path + path_len - ext_len, ext) == 0)) {
- size_t num_paths = context->num_paths;
- size_t size = (num_paths + 2) * sizeof(char*);
- char **paths = (char**)REALLOCATE(context->paths, size);
-
- paths[num_paths] = CFCUtil_strdup(path);
- paths[num_paths + 1] = NULL;
-
- context->num_paths++;
- context->paths = paths;
- }
-}
-
-static void
-S_free_find_files_context(CFCFindFilesContext *context) {
- for (int i = 0; context->paths[i] != NULL; i++) {
- FREEMEM(context->paths[i]);
- }
- FREEMEM(context->paths);
-}
-
-static void
S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
CFCFindFilesContext context;
context.ext = ".cfh";
@@ -420,6 +385,39 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
}
static void
+S_find_files(const char *path, void *arg) {
+ // Ignore updirs and hidden files.
+ if (strstr(path, CHY_DIR_SEP ".") != NULL) {
+ return;
+ }
+
+ CFCFindFilesContext *context = (CFCFindFilesContext*)arg;
+ const char *ext = context->ext;
+ size_t path_len = strlen(path);
+ size_t ext_len = strlen(ext);
+
+ if (path_len > ext_len && (strcmp(path + path_len - ext_len, ext) == 0)) {
+ size_t num_paths = context->num_paths;
+ size_t size = (num_paths + 2) * sizeof(char*);
+ char **paths = (char**)REALLOCATE(context->paths, size);
+
+ paths[num_paths] = CFCUtil_strdup(path);
+ paths[num_paths + 1] = NULL;
+
+ context->num_paths++;
+ context->paths = paths;
+ }
+}
+
+static void
+S_free_find_files_context(CFCFindFilesContext *context) {
+ for (int i = 0; context->paths[i] != NULL; i++) {
+ FREEMEM(context->paths[i]);
+ }
+ FREEMEM(context->paths);
+}
+
+static void
S_connect_classes(CFCHierarchy *self) {
// Wrangle the classes into hierarchies and figure out inheritance.
for (int i = 0; self->classes[i] != NULL; i++) {