Subject: | member arrays in classes derail inline CPP |
Date: | Sat, 9 Oct 2010 23:48:04 -0500 |
To: | bug-Inline-CPP [...] rt.cpan.org |
From: | Intangir <intangir [...] gmail.com> |
if you include an array as a member data in a class whatever parsing is
involved in Inline CPP messes up and fails to create compilable code
it seems to not recognize member data arrays with the grammar definitions
im using Inline-CPP-0.27
here is an example of the problem
-----------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
my $obj = new Foo;
$obj->set_data(5);
use Inline CPP => <<'END';
class Foo {
public:
Foo();
~Foo();
int get_data() { return data; }
void set_data(int a) { data = a; }
private:
int data;
int thiscauseserror[10];
};
Foo::Foo() { cout << "creating a Foo()" << endl; }
Foo::~Foo() { cout << "deleting a Foo()" << endl; }
END
------------------------------------------------------
commenting out the line with 'thiscauseserror' makes it run again
i got help from tc604 in #perl, he found a fix to the grammar file that will
fix it
first here is the code as it was:
./grammar/grammar.pm: line 274:
member_def: anytype <leftop: var ',' var> ';'
{
my @retval;
for my $def (@{$item[2]}) {
my $type = join '', $item[1], @{$def->[0]};
my $name = $def->[1];
# print "member found: type=$type, name=$name\n";
push @retval, { name => $name, type => $type };
}
\@retval;
}
var: star(s?) IDENTIFIER '=' expr { [@item[1,2]] }
| star(s?) IDENTIFIER { [@item[1,2]] }
i added in this line near the bottom:
| star(s?) IDENTIFIER '[' expr ']' { [@item[1,2]] }
see it here below:
----------------------------------------------------------------------
member_def: anytype <leftop: var ',' var> ';'
{
my @retval;
for my $def (@{$item[2]}) {
my $type = join '', $item[1], @{$def->[0]};
my $name = $def->[1];
# print "member found: type=$type, name=$name\n";
push @retval, { name => $name, type => $type };
}
\@retval;
}
var: star(s?) IDENTIFIER '=' expr { [@item[1,2]] }
| star(s?) IDENTIFIER '[' expr ']' { [@item[1,2]] }
| star(s?) IDENTIFIER { [@item[1,2]] }
---------------------------------------------------------------
i added that, reinstalled it, reran my script and it works! :)