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:45 UTC
[lucy-commits] [10/27] Remove bundled Clownfish.
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestMethod.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestMethod.c b/clownfish/compiler/src/CFCTestMethod.c
deleted file mode 100644
index cde5d7e..0000000
--- a/clownfish/compiler/src/CFCTestMethod.c
+++ /dev/null
@@ -1,286 +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 "CFCClass.h"
-#include "CFCMethod.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCSymbol.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-static void
-S_run_basic_tests(CFCTest *test);
-
-static void
-S_run_parser_tests(CFCTest *test);
-
-static void
-S_run_overridden_tests(CFCTest *test);
-
-static void
-S_run_final_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_METHOD = {
- "Clownfish::CFC::Model::Method",
- 74,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- S_run_basic_tests(test);
- S_run_parser_tests(test);
- S_run_overridden_tests(test);
- S_run_final_tests(test);
-}
-
-static void
-S_run_basic_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,
- "(Foo *self, int32_t count = 0)");
- CFCMethod *method
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Return_An_Obj", return_type, param_list,
- NULL, 0, 0);
- OK(test, method != NULL, "new");
- OK(test, CFCSymbol_parcel((CFCSymbol*)method),
- "parcel exposure by default");
-
- {
- CFCMethod *dupe
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Return_An_Obj", return_type, param_list,
- NULL, 0, 0);
- OK(test, CFCMethod_compatible(method, dupe), "compatible");
- CFCBase_decref((CFCBase*)dupe);
- }
-
- {
- CFCMethod *macro_sym_differs
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo", "Eat",
- return_type, param_list, NULL, 0, 0);
- OK(test, !CFCMethod_compatible(method, macro_sym_differs),
- "different macro_sym spoils compatible");
- OK(test, !CFCMethod_compatible(macro_sym_differs, method),
- "... reversed");
- CFCBase_decref((CFCBase*)macro_sym_differs);
- }
-
- {
- static const char *param_strings[5] = {
- "(Foo *self, int32_t count = 0, int b)",
- "(Foo *self, int32_t count = 1)",
- "(Foo *self, int32_t count)",
- "(Foo *self, int32_t countess)",
- "(Foo *self, uint32_t count = 0)"
- };
- static const char *test_names[5] = {
- "extra param",
- "different initial_value",
- "missing initial_value",
- "different param name",
- "different param type"
- };
- for (int i = 0; i < 5; ++i) {
- CFCParamList *other_param_list
- = CFCTest_parse_param_list(test, parser, param_strings[i]);
- CFCMethod *other
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Return_An_Obj", return_type, other_param_list,
- NULL, 0, 0);
- OK(test, !CFCMethod_compatible(method, other),
- "%s spoils compatible", test_names[i]);
- OK(test, !CFCMethod_compatible(other, method),
- "... reversed");
- CFCBase_decref((CFCBase*)other_param_list);
- CFCBase_decref((CFCBase*)other);
- }
- }
-
- {
- CFCParamList *self_differs_list
- = CFCTest_parse_param_list(test, parser,
- "(Bar *self, int32_t count = 0)");
- CFCMethod *self_differs
- = CFCMethod_new(neato_parcel, NULL, "Neato::Bar", "Bar",
- "Return_An_Obj", return_type, self_differs_list,
- NULL, 0, 0);
- OK(test, CFCMethod_compatible(method, self_differs),
- "different self type still compatible(),"
- " since can't test inheritance");
- OK(test, CFCMethod_compatible(self_differs, method),
- "... reversed");
- CFCBase_decref((CFCBase*)self_differs_list);
- CFCBase_decref((CFCBase*)self_differs);
- }
-
- {
- CFCMethod *aliased
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Aliased", return_type, param_list,
- NULL, 0, 0);
- OK(test, !CFCMethod_get_host_alias(aliased),
- "no host alias by default");
- CFCMethod_set_host_alias(aliased, "Host_Alias");
- STR_EQ(test, CFCMethod_get_host_alias(aliased), "Host_Alias",
- "set/get host alias");
- CFCBase_decref((CFCBase*)aliased);
- }
-
- {
- CFCMethod *excluded
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Excluded", return_type, param_list,
- NULL, 0, 0);
- OK(test, !CFCMethod_excluded_from_host(excluded),
- "not excluded by default");
- CFCMethod_exclude_from_host(excluded);
- OK(test, CFCMethod_excluded_from_host(excluded), "exclude from host");
- CFCBase_decref((CFCBase*)excluded);
- }
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)return_type);
- CFCBase_decref((CFCBase*)param_list);
- CFCBase_decref((CFCBase*)method);
-
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_parser_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
- CFCParser_set_class_name(parser, "Neato::Obj");
- CFCParser_set_class_cnick(parser, "Obj");
-
- {
- static const char *method_strings[4] = {
- "public int Do_Foo(Obj *self);",
- "Obj* Gimme_An_Obj(Obj *self);",
- "void Do_Whatever(Obj *self, uint32_t a_num, float real);",
- "Foo* Fetch_Foo(Obj *self, int num);",
- };
- for (int i = 0; i < 4; ++i) {
- CFCMethod *method
- = CFCTest_parse_method(test, parser, method_strings[i]);
- CFCBase_decref((CFCBase*)method);
- }
- }
-
- {
- CFCMethod *method
- = CFCTest_parse_method(test, parser,
- "public final void The_End(Obj *self);");
- OK(test, CFCMethod_final(method), "final");
- CFCBase_decref((CFCBase*)method);
- }
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)parser);
-
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_overridden_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, "(Foo *self)");
- CFCMethod *orig
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Return_An_Obj", return_type, param_list,
- NULL, 0, 0);
-
- CFCParamList *overrider_param_list
- = CFCTest_parse_param_list(test, parser, "(FooJr *self)");
- CFCMethod *overrider
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo::FooJr", "FooJr",
- "Return_An_Obj", return_type, overrider_param_list,
- NULL, 0, 0);
-
- CFCMethod_override(overrider, orig);
- OK(test, !CFCMethod_novel(overrider),
- "A Method which overrides another is not 'novel'");
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)return_type);
- CFCBase_decref((CFCBase*)param_list);
- CFCBase_decref((CFCBase*)orig);
- CFCBase_decref((CFCBase*)overrider_param_list);
- CFCBase_decref((CFCBase*)overrider);
-
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_final_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
- CFCClass *obj_class
- = CFCTest_parse_class(test, parser, "class Obj {}");
- CFCClass *foo_class
- = CFCTest_parse_class(test, parser, "class Neato::Foo {}");
- CFCClass *class_list[3] = { obj_class, foo_class, NULL };
- CFCType *return_type = CFCTest_parse_type(test, parser, "Obj*");
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "(Foo *self)");
-
- CFCMethod *not_final
- = CFCMethod_new(neato_parcel, NULL, "Neato::Foo", "Foo",
- "Return_An_Obj", return_type, param_list,
- NULL, 0, 0);
- CFCMethod_resolve_types(not_final, class_list);
- CFCMethod *final = CFCMethod_finalize(not_final);
- OK(test, CFCMethod_compatible(not_final, final),
- "finalize clones properly");
- OK(test, !CFCMethod_final(not_final), "not final by default");
- OK(test, CFCMethod_final(final), "finalize");
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)obj_class);
- CFCBase_decref((CFCBase*)foo_class);
- CFCBase_decref((CFCBase*)return_type);
- CFCBase_decref((CFCBase*)param_list);
- CFCBase_decref((CFCBase*)not_final);
- CFCBase_decref((CFCBase*)final);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestParamList.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestParamList.c b/clownfish/compiler/src/CFCTestParamList.c
deleted file mode 100644
index 29ff226..0000000
--- a/clownfish/compiler/src/CFCTestParamList.c
+++ /dev/null
@@ -1,96 +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 "CFCClass.h"
-#include "CFCParamList.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-#include "CFCVariable.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_PARAM_LIST = {
- "Clownfish::CFC::Model::ParamList",
- 23,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
- CFCClass *obj_class = CFCTest_parse_class(test, parser, "class Obj {}");
- CFCClass *class_list[2] = { obj_class, NULL };
-
- {
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "(Obj *self, int num)");
- CFCParamList_resolve_types(param_list, class_list);
- OK(test, !CFCParamList_variadic(param_list), "not variadic");
- STR_EQ(test, CFCParamList_to_c(param_list), "neato_Obj* self, int num",
- "to_c");
- STR_EQ(test, CFCParamList_name_list(param_list), "self, num",
- "name_list");
-
- CFCBase_decref((CFCBase*)param_list);
- }
-
- {
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser,
- "(Obj *self=NULL, int num, ...)");
- CFCParamList_resolve_types(param_list, class_list);
- OK(test, CFCParamList_variadic(param_list), "variadic");
- STR_EQ(test, CFCParamList_to_c(param_list),
- "neato_Obj* self, int num, ...", "to_c");
- INT_EQ(test, CFCParamList_num_vars(param_list), 2, "num_vars");
- const char **initial_values
- = CFCParamList_get_initial_values(param_list);
- STR_EQ(test, initial_values[0], "NULL", "initial_values[0]");
- OK(test, initial_values[1] == NULL, "initial_values[1]");
- CFCVariable **variables = CFCParamList_get_variables(param_list);
- OK(test, variables[0] != NULL, "get_variables");
- STR_EQ(test, CFCBase_get_cfc_class((CFCBase*)variables[0]),
- "Clownfish::CFC::Model::Variable", "get_variables return type");
-
- CFCBase_decref((CFCBase*)param_list);
- }
-
- {
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "()");
- CFCParamList_resolve_types(param_list, class_list);
- STR_EQ(test, CFCParamList_to_c(param_list), "void", "to_c");
- INT_EQ(test, CFCParamList_num_vars(param_list), 0, "num_vars");
- CFCVariable **variables = CFCParamList_get_variables(param_list);
- OK(test, variables[0] == NULL, "get_variables");
-
- CFCBase_decref((CFCBase*)param_list);
- }
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)obj_class);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestParcel.c b/clownfish/compiler/src/CFCTestParcel.c
deleted file mode 100644
index d91a271..0000000
--- a/clownfish/compiler/src/CFCTestParcel.c
+++ /dev/null
@@ -1,106 +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 "CFCParcel.h"
-#include "CFCSymbol.h"
-#include "CFCVersion.h"
-#include "CFCTest.h"
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_PARCEL = {
- "Clownfish::CFC::Model::Parcel",
- 12,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- {
- CFCParcel *parcel = CFCParcel_new("Foo", NULL, NULL, false);
- OK(test, parcel != NULL, "new");
- OK(test, !CFCParcel_included(parcel), "not included");
- CFCBase_decref((CFCBase*)parcel);
- }
-
- {
- CFCParcel *parcel = CFCParcel_new("Foo", NULL, NULL, true);
- OK(test, CFCParcel_included(parcel), "included");
- CFCBase_decref((CFCBase*)parcel);
- }
-
- {
- const char *json =
- " {\n"
- " \"name\": \"Crustacean\",\n"
- " \"nickname\": \"Crust\",\n"
- " \"version\": \"v0.1.0\"\n"
- " }\n";
- CFCParcel *parcel = CFCParcel_new_from_json(json, false);
- OK(test, parcel != NULL, "new_from_json");
- CFCBase_decref((CFCBase*)parcel);
- }
-
- {
- const char *path = "t" CHY_DIR_SEP "cfbase" CHY_DIR_SEP "Animal.cfp";
- CFCParcel *parcel = CFCParcel_new_from_file(path, false);
- OK(test, parcel != NULL, "new_from_file");
- CFCBase_decref((CFCBase*)parcel);
- }
-
- {
- CFCParcel *parcel = CFCParcel_default_parcel();
- CFCSymbol *thing = CFCSymbol_new(parcel, "parcel", NULL, NULL, "sym");
- STR_EQ(test, CFCSymbol_get_prefix(thing), "",
- "get_prefix with no parcel");
- STR_EQ(test, CFCSymbol_get_Prefix(thing), "",
- "get_Prefix with no parcel");
- STR_EQ(test, CFCSymbol_get_PREFIX(thing), "",
- "get_PREFIX with no parcel");
- CFCBase_decref((CFCBase*)thing);
- }
-
- {
- CFCParcel *parcel = CFCParcel_new("Crustacean", "Crust", NULL, false);
- CFCParcel_register(parcel);
- STR_EQ(test, CFCVersion_get_vstring(CFCParcel_get_version(parcel)),
- "v0", "get_version");
-
- CFCSymbol *thing = CFCSymbol_new(parcel, "parcel", NULL, NULL, "sym");
- STR_EQ(test, CFCSymbol_get_prefix(thing), "crust_",
- "get_prefix with parcel");
- STR_EQ(test, CFCSymbol_get_Prefix(thing), "Crust_",
- "get_Prefix with parcel");
- STR_EQ(test, CFCSymbol_get_PREFIX(thing), "CRUST_",
- "get_PREFIX with parcel");
-
- CFCBase_decref((CFCBase*)thing);
- CFCBase_decref((CFCBase*)parcel);
- }
-
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestParser.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestParser.c b/clownfish/compiler/src/CFCTestParser.c
deleted file mode 100644
index 556a135..0000000
--- a/clownfish/compiler/src/CFCTestParser.c
+++ /dev/null
@@ -1,331 +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 "CFCClass.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 void
-S_test_initial_value(CFCTest *test, CFCParser *parser,
- const char *const *values, const char *type,
- const char *test_name);
-
-const CFCTestBatch CFCTEST_BATCH_PARSER = {
- "Clownfish::CFC::Model::Parser",
- 203,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- OK(test, parser != NULL, "new");
-
- {
- CFCParcel *fish = CFCTest_parse_parcel(test, parser, "parcel Fish;");
-
- CFCParcel *registered
- = CFCParcel_new("Crustacean", "Crust", NULL, false);
- CFCParcel_register(registered);
- CFCParcel *parcel
- = CFCTest_parse_parcel(test, parser, "parcel Crustacean;");
- OK(test, parcel == registered, "Fetch registered parcel");
- OK(test, CFCParser_get_parcel(parser) == parcel,
- "parcel_definition sets internal var");
-
- CFCBase_decref((CFCBase*)fish);
- CFCBase_decref((CFCBase*)registered);
- CFCBase_decref((CFCBase*)parcel);
- }
-
- {
- static const char *const specifiers[8] = {
- "foo", "_foo", "foo_yoo", "FOO", "Foo", "fOO", "f00", "foo_foo_foo"
- };
- for (int i = 0; i < 8; ++i) {
- const char *specifier = specifiers[i];
- char *src = CFCUtil_sprintf("int32_t %s;", specifier);
- CFCVariable *var = CFCTest_parse_variable(test, parser, src);
- STR_EQ(test, CFCVariable_micro_sym(var), specifier,
- "identifier/declarator: %s", specifier);
- FREEMEM(src);
- CFCBase_decref((CFCBase*)var);
- }
- }
-
- {
- static const char *const specifiers[6] = {
- "void", "float", "uint32_t", "int64_t", "uint8_t", "bool"
- };
- for (int i = 0; i < 6; ++i) {
- const char *specifier = specifiers[i];
- char *src = CFCUtil_sprintf("int32_t %s;", specifier);
- CFCBase *result = CFCParser_parse(parser, src);
- OK(test, result == NULL,
- "reserved word not parsed as identifier: %s", specifier);
- FREEMEM(src);
- CFCBase_decref(result);
- }
- }
-
- {
- static const char *const type_strings[7] = {
- "bool", "const char *", "Obj*", "i32_t", "char[]", "long[1]",
- "i64_t[30]"
- };
- for (int i = 0; i < 7; ++i) {
- const char *type_string = type_strings[i];
- CFCType *type = CFCTest_parse_type(test, parser, type_string);
- CFCBase_decref((CFCBase*)type);
- }
- }
-
- {
- static const char *const class_names[7] = {
- "ByteBuf", "Obj", "ANDMatcher", "Foo", "FooJr", "FooIII", "Foo4th"
- };
- CFCClass *class_list[8];
- for (int i = 0; i < 7; ++i) {
- char *class_code = CFCUtil_sprintf("class %s {}", class_names[i]);
- CFCClass *klass = CFCTest_parse_class(test, parser, class_code);
- class_list[i] = klass;
- FREEMEM(class_code);
- }
- class_list[7] = NULL;
- for (int i = 0; i < 7; ++i) {
- const char *class_name = class_names[i];
- char *src = CFCUtil_sprintf("%s*", class_name);
- char *expected = CFCUtil_sprintf("crust_%s", class_name);
- CFCType *type = CFCTest_parse_type(test, parser, src);
- CFCType_resolve(type, class_list);
- STR_EQ(test, CFCType_get_specifier(type), expected,
- "object_type_specifier: %s", class_name);
- FREEMEM(src);
- FREEMEM(expected);
- CFCBase_decref((CFCBase*)type);
- }
- for (int i = 0; i < 7; ++i) {
- CFCBase_decref((CFCBase*)class_list[i]);
- }
- CFCClass_clear_registry();
- }
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "const char");
- OK(test, CFCType_const(type), "type_qualifier const");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- static const char *const exposures[2] = {
- "public", ""
- };
- static int (*const accessors[2])(CFCSymbol *sym) = {
- CFCSymbol_public, CFCSymbol_parcel
- };
- for (int i = 0; i < 2; ++i) {
- const char *exposure = exposures[i];
- char *src = CFCUtil_sprintf("%s inert int32_t foo;", exposure);
- CFCVariable *var = CFCTest_parse_variable(test, parser, src);
- OK(test, accessors[i]((CFCSymbol*)var), "exposure_specifier %s",
- exposure);
- FREEMEM(src);
- CFCBase_decref((CFCBase*)var);
- }
- }
-
- {
- static const char *const hex_constants[] = {
- "0x1", "0x0a", "0xFFFFFFFF", "-0xFC", NULL
- };
- S_test_initial_value(test, parser, hex_constants, "int32_t",
- "hex_constant:");
- }
-
- {
- static const char *const integer_constants[] = {
- "1", "-9999", "0", "10000", NULL
- };
- S_test_initial_value(test, parser, integer_constants, "int32_t",
- "integer_constant:");
- }
-
- {
- static const char *const float_constants[] = {
- "1.0", "-9999.999", "0.1", "0.0", NULL
- };
- S_test_initial_value(test, parser, float_constants, "double",
- "float_constant:");
- }
-
- {
- static const char *const string_literals[] = {
- "\"blah\"", "\"blah blah\"", "\"\\\"blah\\\" \\\"blah\\\"\"", NULL
- };
- S_test_initial_value(test, parser, string_literals, "String*",
- "string_literal:");
- }
-
- {
- static const char *const composites[5] = {
- "int[]", "i32_t **", "Foo **", "Foo ***", "const void *"
- };
- for (int i = 0; i < 5; ++i) {
- const char *composite = composites[i];
- CFCType *type = CFCTest_parse_type(test, parser, composite);
- OK(test, CFCType_is_composite(type), "composite_type: %s",
- composite);
- CFCBase_decref((CFCBase*)type);
- }
- }
-
- {
- static const char *const object_types[5] = {
- "Obj *", "incremented Foo*", "decremented String *"
- };
- for (int i = 0; i < 3; ++i) {
- const char *object_type = object_types[i];
- CFCType *type = CFCTest_parse_type(test, parser, object_type);
- OK(test, CFCType_is_object(type), "object_type: %s",
- object_type);
- CFCBase_decref((CFCBase*)type);
- }
- }
-
- {
- static const char *const param_list_strings[3] = {
- "()",
- "(int foo)",
- "(Obj *foo, Foo **foo_ptr)"
- };
- for (int i = 0; i < 3; ++i) {
- const char *param_list_string = param_list_strings[i];
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, param_list_string);
- INT_EQ(test, CFCParamList_num_vars(param_list), i,
- "param list num_vars: %d", i);
- CFCBase_decref((CFCBase*)param_list);
- }
- }
-
- {
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, "(int foo, ...)");
- OK(test, CFCParamList_variadic(param_list), "variadic param list");
- CFCBase_decref((CFCBase*)param_list);
- }
-
- {
- const char *param_list_string =
- "(int foo = 0xFF, char *bar =\"blah\")";
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, param_list_string);
- const char **initial_values
- = CFCParamList_get_initial_values(param_list);
- STR_EQ(test, initial_values[0], "0xFF",
- "param list initial_values[0]");
- STR_EQ(test, initial_values[1], "\"blah\"",
- "param list initial_values[1]");
- OK(test, initial_values[2] == NULL, "param list initial_values[2]");
- CFCBase_decref((CFCBase*)param_list);
- }
-
- {
- CFCParser_set_class_name(parser, "Stuff::Obj");
- CFCParser_set_class_cnick(parser, "Obj");
-
- const char *method_string =
- "public Foo* Spew_Foo(Obj *self, uint32_t *how_many);";
- CFCMethod *method = CFCTest_parse_method(test, parser, method_string);
- CFCBase_decref((CFCBase*)method);
-
- const char *var_string =
- "public inert Hash *hash;";
- CFCVariable *var = CFCTest_parse_variable(test, parser, var_string);
- CFCBase_decref((CFCBase*)var);
- }
-
- {
- static const char *const class_names[4] = {
- "Foo", "Foo::FooJr", "Foo::FooJr::FooIII",
- "Foo::FooJr::FooIII::Foo4th"
- };
- for (int i = 0; i < 4; ++i) {
- const char *class_name = class_names[i];
- char *class_string = CFCUtil_sprintf("class %s { }", class_name);
- CFCClass *klass
- = CFCTest_parse_class(test, parser, class_string);
- STR_EQ(test, CFCClass_get_class_name(klass), class_name,
- "class_name: %s", class_name);
- FREEMEM(class_string);
- CFCBase_decref((CFCBase*)klass);
- }
- }
-
- {
- static const char *const cnicks[2] = { "Food", "FF" };
- for (int i = 0; i < 2; ++i) {
- const char *cnick = cnicks[i];
- char *class_string
- = CFCUtil_sprintf("class Foodie%s cnick %s { }", cnick, cnick);
- CFCClass *klass
- = CFCTest_parse_class(test, parser, class_string);
- STR_EQ(test, CFCClass_get_cnick(klass), cnick, "cnick: %s", cnick);
- FREEMEM(class_string);
- CFCBase_decref((CFCBase*)klass);
- }
- }
-
- CFCBase_decref((CFCBase*)parser);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
-static void
-S_test_initial_value(CFCTest *test, CFCParser *parser,
- const char *const *values, const char *type,
- const char *test_name) {
- for (int i = 0; values[i]; ++i) {
- const char *value = values[i];
- char *src = CFCUtil_sprintf("(%s foo = %s)", type, value);
- CFCParamList *param_list
- = CFCTest_parse_param_list(test, parser, src);
- const char **initial_values
- = CFCParamList_get_initial_values(param_list);
- STR_EQ(test, initial_values[0], value, "%s %s", test_name, value);
- FREEMEM(src);
- CFCBase_decref((CFCBase*)param_list);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestSymbol.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestSymbol.c b/clownfish/compiler/src/CFCTestSymbol.c
deleted file mode 100644
index 8f6518e..0000000
--- a/clownfish/compiler/src/CFCTestSymbol.c
+++ /dev/null
@@ -1,150 +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 "CFCParcel.h"
-#include "CFCSymbol.h"
-#include "CFCTest.h"
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_SYMBOL = {
- "Clownfish::CFC::Model::Symbol",
- 28,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParcel *parcel = CFCParcel_default_parcel();
-
- {
- static const char *exposures[4] = {
- "public", "private", "parcel", "local"
- };
- static int (*accessors[4])(CFCSymbol *sym) = {
- CFCSymbol_public,
- CFCSymbol_private,
- CFCSymbol_parcel,
- CFCSymbol_local
- };
- for (int i = 0; i < 4; ++i) {
- CFCSymbol *symbol
- = CFCSymbol_new(parcel, exposures[i], NULL, NULL, "sym");
- for (int j = 0; j < 4; ++j) {
- int has_exposure = accessors[j](symbol);
- if (i == j) {
- OK(test, has_exposure, "exposure %s", exposures[i]);
- }
- else {
- OK(test, !has_exposure, "%s means not %s", exposures[i],
- exposures[j]);
- }
- }
- CFCBase_decref((CFCBase*)symbol);
- }
- }
-
- {
- CFCSymbol *foo = CFCSymbol_new(parcel, "parcel", "Foo", NULL, "sym");
- CFCSymbol *foo_jr
- = CFCSymbol_new(parcel, "parcel", "Foo::FooJr", NULL, "sym");
-
- int equal = CFCSymbol_equals(foo, foo_jr);
- OK(test, !equal, "different class_name spoils equals");
- const char *foo_jr_name = CFCSymbol_get_class_name(foo_jr);
- STR_EQ(test, foo_jr_name, "Foo::FooJr", "get_class_name");
- const char *foo_jr_cnick = CFCSymbol_get_class_cnick(foo_jr);
- STR_EQ(test, foo_jr_cnick, "FooJr",
- "derive class_cnick from class_name");
-
- CFCBase_decref((CFCBase*)foo);
- CFCBase_decref((CFCBase*)foo_jr);
- }
-
- {
- CFCSymbol *public_exposure
- = CFCSymbol_new(parcel, "public", NULL, NULL, "sym");
- CFCSymbol *parcel_exposure
- = CFCSymbol_new(parcel, "parcel", NULL, NULL, "sym");
- int equal = CFCSymbol_equals(public_exposure, parcel_exposure);
- OK(test, !equal, "different exposure spoils equals");
- CFCBase_decref((CFCBase*)public_exposure);
- CFCBase_decref((CFCBase*)parcel_exposure);
- }
-
- {
- CFCParcel *lucifer_parcel
- = CFCParcel_new("Lucifer", NULL, NULL, false);
- CFCParcel_register(lucifer_parcel);
- CFCSymbol *lucifer
- = CFCSymbol_new(lucifer_parcel, "parcel", NULL, NULL, "sym");
-
- CFCParcel *symbol_parcel = CFCSymbol_get_parcel(lucifer);
- OK(test, symbol_parcel == lucifer_parcel, "derive parcel");
- const char *prefix = CFCSymbol_get_prefix(lucifer);
- STR_EQ(test, prefix, "lucifer_", "get_prefix");
- const char *Prefix = CFCSymbol_get_Prefix(lucifer);
- STR_EQ(test, Prefix, "Lucifer_", "get_Prefix");
- const char *PREFIX = CFCSymbol_get_PREFIX(lucifer);
- STR_EQ(test, PREFIX, "LUCIFER_", "get_PREFIX");
-
- CFCParcel *luser_parcel = CFCParcel_new("Luser", NULL, NULL, false);
- CFCParcel_register(luser_parcel);
- CFCSymbol *luser
- = CFCSymbol_new(luser_parcel, "parcel", NULL, NULL, "sym");
- int equal = CFCSymbol_equals(lucifer, luser);
- OK(test, !equal, "different exposure spoils equals");
-
- CFCBase_decref((CFCBase*)lucifer_parcel);
- CFCBase_decref((CFCBase*)lucifer);
- CFCBase_decref((CFCBase*)luser_parcel);
- CFCBase_decref((CFCBase*)luser);
- }
-
- {
- CFCSymbol *ooga = CFCSymbol_new(parcel, "parcel", NULL, NULL, "ooga");
- CFCSymbol *booga
- = CFCSymbol_new(parcel, "parcel", NULL, NULL, "booga");
- int equal = CFCSymbol_equals(ooga, booga);
- OK(test, !equal, "different micro_sym spoils equals");
- CFCBase_decref((CFCBase*)ooga);
- CFCBase_decref((CFCBase*)booga);
- }
-
- {
- CFCParcel *eep_parcel = CFCParcel_new("Eep", NULL, NULL, false);
- CFCParcel_register(eep_parcel);
- CFCSymbol *eep
- = CFCSymbol_new(eep_parcel, "parcel", "Op::Ork", NULL, "ah_ah");
- const char *short_sym = CFCSymbol_short_sym(eep);
- STR_EQ(test, short_sym, "Ork_ah_ah", "short_sym");
- const char *full_sym = CFCSymbol_full_sym(eep);
- STR_EQ(test, full_sym, "eep_Ork_ah_ah", "full_sym");
- CFCBase_decref((CFCBase*)eep_parcel);
- CFCBase_decref((CFCBase*)eep);
- }
-
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestType.c b/clownfish/compiler/src/CFCTestType.c
deleted file mode 100644
index f452767..0000000
--- a/clownfish/compiler/src/CFCTestType.c
+++ /dev/null
@@ -1,545 +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 "CFCClass.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-#include "CFCUtil.h"
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-static void
-S_run_tests(CFCTest *test);
-
-static void
-S_run_basic_tests(CFCTest *test);
-
-static void
-S_run_primitive_tests(CFCTest *test);
-
-static void
-S_run_integer_tests(CFCTest *test);
-
-static void
-S_run_float_tests(CFCTest *test);
-
-static void
-S_run_void_tests(CFCTest *test);
-
-static void
-S_run_object_tests(CFCTest *test);
-
-static void
-S_run_va_list_tests(CFCTest *test);
-
-static void
-S_run_arbitrary_tests(CFCTest *test);
-
-static void
-S_run_composite_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_TYPE = {
- "Clownfish::CFC::Model::Type",
- 360,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- S_run_basic_tests(test);
- S_run_primitive_tests(test);
- S_run_integer_tests(test);
- S_run_float_tests(test);
- S_run_void_tests(test);
- S_run_object_tests(test);
- S_run_va_list_tests(test);
- S_run_arbitrary_tests(test);
- S_run_composite_tests(test);
-}
-
-static void
-S_run_basic_tests(CFCTest *test) {
- CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, false);
- CFCParcel_register(neato_parcel);
- CFCType *type = CFCType_new(0, neato_parcel, "mytype_t", 0);
-
- OK(test, CFCType_get_parcel(type) == neato_parcel, "get_parcel");
- STR_EQ(test, CFCType_to_c(type), "mytype_t", "to_c");
- STR_EQ(test, CFCType_get_specifier(type), "mytype_t", "get_specifier");
-
-#define TEST_BOOL_ACCESSOR(type, name) \
- OK(test, !CFCType_ ## name(type), #name " false by default");
-
- TEST_BOOL_ACCESSOR(type, const);
- TEST_BOOL_ACCESSOR(type, nullable);
- TEST_BOOL_ACCESSOR(type, incremented);
- TEST_BOOL_ACCESSOR(type, decremented);
- TEST_BOOL_ACCESSOR(type, is_void);
- TEST_BOOL_ACCESSOR(type, is_object);
- TEST_BOOL_ACCESSOR(type, is_primitive);
- TEST_BOOL_ACCESSOR(type, is_integer);
- TEST_BOOL_ACCESSOR(type, is_floating);
- TEST_BOOL_ACCESSOR(type, is_string_type);
- TEST_BOOL_ACCESSOR(type, is_va_list);
- TEST_BOOL_ACCESSOR(type, is_arbitrary);
- TEST_BOOL_ACCESSOR(type, is_composite);
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)type);
-
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_primitive_tests(CFCTest *test) {
- CFCParcel *parcel = CFCParcel_default_parcel();
- CFCType *type = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0);
- OK(test, CFCType_is_primitive(type), "is_primitive");
-
- {
- CFCType *twin = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0);
- OK(test, CFCType_equals(type, twin), "equals");
- CFCBase_decref((CFCBase*)twin);
- }
-
- {
- CFCType *other = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "dump_t", 0);
- OK(test, !CFCType_equals(type, other), "equals spoiled by specifier");
- CFCBase_decref((CFCBase*)other);
- }
-
- {
- CFCType *other = CFCType_new(CFCTYPE_PRIMITIVE|CFCTYPE_CONST, parcel,
- "hump_t", 0);
- OK(test, !CFCType_equals(type, other), "equals spoiled by const");
- CFCBase_decref((CFCBase*)other);
- }
-
- CFCBase_decref((CFCBase*)type);
-}
-
-static void
-S_run_integer_tests(CFCTest *test) {
- {
- CFCType *type = CFCType_new_integer(CFCTYPE_CONST, "int32_t");
- OK(test, CFCType_const(type), "const");
- STR_EQ(test, CFCType_get_specifier(type), "int32_t", "get_specifier");
- STR_EQ(test, CFCType_to_c(type), "const int32_t",
- "'const' in C representation");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCParser *parser = CFCParser_new();
- static const char *specifiers[14] = {
- "bool",
- "char",
- "short",
- "int",
- "long",
- "size_t",
- "int8_t",
- "int16_t",
- "int32_t",
- "int64_t",
- "uint8_t",
- "uint16_t",
- "uint32_t",
- "uint64_t"
- };
- for (int i = 0; i < 14; ++i) {
- const char *specifier = specifiers[i];
- CFCType *type;
-
- type = CFCTest_parse_type(test, parser, specifier);
- OK(test, CFCType_is_integer(type), "%s is_integer", specifier);
- CFCBase_decref((CFCBase*)type);
-
- char *const_specifier = CFCUtil_sprintf("const %s", specifier);
- type = CFCTest_parse_type(test, parser, const_specifier);
- OK(test, CFCType_is_integer(type), "%s is_integer",
- const_specifier);
- OK(test, CFCType_const(type), "%s is const", const_specifier);
- FREEMEM(const_specifier);
- CFCBase_decref((CFCBase*)type);
- }
- CFCBase_decref((CFCBase*)parser);
- }
-}
-
-static void
-S_run_float_tests(CFCTest *test) {
- {
- CFCType *type = CFCType_new_float(CFCTYPE_CONST, "float");
- OK(test, CFCType_const(type), "const");
- STR_EQ(test, CFCType_get_specifier(type), "float", "get_specifier");
- STR_EQ(test, CFCType_to_c(type), "const float",
- "'const' in C representation");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCParser *parser = CFCParser_new();
- static const char *specifiers[2] = {
- "float",
- "double"
- };
- for (int i = 0; i < 2; ++i) {
- const char *specifier = specifiers[i];
- CFCType *type;
-
- type = CFCTest_parse_type(test, parser, specifier);
- OK(test, CFCType_is_floating(type), "%s is_floating", specifier);
- CFCBase_decref((CFCBase*)type);
-
- char *const_specifier = CFCUtil_sprintf("const %s", specifier);
- type = CFCTest_parse_type(test, parser, const_specifier);
- OK(test, CFCType_is_floating(type), "%s is_floating",
- const_specifier);
- OK(test, CFCType_const(type), "%s is const", const_specifier);
- FREEMEM(const_specifier);
- CFCBase_decref((CFCBase*)type);
- }
- CFCBase_decref((CFCBase*)parser);
- }
-}
-
-static void
-S_run_void_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
-
- {
- CFCType *type = CFCType_new_void(false);
- STR_EQ(test, CFCType_get_specifier(type), "void", "get_specifier");
- STR_EQ(test, CFCType_to_c(type), "void", "to_c");
- OK(test, CFCType_is_void(type), "is_void");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCType *type = CFCType_new_void(true);
- STR_EQ(test, CFCType_to_c(type), "const void",
- "'const' in C representation");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "void");
- OK(test, CFCType_is_void(type), "void is_void");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "const void");
- OK(test, CFCType_is_void(type), "const void is_void");
- OK(test, CFCType_const(type), "const void is const");
- CFCBase_decref((CFCBase*)type);
- }
-
- CFCBase_decref((CFCBase*)parser);
-}
-
-static void
-S_run_object_tests(CFCTest *test) {
- static const char *modifiers[4] = {
- "const", "incremented", "decremented", "nullable"
- };
- static int flags[4] = {
- CFCTYPE_CONST,
- CFCTYPE_INCREMENTED,
- CFCTYPE_DECREMENTED,
- CFCTYPE_NULLABLE
- };
- static int (*accessors[4])(CFCType *type) = {
- CFCType_const,
- CFCType_incremented,
- CFCType_decremented,
- CFCType_nullable
- };
-
- {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
-
- static const char *specifiers[4] = {
- "Foo", "FooJr", "FooIII", "Foo4th"
- };
- for (int i = 0; i < 4; ++i) {
- const char *specifier = specifiers[i];
-
- char *class_code = CFCUtil_sprintf("class %s {}", specifier);
- CFCClass *klass = CFCTest_parse_class(test, parser, class_code);
- CFCClass *class_list[2] = { klass, NULL };
- FREEMEM(class_code);
-
- static const char *prefixes[2] = { "", "neato_" };
- char *expect = CFCUtil_sprintf("neato_%s", specifier);
- for (int j = 0; j < 2; ++j) {
- char *src = CFCUtil_sprintf("%s%s*", prefixes[j], specifier);
- CFCType *type = CFCTest_parse_type(test, parser, src);
- CFCType_resolve(type, class_list);
- STR_EQ(test, CFCType_get_specifier(type), expect,
- "object_type_specifier: %s", src);
- OK(test, CFCType_is_object(type), "%s is_object", src);
- INT_EQ(test, CFCType_get_indirection(type), 1,
- "%s indirection", src);
-
- FREEMEM(src);
- CFCBase_decref((CFCBase*)type);
- }
- FREEMEM(expect);
-
- for (int j = 0; j < 4; ++j) {
- char *src = CFCUtil_sprintf("%s %s*", modifiers[j], specifier);
- CFCType *type = CFCTest_parse_type(test, parser, src);
- OK(test, CFCType_is_object(type), "%s is_object", src);
- OK(test, accessors[j](type), "%s accessor", src);
-
- FREEMEM(src);
- CFCBase_decref((CFCBase*)type);
- }
-
- CFCBase_decref((CFCBase*)klass);
- CFCClass_clear_registry();
- }
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)parser);
- }
-
- CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, false);
- CFCClass *foo_class
- = CFCClass_create(neato_parcel, NULL, "Foo", NULL, NULL, NULL, NULL,
- NULL, false, false);
- CFCClass *class_list[2] = { foo_class, NULL };
- CFCType *foo = CFCType_new_object(0, NULL, "Foo", 1);
- CFCType_resolve(foo, class_list);
-
- {
- CFCType *another_foo = CFCType_new_object(0, NULL, "Foo", 1);
- CFCType_resolve(another_foo, class_list);
- OK(test, CFCType_equals(foo, another_foo), "equals");
- CFCBase_decref((CFCBase*)another_foo);
- }
-
- {
- CFCType *bar = CFCType_new_object(0, NULL, "Bar", 1);
- OK(test, !CFCType_equals(foo, bar),
- "different specifier spoils equals");
- CFCBase_decref((CFCBase*)bar);
- }
-
- {
- CFCParcel *foreign_parcel
- = CFCParcel_new("Foreign", NULL, NULL, false);
- CFCClass *foreign_foo_class
- = CFCClass_create(foreign_parcel, NULL, "Foreign::Foo", NULL, NULL,
- NULL, NULL, NULL, false, false);
- CFCClass *foreign_class_list[2] = { foreign_foo_class, NULL };
- CFCType *foreign_foo = CFCType_new_object(0, foreign_parcel, "Foo", 1);
- CFCType_resolve(foreign_foo, foreign_class_list);
- OK(test, !CFCType_equals(foo, foreign_foo),
- "different parcel spoils equals");
- STR_EQ(test, CFCType_get_specifier(foreign_foo), "foreign_Foo",
- "prepend parcel prefix to specifier");
- CFCBase_decref((CFCBase*)foreign_parcel);
- CFCBase_decref((CFCBase*)foreign_foo_class);
- CFCBase_decref((CFCBase*)foreign_foo);
- }
-
- {
- for (int i = 0; i < 4; ++i) {
- CFCType *modified_foo
- = CFCType_new_object(flags[i], NULL, "Foo", 1);
- OK(test, accessors[i](modified_foo), "%s", modifiers[i]);
- OK(test, !accessors[i](foo), "not %s", modifiers[i]);
- OK(test, !CFCType_equals(foo, modified_foo),
- "different %s spoils equals", modifiers[i]);
- OK(test, !CFCType_similar(foo, modified_foo),
- "different %s spoils similar", modifiers[i]);
- CFCBase_decref((CFCBase*)modified_foo);
- }
- }
-
- {
- CFCType *string_type = CFCType_new_object(0, NULL, "String", 1);
- OK(test, CFCType_is_string_type(string_type), "%s", "is_string_type");
- OK(test, !CFCType_is_string_type(foo), "not %s", "not is_string_type");
- CFCBase_decref((CFCBase*)string_type);
- }
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)foo_class);
- CFCBase_decref((CFCBase*)foo);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_va_list_tests(CFCTest *test) {
- {
- CFCType *type = CFCType_new_va_list();
- STR_EQ(test, CFCType_get_specifier(type), "va_list",
- "specifier defaults to 'va_list'");
- STR_EQ(test, CFCType_to_c(type), "va_list", "to_c");
- CFCBase_decref((CFCBase*)type);
- }
-
- {
- CFCParser *parser = CFCParser_new();
- CFCType *type = CFCTest_parse_type(test, parser, "va_list");
- OK(test, CFCType_is_va_list(type), "is_va_list");
- CFCBase_decref((CFCBase*)type);
- CFCBase_decref((CFCBase*)parser);
- }
-}
-
-static void
-S_run_arbitrary_tests(CFCTest *test) {
- {
- CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, false);
- CFCParcel_register(neato_parcel);
-
- CFCType *foo = CFCType_new_arbitrary(neato_parcel, "foo_t");
- STR_EQ(test, CFCType_get_specifier(foo), "foo_t", "get_specifier");
- STR_EQ(test, CFCType_to_c(foo), "foo_t", "to_c");
-
- CFCType *twin = CFCType_new_arbitrary(neato_parcel, "foo_t");
- OK(test, CFCType_equals(foo, twin), "equals");
-
- CFCType *compare_t
- = CFCType_new_arbitrary(neato_parcel, "Sort_compare_t");
- OK(test, !CFCType_equals(foo, compare_t),
- "equals spoiled by different specifier");
-
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)foo);
- CFCBase_decref((CFCBase*)compare_t);
- CFCBase_decref((CFCBase*)twin);
- }
-
- {
- CFCParser *parser = CFCParser_new();
- static const char *specifiers[2] = { "foo_t", "Sort_compare_t" };
- for (int i = 0; i < 2; ++i) {
- const char *specifier = specifiers[i];
- CFCType *type = CFCTest_parse_type(test, parser, specifier);
- OK(test, CFCType_is_arbitrary(type), "arbitrary type %s",
- specifier);
- CFCBase_decref((CFCBase*)type);
- }
- CFCBase_decref((CFCBase*)parser);
- }
-
- CFCParcel_reap_singletons();
-}
-
-static void
-S_run_composite_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
-
- {
- static const char *type_strings[14] = {
- "char*",
- "char**",
- "char***",
- "int32_t*",
- "Obj**",
- "int8_t[]",
- "int8_t[1]",
- "neato_method_t[]",
- "neato_method_t[1]",
- "multi_dimensional_t[1][10]",
- "char * * ",
- "const Obj**",
- "const void*",
- "int8_t[ 3 ]"
- };
- for (int i = 0; i < 14; ++i) {
- const char *type_string = type_strings[i];
- CFCType *type = CFCTest_parse_type(test, parser, type_string);
- OK(test, CFCType_is_composite(type), "composite type %s",
- type_string);
- CFCBase_decref((CFCBase*)type);
- }
- }
-
- {
- CFCType *foo = CFCType_new_object(0, NULL, "Foo", 1);
- CFCType *const_foo = CFCType_new_object(CFCTYPE_CONST, NULL, "Foo", 1);
-
- CFCType *composite = CFCType_new_composite(0, foo, 1, NULL);
- OK(test, CFCType_is_composite(composite), "is_composite");
- STR_EQ(test, CFCType_get_specifier(composite), "Foo",
- "get_specifier delegates to child" );
-
- CFCType *twin = CFCType_new_composite(0, foo, 1, NULL);
- OK(test, CFCType_equals(composite, twin), "equals");
- CFCBase_decref((CFCBase*)twin);
-
- CFCType *const_composite
- = CFCType_new_composite(0, const_foo, 1, NULL);
- OK(test, !CFCType_equals(composite, const_composite),
- "equals spoiled by different child");
- CFCBase_decref((CFCBase*)const_composite);
-
- CFCBase_decref((CFCBase*)composite);
- CFCBase_decref((CFCBase*)foo);
- CFCBase_decref((CFCBase*)const_foo);
- }
-
- {
- CFCClass *class_list[1] = { NULL };
- CFCType *foo_array = CFCTest_parse_type(test, parser, "foo_t[]");
- CFCType_resolve(foo_array, class_list);
- STR_EQ(test, CFCType_get_array(foo_array), "[]", "get_array");
- STR_EQ(test, CFCType_to_c(foo_array), "foo_t",
- "array subscripts not included by to_c");
- CFCType *foo_array_array
- = CFCTest_parse_type(test, parser, "foo_t[][]");
- OK(test, !CFCType_equals(foo_array, foo_array_array),
- "equals spoiled by different array postfixes");
-
- CFCBase_decref((CFCBase*)foo_array);
- CFCBase_decref((CFCBase*)foo_array_array);
- }
-
- {
- CFCType *foo_star = CFCTest_parse_type(test, parser, "foo_t*");
- CFCType *foo_star_star = CFCTest_parse_type(test, parser, "foo_t**");
- OK(test, !CFCType_equals(foo_star, foo_star_star),
- "equals spoiled by different levels of indirection");
- INT_EQ(test, CFCType_get_indirection(foo_star), 1,
- "foo_t* indirection");
- INT_EQ(test, CFCType_get_indirection(foo_star_star), 2,
- "foo_t** indirection");
-
- CFCBase_decref((CFCBase*)foo_star);
- CFCBase_decref((CFCBase*)foo_star_star);
- }
-
- CFCBase_decref((CFCBase*)parser);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestUtil.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestUtil.c b/clownfish/compiler/src/CFCTestUtil.c
deleted file mode 100644
index fd431e3..0000000
--- a/clownfish/compiler/src/CFCTestUtil.c
+++ /dev/null
@@ -1,120 +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 <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#define CFC_USE_TEST_MACROS
-#include "CFCUtil.h"
-#include "CFCTest.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-static void
-S_run_string_tests(CFCTest *test);
-
-static void
-S_run_file_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_UTIL = {
- "Clownfish::CFC::Util",
- 15,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- S_run_string_tests(test);
- S_run_file_tests(test);
-}
-
-static void
-S_run_string_tests(CFCTest *test) {
- const char *src = "Source string";
- char *str;
-
- str = CFCUtil_strdup(src);
- STR_EQ(test, str, src, "strdup");
- FREEMEM(str);
- str = CFCUtil_strndup(src, 6);
- STR_EQ(test, str, "Source", "strndup");
- FREEMEM(str);
- str = CFCUtil_sprintf("%s: %d", src, 123456789);
- STR_EQ(test, str, "Source string: 123456789", "sprintf");
- str = CFCUtil_cat(str, " ", "abc", NULL);
- STR_EQ(test, str, "Source string: 123456789 abc", "cat");
- FREEMEM(str);
- str = CFCUtil_strdup(" \r\n\tabc \r\n\tdef \r\n\t");
- CFCUtil_trim_whitespace(str);
- STR_EQ(test, str, "abc \r\n\tdef", "trim_whitespace");
- FREEMEM(str);
-}
-
-static void
-S_run_file_tests(CFCTest *test) {
- const char *foo_txt = "foo.txt";
- remove(foo_txt);
- CFCUtil_write_file(foo_txt, "foo", 3);
-
- {
- FILE *file = fopen(foo_txt, "rb");
- OK(test, file != NULL, "can open file");
- char buf[10];
- size_t chars_read = fread(buf, 1, 10, file);
- INT_EQ(test, chars_read, 3, "read correct number of chars");
- OK(test, memcmp(buf, "foo", 3) == 0, "read correct string");
-
- long file_length = CFCUtil_flength(file);
- INT_EQ(test, file_length, 3, "flength");
-
- fclose(file);
- }
-
- {
- size_t content_len;
- char *content = CFCUtil_slurp_text(foo_txt, &content_len);
- INT_EQ(test, content_len, 3, "slurp_text len");
- OK(test, memcmp(content, "foo", 3) == 0, "slurp_text content");
- FREEMEM(content);
- }
-
- {
- OK(test, CFCUtil_current(foo_txt, foo_txt), "current");
- OK(test, !CFCUtil_current(foo_txt, "nonexistent_file"),
- "not current when dest file missing");
- // TODO: Test two different files.
- }
-
- {
- time_t past_time = time(NULL) - 10;
- CFCTest_set_file_times(foo_txt, past_time);
- past_time = CFCTest_get_file_mtime(foo_txt);
- time_t mtime;
- CFCUtil_write_if_changed(foo_txt, "foo", 3);
- mtime = CFCTest_get_file_mtime(foo_txt);
- OK(test, mtime == past_time,
- "write_if_changed does nothing if contents not changed");
- CFCUtil_write_if_changed(foo_txt, "foofoo", 6);
- mtime = CFCTest_get_file_mtime(foo_txt);
- OK(test, mtime != past_time,
- "write_if_changed writes if contents changed");
- }
-
- remove(foo_txt);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestVariable.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestVariable.c b/clownfish/compiler/src/CFCTestVariable.c
deleted file mode 100644
index e8096e7..0000000
--- a/clownfish/compiler/src/CFCTestVariable.c
+++ /dev/null
@@ -1,108 +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 "CFCClass.h"
-#include "CFCParcel.h"
-#include "CFCParser.h"
-#include "CFCSymbol.h"
-#include "CFCTest.h"
-#include "CFCType.h"
-#include "CFCVariable.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_VARIABLE = {
- "Clownfish::CFC::Model::Variable",
- 29,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCParser *parser = CFCParser_new();
- CFCParcel *neato_parcel
- = CFCTest_parse_parcel(test, parser, "parcel Neato;");
- CFCClass *foo_class = CFCTest_parse_class(test, parser, "class Foo {}");
- CFCClass *class_list[2] = { foo_class, NULL };
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "float*");
- CFCVariable *var
- = CFCVariable_new(NULL, NULL, NULL, NULL, "foo", type, 0);
- CFCVariable_resolve_type(var, class_list);
- STR_EQ(test, CFCVariable_local_c(var), "float* foo", "local_c");
- STR_EQ(test, CFCVariable_local_declaration(var), "float* foo;",
- "local_declaration");
- OK(test, CFCSymbol_local((CFCSymbol*)var), "default to local access");
-
- CFCBase_decref((CFCBase*)type);
- CFCBase_decref((CFCBase*)var);
- }
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "float[1]");
- CFCVariable *var
- = CFCVariable_new(NULL, NULL, NULL, NULL, "foo", type, 0);
- CFCVariable_resolve_type(var, class_list);
- STR_EQ(test, CFCVariable_local_c(var), "float foo[1]",
- "to_c appends array to var name rather than type specifier");
-
- CFCBase_decref((CFCBase*)type);
- CFCBase_decref((CFCBase*)var);
- }
-
- {
- CFCType *type = CFCTest_parse_type(test, parser, "Foo*");
- CFCVariable *var
- = CFCVariable_new(neato_parcel, NULL,
- "Crustacean::Lobster::LobsterClaw", "LobClaw",
- "foo", type, 0);
- CFCVariable_resolve_type(var, class_list);
- STR_EQ(test, CFCVariable_global_c(var), "neato_Foo* neato_LobClaw_foo",
- "global_c");
-
- CFCBase_decref((CFCBase*)type);
- CFCBase_decref((CFCBase*)var);
- }
-
- {
- static const char *variable_strings[7] = {
- "int foo;",
- "inert Obj *obj;",
- "public inert int32_t **foo;",
- "Dog *fido;",
- "uint32_t baz",
- "String *stuff",
- "float **ptr"
- };
- for (int i = 0; i < 7; ++i) {
- CFCVariable *var
- = CFCTest_parse_variable(test, parser, variable_strings[i]);
- CFCBase_decref((CFCBase*)var);
- }
- }
-
- CFCBase_decref((CFCBase*)parser);
- CFCBase_decref((CFCBase*)neato_parcel);
- CFCBase_decref((CFCBase*)foo_class);
-
- CFCClass_clear_registry();
- CFCParcel_reap_singletons();
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCTestVersion.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCTestVersion.c b/clownfish/compiler/src/CFCTestVersion.c
deleted file mode 100644
index 693e01b..0000000
--- a/clownfish/compiler/src/CFCTestVersion.c
+++ /dev/null
@@ -1,69 +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 "CFCVersion.h"
-#include "CFCTest.h"
-
-static void
-S_run_tests(CFCTest *test);
-
-const CFCTestBatch CFCTEST_BATCH_VERSION = {
- "Clownfish::CFC::Model::Version",
- 11,
- S_run_tests
-};
-
-static void
-S_run_tests(CFCTest *test) {
- CFCVersion *v3_2 = CFCVersion_new("v3.2");
- CFCVersion *v3_2_0 = CFCVersion_new("v3.2.0");
- CFCVersion *v3_2_1 = CFCVersion_new("v3.2.1");
- CFCVersion *v3_2_1_0 = CFCVersion_new("v3.2.1.0");
- CFCVersion *v3_3 = CFCVersion_new("v3.3");
- CFCVersion *v90210 = CFCVersion_new("v90210");
-
- INT_EQ(test, CFCVersion_get_major(v3_2_1), 3, "get_major");
- INT_EQ(test, CFCVersion_get_major(v90210), 90210, "parse big number");
- STR_EQ(test, CFCVersion_get_vstring(v3_2_1), "v3.2.1", "get_vstring");
-
- int result;
- result = CFCVersion_compare_to(v3_2_1, v3_2_1_0);
- INT_EQ(test, result, 0, "ignore zeroes in compare_to");
- result = CFCVersion_compare_to(v3_2_1_0, v3_2_1);
- INT_EQ(test, result, 0, "ignore zeroes in compare_to");
- result = CFCVersion_compare_to(v3_2_1, v3_3);
- INT_EQ(test, result, -1, "compare_to A < B_fewer_digits");
- result = CFCVersion_compare_to(v3_3, v3_2_1);
- INT_EQ(test, result, 1, "compare_to A_fewer_digits > B");
- result = CFCVersion_compare_to(v3_2_1, v3_2);
- INT_EQ(test, result, 1, "compare_to A < B_fewer_digits");
- result = CFCVersion_compare_to(v3_2, v3_2_1);
- INT_EQ(test, result, -1, "compare_to A_fewer_digits > B");
- result = CFCVersion_compare_to(v3_2_1, v3_2_0);
- INT_EQ(test, result, 1, "compare_to A > B");
- result = CFCVersion_compare_to(v3_2_0, v3_2_1);
- INT_EQ(test, result, -1, "compare_to A < B");
-
- CFCBase_decref((CFCBase*)v3_2);
- CFCBase_decref((CFCBase*)v3_2_0);
- CFCBase_decref((CFCBase*)v3_2_1);
- CFCBase_decref((CFCBase*)v3_2_1_0);
- CFCBase_decref((CFCBase*)v3_3);
- CFCBase_decref((CFCBase*)v90210);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/1704c275/clownfish/compiler/src/CFCType.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCType.c b/clownfish/compiler/src/CFCType.c
deleted file mode 100644
index a41ecbd..0000000
--- a/clownfish/compiler/src/CFCType.c
+++ /dev/null
@@ -1,535 +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 <stdio.h>
-#include <ctype.h>
-
-#ifndef true
- #define true 1
- #define false 0
-#endif
-
-#define CFC_NEED_BASE_STRUCT_DEF
-#include "CFCBase.h"
-#include "CFCType.h"
-#include "CFCClass.h"
-#include "CFCParcel.h"
-#include "CFCSymbol.h"
-#include "CFCUtil.h"
-
-struct CFCType {
- CFCBase base;
- int flags;
- char *specifier;
- char *vtable_var;
- int indirection;
- struct CFCParcel *parcel;
- char *c_string;
- size_t width;
- char *array;
- struct CFCType *child;
-};
-
-static const CFCMeta CFCTYPE_META = {
- "Clownfish::CFC::Model::Type",
- sizeof(CFCType),
- (CFCBase_destroy_t)CFCType_destroy
-};
-
-CFCType*
-CFCType_new(int flags, struct CFCParcel *parcel, const char *specifier,
- int indirection) {
- CFCType *self = (CFCType*)CFCBase_allocate(&CFCTYPE_META);
- return CFCType_init(self, flags, parcel, specifier, indirection);
-}
-
-static void
-S_check_flags(int supplied, int acceptable, const char *type_name) {
- int bad = (supplied & ~acceptable);
- if (bad) {
- char bad_flag[20];
- if ((bad & CFCTYPE_CONST)) { strcpy(bad_flag, "CONST"); }
- else if ((bad & CFCTYPE_NULLABLE)) { strcpy(bad_flag, "NULLABLE"); }
- else if ((bad & CFCTYPE_INCREMENTED)) { strcpy(bad_flag, "INCREMENTED"); }
- else if ((bad & CFCTYPE_DECREMENTED)) { strcpy(bad_flag, "DECREMENTED"); }
- else if ((bad & CFCTYPE_OBJECT)) { strcpy(bad_flag, "OBJECT"); }
- else if ((bad & CFCTYPE_PRIMITIVE)) { strcpy(bad_flag, "PRIMITIVE"); }
- else if ((bad & CFCTYPE_INTEGER)) { strcpy(bad_flag, "INTEGER"); }
- else if ((bad & CFCTYPE_FLOATING)) { strcpy(bad_flag, "FLOATING"); }
- else if ((bad & CFCTYPE_STRING_TYPE)) { strcpy(bad_flag, "STRING_TYPE"); }
- else if ((bad & CFCTYPE_VA_LIST)) { strcpy(bad_flag, "VA_LIST"); }
- else if ((bad & CFCTYPE_ARBITRARY)) { strcpy(bad_flag, "ARBITRARY"); }
- else if ((bad & CFCTYPE_COMPOSITE)) { strcpy(bad_flag, "COMPOSITE"); }
- else {
- CFCUtil_die("Unknown flags: %d", bad);
- }
- CFCUtil_die("Bad flag for type %s: %s", type_name, bad_flag);
- }
-}
-
-CFCType*
-CFCType_init(CFCType *self, int flags, struct CFCParcel *parcel,
- const char *specifier, int indirection) {
- self->flags = flags;
- self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
- self->specifier = CFCUtil_strdup(specifier);
- self->indirection = indirection;
- self->c_string = NULL;
- self->width = 0;
- self->array = NULL;
- self->child = NULL;
- self->vtable_var = NULL;
-
- return self;
-}
-
-CFCType*
-CFCType_new_integer(int flags, const char *specifier) {
- // Validate specifier, find width.
- size_t width;
- if (!strcmp(specifier, "int8_t") || !strcmp(specifier, "uint8_t")) {
- width = 1;
- }
- else if (!strcmp(specifier, "int16_t") || !strcmp(specifier, "uint16_t")) {
- width = 2;
- }
- else if (!strcmp(specifier, "int32_t") || !strcmp(specifier, "uint32_t")) {
- width = 4;
- }
- else if (!strcmp(specifier, "int64_t") || !strcmp(specifier, "uint64_t")) {
- width = 8;
- }
- else if (!strcmp(specifier, "char")
- || !strcmp(specifier, "short")
- || !strcmp(specifier, "int")
- || !strcmp(specifier, "long")
- || !strcmp(specifier, "size_t")
- || !strcmp(specifier, "bool") // Charmonizer type.
- ) {
- width = 0;
- }
- else {
- CFCUtil_die("Unknown integer specifier: '%s'", specifier);
- }
-
- // Add flags.
- flags |= CFCTYPE_PRIMITIVE;
- flags |= CFCTYPE_INTEGER;
- S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_INTEGER,
- "Integer");
-
- CFCType *self = CFCType_new(flags, NULL, specifier, 0);
- self->width = width;
- return self;
-}
-
-static const char *float_specifiers[] = {
- "float",
- "double",
- NULL
-};
-
-CFCType*
-CFCType_new_float(int flags, const char *specifier) {
- // Validate specifier.
- for (size_t i = 0; ; i++) {
- if (!float_specifiers[i]) {
- CFCUtil_die("Unknown float specifier: '%s'", specifier);
- }
- if (strcmp(float_specifiers[i], specifier) == 0) {
- break;
- }
- }
-
- flags |= CFCTYPE_PRIMITIVE;
- flags |= CFCTYPE_FLOATING;
- S_check_flags(flags, CFCTYPE_CONST | CFCTYPE_PRIMITIVE | CFCTYPE_FLOATING,
- "Floating");
-
- return CFCType_new(flags, NULL, specifier, 0);
-}
-
-CFCType*
-CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier,
- int indirection) {
- // Validate params.
- if (indirection != 1) {
- CFCUtil_die("Parameter 'indirection' can only be 1");
- }
- if (!specifier || !strlen(specifier)) {
- CFCUtil_die("Missing required param 'specifier'");
- }
- if ((flags & CFCTYPE_INCREMENTED) && (flags & CFCTYPE_DECREMENTED)) {
- CFCUtil_die("Can't be both incremented and decremented");
- }
-
- // Use default parcel if none supplied.
- if (!parcel) {
- parcel = CFCParcel_default_parcel();
- }
-
- // Add flags.
- flags |= CFCTYPE_OBJECT;
- if (strstr(specifier, "String")) {
- // Determine whether this type is a string type.
- flags |= CFCTYPE_STRING_TYPE;
- }
-
- // Validate specifier.
- if (!isalpha(*specifier)) {
- CFCUtil_die("Invalid specifier: '%s'", specifier);
- }
- const char *small_specifier = specifier;
- while (!isupper(*small_specifier)) {
- if (!isalnum(*small_specifier) && *small_specifier != '_') {
- CFCUtil_die("Invalid specifier: '%s'", specifier);
- }
- small_specifier++;
- }
- if (!CFCSymbol_validate_class_name_component(small_specifier)) {
- CFCUtil_die("Invalid specifier: '%s'", specifier);
- }
-
- int acceptable_flags = CFCTYPE_OBJECT
- | CFCTYPE_STRING_TYPE
- | CFCTYPE_CONST
- | CFCTYPE_NULLABLE
- | CFCTYPE_INCREMENTED
- | CFCTYPE_DECREMENTED;
- S_check_flags(flags, acceptable_flags, "Object");
-
- return CFCType_new(flags, parcel, specifier, 1);
-}
-
-CFCType*
-CFCType_new_composite(int flags, CFCType *child, int indirection,
- const char *array) {
- if (!child) {
- CFCUtil_die("Missing required param 'child'");
- }
- flags |= CFCTYPE_COMPOSITE;
- S_check_flags(flags, CFCTYPE_COMPOSITE | CFCTYPE_NULLABLE, "Composite");
-
- CFCType *self = CFCType_new(flags, NULL, CFCType_get_specifier(child),
- indirection);
- self->child = (CFCType*)CFCBase_incref((CFCBase*)child);
-
- // Record array spec.
- const char *array_spec = array ? array : "";
- size_t array_spec_size = strlen(array_spec) + 1;
- self->array = (char*)MALLOCATE(array_spec_size);
- strcpy(self->array, array_spec);
-
- return self;
-}
-
-CFCType*
-CFCType_new_void(int is_const) {
- int flags = CFCTYPE_VOID;
- if (is_const) { flags |= CFCTYPE_CONST; }
- return CFCType_new(flags, NULL, "void", 0);
-}
-
-CFCType*
-CFCType_new_va_list(void) {
- return CFCType_new(CFCTYPE_VA_LIST, NULL, "va_list", 0);
-}
-
-CFCType*
-CFCType_new_arbitrary(CFCParcel *parcel, const char *specifier) {
- // Validate specifier.
- for (size_t i = 0, max = strlen(specifier); i < max; i++) {
- if (!isalnum(specifier[i]) && specifier[i] != '_') {
- CFCUtil_die("Illegal specifier: '%s'", specifier);
- }
- }
-
- return CFCType_new(CFCTYPE_ARBITRARY, parcel, specifier, 0);
-}
-
-void
-CFCType_resolve(CFCType *self, CFCClass **classes) {
- if (CFCType_is_composite(self)) {
- CFCType_resolve(self->child, classes);
- return;
- }
- if (!CFCType_is_object(self)) {
- return;
- }
-
- CFCClass *klass = NULL;
- char *specifier = self->specifier;
-
- if (isupper(self->specifier[0])) {
- // Try to find class from class list.
- for (size_t i = 0; classes[i]; ++i) {
- CFCClass *maybe_class = classes[i];
- const char *struct_sym = CFCClass_get_struct_sym(maybe_class);
-
- if (strcmp(specifier, struct_sym) == 0) {
- if (klass) {
- CFCUtil_die("Type '%s' is ambigious", specifier);
- }
- klass = maybe_class;
- }
- }
-
- if (!klass) {
- CFCUtil_die("No class found for type '%s'", specifier);
- }
-
- // Create actual specifier with prefix.
- const char *prefix = CFCClass_get_prefix(klass);
- self->specifier = CFCUtil_sprintf("%s%s", prefix, specifier);
- FREEMEM(specifier);
- }
- else {
- // Try to find class from class list.
- for (size_t i = 0; classes[i]; ++i) {
- CFCClass *maybe_class = classes[i];
- const char *full_struct_sym
- = CFCClass_full_struct_sym(maybe_class);
-
- if (strcmp(specifier, full_struct_sym) == 0) {
- klass = maybe_class;
- break;
- }
- }
- }
-
- // Add parcel dependency.
- if (klass) {
- CFCParcel *class_parcel = CFCClass_get_parcel(klass);
- CFCParcel_add_dependent_parcel(self->parcel, class_parcel);
- }
-}
-
-void
-CFCType_destroy(CFCType *self) {
- if (self->child) {
- CFCBase_decref((CFCBase*)self->child);
- }
- CFCBase_decref((CFCBase*)self->parcel);
- FREEMEM(self->specifier);
- FREEMEM(self->c_string);
- FREEMEM(self->array);
- FREEMEM(self->vtable_var);
- CFCBase_destroy((CFCBase*)self);
-}
-
-int
-CFCType_equals(CFCType *self, CFCType *other) {
- if ((CFCType_const(self) ^ CFCType_const(other))
- || (CFCType_nullable(self) ^ CFCType_nullable(other))
- || (CFCType_is_void(self) ^ CFCType_is_void(other))
- || (CFCType_is_object(self) ^ CFCType_is_object(other))
- || (CFCType_is_primitive(self) ^ CFCType_is_primitive(other))
- || (CFCType_is_integer(self) ^ CFCType_is_integer(other))
- || (CFCType_is_floating(self) ^ CFCType_is_floating(other))
- || (CFCType_is_va_list(self) ^ CFCType_is_va_list(other))
- || (CFCType_is_arbitrary(self) ^ CFCType_is_arbitrary(other))
- || (CFCType_is_composite(self) ^ CFCType_is_composite(other))
- || (CFCType_incremented(self) ^ CFCType_incremented(other))
- || (CFCType_decremented(self) ^ CFCType_decremented(other))
- || !!self->child ^ !!other->child
- || !!self->array ^ !!other->array
- ) {
- return false;
- }
- if (self->indirection != other->indirection) { return false; }
- if (strcmp(self->specifier, other->specifier) != 0) { return false; }
- if (self->child) {
- if (!CFCType_equals(self->child, other->child)) { return false; }
- }
- if (self->array) {
- if (strcmp(self->array, other->array) != 0) { return false; }
- }
- return true;
-}
-
-int
-CFCType_similar(CFCType *self, CFCType *other) {
- if (!CFCType_is_object(self)) {
- CFCUtil_die("Attempt to call 'similar' on a non-object type");
- }
- if ((CFCType_const(self) ^ CFCType_const(other))
- || (CFCType_nullable(self) ^ CFCType_nullable(other))
- || (CFCType_incremented(self) ^ CFCType_incremented(other))
- || (CFCType_decremented(self) ^ CFCType_decremented(other))
- || (CFCType_is_object(self) ^ CFCType_is_object(other))
- ) {
- return false;
- }
- return true;
-}
-
-void
-CFCType_set_specifier(CFCType *self, const char *specifier) {
- FREEMEM(self->specifier);
- self->specifier = CFCUtil_strdup(specifier);
-}
-
-const char*
-CFCType_get_specifier(CFCType *self) {
- return self->specifier;
-}
-
-const char*
-CFCType_get_vtable_var(CFCType *self) {
- if (!self->vtable_var) {
- self->vtable_var = CFCUtil_strdup(self->specifier);
- for (int i = 0; self->vtable_var[i] != 0; i++) {
- self->vtable_var[i] = toupper(self->vtable_var[i]);
- }
- }
- return self->vtable_var;
-}
-
-int
-CFCType_get_indirection(CFCType *self) {
- return self->indirection;
-}
-
-struct CFCParcel*
-CFCType_get_parcel(CFCType *self) {
- return self->parcel;
-}
-
-const char*
-CFCType_to_c(CFCType *self) {
- char *c_string = self->c_string;
-
- if (c_string) { return c_string; }
-
- if (CFCType_is_composite(self)) {
- // NOTE: Array postfixes are NOT included.
- const char *child_c_string = CFCType_to_c(self->child);
- size_t child_c_len = strlen(child_c_string);
- size_t amount = child_c_len + self->indirection;
- c_string = (char*)MALLOCATE(amount + 1);
- strcpy(c_string, child_c_string);
- for (int i = 0; i < self->indirection; i++) {
- strncat(c_string, "*", 1);
- }
- }
- else if (CFCType_is_object(self)) {
- if (CFCType_const(self)) {
- c_string = CFCUtil_sprintf("const %s*", self->specifier);
- }
- else {
- c_string = CFCUtil_sprintf("%s*", self->specifier);
- }
- }
- else {
- if (CFCType_const(self)) {
- c_string = CFCUtil_sprintf("const %s", self->specifier);
- }
- else {
- c_string = CFCUtil_strdup(self->specifier);
- }
- }
-
- self->c_string = c_string;
-
- return c_string;
-}
-
-size_t
-CFCType_get_width(CFCType *self) {
- return self->width;
-}
-
-const char*
-CFCType_get_array(CFCType *self) {
- return self->array;
-}
-
-int
-CFCType_const(CFCType *self) {
- return !!(self->flags & CFCTYPE_CONST);
-}
-
-void
-CFCType_set_nullable(CFCType *self, int nullable) {
- if (nullable) {
- self->flags |= CFCTYPE_NULLABLE;
- }
- else {
- self->flags &= ~CFCTYPE_NULLABLE;
- }
-}
-
-int
-CFCType_nullable(CFCType *self) {
- return !!(self->flags & CFCTYPE_NULLABLE);
-}
-
-int
-CFCType_incremented(CFCType *self) {
- return !!(self->flags & CFCTYPE_INCREMENTED);
-}
-
-int
-CFCType_decremented(CFCType *self) {
- return !!(self->flags & CFCTYPE_DECREMENTED);
-}
-
-int
-CFCType_is_void(CFCType *self) {
- return !!(self->flags & CFCTYPE_VOID);
-}
-
-int
-CFCType_is_object(CFCType *self) {
- return !!(self->flags & CFCTYPE_OBJECT);
-}
-
-int
-CFCType_is_primitive(CFCType *self) {
- return !!(self->flags & CFCTYPE_PRIMITIVE);
-}
-
-int
-CFCType_is_integer(CFCType *self) {
- return !!(self->flags & CFCTYPE_INTEGER);
-}
-
-int
-CFCType_is_floating(CFCType *self) {
- return !!(self->flags & CFCTYPE_FLOATING);
-}
-
-int
-CFCType_is_string_type(CFCType *self) {
- return !!(self->flags & CFCTYPE_STRING_TYPE);
-}
-
-int
-CFCType_is_va_list(CFCType *self) {
- return !!(self->flags & CFCTYPE_VA_LIST);
-}
-
-int
-CFCType_is_arbitrary(CFCType *self) {
- return !!(self->flags & CFCTYPE_ARBITRARY);
-}
-
-int
-CFCType_is_composite(CFCType *self) {
- return !!(self->flags & CFCTYPE_COMPOSITE);
-}
-