[cfe-dev] Using libClang for parsing Source and Comments

Milian Wolff via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 23 11:28:41 PST 2016


Hey Barbara,

see answers inline below from my experience with the Clang C-API working on 
KDevelop.

On Tuesday, February 23, 2016 10:23:52 AM CET barbara via cfe-dev wrote:
> We have not found a tutorial or any documentation addressing our
> requirement to use libClang for parsing C++ source and full comments.
> We are currently using libClang 3.6 for testing however moving to 3.7 is
> possible although we would rather wait for 3.8.
> 
> At the present time we have code to walk the AST and obtain cursors and
> tokens for a sample C++ header. The following are the initial problems
> we have encountered.
> 
> 1)    Locate C++ standard headers
> 
> On Debian we did not have to pass any parameters to libClang for it to
> locate the C++ standard header files.
> 
> On Windows, I had to pass six include lines which referenced GCC std
> header files. This works but it will be cumbersome for our users. We
> talked with a few people at the last llvm meeting  it was mentioned
> there might be some enhancements for detecting the system headers.
> 
> Do anyone have ideas or suggestion about this?

I think this is still unresolved, but would be glad to be told otherwise.

> 2)    We need to retrieve all the comments and using "cursors" this has
> not worked.  We can easily generate a list of the tokens and walking
> these appear to show the comments, however this feels very awkward and
> slow.  We understand the basic idea of cursors and tokens. We are not
> sure about the pros and cons of each approach.

We also iterate over the tokens in KDevelop to find comments not associated 
with a  cursor, such as

///FIXME this is broken
/**
 * doxygen comment
 */
void foo();

If you only need access to the comments of cursors, i.e. the second comment 
above, you should be fine with clang_Cursor_getParsedComment and without 
tokens.

> 3)  Is the -Wdocumentation flag passed to clang when building. Or is
> this flag supposed to be passed to libClang?  Will this provide us with
> more of the user comments?  It appeared to to have no effect.

You need to pass that as part of the argv to clang_parseTranslationUnit2.

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



More information about the cfe-dev mailing list