lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r805217 - in /lucene/lucy/trunk/boilerplater: lib/Boilerplater/Parser.pm lib/Boilerplater/Type/Void.pm t/104-void_type.t
Date Mon, 17 Aug 2009 23:46:25 GMT
Author: marvin
Date: Mon Aug 17 23:46:25 2009
New Revision: 805217

URL: http://svn.apache.org/viewvc?rev=805217&view=rev
Log:
Commit LUCY-13, adding support for Boilerplater::Type::Void.

Added:
    lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm   (with props)
    lucene/lucy/trunk/boilerplater/t/104-void_type.t   (with props)
Modified:
    lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm

Modified: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm?rev=805217&r1=805216&r2=805217&view=diff
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm (original)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm Mon Aug 17 23:46:25 2009
@@ -9,6 +9,7 @@
 use Boilerplater::Type::Primitive;
 use Boilerplater::Type::Integer;
 use Boilerplater::Type::Float;
+use Boilerplater::Type::Void;
 use Carp;
 
 our $grammar = <<'END_GRAMMAR';
@@ -51,6 +52,10 @@
     type_qualifier(s?) c_float_specifier
     { Boilerplater::Parser->new_float_type(\%item) }
 
+void_type:
+    type_qualifier(s?) void_type_specifier
+    { Boilerplater::Parser->new_void_type(\%item) }
+
 type_qualifier:
       'const' 
 
@@ -69,6 +74,9 @@
 c_float_specifier:
     /(?:float|double)(?!\w)/
 
+void_type_specifier:
+    /void(?!\w)/
+
 END_GRAMMAR
 
 sub new { return shift->SUPER::new($grammar) }
@@ -92,6 +100,13 @@
     return Boilerplater::Type::Float->new(%args);
 }
 
+sub new_void_type {
+    my ( undef, $item ) = @_;
+    my %args = ( specifier => $item->{void_type_specifier} );
+    $args{$_} = 1 for @{ $item->{'type_qualifier(s?)'} };
+    return Boilerplater::Type::Void->new(%args);
+}
+
 sub new_parcel {
     my ( undef, $item ) = @_;
     Boilerplater::Parcel->singleton(

Added: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm?rev=805217&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm (added)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm Mon Aug 17 23:46:25 2009
@@ -0,0 +1,87 @@
+use strict;
+use warnings;
+
+package Boilerplater::Type::Void;
+use base qw( Boilerplater::Type );
+use Boilerplater::Util qw( verify_args );
+use Scalar::Util qw( blessed );
+use Carp;
+
+our %new_PARAMS = ( 
+    const     => undef,
+    specifier => 'void', 
+);
+
+sub new {
+    my ( $either, %args ) = @_;
+    verify_args( \%new_PARAMS, %args ) or confess $@;
+    my $c_string = $args{const} ? "const void" : "void";
+    return $either->SUPER::new(
+        %new_PARAMS,
+        %args,
+        specifier => 'void',
+        c_string  => $c_string
+    );
+}
+
+sub is_void {1}
+
+sub equals {
+    my ( $self, $other ) = @_;
+    return 0 unless blessed($other);
+    return 0 unless $other->isa(__PACKAGE__);
+    return 1;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Boilerplater::Type::Void - The void Type.
+
+=head1 DESCRIPTION
+
+Boilerplater::Type::Void is used to represent a void return type.  It is also
+used in conjuction with with L<Boilerplater::Type::Composite> to support the
+C<void*> opaque pointer type.
+
+=head1 METHODS
+
+=head2 new
+
+    my $type = Boilerplater::Type::Void->new(
+        specifier => 'void',    # default: void
+        const     => 1,         # default: undef
+    );
+
+=over
+
+=item * B<specifier> - Must be "void" if supplied.
+
+=item * B<const> - Should be true if the type is const.  (Useful in the
+context of C<const void*>).
+
+=back
+
+=head1 COPYRIGHT AND LICENSE
+
+    /**
+     * Copyright 2009 The Apache Software Foundation
+     *
+     * Licensed 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.
+     */
+
+=cut
+

Propchange: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Void.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/boilerplater/t/104-void_type.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/t/104-void_type.t?rev=805217&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/t/104-void_type.t (added)
+++ lucene/lucy/trunk/boilerplater/t/104-void_type.t Mon Aug 17 23:46:25 2009
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+use Boilerplater::Type::Void;
+use Boilerplater::Parser;
+
+my $void_type = Boilerplater::Type::Void->new;
+is( $void_type->get_specifier, "void", "specifier defaults to 'void'" );
+is( $void_type->to_c,          "void", "to_c" );
+ok( $void_type->is_void, "is_void" );
+
+$void_type = Boilerplater::Type::Void->new(
+    specifier => 'void',
+    const     => 1,
+);
+ok( $void_type->const, "const" );
+like( $void_type->to_c, qr/const/, "'const' in C representation" );
+
+my $parser = Boilerplater::Parser->new;
+
+is( $parser->void_type_specifier('void'), 'void', 'void_type_specifier' );
+isa_ok( $parser->void_type('void'),       "Boilerplater::Type::Void" );
+isa_ok( $parser->void_type('const void'), "Boilerplater::Type::Void" );
+ok( !$parser->void_type_specifier('voidable'),
+    "void_type_specifier guards against partial word matches" );
+

Propchange: lucene/lucy/trunk/boilerplater/t/104-void_type.t
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message