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

Eli Friedman eli.friedman at gmail.com
Mon Oct 31 19:02:04 PDT 2011


On Mon, Oct 31, 2011 at 6:41 PM, Doug <douglas.linder at gmail.com> wrote:
> *cough* Alternatively, is there a different list for questions like this?

No, this is the right list.  I'm pretty sure there are people out
there doing things similar to this, so I was expecting that someone
else would respond.

clang generally does not preserve comments in the AST in any way, so
as far as I know your approach is the only approach. With the C++ API,
you can register a callback that will let you save the locations of
comments, which might help a bit, but isn't substantially different
overall.

-Eli

> On Thu, Oct 27, 2011 at 11:59 AM, Doug <douglas.linder at gmail.com> wrote:
>>
>> 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.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>




More information about the cfe-dev mailing list