<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 4, 2016 at 9:27 PM, Himanshu via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi All, <div><br></div><div>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:</div><div>







<p><span><b>class</b></span><span> </span>FindNamedFunctionAction<span>: </span><span><b>public</b></span><span> clang::</span>ASTFrontendAction<span> {</span></p>
<p><b>public</b><span>:</span></p>
<p><span>   </span><span><b>virtual</b></span> std::<span>unique_ptr</span><clang::<span>ASTConsumer</span>> <b>CreateASTConsumer</b>(</p>
<p><span>   </span><span>       </span><span>       </span>clang::<span>CompilerInstance</span> &Compiler, <span><b>const</b></span> llvm::<span>StringRef</span> InFile) {</p><p>            // implementation of creating consumer and visitor etc. ...</p><p>}</p><p>};</p></div><div>I would like the function name to be a parameter to the action. If I provide an explicit argument </div><div>to the constructor of this action by having something like: </div><div><p><span><b>class</b></span><span> </span>FindNamedFunctionAction<span>: </span><span><b>public</b></span><span> clang::</span>ASTFrontendAction<span> {</span></p><p><span>public: </span></p><p><span>FindNamedFunctionAction(std::string Name): Name(Name){}<br></span></p><p><span>private: </span></p><p><span>std::string Name;</span></p><p><span>...</span></p><p><span>};</span></p><p><span><br></span></p><p><span>But doing this doesn't work with running the tool with:  </span><span>tool.</span><b>run</b><span>(</span><b>newFrontendActionFactory</b><span><</span><span>FindNamedFunctionAction</span><span>>().get());</span></p>







</div><div> 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?</div><div><br></div></div></blockquote><div><br></div><div>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:</div><div>  tool.run(newMyFrontendActionFactory(Name).get());</div><div><br></div><div>-- James</div></div></div></div>