Search code examples
clangllvmabstract-syntax-treellvm-clang

Clang AST dump doesn't show #defines


I'm dumping the AST of some headers like this:

clang -cc1 -ast-dump -fblocks header.h

However, any #defines on the header are not showing on the dump. Is there a way of adding them?


Solution

  • It's true, #defines are handled by the preprocessor, not the compiler. So you need a preprocessor parser stage. I know of two:

    1. Boost Wave can preprocess the input for you, and/or give you hooks to trigger on macro definitions or uses.

    2. The Clang tool pp-trace uses a Clang library that can do callbacks on many preprocessor events, including macro definitions.