Tad McClellan wrote:
> <> wrote:
>
> > I have 5 millions lines of source code, purely written in
> > c++. I want to find all the methods of some classes, used in code.
> ^^^^
> ^^^^
>
> So if a method is defined but never called it should not be reported?
>
>
> > Can any one help me out how to go ahead ?
>
>
> The first step would be to get a C++ parser.
>
>
> --
> Tad McClellan SGML consulting
> Perl programming
> Fort Worth, Texas
Finally, I managed to write a perl script.....
Fortunately..code was so simply written that made scripting very
easy...
I am handling normal delacalaration, construction declaration and
pointer declaration..
#!/usr/bin/perl
sub process($)
{
my($filename) = @_;
open(FILE, $filename) or die("Unable to open file");
@data = <FILE>;
close(FILE);
foreach $line (@data)
{
# declaration with new
if( ($line =~
m/([a-zA-Z0-9._%-]+)\s+=\s+new\s+\(*\s*$eachclass/))
{
$var = $1;
foreach $line2 (@data)
{
if($line2 =~ m/$var->([a-zA-Z0-9]+\([A-Za-z0-9._%-]*\))/)
{
print HANDLE "\t",$1, "\n";
}
}
}
# normal delcaration
elsif ($line =~ m/$eachclass\s+([a-zA-Z0-9]+);/)
{
$var = $1;
foreach $line2 (@data)
{
if($line2 =~
m/$var\.([a-zA-Z0-9]+\([A-Za-z0-9._%-]*\))/)
{
print HANDLE "\t",$1, "\n";
}
}
}
#pointer delcaration
elsif ($line =~ m/$eachclass\s*\*\s*([a-zA-Z0-9]+)\s*;/)
{
$var = $1;
foreach $line2 (@data)
{
if($line2 =~ m/$var->([a-zA-Z0-9]+\([A-Za-z0-9._%-]*\))/)
{
print HANDLE "\t",$1, "\n";
}
}
}
#normal declaration but with constuction
elsif ($line =~ m/$eachclass\s+([a-zA-Z0-9]+)\s*\(*/)
{
#print"\n...................";
#
$var = $1;
foreach $line2 (@data)
{
if($line2 =~
m/$var\.([a-zA-Z0-9]+\([A-Za-z0-9._%-]*\))/)
{
print HANDLE "\t",$1, "\n";
}
}
}
}
}
sub recurse($) {
my($path) = @_;
$path .= '/' if($path !~ /\/$/);
for my $eachFile (glob($path.'*')) {
if( -d $eachFile) {
recurse($eachFile);
} else {
if($eachFile =~ m/[a-zA-Z0-9]\.cpp/)
{
process($eachFile);
}
}
}
}
sub classname($) {
open(FILE1, "rw.txt") or die("Unable to open file");
@data1 = <FILE1>;
close(FILE1);
foreach $line (@data1)
{
print $line;
$eachclass = $line;
chomp($eachclass);
chop($eachclass);
$eachclass =~ s/\s+$//;
$outfile = $eachclass;
open(HANDLE, ">$outfile");
recurse("./");
close(HANDLE);
}
}
classname("some");