Extracting all functions from C++ source code

E

eliss

I'm trying to find a way to extract all the function definitions AND
function uses from thousands of C++ files. For example, if foo.cpp
contains:

int func(char b)
{
return 0;

}

func('d'); func('e');
print("bar");

Then I want to get something that tells me "int func(char b) is on
line 1, pos 0 ; func(char) is on line 5, pos 0 ; func(char) is on
line
5, pos 11 ; print(char*) is on line 6, pos 0"

Is there any tool that can do this? I've looked into ctags, but it can
only get the function definitions. I've also tried g++ to see if there
are command line options for this but it doesn't look like it. I've
also tried rolling me own but the amount of grammar that can be used
overwhelmed me.

Thanks in advance!

- Eliss
 
I

idbaxter

I'm trying to find a way to extract all the function definitions AND
function uses from thousands of C++ files. For example, if foo.cpp
contains:

int func(char b)
{
    return 0;

}

func('d'); func('e');
print("bar");

Then I want to get something that tells me "int func(char b) is on
line 1, pos 0 ; func(char) is on line 5, pos 0 ; func(char) is on
line
5, pos 11 ; print(char*) is on line 6, pos 0"

Is there any tool that can do this? I've looked into ctags, but it can
only get the function definitions. I've also tried g++ to see if there
are command line options for this but it doesn't look like it. I've
also tried rolling me own but the amount of grammar that can be used
overwhelmed me.

Thanks in advance!

- Eliss

It isn't just the grammar that's the problem unless
you're OK with sloppy answers. And if you want to do
this reasonably across thousands of files, I can't
imagine that sloppy answers would be helpful.
You also need to handle the preprocessor, command line switches,
include files, include paths the name resolution problem, too.
In short, you need a full parser for your particular
dialect.

Our DMS Software Reengineering Toolkit has a full C++ parser
for a variety of C++ dialects.
It handles all the above issues,
and collects all this name and type information. What you
want could be pretty easily extracted.

See http://www.semanticdesigns.com/Products/FrontEnds/CppFrontEnd.html

Ira Baxter, CTO
Semantic Designs
 
A

AnonMail2005

I'm trying to find a way to extract all the function definitions AND
function uses from thousands of C++ files. For example, if foo.cpp
contains:

int func(char b)
{
    return 0;

}

func('d'); func('e');
print("bar");

Then I want to get something that tells me "int func(char b) is on
line 1, pos 0 ; func(char) is on line 5, pos 0 ; func(char) is on
line
5, pos 11 ; print(char*) is on line 6, pos 0"

Is there any tool that can do this? I've looked into ctags, but it can
only get the function definitions. I've also tried g++ to see if there
are command line options for this but it doesn't look like it. I've
also tried rolling me own but the amount of grammar that can be used
overwhelmed me.

Thanks in advance!

- Eliss

doxygen can give you all functions. And I'm pretty sure it can give
you call graphs, but I don't think it can give you line and column
numbers. It's worth checking out.

HTH
 

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

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top