lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [1/6] git commit: Switch to single parcel per file
Date Fri, 21 Mar 2014 20:15:59 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 298abe860 -> 52b4793bc


Switch to single parcel per file

.cfh files now must contain a single parcel definition at the start of
the file.


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

Branch: refs/heads/master
Commit: dadbb6b23f2e02fa52aa29ab263a672ece265047
Parents: c77676f
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Tue Mar 18 14:53:04 2014 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Fri Mar 21 21:12:04 2014 +0100

----------------------------------------------------------------------
 compiler/perl/lib/Clownfish/CFC.pm |  7 +++++--
 compiler/perl/lib/Clownfish/CFC.xs | 11 +++++++++--
 compiler/perl/t/404-file.t         | 20 +++++++-------------
 compiler/src/CFCBindFile.c         | 16 ++++++++--------
 compiler/src/CFCFile.c             | 16 +++++++++++++---
 compiler/src/CFCFile.h             |  9 +++++++--
 compiler/src/CFCParseHeader.y      |  7 ++++---
 compiler/src/CFCTestFile.c         | 31 +++++++------------------------
 8 files changed, 60 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/perl/lib/Clownfish/CFC.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.pm b/compiler/perl/lib/Clownfish/CFC.pm
index d5a070b..d60ef1e 100644
--- a/compiler/perl/lib/Clownfish/CFC.pm
+++ b/compiler/perl/lib/Clownfish/CFC.pm
@@ -172,13 +172,16 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.01' ) }
     use Clownfish::CFC::Util qw( verify_args );
     use Carp;
 
-    our %new_PARAMS = ( spec => undef );
+    our %new_PARAMS = (
+        parcel => undef,
+        spec   => undef,
+    );
 
     sub new {
         my ( $either, %args ) = @_;
         confess "no subclassing allowed" unless $either eq __PACKAGE__;
         verify_args( \%new_PARAMS, %args ) or confess $@;
-        return _new( $args{spec} );
+        return _new( @args{ qw( parcel spec ) } );
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index a9a08ed..dfc33af 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -481,10 +481,11 @@ PPCODE:
 MODULE = Clownfish::CFC   PACKAGE = Clownfish::CFC::Model::File
 
 SV*
-_new(spec)
+_new(parcel, spec)
+    CFCParcel *parcel;
     CFCFileSpec *spec;
 CODE:
-    CFCFile *self = CFCFile_new(spec);
+    CFCFile *self = CFCFile_new(parcel, spec);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
@@ -510,6 +511,7 @@ ALIAS:
     classes            = 14
     get_source_dir     = 16
     included           = 18
+    get_parcel         = 20
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -554,6 +556,11 @@ PPCODE:
         case 18:
             retval = newSViv(CFCFile_included(self));
             break;
+        case 20: {
+                CFCParcel *parcel = CFCFile_get_parcel(self);
+                retval = S_cfcbase_to_perlref(parcel);
+            }
+            break;
     END_SET_OR_GET_SWITCH
 }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/perl/t/404-file.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/404-file.t b/compiler/perl/t/404-file.t
index d071c66..eec082c 100644
--- a/compiler/perl/t/404-file.t
+++ b/compiler/perl/t/404-file.t
@@ -76,22 +76,16 @@ my $file_spec = Clownfish::CFC::Model::FileSpec->new(
         'stuff_Foo', 'file production picked up parcel def' );
     is( $bar->get_type->get_specifier, 'stuff_Bar', 'parcel def is sticky' );
 
+    my $parcel = $file->get_parcel;
+    isa_ok( $parcel, "Clownfish::CFC::Model::Parcel" );
+    is( $parcel->get_name, "Stuff", "get_parcel" );
+
     my $blocks = $file->blocks;
-    is( scalar @$blocks, 5, "all five blocks" );
-    isa_ok( $blocks->[0], "Clownfish::CFC::Model::Parcel" );
+    is( scalar @$blocks, 4, "all five blocks" );
+    isa_ok( $blocks->[0], "Clownfish::CFC::Model::Class" );
     isa_ok( $blocks->[1], "Clownfish::CFC::Model::Class" );
     isa_ok( $blocks->[2], "Clownfish::CFC::Model::Class" );
-    isa_ok( $blocks->[3], "Clownfish::CFC::Model::Class" );
-    isa_ok( $blocks->[4], "Clownfish::CFC::Model::CBlock" );
-
-    Clownfish::CFC::Model::Class->_clear_registry();
-}
-
-{
-    my $file = $parser->_parse_file( $class_content, $file_spec );
-    my ($class) = @{ $file->classes };
-    my ( $foo, $bar ) = @{ $class->member_vars };
-    is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
+    isa_ok( $blocks->[3], "Clownfish::CFC::Model::CBlock" );
 
     Clownfish::CFC::Model::Class->_clear_registry();
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/src/CFCBindFile.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindFile.c b/compiler/src/CFCBindFile.c
index 928254d..26c215c 100644
--- a/compiler/src/CFCBindFile.c
+++ b/compiler/src/CFCBindFile.c
@@ -56,19 +56,19 @@ CFCBindFile_write_h(CFCFile *file, const char *dest, const char *header,
     const char *include_guard_start = CFCFile_guard_start(file);
     const char *include_guard_close = CFCFile_guard_close(file);
 
-    // Aggregate block content.
+    // Include parcel header.
     char *content = CFCUtil_strdup("");
+    CFCParcel *parcel = CFCFile_get_parcel(file);
+    const char *prefix = CFCParcel_get_prefix(parcel);
+    content = CFCUtil_cat(content, "#include \"", prefix, "parcel.h\"\n\n",
+                          NULL);
+
+    // Aggregate block content.
     CFCBase **blocks = CFCFile_blocks(file);
     for (int i = 0; blocks[i] != NULL; i++) {
         const char *cfc_class = CFCBase_get_cfc_class(blocks[i]);
 
-        if (strcmp(cfc_class, "Clownfish::CFC::Model::Parcel") == 0) {
-            CFCParcel *parcel = (CFCParcel*)blocks[i];
-            const char *prefix = CFCParcel_get_prefix(parcel);
-            content = CFCUtil_cat(content, "#include \"", prefix,
-                                  "parcel.h\"\n\n", NULL);
-        }
-        else if (strcmp(cfc_class, "Clownfish::CFC::Model::Class") == 0) {
+        if (strcmp(cfc_class, "Clownfish::CFC::Model::Class") == 0) {
             CFCBindClass *class_binding
                 = CFCBindClass_new((CFCClass*)blocks[i]);
             char *c_header = CFCBindClass_to_c_header(class_binding);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/src/CFCFile.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCFile.c b/compiler/src/CFCFile.c
index 84065b1..52a4451 100644
--- a/compiler/src/CFCFile.c
+++ b/compiler/src/CFCFile.c
@@ -29,11 +29,13 @@
 #include "CFCBase.h"
 #include "CFCFile.h"
 #include "CFCFileSpec.h"
+#include "CFCParcel.h"
 #include "CFCUtil.h"
 #include "CFCClass.h"
 
 struct CFCFile {
     CFCBase base;
+    CFCParcel *parcel;
     CFCBase **blocks;
     CFCClass **classes;
     CFCFileSpec *spec;
@@ -50,15 +52,17 @@ static const CFCMeta CFCFILE_META = {
 };
 
 CFCFile*
-CFCFile_new(CFCFileSpec *spec) {
+CFCFile_new(CFCParcel *parcel, CFCFileSpec *spec) {
 
     CFCFile *self = (CFCFile*)CFCBase_allocate(&CFCFILE_META);
-    return CFCFile_init(self, spec);
+    return CFCFile_init(self, parcel, spec);
 }
 
 CFCFile*
-CFCFile_init(CFCFile *self, CFCFileSpec *spec) {
+CFCFile_init(CFCFile *self, CFCParcel *parcel, CFCFileSpec *spec) {
+    CFCUTIL_NULL_CHECK(parcel);
     CFCUTIL_NULL_CHECK(spec);
+    self->parcel     = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
     self->modified   = false;
     self->spec       = (CFCFileSpec*)CFCBase_incref((CFCBase*)spec);
     self->blocks     = (CFCBase**)CALLOCATE(1, sizeof(CFCBase*));
@@ -90,6 +94,7 @@ CFCFile_init(CFCFile *self, CFCFileSpec *spec) {
 
 void
 CFCFile_destroy(CFCFile *self) {
+    CFCBase_decref((CFCBase*)self->parcel);
     for (size_t i = 0; self->blocks[i] != NULL; i++) {
         CFCBase_decref(self->blocks[i]);
     }
@@ -180,6 +185,11 @@ CFCFile_cfh_path(CFCFile *self, const char *base_dir) {
     return S_some_path(self, base_dir, ".cfh");
 }
 
+CFCParcel*
+CFCFile_get_parcel(CFCFile *self) {
+    return self->parcel;
+}
+
 CFCBase**
 CFCFile_blocks(CFCFile *self) {
     return self->blocks;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/src/CFCFile.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCFile.h b/compiler/src/CFCFile.h
index e360605..bb3ecd4 100644
--- a/compiler/src/CFCFile.h
+++ b/compiler/src/CFCFile.h
@@ -31,15 +31,17 @@ typedef struct CFCFile CFCFile;
 struct CFCBase;
 struct CFCClass;
 struct CFCFileSpec;
+struct CFCParcel;
 
 /**
  * @param spec - A CFCFileSpec object describing the file
 */
 CFCFile*
-CFCFile_new(struct CFCFileSpec *spec);
+CFCFile_new(struct CFCParcel *parcel, struct CFCFileSpec *spec);
 
 CFCFile*
-CFCFile_init(CFCFile *self, struct CFCFileSpec *spec);
+CFCFile_init(CFCFile *self, struct CFCParcel *parcel,
+             struct CFCFileSpec *spec);
 
 void
 CFCFile_destroy(CFCFile *self);
@@ -67,6 +69,9 @@ CFCFile_h_path(CFCFile *self, const char *base_dir);
 char*
 CFCFile_cfh_path(CFCFile *self, const char *base_dir);
 
+struct CFCParcel*
+CFCFile_get_parcel(CFCFile *self);
+
 /** Return all blocks as an array.
  */
 struct CFCBase**

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/src/CFCParseHeader.y
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParseHeader.y b/compiler/src/CFCParseHeader.y
index 40530be..7b83fa1 100644
--- a/compiler/src/CFCParseHeader.y
+++ b/compiler/src/CFCParseHeader.y
@@ -309,9 +309,11 @@ result ::= file(A).
     CFCBase_decref((CFCBase*)A);
 }
 
-file(A) ::= FILE_START. /* Pseudo token, not passed by lexer. */
+/* FILE_START is a pseudo token, not passed by lexer. */
+file(A) ::= FILE_START parcel_definition(B).
 {
-    A = CFCFile_new(CFCParser_get_file_spec(state));
+    A = CFCFile_new(B, CFCParser_get_file_spec(state));
+    CFCBase_decref((CFCBase*)B);
 }
 file(A) ::= file(B) major_block(C).
 {
@@ -322,7 +324,6 @@ file(A) ::= file(B) major_block(C).
 
 major_block(A) ::= class_declaration(B). { A = (CFCBase*)B; }
 major_block(A) ::= cblock(B).            { A = (CFCBase*)B; }
-major_block(A) ::= parcel_definition(B). { A = (CFCBase*)B; }
 
 parcel_definition(A) ::= PARCEL qualified_id(B) SEMICOLON.
 {

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dadbb6b2/compiler/src/CFCTestFile.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestFile.c b/compiler/src/CFCTestFile.c
index 44e6f1c..4be6cef 100644
--- a/compiler/src/CFCTestFile.c
+++ b/compiler/src/CFCTestFile.c
@@ -33,7 +33,7 @@ S_run_tests(CFCTest *test);
 
 const CFCTestBatch CFCTEST_BATCH_FILE = {
     "Clownfish::CFC::Model::File",
-    21,
+    20,
     S_run_tests
 };
 
@@ -105,36 +105,19 @@ S_run_tests(CFCTest *test) {
         STR_EQ(test, CFCType_get_specifier(bar_type), "stuff_Bar",
                "parcel def is sticky");
 
+        CFCParcel *parcel = CFCFile_get_parcel(file);
+        STR_EQ(test, CFCParcel_get_name(parcel), "Stuff", "get_parcel");
+
         CFCBase **blocks = CFCFile_blocks(file);
         STR_EQ(test, CFCBase_get_cfc_class(blocks[0]),
-               "Clownfish::CFC::Model::Parcel", "blocks[0]");
+               "Clownfish::CFC::Model::Class", "blocks[0]");
         STR_EQ(test, CFCBase_get_cfc_class(blocks[1]),
                "Clownfish::CFC::Model::Class", "blocks[1]");
         STR_EQ(test, CFCBase_get_cfc_class(blocks[2]),
                "Clownfish::CFC::Model::Class", "blocks[2]");
         STR_EQ(test, CFCBase_get_cfc_class(blocks[3]),
-               "Clownfish::CFC::Model::Class", "blocks[3]");
-        STR_EQ(test, CFCBase_get_cfc_class(blocks[4]),
-               "Clownfish::CFC::Model::CBlock", "blocks[4]");
-        OK(test, blocks[5] == NULL, "blocks[5]");
-
-        CFCBase_decref((CFCBase*)file);
-
-        CFCClass_clear_registry();
-    }
-
-    {
-        const char *string =
-            "class Stuff::Thing {\n"
-            "    Foo *foo;\n"
-            "    Bar *bar;\n"
-            "}\n";
-        CFCFile *file = CFCParser_parse_file(parser, string, file_spec);
-        CFCClass **classes = CFCFile_classes(file);
-        CFCVariable **member_vars = CFCClass_member_vars(classes[0]);
-        CFCType *foo_type = CFCVariable_get_type(member_vars[0]);
-        STR_EQ(test, CFCType_get_specifier(foo_type), "Foo",
-               "file production resets parcel");
+               "Clownfish::CFC::Model::CBlock", "blocks[3]");
+        OK(test, blocks[4] == NULL, "blocks[4]");
 
         CFCBase_decref((CFCBase*)file);
 


Mime
View raw message