[cfe-dev] Regarding clang-c and comments...

Doug douglas.linder at gmail.com
Wed Oct 26 20:59:28 PDT 2011


Hi there,

I'm writing a very simple c parser (dumps formatted symbols, something
similar to ctags but actually working) using clang-c, which is working well,
but I'm hoping to add some support for source comments in the code.

At the moment I'm using the clang-c subset for this, but there doesn't seem
to be any api for accessing comments; specifically CXCursorKind doesn't seem
to have a type for 'comment', and I've ended up doing something similar to:

for each cursor
  get cursor info
  save info (specifically, offset, filename, display name)

for each saved symbol:
  find the closest previous symbol
  walk backwards through the file from position of symbol -> position of
previous symbol looking for closest comment

This is quite annoying to do, and has a few problems (example: symbols with
no filename, unsaved files, large projects means loading every symbol into
memory).

Is there a to get comments as elements through to the visitor function?

If no in clang-c, then perhaps in the full clang api?

Finally, as a slightly better alternative, is there a way to query a cursor
to get the previous lexical cursor? At the very least this would save me
having to save the entire set of data in memory first..

Help much appreciated!

cheers,
Doug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111027/9dbade65/attachment.html>


More information about the cfe-dev mailing list