On Sat, 23 Apr 2011, David Young wrote:

> On Sat, Apr 23, 2011 at 09:39:37AM -0700, yoann padioleau wrote:
> > like indent?
> > 
> > http://www.gnu.org/software/indent/manual/indent.html#SEC12
> 
> Like indent, but based on rules instead of on ad-hoc policies such as:
> 
>      -bs, -nbs       If -bs is specified, a blank is forced after sizeof.
>                      Default: -nbs.
> 
> > It's called pretty printing in the literature I think, e.g. wadler 
> > combinators:
> > homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
> 
> Hmm.  I scanned that paper.  I did not see one beautiful program, but
> did see a bad page break---e.g., the one between pages 15 and 16. :-)
> 
> > One could use the coccinelle infrastructure to write such a pretty
> > printer indeed.
> 
> Glad to hear it!

I think Yoann means that you could eg use the Coccinelle parser and 
perhaps its C code visitors.  But that may not be the solution you are 
looking for.

If what you want is eg to control the spacing after sizeof, you can use 
Coccinelle with the option -smpl_spacing.  With this option you could
write eg

@@
type T;
@@

- sizeof(T)
+ sizeof (T)

or if you prefer

@@
type T;
@@

- sizeof(T) 
+ sizeof ( T )

But I would say that the weakest point of Coccinelle is the pretty 
printing.  So, for example, if there is something special about the 
formatting of T, then that might not be there in the generated code.  So 
you will have converted one problem into another.

But you could certainly try it, as long as you are willing to carefully go 
over the code to be sure that the format has not been broken in another 
way.

You should make one rule per construct of interest.

julia

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

Reply via email to