Accessing ASTContext after run() invocation

Hi all,

Suppose we have created a ClangTool in libtooling.
Is there a way to record ASTContexts (say, in the consumer), and access them after…)?

For example:

std::vector<ASTContext*> contexts;
int main(int argc, char **argv) {

CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);

ClangTool Tool(OptionsParser.getCompilations(),


// I want to access contexts[i] here and possibly use the rewriter.

Any help is appreciated.


I believe this is not possible. The ClangTool::run method calls FrontendActionFactory::runInvocation which captures the FrontEndAction with a unique_ptr, thus freeing everything before it returns.

Can you detail further what you intend to do?