You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/16 03:32:30 UTC
[lucy-commits] svn commit: r1071127 - in /incubator/lucy/trunk/clownfish:
lib/Clownfish/Binding/Core/File.pm lib/Clownfish/File.pm
lib/Clownfish/Hierarchy.pm lib/Clownfish/Parser.pm t/403-file.t
t/500-hierarchy.t
Author: marvin
Date: Wed Feb 16 02:32:30 2011
New Revision: 1071127
URL: http://svn.apache.org/viewvc?rev=1071127&view=rev
Log:
Change interface for Clownfish::File to be more C-like in anticipation of
porting.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm
incubator/lucy/trunk/clownfish/t/403-file.t
incubator/lucy/trunk/clownfish/t/500-hierarchy.t
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Binding/Core/File.pm Wed Feb 16 02:32:30 2011
@@ -54,7 +54,7 @@ sub write_h {
# Aggregate block content.
my $content = "";
- for my $block ( $file->blocks ) {
+ for my $block ( @{ $file->blocks } ) {
if ( a_isa_b( $block, 'Clownfish::Parcel' ) ) { }
elsif ( a_isa_b( $block, 'Clownfish::Class' ) ) {
my $class_binding
@@ -117,7 +117,7 @@ sub write_c {
# Aggregate content.
my $content = "";
my $c_file_syms = "";
- for my $block ( $file->blocks ) {
+ for my $block ( @{ $file->blocks } ) {
if ( blessed($block) ) {
if ( $block->isa('Clownfish::Class') ) {
my $bound
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm Wed Feb 16 02:32:30 2011
@@ -30,7 +30,6 @@ our %parcel;
our %modified;
our %new_PARAMS = (
- blocks => undef,
source_class => undef,
parcel => undef,
);
@@ -41,15 +40,9 @@ sub new {
my $package = ref($either) || $either;
my $self = $either->_new();
$parcel{$self} = Clownfish::Parcel->acquire( $args{parcel} );
- $blocks{$self} = $args{blocks} || [];
+ $blocks{$self} = [];
$source_class{$self} = $args{source_class};
$modified{$self} = 0;
- for my $block ( $self->blocks ) {
- next if a_isa_b( $block, "Clownfish::Parcel" );
- next if a_isa_b( $block, "Clownfish::Class" );
- next if a_isa_b( $block, "Clownfish::CBlock" );
- confess("Invalid block: $block");
- }
confess("Missing required param 'source_class'")
unless $self->get_source_class;
return $self;
@@ -64,16 +57,31 @@ sub DESTROY {
$self->_destroy;
}
+our %block_types = (
+ 'Clownfish::Parcel' => 1,
+ 'Clownfish::Class' => 1,
+ 'Clownfish::CBlock' => 1,
+);
+
+sub add_block {
+ my ( $self, $block ) = @_;
+ my $block_class = ref($block);
+ confess("Invalid block type: $block_class")
+ unless $block_types{$block_class};
+ push @{ $blocks{$self} }, $block;
+}
+
sub get_modified { $modified{ +shift } }
sub set_modified { $modified{ $_[0] } = $_[1] }
sub get_source_class { $source_class{ +shift } }
-sub blocks { @{ $blocks{+shift} } }
+sub blocks { $blocks{ +shift } }
sub classes {
my $self = shift;
- return
- grep { ref $_ and $_->isa('Clownfish::Class') } $self->blocks;
+ my @classes
+ = grep { ref $_ and $_->isa('Clownfish::Class') } @{ $self->blocks };
+ return \@classes;
}
# Return a string used for an include guard, unique per file.
@@ -132,16 +140,12 @@ An abstraction representing a file which
=head2 new
my $file_obj = Clownfish::File->new(
- blocks => \@blocks, # required
source_class => 'Crustacean::Lobster', # required
parcel => 'Crustacean', # default: special
);
=over
-=item * B<blocks> - An arrayref. Each element must be either a
-Clownfish::Class, a Clownfish::Parcel, or a Clownfish::CBlock.
-
=item * B<source_class> - The class name associated with the source file,
regardless of how what classes are defined in the source file. Example: If
source_class is "Foo::Bar", that implies that the source file could be found
@@ -152,17 +156,24 @@ should be 'Foo/Bar.h' within the target
=back
+=head2 add_block
+
+ $file_obj->add_block($block);
+
+Add an element to the blocks array. The block must be either a
+Clownfish::Class, a Clownfish::Parcel, or a Clownfish::CBlock.
+
=head2 blocks
- my @blocks = $file->blocks;
+ my $blocks = $file->blocks;
-Return all blocks as a list.
+Return all blocks as an arrayref.
=head2 classes
- my @classes = $file->classes;
+ my $classes = $file->classes;
-Return all Clownfish::Class blocks from the file as a list.
+Return all Clownfish::Class blocks from the file as an arrayref.
=head2 get_modified set_modified
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Wed Feb 16 02:32:30 2011
@@ -112,7 +112,7 @@ sub _parse_cf_files {
->file( $content, 0, source_class => $source_class, );
confess("parse error for $source_path") unless defined $file;
$self->_get_files->{$source_class} = $file;
- for my $class ( $file->classes ) {
+ for my $class ( @{ $file->classes } ) {
my $class_name = $class->get_class_name;
confess "$class_name already defined"
if exists $classes{$class_name};
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm Wed Feb 16 02:32:30 2011
@@ -508,12 +508,14 @@ sub new_class {
sub new_file {
my ( undef, $item, $arg ) = @_;
-
- return Clownfish::File->new(
+ my $file = Clownfish::File->new(
parcel => $parcel,
- blocks => $item->{'major_block(s)'},
source_class => $arg->{source_class},
);
+ for my $block ( @{ $item->{'major_block(s)'} } ) {
+ $file->add_block( $block, ref($block) );
+ }
+ return $file;
}
sub new_parcel {
Modified: incubator/lucy/trunk/clownfish/t/403-file.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/t/403-file.t?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/t/403-file.t (original)
+++ incubator/lucy/trunk/clownfish/t/403-file.t Wed Feb 16 02:32:30 2011
@@ -51,22 +51,22 @@ is( $file->cfh_path('/path/to'), "/path/
is( $file->c_path('/path/to'), "/path/to/Stuff/Thing.c", "c_path" );
is( $file->h_path('/path/to'), "/path/to/Stuff/Thing.h", "h_path" );
-my @classes = $file->classes;
-is( scalar @classes, 1, "classes() filters blocks" );
-my $class = $classes[0];
+my $classes = $file->classes;
+is( scalar @$classes, 1, "classes() filters blocks" );
+my $class = $classes->[0];
my ( $foo, $bar ) = @{ $class->member_vars };
is( $foo->get_type->get_specifier,
'stuff_Foo', 'file production picked up parcel def' );
is( $bar->get_type->get_specifier, 'stuff_Bar', 'parcel def is sticky' );
-my @blocks = $file->blocks;
-is( scalar @blocks, 3, "all three blocks" );
-isa_ok( $blocks[0], "Clownfish::Parcel" );
-isa_ok( $blocks[1], "Clownfish::Class" );
-isa_ok( $blocks[2], "Clownfish::CBlock" );
+my $blocks = $file->blocks;
+is( scalar @$blocks, 3, "all three blocks" );
+isa_ok( $blocks->[0], "Clownfish::Parcel" );
+isa_ok( $blocks->[1], "Clownfish::Class" );
+isa_ok( $blocks->[2], "Clownfish::CBlock" );
$file = $parser->file( $class_content, 0, source_class => 'Stuff::Thing' );
-($class) = $file->classes;
+($class) = @{ $file->classes };
( $foo, $bar ) = @{ $class->member_vars };
is( $foo->get_type->get_specifier, 'Foo', 'file production resets parcel' );
Modified: incubator/lucy/trunk/clownfish/t/500-hierarchy.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/t/500-hierarchy.t?rev=1071127&r1=1071126&r2=1071127&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/t/500-hierarchy.t (original)
+++ incubator/lucy/trunk/clownfish/t/500-hierarchy.t Wed Feb 16 02:32:30 2011
@@ -48,7 +48,8 @@ my %files;
for my $file (@files) {
die "not a File" unless isa_ok( $file, "Clownfish::File" );
ok( !$file->get_modified, "start off not modified" );
- my ($class) = grep { a_isa_b( $_, "Clownfish::Class" ) } $file->blocks;
+ my ($class)
+ = grep { a_isa_b( $_, "Clownfish::Class" ) } @{ $file->blocks };
die "no class" unless $class;
$files{ $class->get_class_name } = $file;
}