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/25 23:30:31 UTC
[lucy-commits] svn commit: r1074723 - in /incubator/lucy/trunk/clownfish: include/CFC.h
lib/Clownfish.xs lib/Clownfish/Hierarchy.pm src/CFCHierarchy.c
src/CFCHierarchy.h typemap
Author: marvin
Date: Fri Feb 25 22:30:30 2011
New Revision: 1074723
URL: http://svn.apache.org/viewvc?rev=1074723&view=rev
Log:
Change Clownfish::Hierarchy to an inside-out Perl object implementation.
Added:
incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
Modified:
incubator/lucy/trunk/clownfish/include/CFC.h
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
incubator/lucy/trunk/clownfish/typemap
Modified: incubator/lucy/trunk/clownfish/include/CFC.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/include/CFC.h?rev=1074723&r1=1074722&r2=1074723&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Fri Feb 25 22:30:30 2011
@@ -20,6 +20,7 @@
#include "CFCDocuComment.h"
#include "CFCFile.h"
#include "CFCFunction.h"
+#include "CFCHierarchy.h"
#include "CFCMethod.h"
#include "CFCParamList.h"
#include "CFCParcel.h"
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1074723&r1=1074722&r2=1074723&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Feb 25 22:30:30 2011
@@ -558,6 +558,22 @@ PPCODE:
END_SET_OR_GET_SWITCH
}
+MODULE = Clownfish PACKAGE = Clownfish::Hierarchy
+
+SV*
+_new(klass)
+ const char *klass;
+CODE:
+ CFCHierarchy *self = CFCHierarchy_new();
+ RETVAL = newRV(CFCBase_get_perl_obj((CFCBase*)self));
+ CFCBase_decref((CFCBase*)self);
+OUTPUT: RETVAL
+
+void
+_destroy(self)
+ CFCHierarchy *self;
+PPCODE:
+ CFCHierarchy_destroy(self);
MODULE = Clownfish PACKAGE = Clownfish::Method
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm?rev=1074723&r1=1074722&r2=1074723&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Hierarchy.pm Fri Feb 25 22:30:30 2011
@@ -27,34 +27,50 @@ use Clownfish::Util qw( slurp_file curre
use Clownfish::Class;
use Clownfish::Parser;
+# Inside-out member vars.
+our %source;
+our %dest;
+our %parser;
+our %trees;
+our %files;
+
our %new_PARAMS = (
source => undef,
dest => undef,
);
sub new {
- my $either = shift;
- verify_args( \%new_PARAMS, @_ ) or confess $@;
- my $self = bless {
- parser => Clownfish::Parser->new,
- trees => {},
- files => {},
- %new_PARAMS,
- @_,
- },
- ref($either) || $either;
+ my ( $either, %args ) = @_;
+ verify_args( \%new_PARAMS, %args ) or confess $@;
for (qw( source dest)) {
- confess("Missing required param '$_'") unless $self->{$_};
+ confess("Missing required param '$_'") unless $args{$_};
}
+ my $package = ref($either) || $either;
+ my $self = $package->_new();
+ $source{$self} = $args{source};
+ $dest{$self} = $args{dest};
+ $parser{$self} = Clownfish::Parser->new;
+ $trees{$self} = {};
+ $files{$self} = {};
return $self;
}
+sub DESTROY {
+ my $self = shift;
+ delete $parser{$self};
+ delete $trees{$self};
+ delete $files{$self};
+ delete $source{$self};
+ delete $dest{$self};
+ $self->_destroy;
+}
+
# Accessors.
-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} }
+sub get_source { $source{ +shift } }
+sub get_dest { $dest{ +shift } }
+sub _get_trees { $trees{ +shift } }
+sub _get_files { $files{ +shift } }
+sub _get_parser { $parser{ +shift } }
# Return flattened hierarchies.
sub ordered_classes {
Added: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1074723&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Fri Feb 25 22:30:30 2011
@@ -0,0 +1,50 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+#define CFC_NEED_BASE_STRUCT_DEF
+#include "CFCBase.h"
+#include "CFCHierarchy.h"
+#include "CFCUtil.h"
+
+struct CFCHierarchy {
+ CFCBase base;
+};
+
+CFCHierarchy*
+CFCHierarchy_new(void)
+{
+ CFCHierarchy *self = (CFCHierarchy*)CFCBase_allocate(sizeof(CFCHierarchy),
+ "Clownfish::Hierarchy");
+ return CFCHierarchy_init(self);
+}
+
+CFCHierarchy*
+CFCHierarchy_init(CFCHierarchy *self)
+{
+ return self;
+}
+
+void
+CFCHierarchy_destroy(CFCHierarchy *self)
+{
+ CFCBase_destroy((CFCBase*)self);
+}
+
Added: incubator/lucy/trunk/clownfish/src/CFCHierarchy.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.h?rev=1074723&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.h Fri Feb 25 22:30:30 2011
@@ -0,0 +1,32 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_CFCHIERARCHY
+#define H_CFCHIERARCHY
+
+typedef struct CFCHierarchy CFCHierarchy;
+
+CFCHierarchy*
+CFCHierarchy_new(void);
+
+CFCHierarchy*
+CFCHierarchy_init(CFCHierarchy *self);
+
+void
+CFCHierarchy_destroy(CFCHierarchy *self);
+
+#endif /* H_CFCHIERARCHY */
+
Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1074723&r1=1074722&r2=1074723&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Fri Feb 25 22:30:30 2011
@@ -20,6 +20,7 @@ CFCClass* CLOWNFISH_TYPE
CFCDocuComment* CLOWNFISH_TYPE
CFCFile* CLOWNFISH_TYPE
CFCFunction* CLOWNFISH_TYPE
+CFCHierarchy* CLOWNFISH_TYPE
CFCMethod* CLOWNFISH_TYPE
CFCParamList* CLOWNFISH_TYPE
CFCParcel* CLOWNFISH_TYPE