[cfe-dev] How to get the name of a translation unit when using ast matchers?
Manuel Klimek
klimek at google.com
Wed Jan 28 00:46:02 PST 2015
You should be able to use the SourceFileCallbacks for this purpose.
On Sun Jan 25 2015 at 9:16:17 PM Gábor Márton <martongabesz at gmail.com>
wrote:
> Hi,
>
> I am a newby here ... and I have a quesiton, hoping you can help :)
>
> I am writing a tool based on the ast matchers tutorial
> (http://clang.llvm.org/docs/LibASTMatchersTutorial.html).
>
> I would like to have a callback (or similar) to print the filename of
> each and every translation unit which have been processed. I need this
> because I'd like to track the progress of my tool.
>
> For now I've been trying with this:
> struct TuFileHandler : public MatchFinder::MatchCallback {
> virtual void run(const MatchFinder::MatchResult &Result) {
> if (const Decl *D = Result.Nodes.getNodeAs<Decl>("decl")) {
> if (const TranslationUnitDecl *TUD = dyn_cast<TranslationUnitDecl>(D))
> {
> auto loc = TUD->getLocation();
> llvm::outs() << loc.printToString(*Result.SourceManager) << "\n";
> llvm::outs().flush();
> }
> }
> }
> };
> ...
> TuFileHandler FileHandler;
> auto const TuMatcher = decl().bind("decl");
> Finder.addMatcher(TuMatcher, &FileHandler);
> But the TranslationUnitDecl has invalid source location. I might be
> trying with some cumbersome solutions to match different Decls which
> has valid source locations, but that would be overkill. I am pretty
> sure there might be an easier way...
> Is there a way to somehow get this info from the CangTool class?
>
>
> Many Thanks,
> Gabor
> _______________________________________________
> 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/20150128/81db3181/attachment.html>
More information about the cfe-dev
mailing list