You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/03/21 21:15:59 UTC
[lucy-commits] [1/6] git commit: Switch to single parcel per file
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 <we...@aevum.de>
Authored: Tue Mar 18 14:53:04 2014 +0100
Committer: Nick Wellnhofer <we...@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);
[lucy-commits] [6/6] git commit: Only write headers for required parcels
Posted by nw...@apache.org.
Only write headers for required parcels
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/52b4793b
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/52b4793b
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/52b4793b
Branch: refs/heads/master
Commit: 52b4793bc598684c3385a39623a30bbf9134d590
Parents: 86c742b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Mar 18 17:28:25 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Mar 21 21:13:46 2014 +0100
----------------------------------------------------------------------
compiler/src/CFCBindCore.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/52b4793b/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index 754e558..0e24d74 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -132,10 +132,11 @@ CFCBindCore_write_all_modified(CFCBindCore *self, int modified) {
CFCParcel **parcels = CFCParcel_all_parcels();
for (size_t i = 0; parcels[i]; ++i) {
CFCParcel *parcel = parcels[i];
- // TODO: Skip parcels the source parcels don't depend on.
- S_write_parcel_h(self, parcel);
- if (!CFCParcel_included(parcel)) {
- S_write_parcel_c(self, parcel);
+ if (CFCParcel_required(parcel)) {
+ S_write_parcel_h(self, parcel);
+ if (!CFCParcel_included(parcel)) {
+ S_write_parcel_c(self, parcel);
+ }
}
}
}
[lucy-commits] [5/6] git commit: Only add files from required parcels to hierarchy
Posted by nw...@apache.org.
Only add files from required parcels to hierarchy
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/86c742b3
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/86c742b3
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/86c742b3
Branch: refs/heads/master
Commit: 86c742b316001e90ee772d2dd78cc128327f1a8b
Parents: 8722274
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Mar 18 17:09:57 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Mar 21 21:13:46 2014 +0100
----------------------------------------------------------------------
compiler/src/CFCHierarchy.c | 35 +++++++++++++++++++++--------------
compiler/src/CFCParcel.c | 3 +++
compiler/src/CFCPerl.c | 2 --
compiler/src/CFCPerlTypeMap.c | 2 --
4 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/86c742b3/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index 116e172..c5fcac5 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -344,7 +344,7 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
CFCFileSpec *file_spec = CFCFileSpec_new(source_dir, path_part,
is_included);
- // Slurp, parse, add parsed file to pool.
+ // Slurp and parse file.
size_t unused;
char *content = CFCUtil_slurp_text(source_path, &unused);
CFCFile *file = CFCParser_parse_file(self->parser, content, file_spec);
@@ -352,20 +352,13 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
if (!file) {
CFCUtil_die("parser error for %s", source_path);
}
- S_add_file(self, file);
-
- CFCClass **classes_in_file = CFCFile_classes(file);
- for (size_t j = 0; classes_in_file[j] != NULL; j++) {
- if (self->num_classes == self->classes_cap) {
- self->classes_cap += 10;
- self->classes = (CFCClass**)REALLOCATE(
- self->classes,
- (self->classes_cap + 1) * sizeof(CFCClass*));
- }
- self->classes[self->num_classes++]
- = (CFCClass*)CFCBase_incref((CFCBase*)classes_in_file[j]);
- self->classes[self->num_classes] = NULL;
+
+ // Add parsed file to pool if it's from a required parcel.
+ CFCParcel *parcel = CFCFile_get_parcel(file);
+ if (CFCParcel_required(parcel)) {
+ S_add_file(self, file);
}
+
CFCBase_decref((CFCBase*)file);
CFCBase_decref((CFCBase*)file_spec);
}
@@ -530,6 +523,7 @@ static void
S_add_file(CFCHierarchy *self, CFCFile *file) {
CFCUTIL_NULL_CHECK(file);
CFCClass **classes = CFCFile_classes(file);
+
for (size_t i = 0; self->files[i] != NULL; i++) {
CFCFile *existing = self->files[i];
CFCClass **existing_classes = CFCFile_classes(existing);
@@ -545,12 +539,25 @@ S_add_file(CFCHierarchy *self, CFCFile *file) {
}
}
}
+
self->num_files++;
size_t size = (self->num_files + 1) * sizeof(CFCFile*);
self->files = (CFCFile**)REALLOCATE(self->files, size);
self->files[self->num_files - 1]
= (CFCFile*)CFCBase_incref((CFCBase*)file);
self->files[self->num_files] = NULL;
+
+ for (size_t i = 0; classes[i] != NULL; i++) {
+ if (self->num_classes == self->classes_cap) {
+ self->classes_cap += 10;
+ self->classes = (CFCClass**)REALLOCATE(
+ self->classes,
+ (self->classes_cap + 1) * sizeof(CFCClass*));
+ }
+ self->classes[self->num_classes++]
+ = (CFCClass*)CFCBase_incref((CFCBase*)classes[i]);
+ self->classes[self->num_classes] = NULL;
+ }
}
struct CFCFile**
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/86c742b3/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParcel.c b/compiler/src/CFCParcel.c
index 3050613..fd424f4 100644
--- a/compiler/src/CFCParcel.c
+++ b/compiler/src/CFCParcel.c
@@ -480,6 +480,9 @@ CFCParcel_prereq_parcels(CFCParcel *self) {
void
CFCParcel_check_prereqs(CFCParcel *self) {
// This is essentially a depth-first search of the dependency graph.
+ // It might be possible to skip indirect dependencies, at least if
+ // they're not part of the inheritance chain. But for now, all
+ // dependencies are marked recursively.
if (self->is_required) { return; }
self->is_required = true;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/86c742b3/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index a6fbdc3..fe2bc3a 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -404,8 +404,6 @@ CFCPerl_write_bindings(CFCPerl *self) {
// Pound-includes for generated headers.
for (size_t i = 0; ordered[i] != NULL; i++) {
CFCClass *klass = ordered[i];
- // TODO: Don't include headers for parcels the source parcels don't
- // depend on.
const char *include_h = CFCClass_include_h(klass);
generated_xs = CFCUtil_cat(generated_xs, "#include \"", include_h,
"\"\n", NULL);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/86c742b3/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index 4553a13..c7d513d 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -264,8 +264,6 @@ CFCPerlTypeMap_write_xs_typemap(CFCHierarchy *hierarchy) {
char *output = CFCUtil_strdup("");
for (int i = 0; classes[i] != NULL; i++) {
CFCClass *klass = classes[i];
- // TODO: Skip classes from parcels the source parcels don't depend on.
-
const char *full_struct_sym = CFCClass_full_struct_sym(klass);
const char *vtable_var = CFCClass_full_vtable_var(klass);
[lucy-commits] [4/6] git commit: Eliminate default parcel
Posted by nw...@apache.org.
Eliminate default parcel
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/87222743
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/87222743
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/87222743
Branch: refs/heads/master
Commit: 87222743f382d1d12754e972b4db4e1793d3beb7
Parents: 1111017
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Mar 18 15:17:15 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Mar 21 21:12:57 2014 +0100
----------------------------------------------------------------------
compiler/perl/lib/Clownfish/CFC.pm | 6 ++---
compiler/perl/lib/Clownfish/CFC.xs | 9 -------
compiler/perl/t/403-parcel.t | 10 +-------
compiler/src/CFCBindCore.c | 1 -
compiler/src/CFCHierarchy.c | 2 --
compiler/src/CFCParcel.c | 43 +--------------------------------
compiler/src/CFCParcel.h | 8 +-----
compiler/src/CFCPerl.c | 1 -
compiler/src/CFCTestParcel.c | 14 +----------
9 files changed, 7 insertions(+), 87 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/perl/lib/Clownfish/CFC.pm
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.pm b/compiler/perl/lib/Clownfish/CFC.pm
index d60ef1e..2f8c200 100644
--- a/compiler/perl/lib/Clownfish/CFC.pm
+++ b/compiler/perl/lib/Clownfish/CFC.pm
@@ -358,12 +358,12 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.01' ) }
# $parcel = Clownfish::CFC::Model::Parcel->acquire($parcel_name_or_parcel_object);
#
# Aquire a parcel one way or another. If the supplied argument is a
-# Parcel, return it. If it's not defined, return the default Parcel. If
-# it's a name, fetch an existing Parcel or register a new one.
+# Parcel, return it. If it's a name, fetch an existing Parcel or register
+# a new one.
sub acquire {
my ( undef, $thing ) = @_;
if ( !defined $thing ) {
- return Clownfish::CFC::Model::Parcel->default_parcel;
+ confess("Missing required param 'parcel'");
}
elsif ( blessed($thing) ) {
confess("Not a Clownfish::CFC::Model::Parcel")
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/perl/lib/Clownfish/CFC.xs
----------------------------------------------------------------------
diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs
index dfc33af..2725f79 100644
--- a/compiler/perl/lib/Clownfish/CFC.xs
+++ b/compiler/perl/lib/Clownfish/CFC.xs
@@ -1118,20 +1118,11 @@ CODE:
OUTPUT: RETVAL
SV*
-default_parcel(...)
-CODE:
- CHY_UNUSED_VAR(items);
- CFCParcel *default_parcel = CFCParcel_default_parcel();
- RETVAL = S_cfcbase_to_perlref(default_parcel);
-OUTPUT: RETVAL
-
-SV*
all_parcels(...)
CODE:
CHY_UNUSED_VAR(items);
CFCParcel **all_parcels = CFCParcel_all_parcels();
RETVAL = S_array_of_cfcbase_to_av((CFCBase**)all_parcels);
- FREEMEM(all_parcels);
OUTPUT: RETVAL
void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/403-parcel.t b/compiler/perl/t/403-parcel.t
index de93c21..4b8f973 100644
--- a/compiler/perl/t/403-parcel.t
+++ b/compiler/perl/t/403-parcel.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 41;
+use Test::More tests => 38;
use File::Spec::Functions qw( catfile );
BEGIN { use_ok('Clownfish::CFC::Model::Prereq') }
@@ -98,14 +98,6 @@ is( $parcel->get_version->get_vstring, 'v0', "get_version" );
my $thing = Clownfish::CFC::Model::Symbol->new(
micro_sym => 'sym',
- exposure => 'parcel',
-);
-is( $thing->get_prefix, '', 'get_prefix with no parcel' );
-is( $thing->get_Prefix, '', 'get_Prefix with no parcel' );
-is( $thing->get_PREFIX, '', 'get_PREFIx with no parcel' );
-
-$thing = Clownfish::CFC::Model::Symbol->new(
- micro_sym => 'sym',
parcel => 'Crustacean',
exposure => 'parcel'
);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCBindCore.c b/compiler/src/CFCBindCore.c
index e8d49e6..754e558 100644
--- a/compiler/src/CFCBindCore.c
+++ b/compiler/src/CFCBindCore.c
@@ -138,7 +138,6 @@ CFCBindCore_write_all_modified(CFCBindCore *self, int modified) {
S_write_parcel_c(self, parcel);
}
}
- FREEMEM(parcels);
}
return modified;
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index f7e9520..116e172 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -270,8 +270,6 @@ S_check_prereqs() {
CFCParcel_check_prereqs(parcel);
}
}
-
- FREEMEM(parcels);
}
static void
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParcel.c b/compiler/src/CFCParcel.c
index 84b95a8..3050613 100644
--- a/compiler/src/CFCParcel.c
+++ b/compiler/src/CFCParcel.c
@@ -48,8 +48,6 @@ struct CFCParcel {
size_t num_prereqs;
};
-static CFCParcel *default_parcel = NULL;
-
#define JSON_STRING 1
#define JSON_HASH 2
#define JSON_NULL 3
@@ -87,11 +85,6 @@ static size_t num_registered = 0;
CFCParcel*
CFCParcel_fetch(const char *name) {
- // Return the default parcel for either a blank name or a NULL name.
- if (!name || !strlen(name)) {
- return CFCParcel_default_parcel();
- }
-
for (size_t i = 0; i < num_registered ; i++) {
CFCParcel *existing = registry[i];
if (strcmp(existing->name, name) == 0) {
@@ -118,14 +111,6 @@ CFCParcel_register(CFCParcel *self) {
}
}
- if (!num_registered) {
- // Init default parcel as first.
- registry = (CFCParcel**)CALLOCATE(3, sizeof(CFCParcel*));
- CFCParcel *def = CFCParcel_default_parcel();
- registry[0] = (CFCParcel*)CFCBase_incref((CFCBase*)def);
- num_registered++;
- }
-
size_t size = (num_registered + 2) * sizeof(CFCParcel*);
registry = (CFCParcel**)REALLOCATE(registry, size);
registry[num_registered++] = (CFCParcel*)CFCBase_incref((CFCBase*)self);
@@ -134,23 +119,7 @@ CFCParcel_register(CFCParcel *self) {
CFCParcel**
CFCParcel_all_parcels(void) {
- size_t size = (num_registered + 1) * sizeof(CFCParcel*);
- CFCParcel **parcels = (CFCParcel**)MALLOCATE(size);
- size_t n = 0;
-
- for (size_t i = 0; registry[i]; ++i) {
- CFCParcel *parcel = registry[i];
- const char *prefix = CFCParcel_get_prefix(parcel);
-
- // Skip default parcel.
- if (*prefix) {
- parcels[n++] = parcel;
- }
- }
-
- parcels[n] = NULL;
-
- return parcels;
+ return registry;
}
void
@@ -161,8 +130,6 @@ CFCParcel_reap_singletons(void) {
FREEMEM(registry);
num_registered = 0;
registry = NULL;
- CFCBase_decref((CFCBase*)default_parcel);
- default_parcel = NULL;
}
static int
@@ -402,14 +369,6 @@ CFCParcel_destroy(CFCParcel *self) {
CFCBase_destroy((CFCBase*)self);
}
-CFCParcel*
-CFCParcel_default_parcel(void) {
- if (default_parcel == NULL) {
- default_parcel = CFCParcel_new("", "", NULL, false);
- }
- return default_parcel;
-}
-
int
CFCParcel_equals(CFCParcel *self, CFCParcel *other) {
if (strcmp(self->name, other->name)) { return false; }
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCParcel.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParcel.h b/compiler/src/CFCParcel.h
index 4bd822d..dcf1dfe 100644
--- a/compiler/src/CFCParcel.h
+++ b/compiler/src/CFCParcel.h
@@ -51,8 +51,7 @@ CFCParcel_fetch(const char *name);
void
CFCParcel_register(CFCParcel *self);
-/** Return a NULL-terminated list of all registered parcels. Must be freed by
- * the caller.
+/** Return a NULL-terminated list of all registered parcels.
*/
CFCParcel**
CFCParcel_all_parcels(void);
@@ -79,11 +78,6 @@ CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
void
CFCParcel_destroy(CFCParcel *self);
-/** Return the singleton for default parcel, which has no prefix.
- */
-CFCParcel*
-CFCParcel_default_parcel(void);
-
int
CFCParcel_equals(CFCParcel *self, CFCParcel *other);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index 3f51df2..a6fbdc3 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -305,7 +305,6 @@ S_write_boot_c(CFCPerl *self) {
FREEMEM(alias_adds);
FREEMEM(bootstrap_code);
FREEMEM(pound_includes);
- FREEMEM(parcels);
FREEMEM(ordered);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/87222743/compiler/src/CFCTestParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestParcel.c b/compiler/src/CFCTestParcel.c
index 504f2a7..46d8f1c 100644
--- a/compiler/src/CFCTestParcel.c
+++ b/compiler/src/CFCTestParcel.c
@@ -40,7 +40,7 @@ S_run_parcel_tests(CFCTest *test);
const CFCTestBatch CFCTEST_BATCH_PARCEL = {
"Clownfish::CFC::Model::Parcel",
- 35,
+ 32,
S_run_tests
};
@@ -110,18 +110,6 @@ S_run_parcel_tests(CFCTest *test) {
}
{
- 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)),
[lucy-commits] [2/6] git commit: Don't use default parcel in tests
Posted by nw...@apache.org.
Don't use default parcel in tests
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c77676fd
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c77676fd
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c77676fd
Branch: refs/heads/master
Commit: c77676fdb8de6d937402258b1712cff7ea5fc106
Parents: 298abe8
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Mar 18 14:16:14 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Mar 21 21:12:04 2014 +0100
----------------------------------------------------------------------
compiler/perl/t/051-symbol.t | 3 +++
compiler/perl/t/105-object_type.t | 10 +++++++---
compiler/perl/t/108-composite_type.t | 11 +++++++++--
compiler/perl/t/300-variable.t | 16 ++++++++++++----
compiler/perl/t/401-class.t | 2 ++
compiler/src/CFCTestClass.c | 6 +++---
compiler/src/CFCTestSymbol.c | 3 ++-
compiler/src/CFCTestType.c | 14 ++++++++++----
compiler/src/CFCTestVariable.c | 4 ++--
9 files changed, 50 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/perl/t/051-symbol.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/051-symbol.t b/compiler/perl/t/051-symbol.t
index 9356696..70d9f0e 100644
--- a/compiler/perl/t/051-symbol.t
+++ b/compiler/perl/t/051-symbol.t
@@ -19,6 +19,8 @@ use warnings;
use Test::More tests => 40;
use Clownfish::CFC;
+my $parcel = Clownfish::CFC::Model::Parcel->new( name => 'Parcel' );
+
for (qw( foo 1Foo Foo_Bar 1FOOBAR )) {
eval { my $thing = new_symbol( class_name => $_ ) };
like( $@, qr/class_name/, "Reject invalid class name $_" );
@@ -76,6 +78,7 @@ is( $eep->full_sym, "eep_Ork_ah_ah", "full_sym" );
sub new_symbol {
return Clownfish::CFC::Model::Symbol->new(
+ parcel => $parcel,
micro_sym => 'sym',
exposure => 'parcel',
@_
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/perl/t/105-object_type.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/105-object_type.t b/compiler/perl/t/105-object_type.t
index 9bdce59..04d7722 100644
--- a/compiler/perl/t/105-object_type.t
+++ b/compiler/perl/t/105-object_type.t
@@ -63,7 +63,9 @@ for my $specifier (@specifiers) {
"nullable $specifier*" );
}
-eval { my $type = Clownfish::CFC::Model::Type->new_object };
+eval {
+ my $type = Clownfish::CFC::Model::Type->new_object( parcel => 'Neato' );
+};
like( $@, qr/specifier/i, "specifier required" );
for ( 0, 2 ) {
@@ -146,8 +148,10 @@ $const_foo->resolve;
ok( !$foo_type->equals($const_foo), "different const spoils equals" );
like( $const_foo->to_c, qr/const/, "const included in C representation" );
-my $string_type
- = Clownfish::CFC::Model::Type->new_object( specifier => 'String', );
+my $string_type = Clownfish::CFC::Model::Type->new_object(
+ parcel => 'Neato',
+ specifier => 'String',
+);
ok( !$foo_type->is_string_type, "Not is_string_type" );
ok( $string_type->is_string_type, "is_string_type" );
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/perl/t/108-composite_type.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/108-composite_type.t b/compiler/perl/t/108-composite_type.t
index 8a8369d..2bcdc81 100644
--- a/compiler/perl/t/108-composite_type.t
+++ b/compiler/perl/t/108-composite_type.t
@@ -21,6 +21,7 @@ use Clownfish::CFC::Model::Type;
use Clownfish::CFC::Parser;
my $parser = Clownfish::CFC::Parser->new;
+my $parcel = $parser->parse("parcel Neato;");
my @composite_type_strings = (
qw(
@@ -49,7 +50,10 @@ for my $input (@composite_type_strings) {
eval { my $type = Clownfish::CFC::Model::Type->new_composite };
like( $@, qr/child/i, "child required" );
-my $foo_type = Clownfish::CFC::Model::Type->new_object( specifier => 'Foo' );
+my $foo_type = Clownfish::CFC::Model::Type->new_object(
+ parcel => $parcel,
+ specifier => 'Foo',
+);
my $composite_type = Clownfish::CFC::Model::Type->new_composite(
child => $foo_type,
indirection => 1,
@@ -64,7 +68,10 @@ my $other = Clownfish::CFC::Model::Type->new_composite(
ok( $composite_type->equals($other), "equals" );
ok( $composite_type->is_composite, "is_composite" );
-my $bar_type = Clownfish::CFC::Model::Type->new_object( specifier => 'Bar' );
+my $bar_type = Clownfish::CFC::Model::Type->new_object(
+ parcel => $parcel,
+ specifier => 'Bar',
+);
my $bar_composite = Clownfish::CFC::Model::Type->new_composite(
child => $bar_type,
indirection => 1,
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/perl/t/300-variable.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/300-variable.t b/compiler/perl/t/300-variable.t
index bc49d17..a5220e7 100644
--- a/compiler/perl/t/300-variable.t
+++ b/compiler/perl/t/300-variable.t
@@ -21,13 +21,14 @@ use Test::More tests => 13;
BEGIN { use_ok('Clownfish::CFC::Model::Variable') }
my $parser = Clownfish::CFC::Parser->new;
-$parser->parse('parcel Neato;')
+my $parcel = $parser->parse('parcel Neato;')
or die "failed to process parcel_definition";
sub new_type { $parser->parse(shift) }
eval {
my $death = Clownfish::CFC::Model::Variable->new(
+ parcel => $parcel,
micro_sym => 'foo',
type => new_type('int'),
extra_arg => undef,
@@ -36,16 +37,22 @@ eval {
like( $@, qr/extra_arg/, "Extra arg kills constructor" );
eval {
- my $death = Clownfish::CFC::Model::Variable->new( micro_sym => 'foo' );
+ my $death = Clownfish::CFC::Model::Variable->new(
+ parcel => $parcel,
+ micro_sym => 'foo',
+ );
};
like( $@, qr/type/, "type is required" );
eval {
- my $death
- = Clownfish::CFC::Model::Variable->new( type => new_type('int32_t') );
+ my $death = Clownfish::CFC::Model::Variable->new(
+ parcel => $parcel,
+ type => new_type('int32_t'),
+ );
};
like( $@, qr/micro_sym/, "micro_sym is required" );
my $var = Clownfish::CFC::Model::Variable->new(
+ parcel => $parcel,
micro_sym => 'foo',
type => new_type('float*')
);
@@ -55,6 +62,7 @@ is( $var->local_declaration, 'float* foo;', "declaration" );
ok( $var->local, "default to local access" );
$var = Clownfish::CFC::Model::Variable->new(
+ parcel => $parcel,
micro_sym => 'foo',
type => new_type('float[1]')
);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/perl/t/401-class.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/401-class.t b/compiler/perl/t/401-class.t
index 1c83a90..85a1d09 100644
--- a/compiler/perl/t/401-class.t
+++ b/compiler/perl/t/401-class.t
@@ -21,6 +21,7 @@ use Clownfish::CFC::Model::Class;
use Clownfish::CFC::Parser;
my $parser = Clownfish::CFC::Parser->new;
+$parser->parse('parcel Neato;');
my $thing = Clownfish::CFC::Model::Variable->new(
parcel => 'Neato',
@@ -29,6 +30,7 @@ my $thing = Clownfish::CFC::Model::Variable->new(
micro_sym => 'thing',
);
my $widget = Clownfish::CFC::Model::Variable->new(
+ parcel => 'Neato',
class_name => 'Widget',
type => $parser->parse('Widget*'),
micro_sym => 'widget',
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/src/CFCTestClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestClass.c b/compiler/src/CFCTestClass.c
index aa080ae..40c26f1 100644
--- a/compiler/src/CFCTestClass.c
+++ b/compiler/src/CFCTestClass.c
@@ -44,7 +44,7 @@ S_has_symbol(CFCSymbol **symbols, const char *micro_sym);
const CFCTestBatch CFCTEST_BATCH_CLASS = {
"Clownfish::CFC::Model::Class",
- 83,
+ 85,
S_run_tests
};
@@ -52,7 +52,7 @@ static void
S_run_tests(CFCTest *test) {
CFCParser *parser = CFCParser_new();
- CFCParcel *neato = CFCParcel_new("Neato", NULL, NULL, false);
+ CFCParcel *neato = CFCTest_parse_parcel(test, parser, "parcel Neato;");
CFCFileSpec *file_spec = CFCFileSpec_new(".", "Foo/FooJr", 0);
CFCClass *thing_class
= CFCTest_parse_class(test, parser, "class Thing {}");
@@ -69,7 +69,7 @@ S_run_tests(CFCTest *test) {
thing_type, 0);
CFCType *widget_type = CFCTest_parse_type(test, parser, "Widget*");
- widget = CFCVariable_new(NULL, NULL, "Widget", NULL, "widget",
+ widget = CFCVariable_new(neato, NULL, "Widget", NULL, "widget",
widget_type, 0);
CFCType *return_type = CFCTest_parse_type(test, parser, "void");
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/src/CFCTestSymbol.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestSymbol.c b/compiler/src/CFCTestSymbol.c
index 8f6518e..77659d8 100644
--- a/compiler/src/CFCTestSymbol.c
+++ b/compiler/src/CFCTestSymbol.c
@@ -36,7 +36,7 @@ const CFCTestBatch CFCTEST_BATCH_SYMBOL = {
static void
S_run_tests(CFCTest *test) {
- CFCParcel *parcel = CFCParcel_default_parcel();
+ CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, false);
{
static const char *exposures[4] = {
@@ -145,6 +145,7 @@ S_run_tests(CFCTest *test) {
CFCBase_decref((CFCBase*)eep);
}
+ CFCBase_decref((CFCBase*)parcel);
CFCParcel_reap_singletons();
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/src/CFCTestType.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestType.c b/compiler/src/CFCTestType.c
index 693613f..167a497 100644
--- a/compiler/src/CFCTestType.c
+++ b/compiler/src/CFCTestType.c
@@ -112,7 +112,7 @@ S_run_basic_tests(CFCTest *test) {
static void
S_run_primitive_tests(CFCTest *test) {
- CFCParcel *parcel = CFCParcel_default_parcel();
+ CFCParcel *parcel = CFCParcel_new("Parcel", NULL, NULL, false);
CFCType *type = CFCType_new(CFCTYPE_PRIMITIVE, parcel, "hump_t", 0);
OK(test, CFCType_is_primitive(type), "is_primitive");
@@ -136,6 +136,7 @@ S_run_primitive_tests(CFCTest *test) {
}
CFCBase_decref((CFCBase*)type);
+ CFCBase_decref((CFCBase*)parcel);
}
static void
@@ -386,7 +387,8 @@ S_run_object_tests(CFCTest *test) {
}
{
- CFCType *string_type = CFCType_new_object(0, NULL, "String", 1);
+ CFCType *string_type
+ = CFCType_new_object(0, neato_parcel, "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);
@@ -462,6 +464,8 @@ 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, false);
+ CFCParser_set_parcel(parser, neato_parcel);
{
static const char *type_strings[14] = {
@@ -490,8 +494,9 @@ S_run_composite_tests(CFCTest *test) {
}
{
- CFCType *foo = CFCType_new_object(0, NULL, "Foo", 1);
- CFCType *const_foo = CFCType_new_object(CFCTYPE_CONST, NULL, "Foo", 1);
+ CFCType *foo = CFCType_new_object(0, neato_parcel, "Foo", 1);
+ CFCType *const_foo
+ = CFCType_new_object(CFCTYPE_CONST, neato_parcel, "Foo", 1);
CFCType *composite = CFCType_new_composite(0, foo, 1, NULL);
OK(test, CFCType_is_composite(composite), "is_composite");
@@ -542,6 +547,7 @@ S_run_composite_tests(CFCTest *test) {
CFCBase_decref((CFCBase*)foo_star_star);
}
+ CFCBase_decref((CFCBase*)neato_parcel);
CFCBase_decref((CFCBase*)parser);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c77676fd/compiler/src/CFCTestVariable.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestVariable.c b/compiler/src/CFCTestVariable.c
index 022db0b..a68cd73 100644
--- a/compiler/src/CFCTestVariable.c
+++ b/compiler/src/CFCTestVariable.c
@@ -43,7 +43,7 @@ S_run_tests(CFCTest *test) {
{
CFCType *type = CFCTest_parse_type(test, parser, "float*");
CFCVariable *var
- = CFCVariable_new(NULL, NULL, NULL, NULL, "foo", type, 0);
+ = CFCVariable_new(neato_parcel, NULL, NULL, NULL, "foo", type, 0);
CFCVariable_resolve_type(var);
STR_EQ(test, CFCVariable_local_c(var), "float* foo", "local_c");
STR_EQ(test, CFCVariable_local_declaration(var), "float* foo;",
@@ -57,7 +57,7 @@ S_run_tests(CFCTest *test) {
{
CFCType *type = CFCTest_parse_type(test, parser, "float[1]");
CFCVariable *var
- = CFCVariable_new(NULL, NULL, NULL, NULL, "foo", type, 0);
+ = CFCVariable_new(neato_parcel, NULL, NULL, NULL, "foo", type, 0);
CFCVariable_resolve_type(var);
STR_EQ(test, CFCVariable_local_c(var), "float foo[1]",
"to_c appends array to var name rather than type specifier");
[lucy-commits] [3/6] git commit: Don't allow default parcel in classes, vars,
and types
Posted by nw...@apache.org.
Don't allow default parcel in classes, vars, and types
The 'parcel' member of CFCVariables is always set to the parcel where
the variable is declared. This requires a change of the method
compatibility test. Only the method parameter types are compared for
equality while the symbols may differ.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/11110170
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/11110170
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/11110170
Branch: refs/heads/master
Commit: 11110170069239d2c8f56aa810d9e59c716e1ecb
Parents: dadbb6b
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Mar 18 14:16:53 2014 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Mar 21 21:12:56 2014 +0100
----------------------------------------------------------------------
compiler/perl/t/201-method.t | 4 ++--
compiler/src/CFCClass.c | 1 -
compiler/src/CFCMethod.c | 10 +++++++++-
compiler/src/CFCParseHeader.y | 3 +--
compiler/src/CFCSymbol.h | 3 +--
compiler/src/CFCTestMethod.c | 2 +-
compiler/src/CFCType.c | 6 +-----
compiler/src/CFCVariable.c | 3 ---
8 files changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/perl/t/201-method.t
----------------------------------------------------------------------
diff --git a/compiler/perl/t/201-method.t b/compiler/perl/t/201-method.t
index d1b232e..32b02b0 100644
--- a/compiler/perl/t/201-method.t
+++ b/compiler/perl/t/201-method.t
@@ -82,14 +82,14 @@ ok( !$method->compatible($missing_default),
ok( !$missing_default->compatible($method), "... reversed" );
my $param_name_differs = Clownfish::CFC::Model::Method->new( %args,
- param_list => $parser->parse('(Foo *self, int32_t countess)'), );
+ param_list => $parser->parse('(Foo *self, int32_t countess = 0)'), );
ok( !$method->compatible($param_name_differs),
"different param name spoils compatible()"
);
ok( !$param_name_differs->compatible($method), "... reversed" );
my $param_type_differs = Clownfish::CFC::Model::Method->new( %args,
- param_list => $parser->parse('(Foo *self, uint32_t count)'), );
+ param_list => $parser->parse('(Foo *self, uint32_t count = 0)'), );
ok( !$method->compatible($param_type_differs),
"different param type spoils compatible()"
);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCClass.c b/compiler/src/CFCClass.c
index fccecf8..eb84dfb 100644
--- a/compiler/src/CFCClass.c
+++ b/compiler/src/CFCClass.c
@@ -118,7 +118,6 @@ CFCClass_do_create(CFCClass *self, struct CFCParcel *parcel,
CFCUTIL_NULL_CHECK(class_name);
exposure = exposure ? exposure : "parcel";
micro_sym = micro_sym ? micro_sym : "class";
- parcel = parcel ? parcel : CFCParcel_default_parcel();
CFCSymbol_init((CFCSymbol*)self, parcel, exposure, class_name, cnick,
micro_sym);
if (!is_inert
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCMethod.c b/compiler/src/CFCMethod.c
index 97c68ae..090b35d 100644
--- a/compiler/src/CFCMethod.c
+++ b/compiler/src/CFCMethod.c
@@ -185,7 +185,15 @@ CFCMethod_compatible(CFCMethod *self, CFCMethod *other) {
if (strcmp(my_vals[i], other_vals[i])) { return false; }
}
if (my_args[i]) {
- if (!CFCVariable_equals(my_args[i], other_args[i])) {
+ CFCType *my_type = CFCVariable_get_type(my_args[i]);
+ CFCType *other_type = CFCVariable_get_type(other_args[i]);
+ if (!CFCType_equals(my_type, other_type)) {
+ return false;
+ }
+
+ const char *my_sym = CFCVariable_micro_sym(my_args[i]);
+ const char *other_sym = CFCVariable_micro_sym(other_args[i]);
+ if (strcmp(my_sym, other_sym) != 0) {
return false;
}
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCParseHeader.y
----------------------------------------------------------------------
diff --git a/compiler/src/CFCParseHeader.y b/compiler/src/CFCParseHeader.y
index 7b83fa1..1cc84c2 100644
--- a/compiler/src/CFCParseHeader.y
+++ b/compiler/src/CFCParseHeader.y
@@ -68,11 +68,10 @@ S_new_var(CFCParser *state, char *exposure, char *modifiers, CFCType *type,
inert = true;
}
- CFCParcel *parcel = NULL;
+ CFCParcel *parcel = CFCParser_get_parcel(state);
const char *class_name = NULL;
const char *class_cnick = NULL;
if (exposure && strcmp(exposure, "local") != 0) {
- parcel = CFCParser_get_parcel(state);
class_name = CFCParser_get_class_name(state);
class_cnick = CFCParser_get_class_cnick(state);
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCSymbol.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCSymbol.h b/compiler/src/CFCSymbol.h
index 2777c2c..d91bb52 100644
--- a/compiler/src/CFCSymbol.h
+++ b/compiler/src/CFCSymbol.h
@@ -54,8 +54,7 @@ int
CFCSymbol_validate_class_name_component(const char *name);
/**
- * @param parcel A Clownfish::CFC::Model::Parcel. If not supplied, will be
- * assigned to the default Parcel.
+ * @param parcel A Clownfish::CFC::Model::Parcel.
* @param exposure The scope in which the symbol is exposed. Must be
* 'public', 'parcel', 'private', or 'local'.
* @param class_name A optional class name, consisting of one or more
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCTestMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestMethod.c b/compiler/src/CFCTestMethod.c
index 39dd8d3..b2eca23 100644
--- a/compiler/src/CFCTestMethod.c
+++ b/compiler/src/CFCTestMethod.c
@@ -97,7 +97,7 @@ S_run_basic_tests(CFCTest *test) {
"(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, int32_t countess = 0)",
"(Foo *self, uint32_t count = 0)"
};
static const char *test_names[5] = {
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCType.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCType.c b/compiler/src/CFCType.c
index 8a3d774..b3c13ce 100644
--- a/compiler/src/CFCType.c
+++ b/compiler/src/CFCType.c
@@ -167,6 +167,7 @@ CFCType*
CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier,
int indirection) {
// Validate params.
+ CFCUTIL_NULL_CHECK(parcel);
if (indirection != 1) {
CFCUtil_die("Parameter 'indirection' can only be 1");
}
@@ -177,11 +178,6 @@ CFCType_new_object(int flags, CFCParcel *parcel, const char *specifier,
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")) {
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/11110170/compiler/src/CFCVariable.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCVariable.c b/compiler/src/CFCVariable.c
index 71e3473..3443933 100644
--- a/compiler/src/CFCVariable.c
+++ b/compiler/src/CFCVariable.c
@@ -63,9 +63,6 @@ CFCVariable_init(CFCVariable *self, struct CFCParcel *parcel,
struct CFCType *type, int inert) {
// Validate params.
CFCUTIL_NULL_CHECK(type);
- if (!parcel) {
- parcel = CFCParcel_default_parcel();
- }
// Default exposure to "local".
const char *real_exposure = exposure ? exposure : "local";