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

Chris Lattner clattner at apple.com
Sun Nov 28 09:45:16 PST 2010


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.

-Chris 

> 
> On 27.11.2010 22:49, Julia Lawall wrote:
>> On Sat, 27 Nov 2010, Carl-Daniel Hailfinger wrote:
>> 
>>> On 27.11.2010 17:46, Julia Lawall wrote:
>>> 
>>>> On Sat, 27 Nov 2010, Jani Monoses wrote
>>>> 
>>>>> On 11/27/2010 02:44 PM, Julia Lawall wrote:
>>>>> 
>>>>> 
>>>>>> I think it is possible, and indeed a C++ parser has been written that is
>>>>>> compatible with Coccinelle.  Doing the simple case as you suggest is even
>>>>>> probably not too hard.  But at the moment we do not have the resources to
>>>>>> look into it.
>>>>>> 
>>>>>> 
>>>>> thanks for the prompt reply.
>>>>> Is the C++ parser code available along with some documentation on how it can
>>>>> be used with Coccinelle?
>>>>> 
>>>>> 
>>>> There is no documentation.  Furthermore, it is only a parser, it does not 
>>>> construct an abstract syntax tree, so compatible with Coccinelle may not 
>>>> mean much more than it is written in ocaml.  I think it is available, but 
>>>> I am not sure where.  Perhaps Nicolas or Yoann can answer.
>>>> 
>>>> 
>>> This may be a dumb question, but is there any reason the C++ parser in
>>> llvm/clang can't be used? It is compatible with gcc, and AFAIK it is
>>> rather easy to make it spit out an AST in the format you want.
>>> The LLVM developers are very open to suggestions, and many people have
>>> used LLVM in their own projects.
>>> Apparently LLVM ships with OCaml bindings by default, so it may not be
>>> too hard to use it.
>>> 
>> 
>> Perhaps it relies on CPP (ie expansion of macros) having been performed in 
>> advance?  Coccinelle needs to parse the code as it is, not parse it into 
>> some simplified internal representation, so that it can reconstruct the 
>> code after transformation.  This includes keeping information about all 
>> whitespace and comments.
>> 
> 
> 
> Regards,
> Carl-Daniel
> _______________________________________________
> 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