Skip to content

Commit

Permalink
[master] element casing (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Feb 11, 2017
1 parent c5d10f2 commit c2ff2dd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
30 changes: 17 additions & 13 deletions eg/dale-autowrap/dale-autowrap
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ EOF
exit(2);
}

sub case_string
{
my ($string) = @_;

my $casing_fn = $CASING_MAP{$CASING};
my $new_string = $casing_fn->($string);
return $new_string;
}

sub type_to_string
{
my ($type) = @_;
Expand Down Expand Up @@ -110,8 +119,7 @@ sub type_to_string
return $mapped_type;
}
if ($tag eq 'struct') {
my $casing_fn = $CASING_MAP{$CASING};
my $new_name = $casing_fn->($type->{'name'});
my $new_name = case_string($type->{'name'});
return $new_name;
}

Expand All @@ -122,8 +130,7 @@ sub type_to_string
}
}

my $casing_fn = $CASING_MAP{$CASING};
my $new_name = $casing_fn->($tag);
my $new_name = case_string($tag);

return $new_name;
}
Expand Down Expand Up @@ -165,8 +172,7 @@ sub process_function
}
my $param_str = "(".(join ' ', @params).")";

my $casing_fn = $CASING_MAP{$CASING};
my $new_name = $casing_fn->($data->{'name'});
my $new_name = case_string($data->{'name'});

my $original_fn =
sprintf("NC(def %s (fn %s %s %s))",
Expand Down Expand Up @@ -227,7 +233,7 @@ sub process_struct
my ($data) = @_;

my @fields =
map { sprintf("(%s %s)", $_->{'name'},
map { sprintf("(%s %s)", case_string($_->{'name'}),
type_to_string($_->{'type'})) }
@{$data->{'fields'}};
my $field_str = (@fields ? " (".(join ' ', @fields).")" : "");
Expand All @@ -244,7 +250,7 @@ sub process_enum
$IMPORTS{'enum'} = 1;

my @fields =
map { sprintf("(%s %s)", $_->{'name'}, $_->{'value'}) }
map { sprintf("(%s %s)", case_string($_->{'name'}), $_->{'value'}) }
@{$data->{'fields'}};
my $field_str = (@fields ? " (".(join ' ', @fields).")" : "");

Expand Down Expand Up @@ -285,7 +291,7 @@ sub process_union

my @constructors =
map { sprintf("(%s-%s ((value %s)))",
$name,
case_string($name),
type_to_flat_string($_->{'type'}),
type_to_string($_->{'type'})) }
@{$data->{'fields'}};
Expand Down Expand Up @@ -365,8 +371,7 @@ sub print_binding
}
if (not $no_casing) {
my ($name) = ($binding =~ /^\(.*? (.*?) /);
my $casing_fn = $CASING_MAP{$CASING};
my $new_name = $casing_fn->($name);
my $new_name = case_string($name);
$binding =~ s/ (.*?) / $new_name /;
}

Expand Down Expand Up @@ -460,8 +465,7 @@ sub main
}
}

my $casing_fn = $CASING_MAP{$CASING};
my $new_name = $casing_fn->($name);
my $new_name = case_string($name);

if (((($binding =~ /\($name /)
and ($binding !~ /\(\($name/))
Expand Down
29 changes: 29 additions & 0 deletions eg/dale-autowrap/t/008-struct-members.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/perl

use warnings;
use strict;

use Test::More;

my $C2FFI = $ENV{'C2FFI'} || 'c2ffi';

plan tests => 1;

my $header = 't/headers/struct-members.h';
my $res = system("$C2FFI $header > struct-members-output");
if ($res != 0) {
die "$C2FFI against $header failed.";
}

my @lines =
map { chomp; $_ }
`cat struct-members-output | ./dale-autowrap --casing lisp`;
is_deeply(\@lines,
[split /\n/, <<EOF],
(def test-struct (struct extern ((first-element int) (second-element int))))
EOF
"Struct elements cased correctly");
unlink("struct-members-output");
1;
1 change: 1 addition & 0 deletions eg/dale-autowrap/t/headers/struct-members.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef struct { int firstElement; int secondElement; } testStruct;
1 change: 1 addition & 0 deletions eg/dale-autowrap/t/headers/struct-members.h.dt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(def testStruct (struct extern ((firstElement int) (secondElement int))))

0 comments on commit c2ff2dd

Please sign in to comment.