Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to find methods of Classes ?

Reply
Thread Tools

How to find methods of Classes ?

 
 
nkprajapati@gmail.com
Guest
Posts: n/a
 
      09-18-2006
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

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      09-18-2006
<> 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
 
Reply With Quote
 
 
 
 
nkprajapati@gmail.com
Guest
Posts: n/a
 
      09-19-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
methods, methods override classes and scope Ramza Brown Ruby 1 04-18-2006 07:38 AM
Where can I find all the ruby classes and methods? Victor Reyes Ruby 3 04-24-2005 09:59 PM
How to access inner classes variables & methods from outer classes lonelyplanet999 Java 1 11-13-2003 01:54 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57