Get Replacements to FrontendAction

I have a custom FrontendAction that I want to run using RefactoringTool::runAndSave(). runAndSave() takes a FrontendActionFactory and doesn’t appear to have a way to pass parameters to the produced action.

How does one get the replacements list from RefactoringTool::getReplacements() into their FrontendAction?

You hand the refactoring tool pointer to the Frontend action factory, which then hands it to the Frontend action.

I guess that I am doing something wrong. This is my code:

RefactoringTool tool(optionsParser.getCompilations(), optionsParser.getSourcePathList());
MyAction action{tool};
auto a = tool.runAndSave(newFrontendActionFactory(&action).get());

I am getting an error ‘newASTConsumer’: is not a member of ‘MyAction’. It seems to want some kind of action factory, not an action.

I guess that I am doing something wrong. This is my code:

RefactoringTool tool(optionsParser.getCompilations(), optionsParser.getSourcePathList());
MyAction action{tool};
auto a = tool.runAndSave(newFrontendActionFactory(&action).get());

I am getting an error ‘newASTConsumer’: is not a member of ‘MyAction’. It seems to want some kind of action factory, not an action.

This doesn’t work, because we need to be able to create multiple actions - if you want to pass something to the action, you need to implement your own FrontendActionFactory.
The question is why you need your own action - usually you’ll want to use an ASTMatchFinder with your own callback, in which case you hand the tool to the callback, register the callback, and then use newFrontendActionFactory(&match_finder).

I’m manipulating the token stream in my action. I don’t believe that that is possible in AST matchers.

I’m manipulating the token stream in my action. I don’t believe that that is possible in AST matchers.

Yep, then just implement your own FrontendActionFactory - shouldn’t be more than 10 LOC :slight_smile: