<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Thank you for your answer.</p>
<p><br>
</p>
<p>I have found the solution in the Clang Devs archive. This is what I did </p>
<p><br>
</p>
<p></p>
<div>if (func_decl->hasBody()) //in order to get the definitions body and then locate it in the corresponding file</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>const FileEntry *file_entry = astContext->getSourceManager().getFileEntryForID(astContext->getSourceManager().getFileID(func_decl->getLocStart()));</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>string sourcepath = file_entry->getName();</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>const int idx = sourcepath.find_last_of("\\/");</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (std::string::npos != idx) //extract the filename from the entire path</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>  <span class="Apple-tab-span" style="white-space:pre">
</span>filename = sourcepath.substr(idx + 1);</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<br>
<p></p>
<p>My answer is just for the archive.</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Himanshu <himanshu@utexas.edu><br>
<b>Sent:</b> 22 July 2016 17:37:54<br>
<b>To:</b> Georgiou, Andreas<br>
<b>Cc:</b> cfe-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [cfe-dev] How to find the source file, the called function is defined inside</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi, 
<div><br>
</div>
<div>You could use the getFilename() API by SourceManager. Get the function's startLoc and then pass it to the getFileName( ). </div>
</div>
<div class="gmail_extra"><br clear="all">
<div>
<div class="gmail_signature" data-smartmail="gmail_signature">--
<div>Himanshu</div>
</div>
</div>
<br>
<div class="gmail_quote">On Thu, Jul 21, 2016 at 6:53 PM, Georgiou, Andreas 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 dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p><span></span></p>
<div>Hi all,</div>
<div><br>
</div>
<div>I have an ASTvisitor and when it visits a CallExpr node, if the expression is a function call I would like to retrieve the filename of the source code where the called function is defined within. Is it possible?</div>
<div><br>
</div>
<div>Thank you</div>
<span></span><br>
<p></p>
</div>
</div>
<br>
_______________________________________________<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/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</body>
</html>