[cfe-dev] Obtaining file name for functions from included files
Manuel Klimek
klimek at google.com
Tue Jun 19 06:52:17 PDT 2012
On Tue, Jun 19, 2012 at 3:22 PM, Felix Schmitt <
felix.schmitt at zih.tu-dresden.de> wrote:
> Manuel Klimek <klimek at ...> writes:
>
> >
> > On Tue, Jun 19, 2012 at 2:34 PM, Felix Schmitt
> <felix.schmitt <at> zih.tu-dresden.de> wrote:
> > Hi,
> > I got the following problem:
> > I need to traverse the AST (currently using
> RecursiveASTVisitor) and get the
> > file name for every function declaration.
> > Currently, I only get the filename for function
> declarations in my main file but
> > how do I get these for functions in #included files?
> > My relevant code looks like this (srcMgr is the
> SourceManager):
> > bool CMyASTVisitor::VisitFunctionDecl(FunctionDecl*
> decl)
> > {
> > ...
> > const FileEntry* file_entry =
> > srcMgr.getFileEntryForID(srcMgr.getFileID(decl-
> >getLocStart()));
> > if (file_entry == NULL)
> > std::cout << "no file entry" << std::endl;
> > ...
> > }
> > Is there a way to get these filenames?
> >
> >
> > Why does file_entry->getName() not work?
> >
>
> Because file_entry is NULL if the declaration found is
> not in
> the main file but from an included file in the main file.
>
That's news to me - the only place where I've found file_entry to be NULL
is for token-pasted code, for example from macro expansions.
Cheers,
/Manuel
>
> Felix
>
> > Cheers,
> > /Manuel
> >
> >
> >
> >
> > Regards,
> > Felix
> > _______________________________________________
> > cfe-dev mailing listcfe-dev-
> Tmj1lob9twqVc3sceRu5cw at public.gmane.orghttp://
> lists.cs.uiuc.edu/
> mailman/listinfo/cfe-dev
> >
> >
> >
> >
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at ...
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
>
>
>
>
> _______________________________________________
> 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/20120619/f896aa85/attachment.html>
More information about the cfe-dev
mailing list