Instantiating a ToolAction with constructor args

Hi All,

I am fairly new to Clang, so please forgive me if my question is dumb. I am trying to create a ASTFrontendAction to visit functions with a specific name and modifying them. I do the following:

class FindNamedFunctionAction: public clang::ASTFrontendAction {

public:

virtual std::unique_ptrclang::ASTConsumer CreateASTConsumer(

clang::CompilerInstance &Compiler, const llvm::StringRef InFile) {

// implementation of creating consumer and visitor etc. …

}

};

I would like the function name to be a parameter to the action. If I provide an explicit argument
to the constructor of this action by having something like:

class FindNamedFunctionAction: public clang::ASTFrontendAction {

public:

FindNamedFunctionAction(std::string Name): Name(Name){}

private:

std::string Name;

};

But doing this doesn’t work with running the tool with: tool.run(newFrontendActionFactory().get());

I can’t find any way of instantiating my action so that I can pass it to ClangTool’s run method. Could anyone kindly point me in the right direction?

Thanks & Regards!

You're close; to complete the picture you need to create your own factory
`newMyFrontendActionFactory(std::string Name)` that returns a
FindNamedFrontendAction, and pass that:
  tool.run(newMyFrontendActionFactory(Name).get());

-- James