[cfe-dev] [Cocci] Re: using with c++ codebase ?

Chris Lattner clattner at apple.com
Sun Nov 28 10:06:07 PST 2010


On Nov 28, 2010, at 9:57 AM, Julia Lawall wrote:

> On Sun, 28 Nov 2010, Chris Lattner wrote:
> 
>> 
>> On Nov 28, 2010, at 9:24 AM, Carl-Daniel Hailfinger wrote:
>> 
>>> Hi,
>>> 
>>> I added the llvm cfe-dev mailing list to CC so you can get answers
>>> directly from the source.
>>> The quoted mail is archived at
>>> http://lists.diku.dk/pipermail/cocci/2010-November/001348.html and you
>>> can go forward/backward in the archive if you want to see more context.
>> 
>> I don't know much about Coccinelle, but Clang certainly does track accurate source locations, including the original and ultimate location of macro expansions:
>> http://clang.llvm.org/docs/InternalsManual.html#SourceLocation
>> 
>> Clang was built with the intention of supporting refactoring in the future, and we have a suite of source code rewriting applications already in tree.
> 
> Thanks for the feedback.  What is wanted is not just the locations of 
> code, but the actual whitespace, comments, and macros that were around the 
> code?  If that information is not currently kept by the clang parser, 
> might it be easy to add?

Clients like the HTML rewriter process a file twice: first with the clang parser, then with the clang lexer.  The former provides detailed semantic information, the later provides the location of all the whitespace and other tokens, which have no semantics and are not subject to macro expansion.

> And to what extent does the AST resemble the source code?  Is there a 
> simplified intermediate language, or is there a production in the AST for 
> every production in the concrete syntax?

It matches it very closely.  The motivations for doing this are well described on the clang web page :)

-Chris



More information about the cfe-dev mailing list