Add major version to .cfp
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ac45960e Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ac45960e Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ac45960e Branch: refs/heads/master Commit: ac45960e2d3827cef51476bf7c1ee78f9a61dbe1 Parents: 5db69da Author: Nick Wellnhofer <[email protected]> Authored: Fri Jul 15 20:16:23 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Sat Jul 16 16:10:30 2016 +0200 ---------------------------------------------------------------------- compiler/perl/lib/Clownfish/CFC.pm | 13 ++++++---- compiler/perl/lib/Clownfish/CFC.xs | 6 +++-- compiler/src/CFCParcel.c | 45 +++++++++++++++++++++++++-------- compiler/src/CFCParcel.h | 9 +++++-- compiler/src/CFCParseHeader.y | 2 +- compiler/src/CFCTestDocuComment.c | 2 +- compiler/src/CFCTestParcel.c | 33 +++++++++++++++++------- compiler/src/CFCTestParser.c | 2 +- compiler/src/CFCTestSymbol.c | 4 +-- compiler/src/CFCTestType.c | 13 +++++----- 10 files changed, 90 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/perl/lib/Clownfish/CFC.pm ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.pm b/compiler/perl/lib/Clownfish/CFC.pm index 88b687d..c38c3c3 100644 --- a/compiler/perl/lib/Clownfish/CFC.pm +++ b/compiler/perl/lib/Clownfish/CFC.pm @@ -329,17 +329,20 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.5.0' ) } use Carp; our %new_PARAMS = ( - name => undef, - nickname => undef, - version => undef, - file_spec => undef, + name => undef, + nickname => undef, + version => undef, + major_version => undef, + file_spec => undef, ); sub new { my ( $either, %args ) = @_; verify_args( \%new_PARAMS, %args ) or confess $@; confess "no subclassing allowed" unless $either eq __PACKAGE__; - return _new( @args{qw( name nickname version file_spec )} ); + return _new( @args{qw( + name nickname version major_version file_spec + )} ); } our %new_from_json_PARAMS = ( http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/perl/lib/Clownfish/CFC.xs ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index 26b997a..4827fab 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -1065,15 +1065,17 @@ PPCODE: MODULE = Clownfish::CFC PACKAGE = Clownfish::CFC::Model::Parcel SV* -_new(name_sv, nickname_sv, version, file_spec) +_new(name_sv, nickname_sv, version, major_version, file_spec) SV *name_sv; SV *nickname_sv; CFCVersion *version; + CFCVersion *major_version; CFCFileSpec *file_spec; CODE: const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL; const char *nickname = SvOK(nickname_sv) ? SvPV_nolen(nickname_sv) : NULL; - CFCParcel *self = CFCParcel_new(name, nickname, version, file_spec); + CFCParcel *self = CFCParcel_new(name, nickname, version, major_version, + file_spec); RETVAL = S_cfcbase_to_perlref(self); CFCBase_decref((CFCBase*)self); OUTPUT: RETVAL http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCParcel.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCParcel.c b/compiler/src/CFCParcel.c index 525a510..b7f93d5 100644 --- a/compiler/src/CFCParcel.c +++ b/compiler/src/CFCParcel.c @@ -35,6 +35,7 @@ struct CFCParcel { char *name; char *nickname; CFCVersion *version; + CFCVersion *major_version; CFCFileSpec *file_spec; char *prefix; char *Prefix; @@ -128,14 +129,16 @@ static const CFCMeta CFCPARCEL_META = { CFCParcel* CFCParcel_new(const char *name, const char *nickname, CFCVersion *version, - CFCFileSpec *file_spec) { + CFCVersion *major_version, CFCFileSpec *file_spec) { CFCParcel *self = (CFCParcel*)CFCBase_allocate(&CFCPARCEL_META); - return CFCParcel_init(self, name, nickname, version, file_spec); + return CFCParcel_init(self, name, nickname, version, major_version, + file_spec); } CFCParcel* CFCParcel_init(CFCParcel *self, const char *name, const char *nickname, - CFCVersion *version, CFCFileSpec *file_spec) { + CFCVersion *version, CFCVersion *major_version, + CFCFileSpec *file_spec) { // Validate name. if (!name || !S_validate_name_or_nickname(name)) { CFCUtil_die("Invalid name: '%s'", name ? name : "[NULL]"); @@ -161,6 +164,13 @@ CFCParcel_init(CFCParcel *self, const char *name, const char *nickname, else { self->version = CFCVersion_new("v0"); } + if (major_version) { + self->major_version + = (CFCVersion*)CFCBase_incref((CFCBase*)major_version); + } + else { + self->major_version = CFCVersion_new("v0"); + } // Set file_spec. self->file_spec = (CFCFileSpec*)CFCBase_incref((CFCBase*)file_spec); @@ -222,12 +232,13 @@ S_new_from_json(const char *json, CFCFileSpec *file_spec) { if (CFCJson_get_type(parsed) != CFCJSON_HASH) { CFCUtil_die("Parcel definition must be a hash in '%s'", path); } - const char *name = NULL; - const char *nickname = NULL; - int installed = true; - CFCVersion *version = NULL; - CFCJson *prereqs = NULL; - CFCJson **children = CFCJson_get_children(parsed); + const char *name = NULL; + const char *nickname = NULL; + int installed = true; + CFCVersion *version = NULL; + CFCVersion *major_version = NULL; + CFCJson *prereqs = NULL; + CFCJson **children = CFCJson_get_children(parsed); for (size_t i = 0; children[i]; i += 2) { const char *key = CFCJson_get_string(children[i]); CFCJson *value = children[i + 1]; @@ -259,6 +270,13 @@ S_new_from_json(const char *json, CFCFileSpec *file_spec) { } version = CFCVersion_new(CFCJson_get_string(value)); } + else if (strcmp(key, "major_version") == 0) { + if (value_type != CFCJSON_STRING) { + CFCUtil_die("'major_version' must be a string (filepath %s)", + path); + } + major_version = CFCVersion_new(CFCJson_get_string(value)); + } else if (strcmp(key, "prerequisites") == 0) { if (value_type != CFCJSON_HASH) { CFCUtil_die("'prerequisites' must be a hash (filepath %s)", @@ -277,7 +295,8 @@ S_new_from_json(const char *json, CFCFileSpec *file_spec) { if (!version) { CFCUtil_die("Missing required key 'version' (filepath '%s')", path); } - CFCParcel *self = CFCParcel_new(name, nickname, version, file_spec); + CFCParcel *self = CFCParcel_new(name, nickname, version, major_version, + file_spec); self->is_installed = installed; if (prereqs) { S_set_prereqs(self, prereqs, path); @@ -340,6 +359,7 @@ CFCParcel_destroy(CFCParcel *self) { FREEMEM(self->name); FREEMEM(self->nickname); CFCBase_decref((CFCBase*)self->version); + CFCBase_decref((CFCBase*)self->major_version); CFCBase_decref((CFCBase*)self->file_spec); FREEMEM(self->prefix); FREEMEM(self->Prefix); @@ -387,6 +407,11 @@ CFCParcel_get_version(CFCParcel *self) { return self->version; } +CFCVersion* +CFCParcel_get_major_version(CFCParcel *self) { + return self->major_version; +} + const char* CFCParcel_get_prefix(CFCParcel *self) { return self->prefix; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCParcel.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCParcel.h b/compiler/src/CFCParcel.h index 2a15666..47dc445 100644 --- a/compiler/src/CFCParcel.h +++ b/compiler/src/CFCParcel.h @@ -64,7 +64,8 @@ CFCParcel_reap_singletons(void); CFCParcel* CFCParcel_new(const char *name, const char *nickname, - struct CFCVersion *version, struct CFCFileSpec *file_spec); + struct CFCVersion *version, struct CFCVersion *major_version, + struct CFCFileSpec *file_spec); CFCParcel* CFCParcel_new_from_file(struct CFCFileSpec *file_spec); @@ -74,7 +75,8 @@ CFCParcel_new_from_json(const char *json, struct CFCFileSpec *file_spec); CFCParcel* CFCParcel_init(CFCParcel *self, const char *name, const char *nickname, - struct CFCVersion *version, struct CFCFileSpec *file_spec); + struct CFCVersion *version, struct CFCVersion *major_version, + struct CFCFileSpec *file_spec); void CFCParcel_destroy(CFCParcel *self); @@ -94,6 +96,9 @@ CFCParcel_is_installed(CFCParcel *self); struct CFCVersion* CFCParcel_get_version(CFCParcel *self); +struct CFCVersion* +CFCParcel_get_major_version(CFCParcel *self); + /** Return the all-lowercase version of the Parcel's prefix. */ const char* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCParseHeader.y ---------------------------------------------------------------------- diff --git a/compiler/src/CFCParseHeader.y b/compiler/src/CFCParseHeader.y index 2b760f0..edbd9d4 100644 --- a/compiler/src/CFCParseHeader.y +++ b/compiler/src/CFCParseHeader.y @@ -325,7 +325,7 @@ parcel_definition(A) ::= PARCEL qualified_id(B) SEMICOLON. A = CFCParcel_fetch(B); if (!A) { /* Allow unregistered parcels to simplify tests. */ - A = CFCParcel_new(B, NULL, NULL, NULL); + A = CFCParcel_new(B, NULL, NULL, NULL, NULL); CFCParcel_register(A); } else { http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCTestDocuComment.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestDocuComment.c b/compiler/src/CFCTestDocuComment.c index cbad3f4..d08568a 100644 --- a/compiler/src/CFCTestDocuComment.c +++ b/compiler/src/CFCTestDocuComment.c @@ -134,7 +134,7 @@ S_test_md_to_pod(CFCTest *test) { static void S_test_generator(CFCTest *test) { CFCHierarchy *hierarchy = CFCHierarchy_new("autogen"); - CFCParcel *parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCParcel *parcel = CFCParcel_new("Neato", NULL, NULL, NULL, NULL); CFCParcel_register(parcel); CFCDocuComment *docu = CFCDocuComment_parse( http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCTestParcel.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestParcel.c b/compiler/src/CFCTestParcel.c index c71f14b..8103351 100644 --- a/compiler/src/CFCTestParcel.c +++ b/compiler/src/CFCTestParcel.c @@ -46,7 +46,7 @@ S_run_extended_tests(CFCTest *test); const CFCTestBatch CFCTEST_BATCH_PARCEL = { "Clownfish::CFC::Model::Parcel", - 37, + 44, S_run_tests }; @@ -84,13 +84,22 @@ S_run_prereq_tests(CFCTest *test) { static void S_run_basic_tests(CFCTest *test) { - CFCParcel *foo = CFCParcel_new("Foo", NULL, NULL, NULL); + CFCVersion *version = CFCVersion_new("v32.10.102"); + CFCVersion *major = CFCVersion_new("v32.0.0"); + CFCParcel *foo = CFCParcel_new("Foo", "FooNick", version, major, NULL); OK(test, foo != NULL, "new"); + STR_EQ(test, CFCParcel_get_name(foo), "Foo", "get_name"); + STR_EQ(test, CFCParcel_get_nickname(foo), "FooNick", "get_nickname"); + STR_EQ(test, CFCVersion_get_vstring(CFCParcel_get_version(foo)), + "v32.10.102", "get_version"); + STR_EQ(test, CFCVersion_get_vstring(CFCParcel_get_major_version(foo)), + "v32.0.0", "get_major_version"); OK(test, !CFCParcel_included(foo), "not included"); + OK(test, !CFCParcel_is_installed(foo), "not installed"); CFCParcel_register(foo); { - CFCParcel *same_name = CFCParcel_new("Foo", NULL, NULL, NULL); + CFCParcel *same_name = CFCParcel_new("Foo", NULL, NULL, NULL, NULL); char *error; CFCUTIL_TRY { @@ -106,7 +115,7 @@ S_run_basic_tests(CFCTest *test) { { CFCParcel *same_nick - = CFCParcel_new("OtherFoo", "Foo", NULL, NULL); + = CFCParcel_new("OtherFoo", "FooNick", NULL, NULL, NULL); char *error; CFCUTIL_TRY { @@ -122,10 +131,15 @@ S_run_basic_tests(CFCTest *test) { CFCFileSpec *file_spec = CFCFileSpec_new(".", "Parcel", ".cfp", true); CFCParcel *included_foo - = CFCParcel_new("IncludedFoo", NULL, NULL, file_spec); + = CFCParcel_new("IncludedFoo", NULL, NULL, NULL, file_spec); OK(test, CFCParcel_included(included_foo), "included"); STR_EQ(test, CFCParcel_get_cfp_path(included_foo), "." CHY_DIR_SEP "Parcel.cfp", "get_cfp_path"); + STR_EQ(test, CFCVersion_get_vstring(CFCParcel_get_version(included_foo)), + "v0", "version defaults to v0"); + STR_EQ(test, + CFCVersion_get_vstring(CFCParcel_get_major_version(included_foo)), + "v0", "major_version defaults to v0"); CFCParcel_register(included_foo); { @@ -179,7 +193,8 @@ S_run_extended_tests(CFCTest *test) { } { - CFCParcel *parcel = CFCParcel_new("Crustacean", "Crust", NULL, NULL); + CFCParcel *parcel = CFCParcel_new("Crustacean", "Crust", NULL, NULL, + NULL); CFCParcel_register(parcel); STR_EQ(test, CFCVersion_get_vstring(CFCParcel_get_version(parcel)), "v0", "get_version"); @@ -230,14 +245,14 @@ S_run_extended_tests(CFCTest *test) { { CFCFileSpec *foo_file_spec = CFCFileSpec_new(".", "Foo", ".cfp", true); - CFCParcel *foo = CFCParcel_new("Foo", NULL, NULL, foo_file_spec); + CFCParcel *foo = CFCParcel_new("Foo", NULL, NULL, NULL, foo_file_spec); CFCParcel_register(foo); CFCVersion *cfish_version = CFCVersion_new("v0.8.7"); CFCFileSpec *cfish_file_spec = CFCFileSpec_new(".", "Clownfish", ".cfp", true); - CFCParcel *cfish - = CFCParcel_new("Clownfish", NULL, cfish_version, cfish_file_spec); + CFCParcel *cfish = CFCParcel_new("Clownfish", NULL, cfish_version, + NULL, cfish_file_spec); CFCParcel_register(cfish); const char *crust_json = http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCTestParser.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestParser.c b/compiler/src/CFCTestParser.c index 057d5d9..304c8d7 100644 --- a/compiler/src/CFCTestParser.c +++ b/compiler/src/CFCTestParser.c @@ -55,7 +55,7 @@ S_run_tests(CFCTest *test) { CFCParcel *fish = CFCTest_parse_parcel(test, parser, "parcel Fish;"); CFCParcel *registered - = CFCParcel_new("Crustacean", "Crust", NULL, NULL); + = CFCParcel_new("Crustacean", "Crust", NULL, NULL, NULL); CFCParcel_register(registered); CFCParcel *parcel = CFCTest_parse_parcel(test, parser, "parcel Crustacean;"); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCTestSymbol.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestSymbol.c b/compiler/src/CFCTestSymbol.c index e177d50..e21f847 100644 --- a/compiler/src/CFCTestSymbol.c +++ b/compiler/src/CFCTestSymbol.c @@ -54,7 +54,7 @@ S_try_new_symbol(const char *name) { static void S_run_tests(CFCTest *test) { - CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, NULL); + CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, NULL, NULL); { static const char *exposures[4] = { @@ -112,7 +112,7 @@ S_run_tests(CFCTest *test) { } { - CFCParcel *eep_parcel = CFCParcel_new("Eep", NULL, NULL, NULL); + CFCParcel *eep_parcel = CFCParcel_new("Eep", NULL, NULL, NULL, NULL); CFCParcel_register(eep_parcel); CFCClass *ork = CFCClass_create(eep_parcel, NULL, "Op::Ork", NULL, NULL, NULL, http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ac45960e/compiler/src/CFCTestType.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestType.c b/compiler/src/CFCTestType.c index ea61fa0..ba1799b 100644 --- a/compiler/src/CFCTestType.c +++ b/compiler/src/CFCTestType.c @@ -81,7 +81,7 @@ S_run_tests(CFCTest *test) { static void S_run_basic_tests(CFCTest *test) { - CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL, NULL); CFCParcel_register(neato_parcel); CFCType *type = CFCType_new(0, neato_parcel, "mytype_t", 0); @@ -114,7 +114,7 @@ S_run_basic_tests(CFCTest *test) { static void S_run_primitive_tests(CFCTest *test) { - CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, NULL); + CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, NULL, NULL); CFCType *type = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0); OK(test, CFCType_is_primitive(type), "is_primitive"); @@ -344,7 +344,7 @@ S_run_object_tests(CFCTest *test) { CFCBase_decref((CFCBase*)parser); } - CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL, NULL); CFCClass *foo_class = CFCClass_create(neato_parcel, NULL, "Foo", NULL, NULL, NULL, NULL, false, false, false); @@ -399,7 +399,7 @@ S_run_object_tests(CFCTest *test) { { CFCParcel *foreign_parcel - = CFCParcel_new("Foreign", NULL, NULL, NULL); + = CFCParcel_new("Foreign", NULL, NULL, NULL, NULL); CFCClass *foreign_foo_class = CFCClass_create(foreign_parcel, NULL, "Foreign::Foo", NULL, NULL, NULL, NULL, false, false, false); @@ -467,7 +467,8 @@ S_run_va_list_tests(CFCTest *test) { static void S_run_arbitrary_tests(CFCTest *test) { { - CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL, + NULL); CFCParcel_register(neato_parcel); CFCType *foo = CFCType_new_arbitrary(neato_parcel, "foo_t"); @@ -507,7 +508,7 @@ S_run_arbitrary_tests(CFCTest *test) { static void S_run_composite_tests(CFCTest *test) { CFCParser *parser = CFCParser_new(); - CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL); + CFCParcel *neato_parcel = CFCParcel_new("Neato", NULL, NULL, NULL, NULL); CFCParser_set_parcel(parser, neato_parcel); {
