Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing Gtk2 XS files gives "not a function declaration" #1

Open
wsdookadr opened this issue Mar 14, 2014 · 2 comments
Open

Parsing Gtk2 XS files gives "not a function declaration" #1

wsdookadr opened this issue Mar 14, 2014 · 2 comments
Assignees

Comments

@wsdookadr
Copy link

Hi,

I played a bit with Devel::ParseXS, I like it a lot.
I tested it on Gtk2 version 1.249 (here on CPAN ).

I used the latest version of Devel::ParseXS, this one.

I wrote the following small script and named it test.pl. This script uses Devel::ParseXS to parse an XS file which it takes from ARGV. After it's parsed, a traversal of the AST is made. I was interested in nodes with func_name, I wanted to see what kind of attributes the nodes have.

#!/usr/bin/env perl
use strict;
use warnings;
use lib './local/lib/perl5';
use Devel::XS::AST::Boot;
use Devel::ParseXS;
use Scalar::Util qw/blessed/;
use Data::Dumper;
my $parser = Devel::ParseXS->new();
#$parser->parse_file( "/tmp/Gtk2-1.249/xs/GtkCombo.xs" );
$parser->parse_file( $ARGV[0] );
my $ast = $parser->tree;

sub traverse {
    print ref($_[0])."\n";
    my $blacklist = {
        "ARRAY" => 1,
        "HASH"  => 1,
    };
    ###################################
    # Go over all keys of the current node(the one that was
    # passed as a parameter to travers )
    # and print the attributes
    ###################################
    for my $k (%{$_[0]}) {
        next if !defined($k);
        next if !defined($_[0]->{$k});
        next if $blacklist->{ref($_[0]->{$k})};
        next if blessed($_[0]->{$k});
        print "     [ $k  ; $_[0]->{$k} ]\n";
    };
    ###################################
    # Recurse
    ###################################
    for my $c (@{$_[0]->{contents}}) {
        next if !blessed($c);
        traverse($c);
    };
};

traverse($ast);

exit 0;

Then I ran a oneliner to find out how many of the XS files in Gtk2 it parsed without throwing an error:

ls -d ../Gtk2-1.249/xs/* | xargs -I% /bin/bash -c 'source /home/user/.bashrc; perl  test.pl % >/dev/null 2>/dev/null; echo $? ; exit 0;' | sort | uniq -c

And the result was this(first column is count, second column is exit value):

84 0
101 25
27 255

So 84 out of 212. So in 39% of the XS files in Gtk2, test.pl was succesful in parsing(exit value was zero), it's pretty good considering how hard XS is to parse since it's a mix of C and custom-stuff.

In the oneliner above I redirected both stdout and stderr to /dev/null. If I redirect just stdout to /dev/null, I can find what the errors were when parsing some of the XS files. I've put those here. All of the errors were thrown in parse_file on line 11 of test.pl.

I will have a closer look at it soon. But I like the module a lot and I'll play more with it soon.

Thanks a lot for writing this module 👍

@djerius
Copy link
Owner

djerius commented Mar 14, 2014

Cool! Thanks for poking at it. Automated testing using CPAN distributions is on my todo list, as is adding more useful tree traversal/visiting functions.

@djerius djerius self-assigned this Mar 24, 2014
@djerius
Copy link
Owner

djerius commented Mar 24, 2014

The Gtk2 xs files should parse without error now. Whether they're correctly parsed is another story. There's a primitive debug tool in tools/parse which can use Data::Dumper::GUI to display the resultant AST. I'm working on something a bit more clever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants