On Sat, 27 Nov 2010, yoann padioleau wrote:

> >> 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.
> 
> According to:
> http://clang.llvm.org/comparison.html#elsa
> 
> "Elsa does not have an integrated preprocessor, which makes it
> extremely difficult to accurately map from a source location in the
> AST back to its original position before preprocessing. Like GCC, it
> does not keep track of macro expansions."
> 
> which probably implies that clang (as opposed to elsa) has such an
> integrated preprocessor. Maybe it makes
> it possible to do some refactoring. Maybe they have something similar
> to the OriginTok and ExpandedTok in ast_c.ml

It's possible.  But I'm not sure why a compiler front end would be 
motivated to keep track of comments.  But perhaps it would be possible to 
extend it to record comments without too much difficulty.

thanks,
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to