How to find methods of Classes ?

Discussion in 'Perl Misc' started by nkprajapati@gmail.com, Sep 18, 2006.

  1. Guest

    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
     
    , Sep 18, 2006
    #1
    1. Advertising

  2. <> 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
     
    Tad McClellan, Sep 18, 2006
    #2
    1. Advertising

  3. Guest

    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");
     
    , Sep 19, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lonelyplanet999
    Replies:
    1
    Views:
    2,245
    VisionSet
    Nov 13, 2003
  2. Victor Reyes
    Replies:
    3
    Views:
    106
    Nathaniel Talbott
    Apr 24, 2005
  3. Wybo Dekker
    Replies:
    1
    Views:
    379
    Yukihiro Matsumoto
    Nov 15, 2005
  4. Ramza Brown
    Replies:
    1
    Views:
    121
  5. Kenneth McDonald
    Replies:
    5
    Views:
    343
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page