views:

209

answers:

3

Hi all!

I got a pack of c++ files with static source code (already developped, not needed to do anything to them).

There is an program/lib/way to get a list of the number of params each function withing one of those files?

I mean, getting a result like:

#File a.cpp
##a() -> 3 paramss
##foo() -> 0 params (void)

#File b.cpp
##test() -> 1 param

....

And a better question.

There is any way to also process the number of returns it has?

#File a.cpp
##a() -> 3 params, 1 return
##foo() -> 0 params (void), 2 returns

For example if "foo" has a return if condition is true and another if false

Thanks in advance.

+2  A: 

You could try running Doxygen over the source files.

Since the content is (presumably) undocumented, you need to configure doxygen to extract content from undocumented files.

If you just want to browse a list of the available functions, you could use the HTML output.

You could also configure Doxygen output to be XML, and then write a parser to pull statistics that you are looking for on each function.

Zoinks
Doxygen worked well, generating the XML )
Ragnagard
A: 

I would count the number of "," and start at 1. This should give you an accurate count of the number of arguments to a function. Then I would check to see if "void" exists before the function name, if not then you can bet that there is a return value.

ifstream infile;
infile.open(...);
int i, ret, args;
String s;

ret = args = 0;
s = infile.getline();
for( i=0; s[i] != '('; i++ ) {
 if( s[i] == 'v' && s[i+1] == 'o' && s[i+2] == 'i' && s[i+3] == 'd' ) {
  ret = 1;
  break;
 }
}

for( i=0; s[i] != '('; i++ ) {}

for( i; s[i] != ')'; i++ ) {
 if( args == 0 && s[i] != ' ' ) {
  args++;
 }
 if( s[i] == ',' ) {
  args++;
 }
}
Suroot
Counting commas would fail on things such as template<class A, class B> void doSomething(const SomeClass<A,B>
Jasper Bekkers
You are correct, counting comma's would fail with Templates in c++; the easier way to do it would be to write a regular expression to do it.
Suroot
Code has templates (and lots of em), so i couldnt do this hehe
Ragnagard
A: 

All this is way over the top but maybe this might be your cup of tea, Elsa can parse c++ and provide you with an abstract syntax tree of the parsed file. There might be some other free tools out there that can do the same

Harald Scheirich
i may try this when i get the dependencies hehe
Ragnagard