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/01 03:53:42 UTC
[lucy-commits] svn commit: r1065900 - in /incubator/lucy/trunk/clownfish: include/CFC.h
lib/Clownfish.xs lib/Clownfish/DocuComment.pm src/CFCDocuComment.c
src/CFCDocuComment.h typemap
Author: marvin
Date: Tue Feb 1 02:53:41 2011
New Revision: 1065900
URL: http://svn.apache.org/viewvc?rev=1065900&view=rev
Log:
Migrate Clownfish::DocuComment to a partial C implementation.
Added:
incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
Modified:
incubator/lucy/trunk/clownfish/include/CFC.h
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.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=1065900&r1=1065899&r2=1065900&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/include/CFC.h (original)
+++ incubator/lucy/trunk/clownfish/include/CFC.h Tue Feb 1 02:53:41 2011
@@ -14,6 +14,7 @@
* limitations under the License.
*/
-#include "CFCType.h"
+#include "CFCDocuComment.h"
#include "CFCParamList.h"
+#include "CFCType.h"
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1065900&r1=1065899&r2=1065900&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Tue Feb 1 02:53:41 2011
@@ -48,6 +48,74 @@
XSRETURN(0); \
}
+MODULE = Clownfish PACKAGE = Clownfish::DocuComment
+
+SV*
+_new(klass, description, brief, long_description, param_names, param_docs, retval_sv)
+ const char *klass;
+ const char *description;
+ const char *brief;
+ const char *long_description;
+ SV *param_names;
+ SV *param_docs;
+ SV *retval_sv;
+CODE:
+ const char *retval = SvOK(retval_sv) ? SvPV_nolen(retval_sv) : NULL;
+ CFCDocuComment *self = CFCDocuComment_new(description, brief,
+ long_description, param_names, param_docs, retval);
+ RETVAL = newSV(0);
+ sv_setref_pv(RETVAL, klass, (void*)self);
+OUTPUT: RETVAL
+
+void
+DESTROY(self)
+ CFCDocuComment *self;
+PPCODE:
+ CFCDocuComment_destroy(self);
+
+void
+_set_or_get(self, ...)
+ CFCDocuComment *self;
+ALIAS:
+ get_description = 2
+ get_brief = 4
+ get_long = 6
+ get_param_names = 8
+ get_param_docs = 10
+ get_retval = 12
+PPCODE:
+{
+ START_SET_OR_GET_SWITCH
+ case 2: {
+ const char *description = CFCDocuComment_get_description(self);
+ retval = newSVpvn(description, strlen(description));
+ }
+ break;
+ case 4: {
+ const char *brief = CFCDocuComment_get_brief(self);
+ retval = newSVpvn(brief, strlen(brief));
+ }
+ break;
+ case 6: {
+ const char *long_description = CFCDocuComment_get_long(self);
+ retval = newSVpvn(long_description, strlen(long_description));
+ }
+ break;
+ case 8:
+ retval = newSVsv((SV*)CFCDocuComment_get_param_names(self));
+ break;
+ case 10:
+ retval = newSVsv((SV*)CFCDocuComment_get_param_docs(self));
+ break;
+ case 12: {
+ const char *rv = CFCDocuComment_get_retval(self);
+ retval = rv ? newSVpvn(rv, strlen(rv)) : newSV(0);
+ }
+ break;
+ END_SET_OR_GET_SWITCH
+}
+
+
MODULE = Clownfish PACKAGE = Clownfish::ParamList
SV*
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm?rev=1065900&r1=1065899&r2=1065900&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/DocuComment.pm Tue Feb 1 02:53:41 2011
@@ -28,24 +28,9 @@ our %new_PARAMS = (
retval => undef,
);
-sub _new {
- my $either = shift;
- verify_args( \%new_PARAMS, @_ );
- return bless { \%new_PARAMS, @_ };
-}
-
sub parse {
my ( $either, $text ) = @_;
-
- my ( @param_names, @param_docs );
- my $self = bless {
- brief => undef,
- long => undef,
- param_names => \@param_names,
- param_docs => \@param_docs,
- retval => undef,
- },
- ref($either) || $either;
+ my $class_name = ref($either) || $either;
# Strip comment open, close, and left border.
$text =~ s/\A\s*\/\*\*\s+//;
@@ -55,12 +40,13 @@ sub parse {
# Extract the brief description.
$text =~ /^(.+?\.)(\s+|\Z)/s
or confess("Can't find at least one descriptive sentence in '$text'");
- $self->{brief} = $1;
+ my $brief = $1;
# terminated by @, empty line, or string end.
my $terminator = qr/((?=\@)|\n\s*\n|\Z)/;
# Extract @param, @return directives.
+ my ( @param_names, @param_docs );
while (
$text =~ s/^\s*
\@param\s+
@@ -75,28 +61,23 @@ sub parse {
push @param_names, $1;
push @param_docs, $2;
}
+ my $retval;
if ( $text =~ s/^\s*\@return\s+(.*?)$terminator//sm ) {
- $self->{retval} = $1;
+ $retval = $1;
}
$text =~ s/^\s*//;
$text =~ s/\s*$//;
- $self->{description} = $text;
+ my $description = $text;
$text =~ s/^(.+?\.)(\s+|\Z)//s; # zap brief
$text =~ s/^\s*//;
- $self->{long} = $text;
+ my $long = $text;
- return $self;
+ return $class_name->_new( $description, $brief, $long, \@param_names,
+ \@param_docs, $retval );
}
-sub get_param_names { shift->{param_names} }
-sub get_param_docs { shift->{param_docs} }
-sub get_retval { shift->{retval} }
-sub get_brief { shift->{brief} }
-sub get_long { shift->{long} }
-sub get_description { shift->{description} }
-
1;
__END__
Added: incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.c?rev=1065900&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.c (added)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.c Tue Feb 1 02:53:41 2011
@@ -0,0 +1,106 @@
+/* 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"
+
+#include "CFCDocuComment.h"
+
+struct CFCDocuComment {
+ const char *description;
+ const char *brief;
+ const char *long_des;
+ void *param_names;
+ void *param_docs;
+ const char *retval;
+};
+
+CFCDocuComment*
+CFCDocuComment_new(const char *description, const char *brief,
+ const char *long_description, void *param_names,
+ void *param_docs, const char *retval)
+{
+ CFCDocuComment *self = (CFCDocuComment*)malloc(sizeof(CFCDocuComment));
+ if (!self) { croak("malloc failed"); }
+ return CFCDocuComment_init(self, description, brief, long_description,
+ param_names, param_docs, retval);
+}
+
+CFCDocuComment*
+CFCDocuComment_init(CFCDocuComment *self, const char *description,
+ const char *brief, const char *long_description,
+ void *param_names, void *param_docs, const char *retval)
+{
+ self->description = savepv(description);
+ self->brief = savepv(brief);
+ self->long_des = savepv(long_description);
+ self->param_names = newSVsv((SV*)param_names);
+ self->param_docs = newSVsv((SV*)param_docs);
+ self->retval = retval ? savepv(retval) : NULL;
+ return self;
+}
+
+void
+CFCDocuComment_destroy(CFCDocuComment *self)
+{
+ Safefree(self->description);
+ Safefree(self->brief);
+ Safefree(self->long_des);
+ SvREFCNT_dec((SV*)self->param_names);
+ SvREFCNT_dec((SV*)self->param_docs);
+ Safefree(self->retval);
+ free(self);
+}
+
+
+const char*
+CFCDocuComment_get_description(CFCDocuComment *self)
+{
+ return self->description;
+}
+
+const char*
+CFCDocuComment_get_brief(CFCDocuComment *self)
+{
+ return self->brief;
+}
+
+const char*
+CFCDocuComment_get_long(CFCDocuComment *self)
+{
+ return self->long_des;
+}
+
+void*
+CFCDocuComment_get_param_names(CFCDocuComment *self)
+{
+ return self->param_names;
+}
+
+void*
+CFCDocuComment_get_param_docs(CFCDocuComment *self)
+{
+ return self->param_docs;
+}
+
+const char*
+CFCDocuComment_get_retval(CFCDocuComment *self)
+{
+ return self->retval;
+}
+
Added: incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.h?rev=1065900&view=auto
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.h (added)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.h Tue Feb 1 02:53:41 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.
+ */
+
+typedef struct CFCDocuComment CFCDocuComment;
+
+CFCDocuComment*
+CFCDocuComment_new(const char *description, const char *brief,
+ const char *long_description, void *param_names,
+ void *param_docs, const char *retval);
+
+CFCDocuComment*
+CFCDocuComment_init(CFCDocuComment *self, const char *description,
+ const char *brief, const char *long_description,
+ void *param_names, void *param_docs, const char *retval);
+
+void
+CFCDocuComment_destroy(CFCDocuComment *self);
+
+const char*
+CFCDocuComment_get_description(CFCDocuComment *self);
+
+const char*
+CFCDocuComment_get_brief(CFCDocuComment *self);
+
+const char*
+CFCDocuComment_get_long(CFCDocuComment *self);
+
+void*
+CFCDocuComment_get_param_names(CFCDocuComment *self);
+
+void*
+CFCDocuComment_get_param_docs(CFCDocuComment *self);
+
+// May be NULL.
+const char*
+CFCDocuComment_get_retval(CFCDocuComment *self);
+
Modified: incubator/lucy/trunk/clownfish/typemap
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/typemap?rev=1065900&r1=1065899&r2=1065900&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/typemap (original)
+++ incubator/lucy/trunk/clownfish/typemap Tue Feb 1 02:53:41 2011
@@ -14,8 +14,9 @@
# limitations under the License.
TYPEMAP
-CFCType* CLOWNFISH_TYPE
+CFCDocuComment* CLOWNFISH_TYPE
CFCParamList* CLOWNFISH_TYPE
+CFCType* CLOWNFISH_TYPE
INPUT