<div dir="ltr">It's probably easier to do this with ld --wrap than with clang.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 18, 2017 at 7:08 AM, Eran Jakoby 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_8594139425868031087WordSection1">
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal">I'm trying to utilize Clang for mocking. <u></u><u></u></p>
<p class="MsoNormal">Starting for simplicity from C language – I would like to create:<u></u><u></u></p>
<p class="m_8594139425868031087MsoListParagraph"><u></u><span>1.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>Identical function for each function found (e.g. foo_wrapper() for foo()).<u></u><u></u></p>
<p class="m_8594139425868031087MsoListParagraph"><u></u><span>2.<span style="font:7.0pt "Times New Roman"">
</span></span><u></u><span dir="LTR"></span>All calls to original function (e.g. foo()) should instead call the wrapper (e.g. foo_wrapper()).<u></u><u></u></p>
<p class="MsoNormal">(the wrappers themselves can be left as undefined symbols to be resolved in link).<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I started by using Clang plug-in with a RecursiveASTVisitor that when visiting a function does the following code: (the visitor is called from HandleTopLevelDecl of an ASTConsumer)<u></u><u></u></p>
<p class="MsoNormal"> <wbr> FunctionDecl* NewFD=FunctionDecl::Create(<wbr>getContext(), getContext().<wbr>getTranslationUnitDecl(), f->getSourceRange().getBegin()<wbr>, f->getSourceRange().getEnd(), DeclarationName(&<wbr>newNameIdInfo), f->getReturnType(),
f->getTypeSourceInfo(), f->getStorageClass());<u></u><u></u></p>
<p class="MsoNormal"> <wbr> NewFD->setLexicalDeclContext(<wbr>getContext().<wbr>getTranslationUnitDecl());<u></u><u></u></p>
<p class="MsoNormal"> <wbr> SmallVector<ParmVarDecl*, 16> Params;<u></u><u></u></p>
<p class="MsoNormal"> <wbr> for(auto iter = f->param_begin(); iter!=f->param_end(); ++iter) {<u></u><u></u></p>
<p class="MsoNormal"> <wbr> Params.push_back(*iter);<u></u><u></u></p>
<p class="MsoNormal"> <wbr> }<u></u><u></u></p>
<p class="MsoNormal"> <wbr> NewFD->setParams(Params);<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">However this does not work and does not add an identical function to be used as wrapper (using nm I don't see the wrapper function symbol).<u></u><u></u></p>
<p class="MsoNormal">Moreover I have no idea how afterwards to set all calls to foo_wrapper instead of foo.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is my general approach correct? Am I missing something?<u></u><u></u></p>
<p class="MsoNormal">Any advice would be greatly appreciated. <u></u><u></u></p>
<p class="MsoNormal">Thanks!<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></p><span class="HOEnZb"><font color="#888888">
<p class="MsoNormal">Eran<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</font></span></div>
</div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>