[cfe-dev] Range for CXFile

Milian Wolff mail at milianw.de
Fri Jan 9 15:08:40 PST 2015


On Friday 09 January 2015 18:18:47 Jacob Carlborg wrote:
> On 2015-01-09 16:48, Milian Wolff wrote:
> > Hello all,
> > 
> > in the clang-c API, one can find the range for the top-level file of a
> > translation unit via
> > 
> > auto cursor = clang_getTranslationUnitCursor(unit);
> > auto range = clang_getCursorExtent(cursor);
> > 
> > Cool. But, now, I have a CXFile representing a file that was included at
> > some point within the TU. How do I get its range?
> > 
> > Or maybe there is a different way: I want to access all comments in any
> > CXFile encountered in a translation unit. Currently, we tokenize the
> > top-level document and then look for the CXToken_Comment tokens and get
> > their spelling and range.
> > 
> > I cannot find a way to do the same for included files. Help would be
> > appreciated.
> 
> There's a comment introspection API that might be of help:
> http://clang.llvm.org/doxygen/group__CINDEX__COMMENT.html

It won't work. Think about something like this:

// TODO: rewrite this file

/**
 * @file fubar
 */

/**
 * this does bar
 */
void bar();

if I understand the docs about the Documentation API correctly, I will only 
get access to the very last comment, as only stuff that "represents a 
documentable entity" can be passed to clang_Cursor_getParsedComment. Or am I 
missing something?

Bye
-- 
Milian Wolff
mail at milianw.de
http://milianw.de



More information about the cfe-dev mailing list