lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r805210 - in /lucene/lucy/trunk/boilerplater: lib/Boilerplater/Parser.pm lib/Boilerplater/Type/Integer.pm t/102-integer_type.t
Date Mon, 17 Aug 2009 23:32:01 GMT
Author: marvin
Date: Mon Aug 17 23:32:01 2009
New Revision: 805210

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

Added:
    lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Integer.pm   (with props)
    lucene/lucy/trunk/boilerplater/t/102-integer_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=805210&r1=805209&r2=805210&view=diff
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm (original)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm Mon Aug 17 23:32:01 2009
@@ -5,6 +5,9 @@
 use base qw( Parse::RecDescent );
 
 use Boilerplater::Parcel;
+use Boilerplater::Type;
+use Boilerplater::Type::Primitive;
+use Boilerplater::Type::Integer;
 use Carp;
 
 our $grammar = <<'END_GRAMMAR';
@@ -29,6 +32,28 @@
     /([A-Z][A-Za-z0-9]+)(?!\w)/
     { $1 }
 
+c_integer_type:
+    type_qualifier(s?) c_integer_specifier
+    { Boilerplater::Parser->new_integer_type(\%item) }
+
+chy_integer_type:
+    type_qualifier(s?) chy_integer_specifier
+    { Boilerplater::Parser->new_integer_type(\%item) }
+
+type_qualifier:
+      'const' 
+
+primitive_type_specifier:
+      chy_integer_specifier
+    | c_integer_specifier 
+    { $item[1] }
+
+chy_integer_specifier:
+    /(?:chy_)?([iu](8|16|32|64)|bool)_t(?!\w)/
+
+c_integer_specifier:
+    /(?:char|int|short|long|size_t)(?!\w)/
+
 END_GRAMMAR
 
 sub new { return shift->SUPER::new($grammar) }
@@ -36,6 +61,15 @@
 our $parcel = undef;
 sub set_parcel { $parcel = $_[1] }
 
+sub new_integer_type {
+    my ( undef, $item ) = @_;
+    my $specifier = $item->{c_integer_specifier}
+        || $item->{chy_integer_specifier};
+    my %args = ( specifier => $specifier );
+    $args{$_} = 1 for @{ $item->{'type_qualifier(s?)'} };
+    return Boilerplater::Type::Integer->new(%args);
+}
+
 sub new_parcel {
     my ( undef, $item ) = @_;
     Boilerplater::Parcel->singleton(

Added: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Integer.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Integer.pm?rev=805210&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Integer.pm (added)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Type/Integer.pm Mon Aug 17 23:32:01 2009
@@ -0,0 +1,121 @@
+use strict;
+use warnings;
+
+package Boilerplater::Type::Integer;
+use base qw( Boilerplater::Type::Primitive );
+use Boilerplater::Util qw( verify_args );
+use Carp;
+
+our %new_PARAMS = (
+    const     => undef,
+    specifier => undef,
+);
+
+our %specifiers = (
+    bool_t => undef,
+    i8_t   => undef,
+    i16_t  => undef,
+    i32_t  => undef,
+    i64_t  => undef,
+    u8_t   => undef,
+    u16_t  => undef,
+    u32_t  => undef,
+    u64_t  => undef,
+    char   => undef,
+    int    => undef,
+    short  => undef,
+    long   => undef,
+    size_t => undef,
+);
+
+sub new {
+    my ( $either, %args ) = @_;
+    verify_args( \%new_PARAMS, %args ) or confess $@;
+    confess("Unknown specifier: '$args{specifier}'")
+        unless exists $specifiers{ $args{specifier} };
+
+    # Cache the C representation of this type.
+    my $c_string = $args{const} ? 'const ' : '';
+    if ( $args{specifier} =~ /^(?:[iu]\d+|bool)_t$/ ) {
+        $c_string .= "chy_";
+    }
+    $c_string .= $args{specifier};
+
+    return $either->SUPER::new( %args, c_string => $c_string );
+}
+
+sub is_integer {1}
+
+1;
+
+__END__
+
+__POD__
+
+=head1 NAME
+
+Boilerplater::Type::Integer - A primitive Type representing an integer.
+
+=head1 DESCRIPTION
+
+Boilerplater::Type::Integer holds integer types of various widths and various
+styles.  A few standard C integer types are supported:
+
+    char
+    short
+    int
+    long
+    size_t
+
+Many others are not: the types from "inttypes.h", "signed" or "unsigned"
+anything, "long long", "ptrdiff_t", "off_t", etc.  
+
+Instead, the following Charmonizer typedefs are supported:
+
+    bool_t
+    i8_t
+    i16_t
+    i32_t
+    i64_t
+    u8_t
+    u16_t
+    u32_t
+    u64_t
+
+=head1 METHODS
+
+=head2 new
+
+    my $type = Boilerplater::Type::Integer->new(
+        const     => 1,       # default: undef
+        specifier => 'char',  # required
+    );
+
+=over
+
+=item * B<const> - Should be true if the type is const.
+
+=item * B<specifier> - Must match one of the supported types.
+
+=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/Integer.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/lucy/trunk/boilerplater/t/102-integer_type.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/t/102-integer_type.t?rev=805210&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/t/102-integer_type.t (added)
+++ lucene/lucy/trunk/boilerplater/t/102-integer_type.t Mon Aug 17 23:32:01 2009
@@ -0,0 +1,64 @@
+use strict;
+use warnings;
+
+use Test::More tests => 60;
+use Boilerplater::Type::Integer;
+use Boilerplater::Parser;
+
+my $integer_type = Boilerplater::Type::Integer->new(
+    specifier => 'i32_t',
+    const     => 1,
+);
+ok( $integer_type->const, "const" );
+is( $integer_type->get_specifier, "i32_t" );
+like( $integer_type->to_c, qr/chy_i32_t/,
+    "prepend 'chy_' for C representation" );
+like( $integer_type->to_c, qr/const/, "'const' in C representation" );
+
+my $parser = Boilerplater::Parser->new;
+
+my @chy_specifiers = qw(
+    bool_t
+    i8_t
+    i16_t
+    i32_t
+    i64_t
+    u8_t
+    u16_t
+    u32_t
+    u64_t
+);
+my @c_specifiers = qw(
+    char
+    short
+    int
+    long
+    size_t
+);
+
+for my $chy_specifier (@chy_specifiers) {
+    is( $parser->chy_integer_specifier($chy_specifier),
+        $chy_specifier, "chy_integer_specifier: $chy_specifier" );
+    isa_ok( $parser->chy_integer_type($chy_specifier),
+        "Boilerplater::Type::Integer" );
+    isa_ok( $parser->chy_integer_type("const $chy_specifier"),
+        "Boilerplater::Type::Integer" );
+    my $bogus = $chy_specifier . "oot_toot";
+    ok( !$parser->chy_integer_specifier($bogus),
+        "chy_integer_specifier guards against partial word matches" );
+}
+
+for my $c_specifier (@c_specifiers) {
+    is( $parser->c_integer_specifier($c_specifier),
+        $c_specifier, "c_integer_specifier: $c_specifier" );
+    isa_ok(
+        $parser->c_integer_type($c_specifier),
+        "Boilerplater::Type::Integer"
+    );
+    isa_ok( $parser->c_integer_type("const $c_specifier"),
+        "Boilerplater::Type::Integer" );
+    my $bogus = $c_specifier . "y";
+    ok( !$parser->c_integer_specifier($bogus),
+        "c_integer_specifier guards against partial word matches" );
+}
+

Propchange: lucene/lucy/trunk/boilerplater/t/102-integer_type.t
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message