How to find methods of Classes ?

N

nkprajapati

Hi All,

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.
This classes are library implementation. I want to have a script that
will do it. I have 55 such classes, whose methods I have to find from
source.


e.g. I have following source code:

MYType obj1;
obj1.findFirstStream();
obj1.getSourceLength();

so If I run script it will list down all used method (i.e.
findFirstStream and getSourceLength ).

Can any one help me out how to go ahead ?

Thanks,
Naresh Prajapati
 
T

Tad McClellan

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.
 
N

nkprajapati

Tad said:
^^^^
^^^^

So if a method is defined but never called it should not be reported?




The first step would be to get a C++ parser.

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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top