On Fri, 2 Feb 2001, Ben Laurie wrote:
 
> What's C::Scan??

http://www.cpan.org/modules/by-module/C/

i'm using a wrapper around it (Apache::ParseSource), that spits out two
other modules which are Perl structures containing the parsed header
files.  Apache::FunctionTable entries look like so:

  {
    'return_type' => 'int',
    'name' => 'ap_set_keepalive',
    'args' => [
      {
        'type' => 'request_rec *',
        'name' => 'r'
      }
    ],
  }

and Apache::StructureTable entries like so:

  {
    'type' => 'server_addr_rec',
    'elts' => [
      {
        'type' => 'server_addr_rec *',
        'name' => 'next'
      },
      {
        'type' => 'apr_sockaddr_t *',
        'name' => 'host_addr'
      },
      {
        'type' => 'apr_port_t',
        'name' => 'host_port'
      },
      {
        'type' => 'char *',
        'name' => 'virthost'
      }
    ],
  },

i'm planning to use these tables for generating most of the modperl-2.0
glue code.  but it can be used for whatever, here's some sorta neato
stats (probably not 100% accurate):

% perl util/source_stats.pl
80 typedefs
   apr: 55
    ap: 25
71 typedef_structs
   apr: 32
    ap: 39
609 functions
   apr: 319
    ap: 290
431 struct_members
   apr: 147
    ap: 284

% cat util/source_stats.pl

use strict;
use Apache::FunctionTable ();
use Apache::StructureTable ();

my %stats;

for my $entry (@$Apache::FunctionTable) {
    unless ($entry->{name} =~ /^(ap|apr)_/) {
        print "found alien function $entry->{name}\n";
    }

    $stats{functions}->{$1}++;
}

for my $entry (@$Apache::StructureTable) {
    my $elts = $entry->{elts};
    my $type = $entry->{type};

    my $c = $type =~ /^apr_/ ? "apr" : "ap";

    if (@$elts) {
        $stats{typedef_structs}->{$c}++;
        $stats{struct_members}->{$c} += @$elts;
    }
    else {
        $stats{typedefs}->{$c}++;
    }
}

while (my($name, $tab) = each %stats) {
    printf "%d %s\n", $tab->{ap} + $tab->{apr}, $name;
    for (qw(apr ap)) {
        printf "%6s: %d\n", $_, $tab->{$_};
    }
}

Reply via email to