Parsing C++ is tough. You'll likely want to use an existing parser. I know of 4 that are probably useful:
- Edison Design Group front end
- Clang's C++ parser
- DMS Software Reengineering Toolkit and its C++14 front end
- GCC (via Melt)
Most of these won't "parse" macros; they want to expand them using a preprocessor. So macros and PP conditionals disappear from the parse tree.
DMS can do "limited" preprocessing, and collect/keep preprocessor directives and macros found in well structured places and a wide variety of places they commonly occur.
Parsing header files is really tough; they tend to be loaded with conditionals and junk from many previous versions of the software, and idioms from the specific vendor. (MS has some stunningly weird stuff in their headers). Unless you are talking about parsing your header files, make sure you check the tool you choose can handle the dialect of C++ that you are actually handling.