Bhushan
Bhushan

Reputation: 364

clang libtooling: Get Preprocessor object in clang libtool

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?

Upvotes: 0

Views: 261

Answers (1)

Xulei Liu
Xulei Liu

Reputation: 472

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).

Upvotes: 0

Related Questions