Mosi
Mosi

Reputation: 1258

C++ file parser and function extractor

I need to develop a Qt/C++ software that reads in C++ source files, finds the dependencies, and copies only the code used from the dependent files into a file of the same name.

As an example. main.cpp calls foo(). foo() is declared in foofuncs.h and defined in foofuncs.cpp. foofuncs has many different functions other than foo(). I need to copy the foo() declaration from foofuncs.h to a new file (e.g. foofuncs.h.copy) which would just have the foo() declaration (and relevant includes). Similarly I would do the same to foofuncs.cpp.copy which would just contain the foo() definition (as well as the #include "foo.h", etc). This will likely need some kind of recursive process to go through all the includes, etc.

So my question is how can I do that? Can I use QRegularExpressions to find the code blocks? If so I need help with that. Also, is there any related open-source tools to be integrated in my Qt app to help me with that? Thanks

Upvotes: 1

Views: 2167

Answers (1)

elcuco
elcuco

Reputation: 9208

You cannot parse C++ code using regular expressions.

Some directions:

Don't even try to parse C++ code yourself, it's a never ending story.

Upvotes: 6

Related Questions