[cfe-dev] Question on navigating to cc files from header files in MatchCallback::run

Nikola Smiljanic popizdeh at gmail.com
Wed Jul 16 16:13:57 PDT 2014


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.


On Thu, Jul 17, 2014 at 7:14 AM, Lucas Nunno <lnunno at cs.unm.edu> wrote:
>
> Hello all,
>
> 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.
>
> 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.
>
>     ASTContext *context = Result.Context;
>     SourceManager &source_manager = context->getSourceManager();
>     FileManager &file_manager = source_manager->getFileManager();
>     const FileEntry *file_entry = file_manager.getFile(class_name +
".cc");
>     // ... Need code here to get a TranslationUnitDecl from file_entry.
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140717/a3d9cdfc/attachment.html>


More information about the cfe-dev mailing list