I want to get macro names from my source files. Going through a couple of answers I found that
clang::Preprocessor::getPredefines()
does the job.
Question is how to get preprocessor object in ClangTool?
First of all, I'm also a newbie in clang. In my humble opinion, you misunderstood how to use the APIs.
Because you want to do preprocessing, so I guess you need PreprocessOnlyAction and FrontendActionFactory. PreprocessOnlyAction inherits clang::FrontendAction which can give you an instance of CompilerInstance by calling getCompilerInstance ()
. The good thing is this instance has a member function getPreprocessor(). This is what you want.
Take a look at EndSourceFile(). ClangCheck can help you better understand how to use them (based on AST instead of Preprocessor).