Add file extension to FileSpec

This is needed to reconstruct the correct file path. Only affects
error messages for now, but may be useful later.


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

Branch: refs/heads/master
Commit: 253e7391d2a7b982acf17ca50319777a671d6b90
Parents: f01e606
Author: Nick Wellnhofer <[email protected]>
Authored: Mon May 30 14:15:54 2016 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Mon May 30 14:15:54 2016 +0200

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.pm |  5 +++--
 compiler/perl/lib/Clownfish/CFC.xs |  6 ++++--
 compiler/perl/t/400-file_spec.t    |  1 +
 compiler/perl/t/401-class.t        |  1 +
 compiler/perl/t/403-parcel.t       |  9 ++++++---
 compiler/perl/t/404-file.t         |  1 +
 compiler/src/CFCFileSpec.c         | 11 ++++++-----
 compiler/src/CFCFileSpec.h         |  4 ++--
 compiler/src/CFCHierarchy.c        |  4 ++--
 compiler/src/CFCTestClass.c        |  2 +-
 compiler/src/CFCTestFile.c         |  2 +-
 compiler/src/CFCTestFileSpec.c     |  4 ++--
 compiler/src/CFCTestParcel.c       | 10 ++++++----
 13 files changed, 36 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/lib/Clownfish/CFC.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.pm 
b/compiler/perl/lib/Clownfish/CFC.pm
index e5df9e0..50bcab7 100644
--- a/compiler/perl/lib/Clownfish/CFC.pm
+++ b/compiler/perl/lib/Clownfish/CFC.pm
@@ -197,14 +197,15 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.5.0' ) }
     our %new_PARAMS = (
         source_dir  => undef,
         path_part   => undef,
-        is_included => 0,
+        ext         => undef,
+        is_included => undef,
     );
 
     sub new {
         my ( $either, %args ) = @_;
         confess "no subclassing allowed" unless $either eq __PACKAGE__;
         verify_args( \%new_PARAMS, %args ) or confess $@;
-        return _new( @args{ qw( source_dir path_part is_included ) } );
+        return _new( @args{ qw( source_dir path_part ext is_included ) } );
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs 
b/compiler/perl/lib/Clownfish/CFC.xs
index a4e58e9..3a60db1 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -586,12 +586,14 @@ OUTPUT: RETVAL
 MODULE = Clownfish::CFC   PACKAGE = Clownfish::CFC::Model::FileSpec
 
 SV*
-_new(source_dir, path_part, is_included)
+_new(source_dir, path_part, ext, is_included)
     const char *source_dir;
     const char *path_part;
+    const char *ext;
     bool is_included;
 CODE:
-    CFCFileSpec *self = CFCFileSpec_new(source_dir, path_part, is_included);
+    CFCFileSpec *self = CFCFileSpec_new(source_dir, path_part, ext,
+                                        is_included);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/t/400-file_spec.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/400-file_spec.t b/compiler/perl/t/400-file_spec.t
index 246bf33..b974418 100644
--- a/compiler/perl/t/400-file_spec.t
+++ b/compiler/perl/t/400-file_spec.t
@@ -23,6 +23,7 @@ use Clownfish::CFC::Model::FileSpec;
 my %args = (
     source_dir  => 'Clownfish/_include',
     path_part   => 'Stuff/Thing',
+    ext         => '.cfh',
 );
 my $file_spec;
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/t/401-class.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/401-class.t b/compiler/perl/t/401-class.t
index 5e0fcba..04f0bc3 100644
--- a/compiler/perl/t/401-class.t
+++ b/compiler/perl/t/401-class.t
@@ -87,6 +87,7 @@ is( $foo_jr->get_nickname, "FooJr",
 my $file_spec = Clownfish::CFC::Model::FileSpec->new(
     source_dir  => '.',
     path_part   => 'Foo/FooJr',
+    ext         => '.cfh',
 );
 my $final_foo = Clownfish::CFC::Model::Class->create(
     parcel            => 'Neato',

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/403-parcel.t b/compiler/perl/t/403-parcel.t
index fec23e3..b1812ec 100644
--- a/compiler/perl/t/403-parcel.t
+++ b/compiler/perl/t/403-parcel.t
@@ -55,7 +55,8 @@ like( $@, qr/parcel with nickname .* already registered/i,
 
 my $foo_file_spec = Clownfish::CFC::Model::FileSpec->new(
     source_dir  => '.',
-    path_part   => 'Foo.cfp',
+    path_part   => 'Foo',
+    ext         => '.cfp',
     is_included => 1,
 );
 my $included_foo = Clownfish::CFC::Model::Parcel->new(
@@ -139,7 +140,8 @@ Clownfish::CFC::Model::Parcel->reap_singletons();
 {
     my $foo_file_spec = Clownfish::CFC::Model::FileSpec->new(
         source_dir  => '.',
-        path_part   => 'Foo.cfp',
+        path_part   => 'Foo',
+        ext         => '.cfp',
         is_included => 1,
     );
     my $foo = Clownfish::CFC::Model::Parcel->new(
@@ -153,7 +155,8 @@ Clownfish::CFC::Model::Parcel->reap_singletons();
     );
     my $cfish_file_spec = Clownfish::CFC::Model::FileSpec->new(
         source_dir  => '.',
-        path_part   => 'Clownfish.cfp',
+        path_part   => 'Clownfish',
+        ext         => '.cfp',
         is_included => 1,
     );
     my $cfish = Clownfish::CFC::Model::Parcel->new(

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/perl/t/404-file.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/404-file.t b/compiler/perl/t/404-file.t
index a26ff05..d641101 100644
--- a/compiler/perl/t/404-file.t
+++ b/compiler/perl/t/404-file.t
@@ -39,6 +39,7 @@ my $path_part = catdir(qw( Stuff Thing ));
 my $file_spec = Clownfish::CFC::Model::FileSpec->new(
     source_dir  => '.',
     path_part   => $path_part,
+    ext         => '.cfh',
 );
 
 {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCFileSpec.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCFileSpec.c b/compiler/src/CFCFileSpec.c
index 4523f20..7bb3785 100644
--- a/compiler/src/CFCFileSpec.c
+++ b/compiler/src/CFCFileSpec.c
@@ -45,22 +45,23 @@ static const CFCMeta CFCFILESPEC_META = {
 };
 
 CFCFileSpec*
-CFCFileSpec_new(const char *source_dir, const char *path_part,
+CFCFileSpec_new(const char *source_dir, const char *path_part, const char *ext,
                 int is_included) {
     CFCFileSpec *self = (CFCFileSpec*)CFCBase_allocate(&CFCFILESPEC_META);
-    return CFCFileSpec_init(self, source_dir, path_part, is_included);
+    return CFCFileSpec_init(self, source_dir, path_part, ext, is_included);
 }
 
 CFCFileSpec*
 CFCFileSpec_init(CFCFileSpec *self, const char *source_dir,
-                 const char *path_part, int is_included) {
+                 const char *path_part, const char *ext, int is_included) {
     CFCUTIL_NULL_CHECK(source_dir);
     CFCUTIL_NULL_CHECK(path_part);
+    CFCUTIL_NULL_CHECK(ext);
 
     self->source_dir  = CFCUtil_strdup(source_dir);
     self->path_part   = CFCUtil_strdup(path_part);
-    self->path        = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s", source_dir,
-                                        path_part);
+    self->path        = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s%s", source_dir,
+                                        path_part, ext);
     self->is_included = !!is_included;
 
     return self;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCFileSpec.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCFileSpec.h b/compiler/src/CFCFileSpec.h
index 971bdd5..772ec1f 100644
--- a/compiler/src/CFCFileSpec.h
+++ b/compiler/src/CFCFileSpec.h
@@ -42,12 +42,12 @@ struct CFCClass;
  * @param is_included Should be true if the file is from an include dir.
 */
 CFCFileSpec*
-CFCFileSpec_new(const char *source_dir, const char *path_part,
+CFCFileSpec_new(const char *source_dir, const char *path_part, const char *ext,
                 int is_included);
 
 CFCFileSpec*
 CFCFileSpec_init(CFCFileSpec *self, const char *source_dir,
-                 const char *path_part, int is_included);
+                 const char *path_part, const char *ext, int is_included);
 
 void
 CFCFileSpec_destroy(CFCFileSpec *self);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index 5b1e636..fa09c5e 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -263,7 +263,7 @@ S_parse_parcel_files(const char *source_dir, int 
is_included) {
         const char *path = context.paths[i];
         char *path_part = S_extract_path_part(path, source_dir, ".cfp");
         CFCFileSpec *file_spec
-            = CFCFileSpec_new(source_dir, path_part, is_included);
+            = CFCFileSpec_new(source_dir, path_part, ".cfp", is_included);
         CFCParcel *parcel = CFCParcel_new_from_file(path, file_spec);
         const char *name = CFCParcel_get_name(parcel);
         CFCParcel *existing = CFCParcel_fetch(name);
@@ -333,7 +333,7 @@ S_parse_cf_files(CFCHierarchy *self, const char 
*source_dir, int is_included) {
             continue;
         }
 
-        CFCFileSpec *file_spec = CFCFileSpec_new(source_dir, path_part,
+        CFCFileSpec *file_spec = CFCFileSpec_new(source_dir, path_part, ".cfh",
                                                  is_included);
 
         // Slurp and parse file.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCTestClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestClass.c b/compiler/src/CFCTestClass.c
index 9fa182c..20ae9ac 100644
--- a/compiler/src/CFCTestClass.c
+++ b/compiler/src/CFCTestClass.c
@@ -68,7 +68,7 @@ S_run_tests(CFCTest *test) {
     CFCParser *parser = CFCParser_new();
 
     CFCParcel *neato = CFCTest_parse_parcel(test, parser, "parcel Neato;");
-    CFCFileSpec *file_spec = CFCFileSpec_new(".", "Foo/FooJr", 0);
+    CFCFileSpec *file_spec = CFCFileSpec_new(".", "Foo/FooJr", ".cfh", 0);
     CFCClass *thing_class
         = CFCTest_parse_class(test, parser, "class Thing {}");
     CFCClass *widget_class

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCTestFile.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestFile.c b/compiler/src/CFCTestFile.c
index 921eaf4..c1290fb 100644
--- a/compiler/src/CFCTestFile.c
+++ b/compiler/src/CFCTestFile.c
@@ -42,7 +42,7 @@ 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);
+    CFCFileSpec *file_spec = CFCFileSpec_new(".", STUFF_THING, ".cfh", 0);
 
     {
         const char *string =

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCTestFileSpec.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestFileSpec.c b/compiler/src/CFCTestFileSpec.c
index 7fdb2d8..d38c075 100644
--- a/compiler/src/CFCTestFileSpec.c
+++ b/compiler/src/CFCTestFileSpec.c
@@ -32,7 +32,7 @@ static void
 S_run_tests(CFCTest *test) {
     {
         CFCFileSpec *file_spec
-            = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", 0);
+            = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", ".cfh", 0);
         STR_EQ(test, CFCFileSpec_get_source_dir(file_spec),
                "Clownfish/_include", "get_source_dir");
         STR_EQ(test, CFCFileSpec_get_path_part(file_spec),
@@ -44,7 +44,7 @@ S_run_tests(CFCTest *test) {
 
     {
         CFCFileSpec *file_spec
-            = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", 1);
+            = CFCFileSpec_new("Clownfish/_include", "Stuff/Thing", ".cfh", 1);
         OK(test, CFCFileSpec_included(file_spec), "included");
 
         CFCBase_decref((CFCBase*)file_spec);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/253e7391/compiler/src/CFCTestParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestParcel.c b/compiler/src/CFCTestParcel.c
index c4f9085..7a33a6b 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",
-    36,
+    37,
     S_run_tests
 };
 
@@ -120,10 +120,12 @@ S_run_basic_tests(CFCTest *test) {
         CFCBase_decref((CFCBase*)same_nick);
     }
 
-    CFCFileSpec *file_spec = CFCFileSpec_new(".", "Parcel", true);
+    CFCFileSpec *file_spec = CFCFileSpec_new(".", "Parcel", ".cfp", true);
     CFCParcel *included_foo
         = CFCParcel_new("IncludedFoo", 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");
     CFCParcel_register(included_foo);
 
     {
@@ -225,13 +227,13 @@ S_run_extended_tests(CFCTest *test) {
     }
 
     {
-        CFCFileSpec *foo_file_spec = CFCFileSpec_new(".", "Foo", true);
+        CFCFileSpec *foo_file_spec = CFCFileSpec_new(".", "Foo", ".cfp", true);
         CFCParcel *foo = CFCParcel_new("Foo", NULL, NULL, foo_file_spec);
         CFCParcel_register(foo);
 
         CFCVersion *cfish_version = CFCVersion_new("v0.8.7");
         CFCFileSpec *cfish_file_spec
-            = CFCFileSpec_new(".", "Clownfish", true);
+            = CFCFileSpec_new(".", "Clownfish", ".cfp", true);
         CFCParcel *cfish
             = CFCParcel_new("Clownfish", NULL, cfish_version, cfish_file_spec);
         CFCParcel_register(cfish);

Reply via email to