You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2014/04/12 08:49:46 UTC
[lucy-commits] [11/27] Remove bundled Clownfish.
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCRuby.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCRuby.c b/clownfish/compiler/src/CFCRuby.c
deleted file mode 100644
index b69b9d2..0000000
--- a/clownfish/compiler/src/CFCRuby.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "charmony.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <ctype.h>
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCClass.h"
-#include "CFCHierarchy.h"
-#include "CFCParcel.h"
-#include "CFCRuby.h"
-#include "CFCUtil.h"
-
-struct CFCRuby {
- CFCBase base;
- CFCParcel *parcel;
- CFCHierarchy *hierarchy;
- char *lib_dir;
- char *boot_class;
- char *header;
- char *footer;
- char *boot_h_file;
- char *boot_c_file;
- char *boot_h_path;
- char *boot_c_path;
- char *boot_func;
-};
-
-// Modify a string in place, swapping out "::" for the supplied character.
-static void
-S_replace_double_colons(char *text, char replacement);
-
-static const CFCMeta CFCRUBY_META = {
- "Clownfish::CFC::Binding::Ruby",
- sizeof(CFCRuby),
- (CFCBase_destroy_t)CFCRuby_destroy
-};
-
-CFCRuby*
-CFCRuby_new(CFCParcel *parcel, CFCHierarchy *hierarchy, const char *lib_dir,
- const char *boot_class, const char *header, const char *footer) {
- CFCRuby *self = (CFCRuby*)CFCBase_allocate(&CFCRUBY_META);
- return CFCRuby_init(self, parcel, hierarchy, lib_dir, boot_class, header,
- footer);
-}
-
-CFCRuby*
-CFCRuby_init(CFCRuby *self, CFCParcel *parcel, CFCHierarchy *hierarchy,
- const char *lib_dir, const char *boot_class, const char *header,
- const char *footer) {
- CFCUTIL_NULL_CHECK(parcel);
- CFCUTIL_NULL_CHECK(hierarchy);
- CFCUTIL_NULL_CHECK(lib_dir);
- CFCUTIL_NULL_CHECK(boot_class);
- CFCUTIL_NULL_CHECK(header);
- CFCUTIL_NULL_CHECK(footer);
- self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
- self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
- self->lib_dir = CFCUtil_strdup(lib_dir);
- self->boot_class = CFCUtil_strdup(boot_class);
- self->header = CFCUtil_strdup(header);
- self->footer = CFCUtil_strdup(footer);
-
- const char *prefix = CFCParcel_get_prefix(parcel);
- const char *inc_dest = CFCHierarchy_get_include_dest(hierarchy);
- const char *src_dest = CFCHierarchy_get_source_dest(hierarchy);
- self->boot_h_file = CFCUtil_sprintf("%sboot.h", prefix);
- self->boot_c_file = CFCUtil_sprintf("%sboot.c", prefix);
- self->boot_h_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s", inc_dest,
- self->boot_h_file);
- self->boot_c_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s", src_dest,
- self->boot_c_file);
- self->boot_func = CFCUtil_sprintf("%s%s_bootstrap", prefix, boot_class);
-
- for (int i = 0; self->boot_func[i] != 0; i++) {
- if (!isalnum(self->boot_func[i])) {
- self->boot_func[i] = '_';
- }
- }
-
- return self;
-}
-
-void
-CFCRuby_destroy(CFCRuby *self) {
- CFCBase_decref((CFCBase*)self->parcel);
- CFCBase_decref((CFCBase*)self->hierarchy);
- FREEMEM(self->lib_dir);
- FREEMEM(self->boot_class);
- FREEMEM(self->header);
- FREEMEM(self->footer);
- FREEMEM(self->boot_h_file);
- FREEMEM(self->boot_c_file);
- FREEMEM(self->boot_h_path);
- FREEMEM(self->boot_c_path);
- FREEMEM(self->boot_func);
- CFCBase_destroy((CFCBase*)self);
-}
-
-static void
-S_replace_double_colons(char *text, char replacement) {
- size_t pos = 0;
- for (char *ptr = text; *ptr != '\0'; ptr++) {
- if (strncmp(ptr, "::", 2) == 0) {
- text[pos++] = replacement;
- ptr++;
- }
- else {
- text[pos++] = *ptr;
- }
- }
- text[pos] = '\0';
-}
-
-static void
-S_write_boot_h(CFCRuby *self) {
- char *guard = CFCUtil_cat(CFCUtil_strdup(""), self->boot_class,
- "_BOOT", NULL);
- S_replace_double_colons(guard, '_');
- for (char *ptr = guard; *ptr != '\0'; ptr++) {
- if (isalpha(*ptr)) {
- *ptr = toupper(*ptr);
- }
- }
-
- const char pattern[] =
- "%s\n"
- "\n"
- "#ifndef %s\n"
- "#define %s 1\n"
- "\n"
- "void\n"
- "%s();\n"
- "\n"
- "#endif /* %s */\n"
- "\n"
- "%s\n";
-
- size_t size = sizeof(pattern)
- + strlen(self->header)
- + strlen(guard)
- + strlen(guard)
- + strlen(self->boot_func)
- + strlen(guard)
- + strlen(self->footer)
- + 20;
- char *content = (char*)MALLOCATE(size);
- sprintf(content, pattern, self->header, guard, guard, self->boot_func,
- guard, self->footer);
- CFCUtil_write_file(self->boot_h_path, content, strlen(content));
-
- FREEMEM(content);
- FREEMEM(guard);
-}
-
-static void
-S_write_boot_c(CFCRuby *self) {
- CFCClass **ordered = CFCHierarchy_ordered_classes(self->hierarchy);
- char *pound_includes = CFCUtil_strdup("");
- const char *prefix = CFCParcel_get_prefix(self->parcel);
-
- for (size_t i = 0; ordered[i] != NULL; i++) {
- CFCClass *klass = ordered[i];
- if (CFCClass_included(klass)) { continue; }
-
- const char *include_h = CFCClass_include_h(klass);
- pound_includes = CFCUtil_cat(pound_includes, "#include \"",
- include_h, "\"\n", NULL);
-
- if (CFCClass_inert(klass)) { continue; }
-
- CFCClass *parent = CFCClass_get_parent(klass);
- if (parent) {
- /* Need to implement */
- }
- }
-
- const char pattern[] =
- "%s\n"
- "\n"
- "#include \"charmony.h\"\n"
- "#include \"%s\"\n"
- "#include \"%sparcel.h\"\n"
- "#include \"Clownfish/String.h\"\n"
- "#include \"Clownfish/VTable.h\"\n"
- "%s\n"
- "\n"
- "void\n"
- "%s() {\n"
- " %sbootstrap_parcel();\n"
- "\n"
- " cfish_StackString *alias = CFISH_SSTR_WRAP_UTF8(\"\", 0);\n"
- "}\n"
- "\n"
- "%s\n"
- "\n";
-
- char *content
- = CFCUtil_sprintf(pattern, self->header, self->boot_h_file, prefix,
- pound_includes, self->boot_func, prefix,
- self->footer);
- CFCUtil_write_file(self->boot_c_path, content, strlen(content));
-
- FREEMEM(content);
- FREEMEM(pound_includes);
- FREEMEM(ordered);
-}
-
-void
-CFCRuby_write_boot(CFCRuby *self) {
- S_write_boot_h(self);
- S_write_boot_c(self);
-}
-
-void
-CFCRuby_write_hostdefs(CFCRuby *self) {
- const char pattern[] =
- "%s\n"
- "\n"
- "#ifndef H_CFISH_HOSTDEFS\n"
- "#define H_CFISH_HOSTDEFS 1\n"
- "\n"
- "/* Refcount / host object */\n"
- "typedef union {\n"
- " size_t count;\n"
- " void *host_obj;\n"
- "} cfish_ref_t;\n"
- "\n"
- "#define CFISH_OBJ_HEAD\\\n"
- " cfish_ref_t ref;\n"
- "\n"
- "#endif /* H_CFISH_HOSTDEFS */\n"
- "\n"
- "%s\n";
- char *content
- = CFCUtil_sprintf(pattern, self->header, self->footer);
-
- // Unlink then write file.
- const char *inc_dest = CFCHierarchy_get_include_dest(self->hierarchy);
- char *filepath = CFCUtil_sprintf("%s" CHY_DIR_SEP "cfish_hostdefs.h",
- inc_dest);
- remove(filepath);
- CFCUtil_write_file(filepath, content, strlen(content));
- FREEMEM(filepath);
-
- FREEMEM(content);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCRuby.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCRuby.h b/clownfish/compiler/src/CFCRuby.h
deleted file mode 100644
index ebe2cfa..0000000
--- a/clownfish/compiler/src/CFCRuby.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef H_CFCRUBY
-#define H_CFCRUBY
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCRuby CFCRuby;
-struct CFCParcel;
-struct CFCHierarchy;
-
-/** Clownfish::CFC::Binding::Ruby - Perl bindings for a
- * Clownfish::CFC::Model::Hierarchy.
- *
- * Clownfish::CFC::Binding::Ruby presents an interface for auto-generating XS
- * and Perl code to bind C code for a Clownfish class hierarchy to Perl.
- *
- * In theory this module could be much more flexible and its API could be more
- * elegant. There are many ways which you could walk the parsed parcels,
- * classes, methods, etc. in a Clownfish::CFC::Model::Hierarchy and generate
- * binding code. However, our needs are very limited, so we are content with
- * a "one size fits one" solution.
- *
- * In particular, this module assumes that the XS bindings for all classes in
- * the hierarchy should be assembled into a single shared object which belongs
- * to the primary, "boot" class. There's no reason why it could not write one
- * .xs file per class, or one per parcel, instead.
- *
- * The files written by this class are derived from the name of the boot class.
- * If it is "Crustacean", the following files will be generated.
- *
- * # Generated by write_bindings()
- * $lib_dir/Crustacean.xs
- *
- * # Generated by write_boot()
- * $hierarchy_dest_dir/crust_boot.h
- * $hierarchy_dest_dir/crust_boot.c
- */
-
-/**
- * @param parcel The L<Clownfish::CFC::Model::Parcel> to which the
- * C<boot_class> belongs.
- * @param hierarchy A Clownfish::CFC::Model::Hierarchy.
- * @param lib_dir location of the Perl lib directory to which files will be
- * written.
- * @param boot_class The name of the main class, which will own the shared
- * object.
- * @param header Text which will be prepended to generated C/XS files --
- * typically, an "autogenerated file" warning.
- * @param footer Text to be appended to the end of generated C/XS files --
- * typically copyright information.
- */
-CFCRuby*
-CFCRuby_new(struct CFCParcel *parcel, struct CFCHierarchy *hierarchy,
- const char *lib_dir, const char *boot_class, const char *header,
- const char *footer);
-
-CFCRuby*
-CFCRuby_init(CFCRuby *self, struct CFCParcel *parcel,
- struct CFCHierarchy *hierarchy, const char *lib_dir,
- const char *boot_class, const char *header, const char *footer);
-
-void
-CFCRuby_destroy(CFCRuby *self);
-
-/** Write out "boot" files to the Hierarchy's "dest_dir" which contain code
- * for bootstrapping Clownfish classes.
- */
-void
-CFCRuby_write_boot(CFCRuby *self);
-
-/** Write out cfish_hostdefs.h file.
- */
-void
-CFCRuby_write_hostdefs(CFCRuby *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCPERL */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCSymbol.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCSymbol.c b/clownfish/compiler/src/CFCSymbol.c
deleted file mode 100644
index 4d06677..0000000
--- a/clownfish/compiler/src/CFCSymbol.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-#include <ctype.h>
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-#define CFC_NEED_SYMBOL_STRUCT_DEF
-#include "CFCSymbol.h"
-#include "CFCParcel.h"
-#include "CFCUtil.h"
-
-static const CFCMeta CFCSYMBOL_META = {
- "Clownfish::CFC::Model::Symbol",
- sizeof(CFCSymbol),
- (CFCBase_destroy_t)CFCSymbol_destroy
-};
-
-CFCSymbol*
-CFCSymbol_new(struct CFCParcel *parcel, const char *exposure,
- const char *class_name, const char *class_cnick,
- const char *micro_sym) {
- CFCSymbol *self = (CFCSymbol*)CFCBase_allocate(&CFCSYMBOL_META);
- return CFCSymbol_init(self, parcel, exposure, class_name, class_cnick,
- micro_sym);
-}
-
-static int
-S_validate_exposure(const char *exposure) {
- if (!exposure) { return false; }
- if (strcmp(exposure, "public")
- && strcmp(exposure, "parcel")
- && strcmp(exposure, "private")
- && strcmp(exposure, "local")
- ) {
- return false;
- }
- return true;
-}
-
-static int
-S_validate_class_name(const char *class_name) {
- // The last component must contain lowercase letters (for now).
- const char *last_colon = strrchr(class_name, ':');
- const char *substring = last_colon ? last_colon + 1 : class_name;
- for (;;substring++) {
- if (*substring == 0) { return false; }
- else if (*substring == ':') { return false; }
- else if (islower(*substring)) { break; }
- }
-
- // Must be UpperCamelCase, separated by "::".
- const char *ptr = class_name;
- if (!isupper(*ptr)) { return false; }
- while (*ptr != 0) {
- if (*ptr == 0) { break; }
- else if (*ptr == ':') {
- ptr++;
- if (*ptr != ':') { return false; }
- ptr++;
- if (!isupper(*ptr)) { return false; }
- ptr++;
- }
- else if (!isalnum(*ptr)) { return false; }
- else { ptr++; }
- }
-
- return true;
-}
-
-int
-CFCSymbol_validate_class_name_component(const char *name) {
- if (!name || !strlen(name)) { return false; }
- if (!S_validate_class_name(name)) { return false; }
- if (strchr(name, ':') != NULL) { return false; }
- return true;
-}
-
-static int
-S_validate_class_cnick(const char *class_cnick) {
- // Allow all caps.
- const char *ptr;
- for (ptr = class_cnick; ; ptr++) {
- if (*ptr == 0) {
- if (strlen(class_cnick)) { return true; }
- else { break; }
- }
- else if (!isupper(*ptr)) { break; }
- }
-
- // Same as one component of a class name.
- return CFCSymbol_validate_class_name_component(class_cnick);
-}
-
-static int
-S_validate_identifier(const char *identifier) {
- const char *ptr = identifier;
- if (!isalpha(*ptr) && *ptr != '_') { return false; }
- for (; *ptr != 0; ptr++) {
- if (!isalnum(*ptr) && *ptr != '_') { return false; }
- }
- return true;
-}
-
-CFCSymbol*
-CFCSymbol_init(CFCSymbol *self, struct CFCParcel *parcel,
- const char *exposure, const char *class_name,
- const char *class_cnick, const char *micro_sym) {
- // Validate.
- CFCUTIL_NULL_CHECK(parcel);
- if (!S_validate_exposure(exposure)) {
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Invalid exposure: '%s'", exposure ? exposure : "[NULL]");
- }
- if (class_name && !S_validate_class_name(class_name)) {
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Invalid class_name: '%s'", class_name);
- }
- if (!micro_sym || !S_validate_identifier(micro_sym)) {
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Invalid micro_sym: '%s'", micro_sym ? micro_sym : "[NULL]");
- }
-
- // Derive class_cnick if necessary, then validate.
- const char *real_cnick = NULL;
- if (class_name) {
- if (class_cnick) {
- real_cnick = class_cnick;
- }
- else {
- const char *last_colon = strrchr(class_name, ':');
- real_cnick = last_colon ? last_colon + 1 : class_name;
- }
- }
- else if (class_cnick) {
- // Sanity check class_cnick without class_name.
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Can't supply class_cnick without class_name");
- }
- else {
- real_cnick = NULL;
- }
- if (real_cnick && !S_validate_class_cnick(real_cnick)) {
- CFCBase_decref((CFCBase*)self);
- CFCUtil_die("Invalid class_cnick: '%s'", real_cnick);
- }
-
- // Assign.
- self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
- self->exposure = CFCUtil_strdup(exposure);
- self->class_name = CFCUtil_strdup(class_name);
- self->class_cnick = CFCUtil_strdup(real_cnick);
- self->micro_sym = CFCUtil_strdup(micro_sym);
-
- // Derive short_sym and full_sym.
- char *cnick = self->class_cnick ? self->class_cnick : "";
- self->short_sym = CFCUtil_sprintf("%s_%s", cnick, micro_sym);
- self->full_sym
- = CFCUtil_sprintf("%s%s", CFCParcel_get_prefix(self->parcel),
- self->short_sym);
-
- return self;
-}
-
-void
-CFCSymbol_destroy(CFCSymbol *self) {
- CFCBase_decref((CFCBase*)self->parcel);
- FREEMEM(self->exposure);
- FREEMEM(self->class_name);
- FREEMEM(self->class_cnick);
- FREEMEM(self->micro_sym);
- FREEMEM(self->short_sym);
- FREEMEM(self->full_sym);
- CFCBase_destroy((CFCBase*)self);
-}
-
-int
-CFCSymbol_equals(CFCSymbol *self, CFCSymbol *other) {
- if (strcmp(self->micro_sym, other->micro_sym) != 0) { return false; }
- if (!CFCParcel_equals(self->parcel, other->parcel)) { return false; }
- if (strcmp(self->exposure, other->exposure) != 0) { return false; }
- if (self->class_name) {
- if (!other->class_name) { return false; }
- if (strcmp(self->class_name, other->class_name) != 0) {
- return false;
- }
- }
- else if (other->class_name) {
- return false;
- }
- return true;
-}
-
-int
-CFCSymbol_public(CFCSymbol *self) {
- return !strcmp(self->exposure, "public");
-}
-
-int
-CFCSymbol_parcel(CFCSymbol *self) {
- return !strcmp(self->exposure, "parcel");
-}
-
-int
-CFCSymbol_private(CFCSymbol *self) {
- return !strcmp(self->exposure, "private");
-}
-
-int
-CFCSymbol_local(CFCSymbol *self) {
- return !strcmp(self->exposure, "local");
-}
-
-const char*
-CFCSymbol_full_sym(CFCSymbol *self) {
- return self->full_sym;
-}
-
-const char*
-CFCSymbol_short_sym(CFCSymbol *self) {
- return self->short_sym;
-}
-
-struct CFCParcel*
-CFCSymbol_get_parcel(CFCSymbol *self) {
- return self->parcel;
-}
-
-const char*
-CFCSymbol_get_class_name(CFCSymbol *self) {
- return self->class_name;
-}
-
-const char*
-CFCSymbol_get_class_cnick(CFCSymbol *self) {
- return self->class_cnick;
-}
-
-const char*
-CFCSymbol_get_exposure(CFCSymbol *self) {
- return self->exposure;
-}
-
-const char*
-CFCSymbol_micro_sym(CFCSymbol *self) {
- return self->micro_sym;
-}
-
-const char*
-CFCSymbol_get_prefix(CFCSymbol *self) {
- return CFCParcel_get_prefix(self->parcel);
-}
-
-const char*
-CFCSymbol_get_Prefix(CFCSymbol *self) {
- return CFCParcel_get_Prefix(self->parcel);
-}
-
-const char*
-CFCSymbol_get_PREFIX(CFCSymbol *self) {
- return CFCParcel_get_PREFIX(self->parcel);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCSymbol.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCSymbol.h b/clownfish/compiler/src/CFCSymbol.h
deleted file mode 100644
index 2777c2c..0000000
--- a/clownfish/compiler/src/CFCSymbol.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** Clownfish::CFC::Model::Symbol - Base class for Clownfish symbols.
- *
- * Clownfish::CFC::Model::Symbol serves as a parent class for entities which
- * may live in the global namespace, such as classes, functions, methods, and
- * variables.
- */
-
-#ifndef H_CFCSYMBOL
-#define H_CFCSYMBOL
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct CFCSymbol CFCSymbol;
-struct CFCParcel;
-
-#ifdef CFC_NEED_SYMBOL_STRUCT_DEF
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-struct CFCSymbol {
- CFCBase base;
- struct CFCParcel *parcel;
- char *exposure;
- char *class_name;
- char *class_cnick;
- char *micro_sym;
- char *short_sym;
- char *full_sym;
-};
-#endif
-
-/** Return true if the supplied string is comprised solely of alphanumeric
- * characters, begins with an uppercase letter, and contains at least one
- * lower case letter.
- */
-int
-CFCSymbol_validate_class_name_component(const char *name);
-
-/**
- * @param parcel A Clownfish::CFC::Model::Parcel. If not supplied, will be
- * assigned to the default Parcel.
- * @param exposure The scope in which the symbol is exposed. Must be
- * 'public', 'parcel', 'private', or 'local'.
- * @param class_name A optional class name, consisting of one or more
- * components separated by "::". Each component must start with a capital
- * letter, contain at least one lower-case letter, and consist entirely of the
- * characters [A-Za-z0-9].
- * @param class_cnick The C nickname associated with the supplied class
- * name. If not supplied, will be derived if possible from C<class_name> by
- * extracting the last class name component.
- * @param micro_sym The local identifier for the symbol.
- */
-CFCSymbol*
-CFCSymbol_new(struct CFCParcel *parcel, const char *exposure, const char *class_name,
- const char *class_cnick, const char *micro_sym);
-
-CFCSymbol*
-CFCSymbol_init(CFCSymbol *self, struct CFCParcel *parcel, const char *exposure,
- const char *class_name, const char *class_cnick,
- const char *micro_sym);
-
-void
-CFCSymbol_destroy(CFCSymbol *self);
-
-/** Return true if the symbols are "equal", false otherwise.
- */
-int
-CFCSymbol_equals(CFCSymbol *self, CFCSymbol *other);
-
-struct CFCParcel*
-CFCSymbol_get_parcel(CFCSymbol *self);
-
-// May be NULL.
-const char*
-CFCSymbol_get_class_name(CFCSymbol *self);
-
-// May be NULL.
-const char*
-CFCSymbol_get_class_cnick(CFCSymbol *self);
-
-const char*
-CFCSymbol_get_exposure(CFCSymbol *self);
-
-/** Return true if the Symbol's exposure is "public".
- */
-int
-CFCSymbol_public(CFCSymbol *self);
-
-/** Return true if the Symbol's exposure is "parcel".
- */
-int
-CFCSymbol_parcel(CFCSymbol *self);
-
-/** Return true if the Symbol's exposure is "private".
- */
-int
-CFCSymbol_private(CFCSymbol *self);
-
-/** Return true if the Symbol's exposure is "local".
- */
-int
-CFCSymbol_local(CFCSymbol *self);
-
-/** Accessor for the Symbol's micro_sym.
- */
-const char*
-CFCSymbol_micro_sym(CFCSymbol *self);
-
-/** Returns the C representation for the symbol minus the parcel's prefix,
- * e.g. "Lobster_average_lifespan".
- */
-const char*
-CFCSymbol_short_sym(CFCSymbol *self);
-
-/** Returns the fully qualified C representation for the symbol, e.g.
- * "crust_Lobster_average_lifespan".
- */
-const char*
-CFCSymbol_full_sym(CFCSymbol *self);
-
-/** Get the Symbol's all-lowercase prefix, delegating to <code>parcel</code>.
- */
-const char*
-CFCSymbol_get_prefix(CFCSymbol *self);
-
-/** Get the Symbol's Titlecase prefix, delegating to <code>parcel</code>.
- */
-const char*
-CFCSymbol_get_Prefix(CFCSymbol *self);
-
-/** Get the Symbol's all-uppercase prefix, delegating to <code>parcel</code>.
- */
-const char*
-CFCSymbol_get_PREFIX(CFCSymbol *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* H_CFCSYMBOL */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTest.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTest.c b/clownfish/compiler/src/CFCTest.c
deleted file mode 100644
index 21cff48..0000000
--- a/clownfish/compiler/src/CFCTest.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "charmony.h"
-
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#define CFC_USE_TEST_MACROS
-#include "CFCTest.h"
-#include "CFCBase.h"
-#include "CFCParser.h"
-#include "CFCUtil.h"
-
-typedef struct CFCTestFormatter {
- void (*batch_prologue)(const CFCTestBatch *batch);
- void (*vtest_result)(int pass, int test_num, const char *fmt,
- va_list args);
- void (*test_comment)(const char *fmt, ...);
- void (*batch_comment)(const char *fmt, ...);
- void (*summary)(const CFCTest *test);
-} CFCTestFormatter;
-
-struct CFCTest {
- CFCBase base;
- const CFCTestFormatter *formatter;
- int num_tests;
- int num_tests_failed;
- int num_batches;
- int num_batches_failed;
- int num_tests_in_batch;
- int num_failed_in_batch;
-};
-
-static int
-S_do_run_batch(CFCTest *self, const CFCTestBatch *batch);
-
-static void
-S_vtest_true(CFCTest *self, int cond, const char *fmt, va_list args);
-
-static void
-S_format_cfish_batch_prologue(const CFCTestBatch *batch);
-
-static void
-S_format_cfish_vtest_result(int pass, int test_num, const char *fmt,
- va_list args);
-
-static void
-S_format_cfish_test_comment(const char *fmt, ...);
-
-static void
-S_format_cfish_batch_comment(const char *fmt, ...);
-
-static void
-S_format_cfish_summary(const CFCTest *test);
-
-static void
-S_format_tap_batch_prologue(const CFCTestBatch *batch);
-
-static void
-S_format_tap_vtest_result(int pass, int test_num, const char *fmt,
- va_list args);
-
-static void
-S_format_tap_test_comment(const char *fmt, ...);
-
-static void
-S_format_tap_batch_comment(const char *fmt, ...);
-
-static void
-S_format_tap_summary(const CFCTest *test);
-
-static const CFCMeta CFCTEST_META = {
- "Clownfish::CFC::Test",
- sizeof(CFCTest),
- (CFCBase_destroy_t)CFCTest_destroy
-};
-
-static const CFCTestFormatter S_formatter_cfish = {
- S_format_cfish_batch_prologue,
- S_format_cfish_vtest_result,
- S_format_cfish_test_comment,
- S_format_cfish_batch_comment,
- S_format_cfish_summary
-};
-
-static const CFCTestFormatter S_formatter_tap = {
- S_format_tap_batch_prologue,
- S_format_tap_vtest_result,
- S_format_tap_test_comment,
- S_format_tap_batch_comment,
- S_format_tap_summary
-};
-
-static const CFCTestBatch *const S_batches[] = {
- &CFCTEST_BATCH_UTIL,
- &CFCTEST_BATCH_DOCU_COMMENT,
- &CFCTEST_BATCH_SYMBOL,
- &CFCTEST_BATCH_VERSION,
- &CFCTEST_BATCH_TYPE,
- &CFCTEST_BATCH_FUNCTION,
- &CFCTEST_BATCH_METHOD,
- &CFCTEST_BATCH_VARIABLE,
- &CFCTEST_BATCH_PARAM_LIST,
- &CFCTEST_BATCH_FILE_SPEC,
- &CFCTEST_BATCH_CLASS,
- &CFCTEST_BATCH_C_BLOCK,
- &CFCTEST_BATCH_PARCEL,
- &CFCTEST_BATCH_FILE,
- &CFCTEST_BATCH_HIERARCHY,
- &CFCTEST_BATCH_PARSER,
- NULL
-};
-
-CFCTest*
-CFCTest_new(const char *formatter_name) {
- CFCTest *self = (CFCTest*)CFCBase_allocate(&CFCTEST_META);
- return CFCTest_init(self, formatter_name);
-}
-
-CFCTest*
-CFCTest_init(CFCTest *self, const char *formatter_name) {
- if (strcmp(formatter_name, "clownfish") == 0) {
- self->formatter = &S_formatter_cfish;
- }
- else if (strcmp(formatter_name, "tap") == 0) {
- self->formatter = &S_formatter_tap;
- }
- else {
- CFCUtil_die("Unknown formatter name '%s'", formatter_name);
- }
-
- self->num_tests = 0;
- self->num_tests_failed = 0;
- self->num_batches = 0;
- self->num_batches_failed = 0;
- self->num_tests_in_batch = 0;
- self->num_failed_in_batch = 0;
-
- return self;
-}
-
-void
-CFCTest_destroy(CFCTest *self) {
- CFCBase_destroy((CFCBase*)self);
-}
-
-int
-CFCTest_run_all(CFCTest *self) {
- int failed = 0;
-
- for (int i = 0; S_batches[i]; ++i) {
- if (!S_do_run_batch(self, S_batches[i])) { failed = 1; }
- }
-
- return !failed;
-}
-
-int
-CFCTest_run_batch(CFCTest *self, const char *name) {
- for (int i = 0; S_batches[i]; ++i) {
- const CFCTestBatch *batch = S_batches[i];
- if (strcmp(batch->name, name) == 0) {
- return S_do_run_batch(self, batch);
- }
- }
-
- CFCUtil_die("Test batch '%s' not found", name);
- return 0;
-}
-
-static int
-S_do_run_batch(CFCTest *self, const CFCTestBatch *batch) {
- self->formatter->batch_prologue(batch);
-
- batch->run(self);
-
- int failed = 0;
- void (*comment)(const char *fmt, ...) = self->formatter->batch_comment;
-
- if (self->num_failed_in_batch > 0) {
- failed = 1;
- comment("%d/%d tests failed.\n", self->num_failed_in_batch,
- self->num_tests_in_batch);
- }
- if (self->num_tests_in_batch != batch->num_planned) {
- failed = 1;
- comment("Bad plan: You planned %d tests but ran %d.\n",
- batch->num_planned, self->num_tests_in_batch);
- }
-
- if (failed) {
- self->num_batches_failed += 1;
- }
-
- self->num_batches += 1;
- self->num_tests_in_batch = 0;
- self->num_failed_in_batch = 0;
-
- return !failed;
-}
-
-void
-CFCTest_test_true(CFCTest *self, int cond, const char *fmt, ...) {
- va_list args;
- va_start(args, fmt);
- S_vtest_true(self, cond, fmt, args);
- va_end(args);
-}
-
-void
-CFCTest_test_string_equals(CFCTest *self, const char *result,
- const char *expected, const char *fmt, ...) {
- int cond = (strcmp(result, expected) == 0);
-
- va_list args;
- va_start(args, fmt);
- S_vtest_true(self, cond, fmt, args);
- va_end(args);
-
- if (!cond) {
- self->formatter->test_comment("Expected '%s', got '%s'.\n",
- expected, result);
- }
-}
-
-void
-CFCTest_test_int_equals(CFCTest *self, long result, long expected,
- const char *fmt, ...) {
- int cond = (result == expected);
-
- va_list args;
- va_start(args, fmt);
- S_vtest_true(self, cond, fmt, args);
- va_end(args);
-
- if (!cond) {
- self->formatter->test_comment("Expected '%ld', got '%ld'.\n",
- expected, result);
- }
-}
-
-void
-CFCTest_skip(CFCTest *self, int num) {
- self->num_tests += num;
- self->num_tests_in_batch += num;
-}
-
-int
-CFCTest_finish(CFCTest *self) {
- self->formatter->summary(self);
-
- return self->num_batches != 0 && self->num_batches_failed == 0;
-}
-
-static void
-S_vtest_true(CFCTest *self, int cond, const char *fmt, va_list args) {
- self->num_tests += 1;
- self->num_tests_in_batch += 1;
-
- if (!cond) {
- self->num_tests_failed += 1;
- self->num_failed_in_batch += 1;
- }
-
- self->formatter->vtest_result(cond, self->num_tests_in_batch, fmt, args);
-}
-
-static void
-S_format_cfish_batch_prologue(const CFCTestBatch *batch) {
- printf("Testing %s...\n", batch->name);
-}
-
-static void
-S_format_cfish_vtest_result(int pass, int test_num, const char *fmt,
- va_list args) {
- if (!pass) {
- printf(" Failed test %d: ", test_num);
- vprintf(fmt, args);
- printf("\n");
- }
- else if (getenv("CFCTEST_VERBOSE")) {
- printf(" Passed test %d: ", test_num);
- vprintf(fmt, args);
- printf("\n");
- }
-}
-
-static void
-S_format_cfish_test_comment(const char *fmt, ...) {
- printf(" ");
-
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
-static void
-S_format_cfish_batch_comment(const char *fmt, ...) {
- printf(" ");
-
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
-static void
-S_format_cfish_summary(const CFCTest *test) {
- if (test->num_batches == 0) {
- printf("No tests planned or run.\n");
- }
- else if (test->num_batches_failed == 0) {
- printf("%d batches passed. %d tests passed.\n",
- test->num_batches, test->num_tests);
- printf("Result: PASS\n");
- }
- else {
- printf("%d/%d batches failed. %d/%d tests failed.\n",
- test->num_batches_failed, test->num_batches,
- test->num_tests_failed, test->num_tests);
- printf("Result: FAIL\n");
- }
-}
-
-static void
-S_format_tap_batch_prologue(const CFCTestBatch *batch) {
- printf("1..%d\n", batch->num_planned);
-}
-
-static void
-S_format_tap_vtest_result(int pass, int test_num, const char *fmt,
- va_list args) {
- const char *result = pass ? "ok" : "not ok";
- printf("%s %d - ", result, test_num);
- vprintf(fmt, args);
- printf("\n");
-}
-
-static void
-S_format_tap_test_comment(const char *fmt, ...) {
- printf("# ");
-
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
-static void
-S_format_tap_batch_comment(const char *fmt, ...) {
- printf("# ");
-
- va_list args;
- va_start(args, fmt);
- vprintf(fmt, args);
- va_end(args);
-}
-
-static void
-S_format_tap_summary(const CFCTest *test) {
- (void)test; // unused
-}
-
-struct CFCParcel*
-CFCTest_parse_parcel(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Parcel", "result class of '%s'", src);
- return (struct CFCParcel*)result;
-}
-
-struct CFCType*
-CFCTest_parse_type(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Type", "result class of '%s'", src);
- return (struct CFCType*)result;
-}
-
-struct CFCVariable*
-CFCTest_parse_variable(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Variable", "result class of '%s'", src);
- return (struct CFCVariable*)result;
-}
-
-struct CFCParamList*
-CFCTest_parse_param_list(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::ParamList", "result class of '%s'", src);
- return (struct CFCParamList*)result;
-}
-
-struct CFCFunction*
-CFCTest_parse_function(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Function", "result class of '%s'", src);
- return (struct CFCFunction*)result;
-}
-
-struct CFCMethod*
-CFCTest_parse_method(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse '%s'", src);
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Method", "result class of '%s'", src);
- return (struct CFCMethod*)result;
-}
-
-struct CFCClass*
-CFCTest_parse_class(CFCTest *test, CFCParser *parser, const char *src) {
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result != NULL, "parse class");
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::Class", "result class");
- return (struct CFCClass*)result;
-}
-
-time_t
-CFCTest_get_file_mtime(const char *path) {
- struct stat buf;
- if (stat(path, &buf)) {
- CFCUtil_die("Can't stat '%s': %s", path, strerror(errno));
- }
- return buf.st_mtime;
-}
-
-#if defined(CHY_HAS_UTIME_H)
-
-#include <utime.h>
-
-void
-CFCTest_set_file_times(const char *path, time_t time) {
- struct utimbuf buf;
- buf.actime = time;
- buf.modtime = time;
- if (utime(path, &buf)) {
- CFCUtil_die("Can't set file time of '%s': %s", path, strerror(errno));
- }
-}
-
-#elif defined(CHY_HAS_WINDOWS_H)
-
-#include <windows.h>
-
-void
-CFCTest_set_file_times(const char *path, time_t time) {
- HANDLE handle = CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, 0, NULL);
- if (handle == INVALID_HANDLE_VALUE) {
- CFCUtil_die("Can't open '%s': %u", path, GetLastError());
- }
- uint64_t ticks = 10000000 * (UINT64_C(11644473600) + time);
- FILETIME file_time;
- file_time.dwLowDateTime = (DWORD)ticks;
- file_time.dwHighDateTime = (DWORD)(ticks >> 32);
- if (!SetFileTime(handle, &file_time, &file_time, &file_time)) {
- CFCUtil_die("Can't set file time of '%s': %u", path, GetLastError());
- }
- CloseHandle(handle);
-}
-
-#else
-
-#error Need either utime.h or windows.h
-
-#endif
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTest.h
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTest.h b/clownfish/compiler/src/CFCTest.h
deleted file mode 100644
index dbb3a17..0000000
--- a/clownfish/compiler/src/CFCTest.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/** Clownfish::CFC::Test - An object to collect results from test runs and
- * print summaries in multiple formats.
- */
-
-#ifndef H_CFCTEST
-#define H_CFCTEST
-
-#include <time.h>
-
-#ifdef CFC_USE_TEST_MACROS
- #define OK CFCTest_test_true
- #define STR_EQ CFCTest_test_string_equals
- #define INT_EQ CFCTest_test_int_equals
-#endif
-
-typedef struct CFCTest CFCTest;
-
-typedef struct CFCTestBatch {
- const char *name;
- int num_planned;
- void (*run)(CFCTest *test);
-} CFCTestBatch;
-
-struct CFCClass;
-struct CFCFunction;
-struct CFCMethod;
-struct CFCParamList;
-struct CFCParcel;
-struct CFCParser;
-struct CFCType;
-struct CFCVariable;
-
-/** Create a new test object.
- *
- * @param formatter_name Name of the built-in formatter that should be used
- * to create the output. Supported values are "tap" for TAP output and
- * "clownfish" for the generic Clownfish format.
- * @return a new test object.
- */
-CFCTest*
-CFCTest_new(const char *formatter_name);
-
-CFCTest*
-CFCTest_init(CFCTest *self, const char *formatter_name);
-
-void
-CFCTest_destroy(CFCTest *self);
-
-/** Run all test batches.
- *
- * @return true if all tests were successful.
- */
-int
-CFCTest_run_all(CFCTest *self);
-
-/** Run a test batch by name.
- *
- * @param name Name of the test batch.
- * @return true if all tests in the batch were successful.
- */
-int
-CFCTest_run_batch(CFCTest *self, const char *name);
-
-/* Collect result of a test.
- *
- * @param cond Test condition. True if the test succeeded, false if it failed.
- * @param fmt printf-like format string describing the test.
- */
-void
-CFCTest_test_true(CFCTest *self, int cond, const char *fmt, ...);
-
-/* Test strings for equality and collect result.
- *
- * @param result Result string to be tested.
- * @param expected Expected result string.
- * @param fmt printf-like format string describing the test.
- */
-void
-CFCTest_test_string_equals(CFCTest *self, const char *result,
- const char *expected, const char *fmt, ...);
-
-/* Test integers for equality and collect result.
- *
- * @param result Result integer to be tested.
- * @param expected Expected result integer.
- * @param fmt printf-like format string describing the test.
- */
-void
-CFCTest_test_int_equals(CFCTest *self, long result, long expected,
- const char *fmt, ...);
-
-/* Skip tests.
- *
- * @param num Number of tests to skip.
- */
-void
-CFCTest_skip(CFCTest *self, int num);
-
-/* Finish testing.
- *
- * @return true if tests were run and all tests were successful.
- */
-int
-CFCTest_finish(CFCTest *self);
-
-/* Utility functions for tests. */
-
-struct CFCParcel*
-CFCTest_parse_parcel(CFCTest *test, struct CFCParser *parser, const char *src);
-
-struct CFCType*
-CFCTest_parse_type(CFCTest *test, struct CFCParser *parser, const char *src);
-
-struct CFCVariable*
-CFCTest_parse_variable(CFCTest *test, struct CFCParser *parser,
- const char *src);
-
-struct CFCParamList*
-CFCTest_parse_param_list(CFCTest *test, struct CFCParser *parser,
- const char *src);
-
-struct CFCFunction*
-CFCTest_parse_function(CFCTest *test, struct CFCParser *parser,
- const char *src);
-
-struct CFCMethod*
-CFCTest_parse_method(CFCTest *test, struct CFCParser *parser, const char *src);
-
-struct CFCClass*
-CFCTest_parse_class(CFCTest *test, struct CFCParser *parser, const char *src);
-
-time_t
-CFCTest_get_file_mtime(const char *path);
-
-void
-CFCTest_set_file_times(const char *path, time_t time);
-
-/* Test batch structs. */
-
-extern const CFCTestBatch CFCTEST_BATCH_CLASS;
-extern const CFCTestBatch CFCTEST_BATCH_C_BLOCK;
-extern const CFCTestBatch CFCTEST_BATCH_DOCU_COMMENT;
-extern const CFCTestBatch CFCTEST_BATCH_FILE;
-extern const CFCTestBatch CFCTEST_BATCH_FILE_SPEC;
-extern const CFCTestBatch CFCTEST_BATCH_FUNCTION;
-extern const CFCTestBatch CFCTEST_BATCH_HIERARCHY;
-extern const CFCTestBatch CFCTEST_BATCH_METHOD;
-extern const CFCTestBatch CFCTEST_BATCH_PARAM_LIST;
-extern const CFCTestBatch CFCTEST_BATCH_PARCEL;
-extern const CFCTestBatch CFCTEST_BATCH_PARSER;
-extern const CFCTestBatch CFCTEST_BATCH_SYMBOL;
-extern const CFCTestBatch CFCTEST_BATCH_TYPE;
-extern const CFCTestBatch CFCTEST_BATCH_UTIL;
-extern const CFCTestBatch CFCTEST_BATCH_VARIABLE;
-extern const CFCTestBatch CFCTEST_BATCH_VERSION;
-
-#endif /* H_CFCTEST */
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestCBlock.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestCBlock.c b/clownfish/compiler/src/CFCTestCBlock.c
deleted file mode 100644
index 6061d44..0000000
--- a/clownfish/compiler/src/CFCTestCBlock.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCCBlock.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_C_BLOCK = {
- "Clownfish::CFC::Model::CBlock",
- 4,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
-
- {
- CFCCBlock *block = CFCCBlock_new("int foo;");
- STR_EQ(test, CFCCBlock_get_contents(block), "int foo;",
- "get_contents");
- CFCBase_decref((CFCBase*)block);
- }
-
- {
- const char *cblock_string =
- " __C__\n"
- "#define FOO_BAR 1\n"
- "__END_C__ ";
- CFCBase *result = CFCParser_parse(parser, cblock_string);
- OK(test, result != NULL, "parse cblock");
- STR_EQ(test, CFCBase_get_cfc_class(result),
- "Clownfish::CFC::Model::CBlock", "result class of cblock");
- CFCCBlock *block = (CFCCBlock*)result;
- STR_EQ(test, CFCCBlock_get_contents(block), "#define FOO_BAR 1\n",
- "parse embed_c");
- CFCBase_decref((CFCBase*)block);
- }
-
- CFCBase_decref((CFCBase*)parser);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestClass.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestClass.c b/clownfish/compiler/src/CFCTestClass.c
deleted file mode 100644
index e33d454..0000000
--- a/clownfish/compiler/src/CFCTestClass.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCClass.h"
-#include "CFCFileSpec.h"
-#include "CFCFunction.h"
-#include "CFCMethod.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCSymbol.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-#include "CFCUtil.h"
-#include "CFCVariable.h"
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-static void
-S_run_tests(CFCTest *test);
-
-static int
-S_has_symbol(CFCSymbol **symbols, const char *micro_sym);
-
-const CFCTestBatch CFCTEST_BATCH_CLASS = {
- "Clownfish::CFC::Model::Class",
- 83,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
-
- CFCParcel *neato = CFCParcel_new("Neato", NULL, NULL, false);
- CFCFileSpec *file_spec = CFCFileSpec_new(".", "Foo/FooJr", 0);
- CFCClass *thing_class
- = CFCTest_parse_class(test, parser, "class Thing {}");
- CFCClass *widget_class
- = CFCTest_parse_class(test, parser, "class Widget {}");
-
- CFCVariable *thing;
- CFCVariable *widget;
- CFCFunction *tread_water;
-
- {
- CFCType *thing_type = CFCTest_parse_type(test, parser, "Thing*");
- thing = CFCVariable_new(neato, NULL, "Foo", NULL, "thing",
- thing_type, 0);
-
- CFCType *widget_type = CFCTest_parse_type(test, parser, "Widget*");
- widget = CFCVariable_new(NULL, NULL, "Widget", NULL, "widget",
- widget_type, 0);
-
- CFCType *return_type = CFCTest_parse_type(test, parser, "void");
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "()");
- tread_water
- = CFCFunction_new(neato, NULL, "Foo", NULL, "tread_water",
- return_type, param_list, NULL, 0);
-
- CFCBase_decref((CFCBase*)thing_type);
- CFCBase_decref((CFCBase*)widget_type);
- CFCBase_decref((CFCBase*)return_type);
- CFCBase_decref((CFCBase*)param_list);
- }
-
- CFCClass *foo
- = CFCClass_create(neato, NULL, "Foo", NULL, NULL, NULL, NULL, NULL,
- 0, 0);
- CFCClass_add_function(foo, tread_water);
- CFCClass_add_member_var(foo, thing);
- CFCClass_add_inert_var(foo, widget);
-
- {
- CFCClass *should_be_foo = CFCClass_fetch_singleton(neato, "Foo");
- OK(test, should_be_foo == foo, "fetch_singleton");
- }
-
- CFCClass *foo_jr
- = CFCClass_create(neato, NULL, "Foo::FooJr", NULL, NULL, NULL, NULL,
- "Foo", 0, 0);
- STR_EQ(test, CFCClass_get_struct_sym(foo_jr), "FooJr",
- "get_struct_sym");
- STR_EQ(test, CFCClass_full_struct_sym(foo_jr), "neato_FooJr",
- "full_struct_sym");
-
- CFCClass *final_foo
- = CFCClass_create(neato, NULL, "Foo::FooJr::FinalFoo", NULL, NULL, NULL,
- file_spec, "Foo::FooJr", 1, 0);
- OK(test, CFCClass_final(final_foo), "final");
- STR_EQ(test, CFCClass_include_h(final_foo), "Foo/FooJr.h",
- "include_h uses path_part");
- STR_EQ(test, CFCClass_get_parent_class_name(final_foo), "Foo::FooJr",
- "get_parent_class_name");
-
- {
- CFCParcel *parsed_neato
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
- CFCBase_decref((CFCBase*)parsed_neato);
- }
-
- CFCParser_set_class_name(parser, "Foo");
- CFCMethod *do_stuff
- = CFCTest_parse_method(test, parser, "void Do_Stuff(Foo *self);");
- CFCClass_add_method(foo, do_stuff);
-
- CFCClass *class_list[6] = {
- foo, foo_jr, final_foo, thing_class, widget_class, NULL
- };
- CFCClass_resolve_types(foo, class_list);
- CFCClass_resolve_types(foo_jr, class_list);
- CFCClass_resolve_types(final_foo, class_list);
-
- CFCClass_add_child(foo, foo_jr);
- CFCClass_add_child(foo_jr, final_foo);
- CFCClass_grow_tree(foo);
-
- OK(test, CFCClass_get_parent(foo_jr) == foo, "grow_tree, one level" );
- OK(test, CFCClass_get_parent(final_foo) == foo_jr,
- "grow_tree, two levels");
- OK(test, CFCClass_fresh_method(foo, "Do_Stuff") == do_stuff,
- "fresh_method");
- OK(test, CFCClass_method(foo_jr, "Do_Stuff") == do_stuff,
- "inherited method");
- OK(test, CFCClass_fresh_method(foo_jr, "Do_Stuff") == NULL,
- "inherited method not 'fresh'");
- OK(test, CFCMethod_final(CFCClass_method(final_foo, "Do_Stuff")),
- "Finalize inherited method");
- OK(test, !CFCMethod_final(CFCClass_method(foo_jr, "Do_Stuff")),
- "Don't finalize method in parent");
-
- {
- CFCVariable **inert_vars = CFCClass_inert_vars(foo);
- OK(test, inert_vars[0] == widget, "inert_vars[0]");
- OK(test, inert_vars[1] == NULL, "inert_vars[1]");
-
- CFCFunction **functions = CFCClass_functions(foo);
- OK(test, functions[0] == tread_water, "functions[0]");
- OK(test, functions[1] == NULL, "functions[1]");
-
- CFCMethod **methods = CFCClass_methods(foo);
- OK(test, methods[0] == do_stuff, "methods[0]");
- OK(test, methods[1] == NULL, "methods[1]");
-
- CFCMethod **fresh_methods = CFCClass_fresh_methods(foo);
- OK(test, fresh_methods[0] == do_stuff, "fresh_methods[0]");
- OK(test, fresh_methods[1] == NULL, "fresh_methods[1]");
-
- CFCVariable **fresh_member_vars = CFCClass_fresh_member_vars(foo);
- OK(test, fresh_member_vars[0] == thing, "fresh_member_vars[0]");
- OK(test, fresh_member_vars[1] == NULL, "fresh_member_vars[1]");
-
- FREEMEM(fresh_methods);
- FREEMEM(fresh_member_vars);
- }
-
- {
- CFCVariable **member_vars = CFCClass_member_vars(foo_jr);
- OK(test, member_vars[0] == thing, "member_vars[0]");
- OK(test, member_vars[1] == NULL, "member_vars[1]");
-
- CFCFunction **functions = CFCClass_functions(foo_jr);
- OK(test, functions[0] == NULL, "functions[0]");
-
- CFCVariable **fresh_member_vars = CFCClass_fresh_member_vars(foo_jr);
- OK(test, fresh_member_vars[0] == NULL, "fresh_member_vars[0]");
-
- CFCVariable **inert_vars = CFCClass_inert_vars(foo_jr);
- OK(test, inert_vars[0] == NULL, "inert_vars[0]");
-
- FREEMEM(fresh_member_vars);
- }
-
- {
- CFCMethod **fresh_methods = CFCClass_fresh_methods(final_foo);
- OK(test, fresh_methods[0] == NULL, "fresh_methods[0]");
- FREEMEM(fresh_methods);
- }
-
- {
- CFCClass **ladder = CFCClass_tree_to_ladder(foo);
- OK(test, ladder[0] == foo, "ladder[0]");
- OK(test, ladder[1] == foo_jr, "ladder[1]");
- OK(test, ladder[2] == final_foo, "ladder[2]");
- OK(test, ladder[3] == NULL, "ladder[3]");
- FREEMEM(ladder);
- }
-
- {
- CFCClass *final_class
- = CFCTest_parse_class(test, parser, "final class Iamfinal { }");
- OK(test, CFCClass_final(final_class), "class modifer: final");
- CFCClass *inert_class
- = CFCTest_parse_class(test, parser, "inert class Iaminert { }");
- OK(test, CFCClass_inert(inert_class), "class modifer: inert");
-
- CFCBase_decref((CFCBase*)final_class);
- CFCBase_decref((CFCBase*)inert_class);
- }
-
- {
- static const char *names[2] = { "Fooble", "Foo::FooJr::FooIII" };
- for (int i = 0; i < 2; ++i) {
- const char *name = names[i];
- char *class_src
- = CFCUtil_sprintf("class Fu::%s inherits %s { }", name, name);
- CFCClass *klass = CFCTest_parse_class(test, parser, class_src);
- STR_EQ(test, CFCClass_get_parent_class_name(klass), name,
- "class_inheritance: %s", name);
- FREEMEM(class_src);
- CFCBase_decref((CFCBase*)klass);
- }
- }
-
- {
- const char *class_src =
- "public class Foo::Foodie cnick Foodie inherits Foo {\n"
- " int num;\n"
- "}\n";
- CFCClass *klass = CFCTest_parse_class(test, parser, class_src);
- CFCSymbol **member_vars = (CFCSymbol**)CFCClass_member_vars(klass);
- OK(test, S_has_symbol(member_vars, "num"),
- "parsed member var");
-
- CFCBase_decref((CFCBase*)klass);
- }
-
- {
- const char *class_src =
- "/**\n"
- " * Bow wow.\n"
- " *\n"
- " * Wow wow wow.\n"
- " */\n"
- "public class Animal::Dog inherits Animal {\n"
- " public inert Dog* init(Dog *self, String *name,\n"
- " String *fave_food);\n"
- " inert uint32_t count();\n"
- " inert uint64_t num_dogs;\n"
- " public inert Dog *top_dog;\n"
- "\n"
- " String *name;\n"
- " bool likes_to_go_fetch;\n"
- " ChewToy *squishy;\n"
- " Owner *mom;\n"
- "\n"
- " void Destroy(Dog *self);\n"
- " public String* Bark(Dog *self);\n"
- " public void Eat(Dog *self);\n"
- " public void Bite(Dog *self, Enemy *enemy);\n"
- " public Thing *Fetch(Dog *self, Thing *thing);\n"
- " public final void Bury(Dog *self, Bone *bone);\n"
- " public abstract incremented nullable Thing*\n"
- " Scratch(Dog *self);\n"
- "\n"
- " int32_t[1] flexible_array_at_end_of_struct;\n"
- "}\n";
- CFCClass *klass = CFCTest_parse_class(test, parser, class_src);
-
- CFCSymbol **inert_vars = (CFCSymbol**)CFCClass_inert_vars(klass);
- CFCSymbol **member_vars = (CFCSymbol**)CFCClass_member_vars(klass);
- CFCSymbol **functions = (CFCSymbol**)CFCClass_functions(klass);
- CFCSymbol **methods = (CFCSymbol**)CFCClass_methods(klass);
- OK(test, S_has_symbol(inert_vars, "num_dogs"), "parsed inert var");
- OK(test, S_has_symbol(inert_vars, "top_dog"), "parsed public inert var");
- OK(test, S_has_symbol(member_vars, "mom"), "parsed member var");
- OK(test, S_has_symbol(member_vars, "squishy"), "parsed member var");
- OK(test, S_has_symbol(functions, "init"), "parsed function");
- OK(test, S_has_symbol(methods, "destroy"), "parsed parcel method");
- OK(test, S_has_symbol(methods, "bury"), "parsed public method");
- OK(test, S_has_symbol(methods, "scratch"),
- "parsed public abstract nullable method");
-
- CFCMethod *scratch = CFCClass_method(klass, "scratch");
- OK(test, scratch != NULL, "find method 'scratch'");
- OK(test, CFCType_nullable(CFCMethod_get_return_type(scratch)),
- "public abstract incremented nullable flagged as nullable");
-
- int num_public_methods = 0;
- for (int i = 0; methods[i]; ++i) {
- if (CFCSymbol_public(methods[i])) { ++num_public_methods; }
- }
- INT_EQ(test, num_public_methods, 6, "pass acl to Method constructor");
-
- CFCBase_decref((CFCBase*)klass);
- }
-
- {
- const char *class_src =
- "inert class Rigor::Mortis cnick Mort {\n"
- " inert void lie_still();\n"
- "}\n";
- CFCClass *klass = CFCTest_parse_class(test, parser, class_src);
- OK(test, CFCClass_inert(klass),
- "inert modifier parsed and passed to constructor");
-
- CFCBase_decref((CFCBase*)klass);
- }
-
- {
- const char *class_src =
- "final class Ultimo {\n"
- " /** Throws an error.\n"
- " */\n"
- " void Say_Never(Ultimo *self);\n"
- "}\n";
- CFCClass *klass = CFCTest_parse_class(test, parser, class_src);
- OK(test, CFCClass_final(klass), "final class_declaration");
- CFCBase_decref((CFCBase*)klass);
- }
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato);
- CFCBase_decref((CFCBase*)file_spec);
- CFCBase_decref((CFCBase*)thing_class);
- CFCBase_decref((CFCBase*)widget_class);
- CFCBase_decref((CFCBase*)thing);
- CFCBase_decref((CFCBase*)widget);
- CFCBase_decref((CFCBase*)tread_water);
- CFCBase_decref((CFCBase*)foo);
- CFCBase_decref((CFCBase*)foo_jr);
- CFCBase_decref((CFCBase*)final_foo);
- CFCBase_decref((CFCBase*)do_stuff);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
-static int
-S_has_symbol(CFCSymbol **symbols, const char *micro_sym) {
- for (int i = 0; symbols[i]; ++i) {
- if (strcmp(CFCSymbol_micro_sym(symbols[i]), micro_sym) == 0) {
- return 1;
- }
- }
-
- return 0;
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestDocuComment.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestDocuComment.c b/clownfish/compiler/src/CFCTestDocuComment.c
deleted file mode 100644
index dba5f3c..0000000
--- a/clownfish/compiler/src/CFCTestDocuComment.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCDocuComment.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-#include "CFCUtil.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_DOCU_COMMENT = {
- "Clownfish::CFC::Model::DocuComment",
- 15,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCDocuComment *docucomment;
-
- docucomment = CFCDocuComment_parse("/** foo. */");
- OK(test, docucomment != NULL, "parse");
- CFCBase_decref((CFCBase*)docucomment);
-
- CFCParser *parser = CFCParser_new();
- const char *text =
- "/**\n"
- " * Brief description. Long description.\n"
- " *\n"
- " * More long description.\n"
- " *\n"
- " * @param foo A foo.\n"
- " * @param bar A bar.\n"
- " *\n"
- " * @param baz A baz.\n"
- " * @return a return value.\n"
- " */\n";
- CFCBase *result = CFCParser_parse(parser, text);
- OK(test, result != NULL, "parse with CFCParser");
- const char *klass = CFCBase_get_cfc_class(result);
- STR_EQ(test, klass, "Clownfish::CFC::Model::DocuComment", "result class");
- docucomment = (CFCDocuComment*)result;
-
- const char *brief_desc = CFCDocuComment_get_brief(docucomment);
- const char *brief_expect = "Brief description.";
- STR_EQ(test, brief_desc, brief_expect, "brief description");
-
- const char *long_desc = CFCDocuComment_get_long(docucomment);
- const char *long_expect =
- "Long description.\n"
- "\n"
- "More long description.";
- STR_EQ(test, long_desc, long_expect, "long description");
-
- const char *description = CFCDocuComment_get_description(docucomment);
- char *desc_expect = CFCUtil_sprintf("%s %s", brief_expect, long_expect);
- STR_EQ(test, description, desc_expect, "description");
- FREEMEM(desc_expect);
-
- const char **param_names = CFCDocuComment_get_param_names(docucomment);
- int num_param_names = 0;
- for (const char **p = param_names; *p; ++p) { ++num_param_names; }
- INT_EQ(test, num_param_names, 3, "number of param names");
- const char *param_names_expect[3] = { "foo", "bar", "baz" };
- for (int i = 0; i < 3; ++i) {
- STR_EQ(test, param_names[i], param_names_expect[i],
- "param name %d", i);
- }
-
- const char **param_docs = CFCDocuComment_get_param_docs(docucomment);
- int num_param_docs = 0;
- for (const char **p = param_docs; *p; ++p) { ++num_param_docs; }
- INT_EQ(test, num_param_docs, 3, "number of param docs");
- const char *param_docs_expect[3] = { "A foo.", "A bar.", "A baz." };
- const char *param_docs_test[3] = {
- "@param terminated by @",
- "@param terminated by empty line",
- "@param terminated next element, @return"
- };
- for (int i = 0; i < 3; ++i) {
- STR_EQ(test, param_docs[i], param_docs_expect[i], param_docs_test[i]);
- }
-
- const char *retval = CFCDocuComment_get_retval(docucomment);
- const char *retval_expect = "a return value.";
- STR_EQ(test, retval, retval_expect, "retval");
-
- CFCBase_decref((CFCBase*)docucomment);
- CFCBase_decref((CFCBase*)parser);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestFile.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestFile.c b/clownfish/compiler/src/CFCTestFile.c
deleted file mode 100644
index ad1cd5c..0000000
--- a/clownfish/compiler/src/CFCTestFile.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "charmony.h"
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCClass.h"
-#include "CFCFile.h"
-#include "CFCFileSpec.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-#include "CFCUtil.h"
-#include "CFCVariable.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_FILE = {
- "Clownfish::CFC::Model::File",
- 21,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
-#define STUFF_THING "Stuff" CHY_DIR_SEP "Thing"
-
- CFCParser *parser = CFCParser_new();
- CFCFileSpec *file_spec = CFCFileSpec_new(".", STUFF_THING, 0);
-
- {
- const char *string =
- "parcel Stuff;\n"
- "class Stuff::Thing {\n"
- " Foo *foo;\n"
- " Bar *bar;\n"
- "}\n"
- "class Foo {}\n"
- "class Bar {}\n"
- "__C__\n"
- "int foo;\n"
- "__END_C__\n";
- CFCFile *file = CFCParser_parse_file(parser, string, file_spec);
-
- STR_EQ(test, CFCFile_get_source_dir(file), ".", "get_source_dir");
- STR_EQ(test, CFCFile_get_path_part(file), STUFF_THING,
- "get_path_part");
- OK(test, !CFCFile_included(file), "included");
-
- STR_EQ(test, CFCFile_guard_name(file), "H_STUFF_THING", "guard_name");
- STR_EQ(test, CFCFile_guard_start(file),
- "#ifndef H_STUFF_THING\n#define H_STUFF_THING 1\n",
- "guard_start");
- STR_EQ(test, CFCFile_guard_close(file), "#endif /* H_STUFF_THING */\n",
- "guard_close");
-
- OK(test, !CFCFile_get_modified(file), "modified false at start");
- CFCFile_set_modified(file, 1);
- OK(test, CFCFile_get_modified(file), "set_modified, get_modified");
-
-#define PATH_TO_STUFF_THING \
- "path" CHY_DIR_SEP \
- "to" CHY_DIR_SEP \
- "Stuff" CHY_DIR_SEP \
- "Thing"
-
- char *cfh_path = CFCFile_cfh_path(file, "path/to");
- STR_EQ(test, cfh_path, PATH_TO_STUFF_THING ".cfh", "cfh_path");
- FREEMEM(cfh_path);
- char *c_path = CFCFile_c_path(file, "path/to");
- STR_EQ(test, c_path, PATH_TO_STUFF_THING ".c", "c_path");
- FREEMEM(c_path);
- char *h_path = CFCFile_h_path(file, "path/to");
- STR_EQ(test, h_path, PATH_TO_STUFF_THING ".h", "h_path");
- FREEMEM(h_path);
-
- CFCClass **classes = CFCFile_classes(file);
- OK(test,
- classes[0] != NULL && classes[1] != NULL && classes[2] != NULL
- && classes[3] == NULL,
- "classes() filters blocks");
- CFCVariable **member_vars = CFCClass_member_vars(classes[0]);
- CFCType *foo_type = CFCVariable_get_type(member_vars[0]);
- CFCType_resolve(foo_type, classes);
- STR_EQ(test, CFCType_get_specifier(foo_type), "stuff_Foo",
- "file production picked up parcel def");
- CFCType *bar_type = CFCVariable_get_type(member_vars[1]);
- CFCType_resolve(bar_type, classes);
- STR_EQ(test, CFCType_get_specifier(bar_type), "stuff_Bar",
- "parcel def is sticky");
-
- CFCBase **blocks = CFCFile_blocks(file);
- STR_EQ(test, CFCBase_get_cfc_class(blocks[0]),
- "Clownfish::CFC::Model::Parcel", "blocks[0]");
- STR_EQ(test, CFCBase_get_cfc_class(blocks[1]),
- "Clownfish::CFC::Model::Class", "blocks[1]");
- STR_EQ(test, CFCBase_get_cfc_class(blocks[2]),
- "Clownfish::CFC::Model::Class", "blocks[2]");
- STR_EQ(test, CFCBase_get_cfc_class(blocks[3]),
- "Clownfish::CFC::Model::Class", "blocks[3]");
- STR_EQ(test, CFCBase_get_cfc_class(blocks[4]),
- "Clownfish::CFC::Model::CBlock", "blocks[4]");
- OK(test, blocks[5] == NULL, "blocks[5]");
-
- CFCBase_decref((CFCBase*)file);
-
- CFCClass_clear_registry();
- }
-
- {
- const char *string =
- "class Stuff::Thing {\n"
- " Foo *foo;\n"
- " Bar *bar;\n"
- "}\n";
- CFCFile *file = CFCParser_parse_file(parser, string, file_spec);
- CFCClass **classes = CFCFile_classes(file);
- CFCVariable **member_vars = CFCClass_member_vars(classes[0]);
- CFCType *foo_type = CFCVariable_get_type(member_vars[0]);
- STR_EQ(test, CFCType_get_specifier(foo_type), "Foo",
- "file production resets parcel");
-
- CFCBase_decref((CFCBase*)file);
-
- CFCClass_clear_registry();
- }
-
- CFCBase_decref((CFCBase*)file_spec);
- CFCBase_decref((CFCBase*)parser);
-
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestFileSpec.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestFileSpec.c b/clownfish/compiler/src/CFCTestFileSpec.c
deleted file mode 100644
index 7fdb2d8..0000000
--- a/clownfish/compiler/src/CFCTestFileSpec.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCFileSpec.h"
-#include "CFCTest.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_FILE_SPEC = {
- "Clownfish::CFC::Model::FileSpec",
- 4,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- {
- CFCFileSpec *file_spec
- = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", 0);
- STR_EQ(test, CFCFileSpec_get_source_dir(file_spec),
- "Clownfish/_include", "get_source_dir");
- STR_EQ(test, CFCFileSpec_get_path_part(file_spec),
- "Stuff/Thing", "get_path_part");
- OK(test, !CFCFileSpec_included(file_spec), "not included");
-
- CFCBase_decref((CFCBase*)file_spec);
- }
-
- {
- CFCFileSpec *file_spec
- = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", 1);
- OK(test, CFCFileSpec_included(file_spec), "included");
-
- CFCBase_decref((CFCBase*)file_spec);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestFunction.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestFunction.c b/clownfish/compiler/src/CFCTestFunction.c
deleted file mode 100644
index 4cd6967..0000000
--- a/clownfish/compiler/src/CFCTestFunction.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCFunction.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_FUNCTION = {
- "Clownfish::CFC::Model::Function",
- 11,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
-
- {
- CFCType *return_type = CFCTest_parse_type(test, parser, "Obj*");
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "(int32_t some_num)");
- CFCFunction *func
- = CFCFunction_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "return_an_obj", return_type, param_list,
- NULL, 0);
- OK(test, func != NULL, "new");
-
- CFCBase_decref((CFCBase*)return_type);
- CFCBase_decref((CFCBase*)param_list);
- CFCBase_decref((CFCBase*)func);
- }
-
- {
- CFCParser_set_class_name(parser, "Neato::Obj");
- CFCParser_set_class_cnick(parser, "Obj");
- static const char *func_strings[2] = {
- "inert int running_count(int biscuit);",
- "public inert Hash* init_fave_hash(int32_t num_buckets,"
- " bool o_rly);"
- };
- for (int i = 0; i < 2; ++i) {
- CFCFunction *func
- = CFCTest_parse_function(test, parser, func_strings[i]);
- CFCBase_decref((CFCBase*)func);
- }
- }
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)parser);
-
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestHierarchy.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestHierarchy.c b/clownfish/compiler/src/CFCTestHierarchy.c
deleted file mode 100644
index 8941fe2..0000000
--- a/clownfish/compiler/src/CFCTestHierarchy.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "charmony.h"
-
-#include <stdio.h>
-#include <string.h>
-
-/* For rmdir */
-#ifdef CHY_HAS_UNISTD_H
- #include <unistd.h>
-#endif
-#ifdef CHY_HAS_DIRECT_H
- #include <direct.h>
-#endif
-
-#define CFC_USE_TEST_MACROS
-#include "CFCBase.h"
-#include "CFCClass.h"
-#include "CFCFile.h"
-#include "CFCHierarchy.h"
-#include "CFCParcel.h"
-#include "CFCTest.h"
-#include "CFCUtil.h"
-
-#define T_CFBASE "t" CHY_DIR_SEP "cfbase"
-#define T_CFEXT "t" CHY_DIR_SEP "cfext"
-#define T_CFDEST "t" CHY_DIR_SEP "cfdest"
-#define T_CFDEST_INCLUDE T_CFDEST CHY_DIR_SEP "include"
-#define T_CFDEST_SOURCE T_CFDEST CHY_DIR_SEP "source"
-
-static void
-S_run_tests(CFCTest *test);
-
-static void
-S_run_basic_tests(CFCTest *test);
-
-static void
-S_run_include_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_HIERARCHY = {
- "Clownfish::CFC::Model::Hierarchy",
- 39,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- S_run_basic_tests(test);
- S_run_include_tests(test);
-}
-
-static void
-S_run_basic_tests(CFCTest *test) {
- CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
- STR_EQ(test, CFCHierarchy_get_dest(hierarchy), T_CFDEST, "get_dest");
- STR_EQ(test, CFCHierarchy_get_include_dest(hierarchy), T_CFDEST_INCLUDE,
- "get_include_dest");
- STR_EQ(test, CFCHierarchy_get_source_dest(hierarchy), T_CFDEST_SOURCE,
- "get_source_dest");
-
- CFCHierarchy_add_source_dir(hierarchy, T_CFBASE);
- const char **source_dirs = CFCHierarchy_get_source_dirs(hierarchy);
- STR_EQ(test, source_dirs[0], T_CFBASE, "source_dirs[0]");
- OK(test, source_dirs[1] == NULL, "source_dirs[1]");
-
- CFCHierarchy_build(hierarchy);
-
- CFCFile **files = CFCHierarchy_files(hierarchy);
- CFCFile *animal;
- CFCFile *dog;
- CFCFile *util;
- for (int i = 0; i < 3; ++i) {
- CFCFile *file = files[i];
- OK(test, file != NULL, "files[%d]", i);
- OK(test, !CFCFile_get_modified(file), "start off not modified");
-
- CFCBase **blocks = CFCFile_blocks(file);
- for (int j = 0; blocks[j]; ++j) {
- CFCBase *block = blocks[j];
- const char *cfc_class_name = CFCBase_get_cfc_class(block);
- if (strcmp(cfc_class_name, "Clownfish::CFC::Model::Class") == 0) {
- CFCClass *klass = (CFCClass*)block;
- const char *class_name = CFCClass_get_class_name(klass);
- if (strcmp(class_name, "Animal") == 0) {
- animal = file;
- }
- else if (strcmp(class_name, "Animal::Dog") == 0) {
- dog = file;
- }
- else if (strcmp(class_name, "Animal::Util") == 0) {
- util = file;
- }
- }
- }
- }
- OK(test, files[3] == NULL, "recursed and found all three files");
-
- {
- CFCClass **ordered_classes = CFCHierarchy_ordered_classes(hierarchy);
- OK(test, ordered_classes[0] != NULL, "ordered_classes[0]");
- OK(test, ordered_classes[1] != NULL, "ordered_classes[1]");
- OK(test, ordered_classes[2] != NULL, "ordered_classes[2]");
- OK(test, ordered_classes[3] != NULL, "ordered_classes[3]");
- OK(test, ordered_classes[4] == NULL, "all classes");
- FREEMEM(ordered_classes);
- }
-
- // Generate fake C files, with times set to two seconds ago.
- time_t now = time(NULL);
- time_t past_time = now - 2;
- static const char *const h_paths[] = {
- T_CFDEST_INCLUDE CHY_DIR_SEP "Animal.h",
- T_CFDEST_INCLUDE CHY_DIR_SEP "Animal" CHY_DIR_SEP "Dog.h",
- T_CFDEST_INCLUDE CHY_DIR_SEP "Animal" CHY_DIR_SEP "Util.h"
- };
- OK(test, CFCUtil_make_path(T_CFDEST_INCLUDE CHY_DIR_SEP "Animal"),
- "make_path");
- for (int i = 0; i < 3; ++i) {
- const char *h_path = h_paths[i];
- const char *content = "#include <stdio.h>\n";
- CFCUtil_write_file(h_path, content, strlen(content));
- CFCTest_set_file_times(h_path, past_time);
- }
-
- char *cfh_path = CFCFile_cfh_path(animal, T_CFBASE);
- CFCTest_set_file_times(cfh_path, now);
- FREEMEM(cfh_path);
-
- CFCHierarchy_propagate_modified(hierarchy, 0);
-
- OK(test, CFCFile_get_modified(animal), "Animal modified");
- OK(test, CFCFile_get_modified(dog),
- "Parent's modification propagates to child's file");
- OK(test, !CFCFile_get_modified(util),
- "Modification doesn't propagate to inert class");
-
- for (int i = 0; i < 3; ++i) {
- remove(h_paths[i]);
- }
- rmdir(T_CFDEST_INCLUDE CHY_DIR_SEP "Animal");
- rmdir(T_CFDEST_INCLUDE);
- rmdir(T_CFDEST_SOURCE);
- rmdir(T_CFDEST);
-
- CFCBase_decref((CFCBase*)hierarchy);
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_include_tests(CFCTest *test) {
- {
- CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
- CFCHierarchy_add_source_dir(hierarchy, T_CFEXT);
- CFCHierarchy_add_include_dir(hierarchy, T_CFBASE);
- const char **include_dirs = CFCHierarchy_get_include_dirs(hierarchy);
- STR_EQ(test, include_dirs[0], T_CFBASE, "include_dirs[0]");
- OK(test, include_dirs[1] == NULL, "include_dirs[1]");
-
- CFCHierarchy_build(hierarchy);
-
- CFCClass **classes = CFCHierarchy_ordered_classes(hierarchy);
- CFCClass *rottweiler = NULL;;
- int num_classes;
- int num_source_classes = 0;
- for (num_classes = 0; classes[num_classes]; ++num_classes) {
- CFCClass *klass = classes[num_classes];
- int expect_included = 1;
- const char *class_name = CFCClass_get_class_name(klass);
- if (strcmp(class_name, "Animal::Rottweiler") == 0) {
- rottweiler = klass;
- expect_included = 0;
- ++num_source_classes;
- }
- INT_EQ(test, CFCClass_included(klass), expect_included,
- "included");
- }
- INT_EQ(test, num_classes, 5, "class count");
- INT_EQ(test, num_source_classes, 1, "source class count");
- STR_EQ(test, CFCClass_get_class_name(CFCClass_get_parent(rottweiler)),
- "Animal::Dog", "parent of included class");
-
- FREEMEM(classes);
- CFCBase_decref((CFCBase*)hierarchy);
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
- }
-
- {
- CFCHierarchy *hierarchy = CFCHierarchy_new(T_CFDEST);
- CFCHierarchy_add_source_dir(hierarchy, T_CFBASE);
- CFCHierarchy_add_source_dir(hierarchy, T_CFEXT);
-
- CFCHierarchy_build(hierarchy);
-
- CFCClass **classes = CFCHierarchy_ordered_classes(hierarchy);
- CFCClass *rottweiler = NULL;;
- int num_classes;
- for (num_classes = 0; classes[num_classes]; ++num_classes) {
- CFCClass *klass = classes[num_classes];
- const char *class_name = CFCClass_get_class_name(klass);
- if (strcmp(class_name, "Animal::Rottweiler") == 0) {
- rottweiler = klass;
- }
- OK(test, !CFCClass_included(klass), "not included");
- }
- INT_EQ(test, num_classes, 5, "class count");
- OK(test, rottweiler != NULL, "found rottweiler");
- STR_EQ(test, CFCClass_get_class_name(CFCClass_get_parent(rottweiler)),
- "Animal::Dog", "parent of class from second source");
-
- FREEMEM(classes);
- CFCBase_decref((CFCBase*)hierarchy);
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
- }
-
- rmdir(T_CFDEST_INCLUDE);
- rmdir(T_CFDEST_SOURCE);
- rmdir(T_CFDEST);
-}
-