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/01/19 23:22:55 UTC
[lucy-commits] svn commit: r1061030 - in /incubator/lucy/trunk/clownfish/lib/Clownfish:
CBlock.pm File.pm Function.pm Hierarchy.pm Method.pm ParamList.pm Parcel.pm
Symbol.pm Type.pm Type/Arbitrary.pm Type/Composite.pm Type/Object.pm
Type/Primitive.pm Variable.pm
Author: marvin
Date: Wed Jan 19 22:22:54 2011
New Revision: 1061030
URL: http://svn.apache.org/viewvc?rev=1061030&view=rev
Log:
Reduce direct hash member variable access and increase use of accessors, so
that the code base is less dependent on objects implemented as blessed hashes
and switching to C-struct based objects will be less involved.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Function.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/CBlock.pm Wed Jan 19 22:22:54 2011
@@ -27,7 +27,7 @@ sub new {
verify_args( \%new_PARAMS, @_ ) or confess $@;
my $self = bless { %new_PARAMS, @_ }, ref($either) || $either;
confess("Missing required param 'contents'")
- unless defined $self->{contents};
+ unless defined $self->get_contents;
return $self;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/File.pm Wed Jan 19 22:22:54 2011
@@ -30,24 +30,25 @@ our %new_PARAMS = (
);
sub new {
- my $either = shift;
- verify_args( \%new_PARAMS, @_ ) or confess $@;
+ my ( $either, %args ) = @_;
+ verify_args( \%new_PARAMS, %args ) or confess $@;
+ my $parcel = $args{parcel};
+ if ( defined $parcel ) {
+ if ( !blessed($parcel) ) {
+ $parcel = Clownfish::Parcel->singleton( name => $parcel );
+ }
+ confess("Not a Clownfish::Parcel")
+ unless $parcel->isa('Clownfish::Parcel');
+ }
my $self = bless {
%new_PARAMS,
blocks => [],
source_class => undef,
modified => 0,
- @_,
+ %args,
+ parcel => $parcel,
},
ref($either) || $either;
- if ( defined $self->{parcel} ) {
- if ( !blessed( $self->{parcel} ) ) {
- $self->{parcel}
- = Clownfish::Parcel->singleton( name => $self->{parcel} );
- }
- confess("Not a Clownfish::Parcel")
- unless $self->{parcel}->isa('Clownfish::Parcel');
- }
for my $block ( @{ $self->{blocks} } ) {
next if a_isa_b( $block, "Clownfish::Parcel" );
next if a_isa_b( $block, "Clownfish::Class" );
@@ -55,7 +56,7 @@ sub new {
confess("Invalid block: $block");
}
confess("Missing required param 'source_class'")
- unless $self->{source_class};
+ unless $self->get_source_class;
return $self;
}
@@ -74,7 +75,7 @@ sub classes {
# Return a string used for an include guard, unique per file.
sub guard_name {
my $self = shift;
- my $guard_name = "H_" . uc( $self->{source_class} );
+ my $guard_name = "H_" . uc( $self->get_source_class );
$guard_name =~ s/\W+/_/g;
return $guard_name;
}
@@ -100,7 +101,7 @@ sub cfh_path { return $_[0]->_some_path(
sub _some_path {
my ( $self, $base_dir, $ext ) = @_;
- my @components = split( '::', $self->{source_class} );
+ my @components = split( '::', $self->get_source_class );
unshift @components, $base_dir
if defined $base_dir;
$components[-1] .= $ext;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Function.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Function.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Function.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Function.pm Wed Jan 19 22:22:54 2011
@@ -44,12 +44,12 @@ sub new {
for (qw( return_type class_name param_list )) {
confess("$_ is mandatory") unless defined $self->{$_};
}
- confess("Invalid micro_sym: '$self->{micro_sym}'")
- unless $self->{micro_sym} =~ /^[a-z0-9_]+$/;
+ confess( "Invalid micro_sym: '" . $self->micro_sym . "'" )
+ unless $self->micro_sym =~ /^[a-z0-9_]+$/;
confess 'param_list must be a ParamList object'
- unless a_isa_b( $self->{param_list}, "Clownfish::ParamList" );
+ unless a_isa_b( $self->get_param_list, "Clownfish::ParamList" );
confess 'return_type must be a Type object'
- unless a_isa_b( $self->{return_type}, "Clownfish::Type" );
+ unless a_isa_b( $self->get_return_type, "Clownfish::Type" );
return $self;
}
@@ -59,7 +59,7 @@ sub get_param_list { shift->{param_list
sub get_docucomment { shift->{docucomment} }
sub inline { shift->{inline} }
-sub void { shift->{return_type}->is_void }
+sub void { shift->get_return_type->is_void }
sub full_func_sym { shift->SUPER::full_sym }
sub short_func_sym { shift->SUPER::short_sym }
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Wed Jan 19 22:22:54 2011
@@ -50,32 +50,35 @@ sub new {
}
# Accessors.
-sub get_source { shift->{source} }
-sub get_dest { shift->{dest} }
+sub get_source { shift->{source} }
+sub get_dest { shift->{dest} }
+sub _get_trees { shift->{trees} }
+sub _get_files { shift->{files} }
+sub _get_parser { shift->{parser} }
# Return flattened hierarchies.
sub ordered_classes {
my $self = shift;
my @all;
- for my $tree ( values %{ $self->{trees} } ) {
+ for my $tree ( values %{ $self->_get_trees } ) {
push @all, $tree->tree_to_ladder;
}
return @all;
}
-sub files { values %{ shift->{files} } }
+sub files { values %{ shift->_get_files } }
# Slurp all Clownfish header files.
# Arrange the class objects into inheritance trees.
sub build {
my $self = shift;
$self->_parse_cf_files;
- $_->grow_tree for values %{ $self->{trees} };
+ $_->grow_tree for values %{ $self->_get_trees };
}
sub _parse_cf_files {
my $self = shift;
- my $source = $self->{source};
+ my $source = $self->get_source;
# Collect filenames.
my @all_source_paths;
@@ -104,11 +107,11 @@ sub _parse_cf_files {
# Slurp, parse, add parsed file to pool.
my $content = slurp_file($source_path);
- $content = $self->{parser}->strip_plain_comments($content);
- my $file = $self->{parser}
+ $content = $self->_get_parser->strip_plain_comments($content);
+ my $file = $self->_get_parser
->file( $content, 0, source_class => $source_class, );
confess("parse error for $source_path") unless defined $file;
- $self->{files}{$source_class} = $file;
+ $self->_get_files->{$source_class} = $file;
for my $class ( $file->classes ) {
my $class_name = $class->get_class_name;
confess "$class_name already defined"
@@ -128,7 +131,7 @@ sub _parse_cf_files {
$classes{$parent_name}->add_child($class);
}
else {
- $self->{trees}{$class_name} = $class;
+ $self->_get_trees->{$class_name} = $class;
}
}
}
@@ -137,7 +140,7 @@ sub propagate_modified {
my ( $self, $modified ) = @_;
# Seed the recursive write.
my $somebody_is_modified;
- for my $tree ( values %{ $self->{trees} } ) {
+ for my $tree ( values %{ $self->_get_trees } ) {
next unless $self->_propagate_modified( $tree, $modified );
$somebody_is_modified = 1;
}
@@ -147,9 +150,9 @@ sub propagate_modified {
# Recursive helper function.
sub _propagate_modified {
my ( $self, $class, $modified ) = @_;
- my $file = $self->{files}{ $class->get_source_class };
- my $source_path = $file->cfh_path( $self->{source} );
- my $h_path = $file->h_path( $self->{dest} );
+ my $file = $self->_get_files->{ $class->get_source_class };
+ my $source_path = $file->cfh_path( $self->get_source );
+ my $h_path = $file->h_path( $self->get_dest );
if ( !current( $source_path, $h_path ) ) {
$modified = 1;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm Wed Jan 19 22:22:54 2011
@@ -65,17 +65,15 @@ sub new {
# Verify that the first element in the arg list is a self.
my $args = $self->get_param_list->get_variables;
confess "Not enough args" unless @$args;
- my $specifier = $args->[0]->get_type->get_specifier;
- my ($struct_sym) = $self->{class_name} =~ /(\w+)$/;
- confess
- "First arg type doesn't match class: $self->{class_name} $specifier"
+ my $specifier = $args->[0]->get_type->get_specifier;
+ my $class_name = $self->get_class_name;
+ my ($struct_sym) = $class_name =~ /(\w+)$/;
+ confess "First arg type doesn't match class: $class_name $specifier"
unless $specifier eq $self->get_prefix . $struct_sym;
# Cache typedef.
$self->{short_typedef}
- = defined $short_typedef
- ? $short_typedef
- : "$self->{class_cnick}_$self->{micro_sym}_t";
+ = defined $short_typedef ? $short_typedef : $self->short_sym . "_t";
return $self;
}
@@ -90,7 +88,7 @@ sub self_type { shift->get_param_list->g
sub short_method_sym {
my ( $self, $invoker ) = @_;
confess("Missing invoker") unless $invoker;
- return $invoker . "_$self->{macro_sym}";
+ return $invoker . '_' . $self->get_macro_sym;
}
sub full_method_sym {
@@ -102,7 +100,7 @@ sub full_method_sym {
sub full_offset_sym {
my ( $self, $invoker ) = @_;
confess("Missing invoker") unless $invoker;
- return $self->get_Prefix . "$invoker\_$self->{macro_sym}_OFFSET";
+ return $self->full_method_sym($invoker) . '_OFFSET';
}
sub full_callback_sym { shift->full_func_sym . "_CALLBACK" }
@@ -111,16 +109,20 @@ sub full_override_sym { shift->full_func
sub short_typedef { shift->{short_typedef} }
sub full_typedef {
my $self = shift;
- return $self->get_prefix . $self->{short_typedef};
+ return $self->get_prefix . $self->short_typedef;
}
sub override {
my ( $self, $orig ) = @_;
# Check that the override attempt is legal.
- confess( "Attempt to override final method '$orig->{micro_sym}' from "
- . "$orig->{class_cnick} by $self->{class_cnick}" )
- if $orig->final;
+ if ( $orig->final ) {
+ my $orig_micro_sym = $orig->micro_sym;
+ my $orig_class = $orig->get_class_name;
+ my $class_name = $self->get_class_name;
+ confess( "Attempt to override final method '$orig_micro_sym' "
+ . " from $orig_class by $class_name" );
+ }
if ( !$self->compatible($orig) ) {
my $func_name = $self->full_func_sym;
my $orig_func = $orig->full_func_sym;
@@ -133,7 +135,7 @@ sub override {
sub compatible {
my ( $self, $other ) = @_;
- return 0 unless $self->{macro_sym} eq $other->{macro_sym};
+ return 0 unless $self->get_macro_sym eq $other->get_macro_sym;
return 0 if ( $self->public xor $other->public );
my $param_list = $self->get_param_list;
my $other_param_list = $other->get_param_list;
@@ -159,8 +161,8 @@ sub compatible {
}
# Weak validation of return type to allow covariant object return types.
- my $return_type = $self->{return_type};
- my $other_return_type = $other->{return_type};
+ my $return_type = $self->get_return_type;
+ my $other_return_type = $other->get_return_type;
if ( $return_type->is_object ) {
return 0 unless $return_type->similar($other_return_type);
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/ParamList.pm Wed Jan 19 22:22:54 2011
@@ -34,24 +34,24 @@ sub new {
# Validate variables.
confess "variables must be an arrayref"
- unless ref( $self->{variables} ) eq 'ARRAY';
- for my $var ( @{ $self->{variables} } ) {
+ unless ref( $self->get_variables ) eq 'ARRAY';
+ for my $var ( @{ $self->get_variables } ) {
confess "invalid variable: '$var'"
unless ref($var) && $var->isa("Clownfish::Variable");
}
# Validate or init initial_values.
- if ( defined $self->{initial_values} ) {
+ if ( defined $self->get_initial_values ) {
confess "variables must be an arrayref"
- unless ref( $self->{initial_values} ) eq 'ARRAY';
- my $num_init = scalar @{ $self->{initial_values} };
+ unless ref( $self->get_initial_values ) eq 'ARRAY';
+ my $num_init = scalar @{ $self->get_initial_values };
my $num_vars = $self->num_vars;
confess("mismatch of num vars and init values: $num_vars $num_init")
unless $num_init == $num_vars;
}
else {
my @initial_values;
- $#initial_values = $#{ $self->{variables} };
+ $#initial_values = $#{ $self->get_variables };
$self->{initial_values} = \@initial_values;
}
@@ -61,18 +61,18 @@ sub new {
sub get_variables { shift->{variables} }
sub get_initial_values { shift->{initial_values} }
sub variadic { shift->{variadic} }
-sub num_vars { scalar @{ shift->{variables} } }
+sub num_vars { scalar @{ shift->get_variables } }
sub to_c {
my $self = shift;
- my $string = join( ', ', map { $_->local_c } @{ $self->{variables} } );
- $string .= ", ..." if $self->{variadic};
+ my $string = join( ', ', map { $_->local_c } @{ $self->get_variables } );
+ $string .= ", ..." if $self->variadic;
return $string;
}
sub name_list {
my $self = shift;
- return join( ', ', map { $_->micro_sym } @{ $self->{variables} } );
+ return join( ', ', map { $_->micro_sym } @{ $self->get_variables } );
}
1;
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm Wed Jan 19 22:22:54 2011
@@ -47,22 +47,23 @@ sub singleton {
# Return an existing singleton if the parcel has already been registered.
my $existing = $parcels{$name};
if ($existing) {
- if ( $cnick and $cnick ne $existing->{cnick} ) {
- confess( "cnick '$cnick' for parcel '$name' conflicts with "
- . "'$existing->{cnick}'" );
+ if ( $cnick and $cnick ne $existing->get_cnick ) {
+ confess( "cnick '$cnick' for parcel '$name' conflicts with '"
+ . $existing->get_cnick
+ . "'" );
}
return $existing;
}
# Register new parcel. Default cnick to name.
my $self = bless { %singleton_PARAMS, %args, }, ref($either) || $either;
- defined $self->{cnick} or $self->{cnick} = $self->{name};
+ defined $self->get_cnick or $self->{cnick} = $self->get_name;
$parcels{$name} = $self;
# Pre-generate prefixes.
- $self->{Prefix} = length $self->{cnick} ? "$self->{cnick}_" : "";
- $self->{prefix} = lc( $self->{Prefix} );
- $self->{PREFIX} = uc( $self->{Prefix} );
+ $self->{Prefix} = length $self->get_cnick ? $self->get_cnick . '_' : "";
+ $self->{prefix} = lc( $self->get_Prefix );
+ $self->{PREFIX} = uc( $self->get_Prefix );
return $self;
}
@@ -76,8 +77,8 @@ sub get_cnick { shift->{cnick} }
sub equals {
my ( $self, $other ) = @_;
- return 0 unless $self->{name} eq $other->{name};
- return 0 unless $self->{cnick} eq $other->{cnick};
+ return 0 unless $self->get_name eq $other->get_name;
+ return 0 unless $self->get_cnick eq $other->get_cnick;
return 1;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Symbol.pm Wed Jan 19 22:22:54 2011
@@ -35,9 +35,13 @@ my $class_name_regex = qr/^$struct_regex
sub new {
my ( $either, %args ) = @_;
+ my $class_name = $args{class_name};
+ my $class_cnick = $args{class_cnick};
+ my $micro_sym = $args{micro_sym};
+ my $parcel = $args{parcel};
+ my $exposure = $args{exposure};
# Acquire a Parcel.
- my $parcel = $args{parcel};
if ( !defined $parcel ) {
$parcel = Clownfish::Parcel->default_parcel;
}
@@ -49,81 +53,89 @@ sub new {
$parcel = Clownfish::Parcel->singleton( name => $args{parcel} );
}
- # Create the object.
- my $self = bless { %new_PARAMS, %args, parcel => $parcel },
- ref($either) || $either;
-
# Validate micro_sym.
- confess "micro_sym is required" unless $self->{micro_sym};
- confess("Invalid micro_sym: '$self->{micro_sym}'")
- unless $self->{micro_sym} =~ /^[A-Za-z_][A-Za-z0-9_]*$/;
+ confess "micro_sym is required" unless $micro_sym;
+ confess("Invalid micro_sym: '$micro_sym'")
+ unless $micro_sym =~ /^[A-Za-z_][A-Za-z0-9_]*$/;
# Validate exposure.
- confess("Invalid value for 'exposure': $self->{exposure}")
- unless $self->{exposure} =~ /^(?:public|parcel|private|local)$/;
+ confess("Invalid value for 'exposure': $exposure")
+ unless $exposure =~ /^(?:public|parcel|private|local)$/;
# Validate class name, validate or derive class_cnick.
- if ( defined $self->{class_name} ) {
- confess("Invalid class name: $self->{class_name}")
- unless $self->{class_name} =~ $class_name_regex;
- if ( !defined $self->{class_cnick} ) {
- $self->{class_name} =~ /(\w+)$/;
- $self->{class_cnick} = $1;
+ if ( defined $class_name ) {
+ confess("Invalid class name: $class_name")
+ unless $class_name =~ $class_name_regex;
+ if ( !defined $class_cnick ) {
+ $class_name =~ /(\w+)$/;
+ $class_cnick = $1;
}
- confess("Invalid class_cnick: $self->{class_cnick}")
- unless $self->{class_cnick} =~ /^[A-Z]+[A-Za-z0-9]*$/;
+ confess("Invalid class_cnick: $class_cnick")
+ unless $class_cnick =~ /^[A-Z]+[A-Za-z0-9]*$/;
}
- elsif ( defined $self->{class_cnick} ) {
+ elsif ( defined $class_cnick ) {
# Sanity check class_cnick without class_name.
confess("Can't supply class_cnick without class_name");
}
+ # Create the object.
+ my $self = bless {
+ %new_PARAMS,
+ %args,
+ parcel => $parcel,
+ micro_sym => $micro_sym,
+ exposure => $exposure,
+ class_name => $class_name,
+ class_cnick => $class_cnick,
+ },
+ ref($either) || $either;
+
return $self;
}
sub get_parcel { shift->{parcel} }
sub get_class_name { shift->{class_name} }
sub get_class_cnick { shift->{class_cnick} }
+sub get_exposure { shift->{exposure} }
sub micro_sym { shift->{micro_sym} }
-sub get_prefix { shift->{parcel}->get_prefix; }
-sub get_Prefix { shift->{parcel}->get_Prefix; }
-sub get_PREFIX { shift->{parcel}->get_PREFIX; }
-
-sub public { shift->{exposure} eq 'public' }
-sub private { shift->{exposure} eq 'private' }
-sub parcel { shift->{exposure} eq 'parcel' }
-sub local { shift->{exposure} eq 'local' }
+sub get_prefix { shift->get_parcel->get_prefix; }
+sub get_Prefix { shift->get_parcel->get_Prefix; }
+sub get_PREFIX { shift->get_parcel->get_PREFIX; }
+
+sub public { shift->get_exposure eq 'public' }
+sub private { shift->get_exposure eq 'private' }
+sub parcel { shift->get_exposure eq 'parcel' }
+sub local { shift->get_exposure eq 'local' }
sub full_sym {
my $self = shift;
- my $prefix = $self->get_prefix;
- return "$prefix$self->{class_cnick}_$self->{micro_sym}";
+ return $self->get_prefix . $self->short_sym;
}
sub short_sym {
my $self = shift;
- return "$self->{class_cnick}_$self->{micro_sym}";
+ return $self->get_class_cnick . '_' . $self->micro_sym;
}
sub equals {
my ( $self, $other ) = @_;
return 0 unless a_isa_b( $other, __PACKAGE__ );
- return 0 unless $self->{micro_sym} eq $other->{micro_sym};
- return 0 unless $self->{parcel}->equals( $other->{parcel} );
- if ( defined $self->{exposure} ) {
- return 0 unless defined $other->{exposure};
- return 0 unless $self->{exposure} eq $other->{exposure};
+ return 0 unless $self->micro_sym eq $other->micro_sym;
+ return 0 unless $self->get_parcel->equals( $other->get_parcel );
+ if ( defined $self->get_exposure ) {
+ return 0 unless defined $other->get_exposure;
+ return 0 unless $self->get_exposure eq $other->get_exposure;
}
else {
- return 0 if defined $other->{exposure};
+ return 0 if defined $other->get_exposure;
}
- if ( defined $self->{class_name} ) {
- return 0 unless defined $other->{class_name};
- return 0 unless $self->{class_name} eq $other->{class_name};
+ if ( defined $self->get_class_name ) {
+ return 0 unless defined $other->get_class_name;
+ return 0 unless $self->get_class_name eq $other->get_class_name;
}
else {
- return 0 if defined $other->{class_name};
+ return 0 if defined $other->get_class_name;
}
return 1;
}
@@ -177,7 +189,7 @@ extracting the last class name component
=head1 OBJECT METHODS
-=head2 get_parcel get_class_name get_class_cnick micro_sym
+=head2 get_parcel get_class_name get_class_cnick get_exposure micro_sym
Getters.
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type.pm Wed Jan 19 22:22:54 2011
@@ -37,13 +37,13 @@ sub new {
if $package eq __PACKAGE__;
verify_args( \%new_PARAMS, @_ ) or confess $@;
my $self = bless { %new_PARAMS, @_, }, $package;
- if ( defined $self->{parcel} ) {
- if ( !blessed( $self->{parcel} ) ) {
+ if ( defined $self->get_parcel ) {
+ if ( !blessed( $self->get_parcel ) ) {
$self->{parcel}
- = Clownfish::Parcel->singleton( name => $self->{parcel} );
+ = Clownfish::Parcel->singleton( name => $self->get_parcel );
}
confess("Not a Clownfish::Parcel")
- unless $self->{parcel}->isa('Clownfish::Parcel');
+ unless $self->get_parcel->isa('Clownfish::Parcel');
}
return $self;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Arbitrary.pm Wed Jan 19 22:22:54 2011
@@ -33,19 +33,20 @@ sub new {
my $self = $either->SUPER::new(@_);
# Validate specifier.
- confess("illegal specifier: '$self->{specifier}")
- unless $self->{specifier} =~ /^\w+$/;
-
- if ( $self->{specifier} =~ /^[A-Z]/ and $self->{parcel} ) {
- my $prefix = $self->{parcel}->get_prefix;
+ my $specifier = $self->get_specifier;
+ my $parcel = $self->get_parcel;
+ confess("illegal specifier: '$specifier'")
+ unless $specifier =~ /^\w+$/;
+ if ( $specifier =~ /^[A-Z]/ and $parcel ) {
+ my $prefix = $parcel->get_prefix;
# Add $prefix to what appear to be namespaced types.
- $self->{specifier} = $prefix . $self->{specifier}
- unless $self->{specifier} =~ /^$prefix/;
+ $specifier = $self->{specifier} = $prefix . $specifier
+ unless $specifier =~ /^$prefix/;
}
# Cache C representation.
my $string = $self->const ? 'const ' : '';
- $string .= $self->{specifier};
+ $string .= $specifier;
$self->set_c_string($string);
return $self;
@@ -55,7 +56,7 @@ sub equals {
my ( $self, $other ) = @_;
return 0 unless blessed($other);
return 0 unless $other->isa(__PACKAGE__);
- return 0 unless $self->{specifier} eq $other->{specifier};
+ return 0 unless $self->get_specifier eq $other->get_specifier;
return 1;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Composite.pm Wed Jan 19 22:22:54 2011
@@ -43,12 +43,12 @@ sub new {
$self->{nullable} = $nullable;
# Default indirection to 0.
- $self->{indirection} ||= 0;
+ my $indirection = $self->{indirection} ||= 0;
# Cache C representation.
# NOTE: Array postfixes are NOT included.
- my $string = $self->{child}->to_c;
- for ( my $i = 0; $i < $self->{indirection}; $i++ ) {
+ my $string = $child->to_c;
+ for ( my $i = 0; $i < $indirection; $i++ ) {
$string .= '*';
}
$self->set_c_string($string);
@@ -56,16 +56,18 @@ sub new {
return $self;
}
-sub get_specifier { shift->{child}->get_specifier }
-sub get_array { shift->{array} }
-sub is_composite {1}
+sub get_specifier { shift->_get_child->get_specifier }
+sub get_array { shift->{array} }
+sub _get_child { shift->{child} }
+sub _get_indirection { shift->{indirection} }
+sub is_composite {1}
sub equals {
my ( $self, $other ) = @_;
- return 0 unless $self->{indirection} == $other->{indirection};
- return 0 unless $self->{child}->equals( $other->{child} );
- return 0 if ( $self->{array} xor $other->{array} );
- return 0 if ( $self->{array} and $self->{array} ne $other->{array} );
+ return 0 unless $self->_get_indirection == $other->_get_indirection;
+ return 0 unless $self->_get_child->equals( $other->_get_child );
+ return 0 if ( $self->get_array xor $other->get_array );
+ return 0 if ( $self->get_array and $self->get_array ne $other->get_array );
return 1;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Object.pm Wed Jan 19 22:22:54 2011
@@ -41,35 +41,38 @@ sub new {
my $nullable = delete $args{nullable} || 0;
my $indirection = delete $args{indirection};
$indirection = 1 unless defined $indirection;
+ $args{parcel} ||= Clownfish::Parcel->default_parcel;
my $self = $either->SUPER::new(%args);
$self->{incremented} = $incremented;
$self->{decremented} = $decremented;
$self->{indirection} = $indirection;
$self->{nullable} = $nullable;
- $self->{parcel} ||= Clownfish::Parcel->default_parcel;
- my $prefix = $self->{parcel}->get_prefix;
+ my $prefix = $self->get_parcel->get_prefix;
+ my $specifier = $self->get_specifier;
# Validate params.
- confess("Indirection must be 1") unless $self->{indirection} == 1;
+ confess("Indirection must be 1") unless $indirection == 1;
confess("Can't be both incremented and decremented")
if ( $incremented && $decremented );
confess("Missing required param 'specifier'")
- unless defined $self->{specifier};
- confess("Illegal specifier: '$self->{specifier}")
- unless $self->{specifier}
+ unless defined $specifier;
+ confess("Illegal specifier: '$specifier'")
+ unless $specifier
=~ /^(?:$prefix)?[A-Z][A-Za-z0-9]*[a-z]+[A-Za-z0-9]*(?!\w)/;
# Add $prefix if necessary.
- $self->{specifier} = $prefix . $self->{specifier}
- unless $self->{specifier} =~ /^$prefix/;
+ if ( $specifier !~ /^$prefix/ ) {
+ $specifier = $prefix . $specifier;
+ $self->{specifier} = $specifier;
+ }
# Cache C representation.
my $string = $self->const ? 'const ' : '';
- $string .= "$self->{specifier}*";
+ $string .= "$specifier*";
$self->set_c_string($string);
# Cache boolean indicating whether this type is a string type.
- $self->{is_string_type} = $self->{specifier} =~ /CharBuf/ ? 1 : 0;
+ $self->{is_string_type} = $specifier =~ /CharBuf/ ? 1 : 0;
return $self;
}
@@ -92,7 +95,7 @@ sub similar {
sub equals {
my ( $self, $other ) = @_;
return 0 unless $self->similar($other);
- return 0 unless $self->{specifier} eq $other->{specifier};
+ return 0 unless $self->get_specifier eq $other->get_specifier;
return 1;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Type/Primitive.pm Wed Jan 19 22:22:54 2011
@@ -42,8 +42,8 @@ sub equals {
my ( $self, $other ) = @_;
return 0 unless blessed($other);
return 0 unless $other->isa(__PACKAGE__);
- return 0 unless $self->{specifier} eq $other->{specifier};
- return 0 if ( $self->{const} xor $other->{const} );
+ return 0 unless $self->get_specifier eq $other->get_specifier;
+ return 0 if ( $self->const xor $other->const );
return 1;
}
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm?rev=1061030&r1=1061029&r2=1061030&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm Wed Jan 19 22:22:54 2011
@@ -36,7 +36,7 @@ sub new {
verify_args( \%new_PARAMS, @_ ) or confess $@;
my $self = $either->SUPER::new( %new_PARAMS, @_ );
confess "invalid type"
- unless a_isa_b( $self->{type}, "Clownfish::Type" );
+ unless a_isa_b( $self->get_type, "Clownfish::Type" );
return $self;
}
@@ -44,24 +44,24 @@ sub get_type { shift->{type} }
sub equals {
my ( $self, $other ) = @_;
- return 0 unless $self->{type}->equals( $other->{type} );
+ return 0 unless $self->get_type->equals( $other->get_type );
return $self->SUPER::equals($other);
}
sub local_c {
my $self = shift;
- my $type = $self->{type};
+ my $type = $self->get_type;
my $array_str = '';
if ( $type->is_composite ) {
$array_str = $type->get_array || '';
}
my $type_str = $array_str ? $type->to_c : $type->to_c;
- return "$type_str $self->{micro_sym}$array_str";
+ return "$type_str " . $self->micro_sym . $array_str;
}
sub global_c {
my $self = shift;
- my $type = $self->{type};
+ my $type = $self->get_type;
my $name = $self->full_sym;
my $postfix = '';
if ( $type->is_composite ) {