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/15 03:15:09 UTC
[lucy-commits] svn commit: r1070755 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Method.pm src/CFCMethod.c src/CFCMethod.h
Author: marvin
Date: Tue Feb 15 02:15:09 2011
New Revision: 1070755
URL: http://svn.apache.org/viewvc?rev=1070755&view=rev
Log:
Move member variables and accessors in Clownfish::Method from Perl inside-out
implementation to C.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
incubator/lucy/trunk/clownfish/src/CFCMethod.c
incubator/lucy/trunk/clownfish/src/CFCMethod.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1070755&r1=1070754&r2=1070755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Tue Feb 15 02:15:09 2011
@@ -209,7 +209,7 @@ PPCODE:
MODULE = Clownfish PACKAGE = Clownfish::Method
SV*
-_new(klass, parcel, exposure, class_name_sv, class_cnick_sv, micro_sym_sv, return_type, param_list, docucomment, is_inline)
+_new(klass, parcel, exposure, class_name_sv, class_cnick_sv, micro_sym_sv, return_type, param_list, docucomment, is_inline, macro_sym, is_final, is_abstract)
const char *klass;
CFCParcel *parcel;
const char *exposure;
@@ -220,6 +220,9 @@ _new(klass, parcel, exposure, class_name
SV *param_list;
SV *docucomment;
int is_inline;
+ const char *macro_sym;
+ int is_final;
+ int is_abstract;
CODE:
const char *class_name = SvOK(class_name_sv)
? SvPV_nolen(class_name_sv) : NULL;
@@ -228,17 +231,60 @@ CODE:
const char *micro_sym = SvOK(micro_sym_sv)
? SvPV_nolen(micro_sym_sv) : NULL;
CFCMethod *self = CFCMethod_new(parcel, exposure, class_name, class_cnick,
- micro_sym, return_type, param_list, docucomment, is_inline);
+ micro_sym, return_type, param_list, docucomment, is_inline, macro_sym,
+ is_final, is_abstract);
RETVAL = newSV(0);
sv_setref_pv(RETVAL, klass, (void*)self);
OUTPUT: RETVAL
void
-_destroy(self)
+DESTROY(self)
CFCMethod *self;
PPCODE:
CFCMethod_destroy(self);
+void
+_set_or_get(self, ...)
+ CFCMethod *self;
+ALIAS:
+ get_macro_sym = 2
+ _set_short_typedef = 3
+ short_typedef = 4
+ abstract = 6
+ _set_novel = 7
+ novel = 8
+ final = 10;
+PPCODE:
+{
+ START_SET_OR_GET_SWITCH
+ case 2: {
+ const char *macro_sym = CFCMethod_get_macro_sym(self);
+ retval = newSVpvn(macro_sym, strlen(macro_sym));
+ }
+ break;
+ case 3:
+ CFCMethod_set_short_typedef(self, SvPV_nolen(ST(1)));
+ break;
+ case 4: {
+ const char *short_typedef = CFCMethod_short_typedef(self);
+ retval = newSVpvn(short_typedef, strlen(short_typedef));
+ }
+ break;
+ case 6:
+ retval = newSViv(CFCMethod_abstract(self));
+ break;
+ case 7:
+ CFCMethod_set_novel(self, !!SvIV(ST(1)));
+ break;
+ case 8:
+ retval = newSViv(CFCMethod_novel(self));
+ break;
+ case 10:
+ retval = newSViv(CFCMethod_final(self));
+ break;
+ END_SET_OR_GET_SWITCH
+}
+
MODULE = Clownfish PACKAGE = Clownfish::ParamList
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm?rev=1070755&r1=1070754&r2=1070755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Method.pm Tue Feb 15 02:15:09 2011
@@ -21,12 +21,6 @@ use base qw( Clownfish::Function );
use Clownfish::Util qw( verify_args );
use Carp;
-our %macro_sym;
-our %abstract;
-our %final;
-our %novel;
-our %short_typedef;
-
my %new_PARAMS = (
return_type => undef,
class_name => undef,
@@ -43,16 +37,14 @@ my %new_PARAMS = (
sub new {
my ( $either, %args ) = @_;
verify_args( \%new_PARAMS, %args ) or confess $@;
- my $abstract = delete $args{abstract};
- my $final = delete $args{final};
- my $macro_sym = delete $args{macro_sym};
- my $novel = delete $args{novel};
- my $short_typedef = delete $args{short_typedef};
$args{inline} = 0;
+ $args{abstract} ||= 0;
$args{exposure} ||= 'parcel';
$args{parcel} = Clownfish::Parcel->acquire( $args{parcel} );
+ $args{final} = 0 unless defined $args{final};
# Validate macro_sym, derive micro_sym.
+ my $macro_sym = $args{macro_sym};
confess("macro_sym is required") unless defined $macro_sym;
confess("Invalid macro_sym: '$macro_sym'")
unless $macro_sym =~ /^[A-Z][A-Za-z0-9]*(?:_[A-Z0-9][A-Za-z0-9]*)*$/;
@@ -63,16 +55,10 @@ sub new {
my $self = $package->_new(
@args{
qw( parcel exposure class_name class_cnick micro_sym
- return_type param_list docucomment inline )
+ return_type param_list docucomment inline macro_sym
+ final abstract )
}
);
- $macro_sym{$self} = $macro_sym;
- $abstract{$self} = $abstract;
- $final{$self} = $final;
-
- # Assume that this method is novel until we discover when applying
- # inheritance that it was overridden.
- $novel{$self} = defined $novel ? $novel : 1;
# Verify that the first element in the arg list is a self.
my $args = $self->get_param_list->get_variables;
@@ -84,28 +70,11 @@ sub new {
unless $specifier eq $self->get_prefix . $struct_sym;
# Cache typedef.
- $short_typedef{$self}
- = defined $short_typedef ? $short_typedef : $self->short_sym . "_t";
+ $self->_set_short_typedef( $self->short_sym . "_t" );
return $self;
}
-sub DESTROY {
- my $self = shift;
- delete $macro_sym{$self};
- delete $abstract{$self};
- delete $final{$self};
- delete $novel{$self};
- delete $short_typedef{$self};
- $self->_destroy;
-}
-
-sub abstract { $abstract{ +shift } }
-sub novel { $novel{ +shift } }
-sub final { $final{ +shift } }
-sub get_macro_sym { $macro_sym{ +shift } }
-sub _set_novel { $novel{ $_[0] } = $_[1] }
-
sub self_type { shift->get_param_list->get_variables->[0]->get_type }
sub short_method_sym {
@@ -129,8 +98,6 @@ sub full_offset_sym {
sub full_callback_sym { shift->full_func_sym . "_CALLBACK" }
sub full_override_sym { shift->full_func_sym . "_OVERRIDE" }
-sub short_typedef { $short_typedef{ +shift } }
-sub _set_short_typedef { $short_typedef{ $_[0] } = $_[1] }
sub full_typedef {
my $self = shift;
return $self->get_prefix . $self->short_typedef;
Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.c?rev=1070755&r1=1070754&r2=1070755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.c Tue Feb 15 02:15:09 2011
@@ -25,36 +25,97 @@
struct CFCMethod {
CFCFunction function;
+ const char *macro_sym;
+ const char *short_typedef;
+ int is_final;
+ int is_abstract;
+ int is_novel;
};
CFCMethod*
CFCMethod_new(void *parcel, const char *exposure, const char *class_name,
const char *class_cnick, const char *micro_sym,
void *return_type, void *param_list, void *docucomment,
- int is_inline)
+ int is_inline, const char *macro_sym, int is_final,
+ int is_abstract)
{
CFCMethod *self = (CFCMethod*)malloc(sizeof(CFCMethod));
if (!self) { croak("malloc failed"); }
return CFCMethod_init(self, parcel, exposure, class_name, class_cnick,
- micro_sym, return_type, param_list, docucomment, is_inline);
+ micro_sym, return_type, param_list, docucomment, is_inline, macro_sym,
+ is_final, is_abstract);
}
CFCMethod*
CFCMethod_init(CFCMethod *self, void *parcel, const char *exposure,
const char *class_name, const char *class_cnick,
const char *micro_sym, void *return_type, void *param_list,
- void *docucomment, int is_inline)
+ void *docucomment, int is_inline, const char *macro_sym,
+ int is_final, int is_abstract)
{
CFCFunction_init((CFCFunction*)self, parcel, exposure, class_name,
class_cnick, micro_sym, return_type, param_list, docucomment,
is_inline);
+ self->macro_sym = savepv(macro_sym);
+ self->short_typedef = NULL;
+ self->is_final = is_final;
+ self->is_abstract = is_abstract;
+
+ // Assume that this method is novel until we discover when applying
+ // inheritance that it was overridden.
+ self->is_novel = 1;
+
return self;
}
void
CFCMethod_destroy(CFCMethod *self)
{
+ Safefree(self->macro_sym);
+ Safefree(self->short_typedef);
CFCFunction_destroy((CFCFunction*)self);
}
+const char*
+CFCMethod_get_macro_sym(CFCMethod *self)
+{
+ return self->macro_sym;
+}
+
+void
+CFCMethod_set_short_typedef(CFCMethod *self, const char *short_typedef)
+{
+ Safefree(self->short_typedef);
+ self->short_typedef = short_typedef ? savepv(short_typedef) : NULL;
+}
+
+const char*
+CFCMethod_short_typedef(CFCMethod *self)
+{
+ return self->short_typedef;
+}
+
+int
+CFCMethod_final(CFCMethod *self)
+{
+ return self->is_final;
+}
+
+int
+CFCMethod_abstract(CFCMethod *self)
+{
+ return self->is_abstract;
+}
+
+void
+CFCMethod_set_novel(CFCMethod *self, int is_novel)
+{
+ self->is_novel = !!is_novel;
+}
+
+int
+CFCMethod_novel(CFCMethod *self)
+{
+ return self->is_novel;
+}
Modified: incubator/lucy/trunk/clownfish/src/CFCMethod.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCMethod.h?rev=1070755&r1=1070754&r2=1070755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCMethod.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCMethod.h Tue Feb 15 02:15:09 2011
@@ -20,15 +20,38 @@ CFCMethod*
CFCMethod_new(void *parcel, const char *exposure, const char *class_name,
const char *class_cnick, const char *micro_sym,
void *return_type, void *param_list, void *docucomment,
- int is_inline);
+ int is_inline, const char *macro_sym, int is_final,
+ int is_abstract);
CFCMethod*
CFCMethod_init(CFCMethod *self, void *parcel, const char *exposure,
const char *class_name, const char *class_cnick,
- const char *micro_sym, void *return_type, void *param_list,
- void *docucomment, int is_inline);
+ const char *micro_sym, void *return_type, void *param_list,
+ void *docucomment, int is_inline, const char *macro_sym,
+ int is_final, int is_abstract);
void
CFCMethod_destroy(CFCMethod *self);
+const char*
+CFCMethod_get_macro_sym(CFCMethod *self);
+
+void
+CFCMethod_set_short_typedef(CFCMethod *self, const char *short_typedef);
+
+const char*
+CFCMethod_short_typedef(CFCMethod *self);
+
+int
+CFCMethod_final(CFCMethod *self);
+
+int
+CFCMethod_abstract(CFCMethod *self);
+
+void
+CFCMethod_set_novel(CFCMethod *self, int is_novel);
+
+int
+CFCMethod_novel(CFCMethod *self);
+