<div dir="ltr">So to give more context to the question, I have a match that is generated on the header file and I'm trying to jump to the mapped .cc file that actually defines that class. I'm pretty new to clang development so I might not be doing this the best way, but I have a custom ASTFrontendAction for matching the header file pattern that I have defined that then calls a custom subclassed MatchFinder::MatchCallback. <div>
<br></div><div>I will try using runToolOnCode and define a new FrontEndAction for the operation that I will run on the cc file. Is there also an easy way to convert an llvm::MemoryBuffer to a Twine? I noticed runToolOnCode requires a Twine, not a MemoryBuffer. I was thinking of doing MemoryBuffer::getBuffer() and constructing a Twine out of this, but is there a simpler way?<br>
<div><br></div><div>I've made a stackoverflow question here if that's helpful: <a href="http://stackoverflow.com/questions/24791674/clang-get-a-translation-unit-from-file-path">http://stackoverflow.com/questions/24791674/clang-get-a-translation-unit-from-file-path</a> <br>
</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 16, 2014 at 5:13 PM, Nikola Smiljanic <span dir="ltr"><<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</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">I think that you're doing it wrong, but then again I know very little about this so this is all just guessing. I don't think that FileManager and SourceManager will magically parse your file, you can obtain FileEntry but that's just a low level class that wraps some file system stuff... I think that you need to do the same thing you're doing with your header file, how are you feeding that into RecurisiveASTVisitor? clang::tooling::runToolOnCode seems to be the way to go, you just need to pass it the contents of your .cc file. You might be able to get it by calling SourceManager::getMemoryBufferForFile, but I'm not sure if you have to use clang's infrastucture for this at all.<div>
<div class="h5"><br>

<br><br>On Thu, Jul 17, 2014 at 7:14 AM, Lucas Nunno <<a href="mailto:lnunno@cs.unm.edu" target="_blank">lnunno@cs.unm.edu</a>> wrote:<br>><br>> Hello all,<br>><br>> I'm trying to get the .cc file's translation unit from the .h file that I've currently matched with a `MatchCallback`, I am doing this by name where I've matched a class declaration `D` defined in D.hh and I need to run a `RecursiveASTVisitor` on D.cc. So far I've figured out how to get a `FileEntry` object and I'm stuck trying to figure out how to get a `TranslationUnitDecl` that I can then run the ASTVisitor on.<br>


><br>> This is my code so far inside my `MatchCallback::run` method , any advice on how to parse this .cc file from the .hh file? I would like to avoid building *another* FrontendAction and ASTConsumer, but let me know if this is the only way to accomplish this. Any help would be appreciated.<br>


><br>>     ASTContext *context = Result.Context;<br>>     SourceManager &source_manager = context->getSourceManager();<br>>     FileManager &file_manager = source_manager->getFileManager();<br>>     const FileEntry *file_entry = file_manager.getFile(class_name + ".cc");<br>


>     // ... Need code here to get a TranslationUnitDecl from file_entry.<br>>     <br>><br>><br>><br></div></div>> _______________________________________________<br>> cfe-dev mailing list<br>> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>


> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>><br></div>
</blockquote></div><br></div>