[cfe-dev] Instantiating a ToolAction with constructor args

Himanshu via cfe-dev cfe-dev at lists.llvm.org
Mon Jul 4 21:27:09 PDT 2016


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_ptr<clang::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*<FindNamedFunctionAction>().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!
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160704/0f56baf1/attachment.html>


More information about the cfe-dev mailing list