On Tue, Aug 23, 2011 at 06:25:45PM +0200, Julia Lawall wrote: > On Tue, 23 Aug 2011, SF Markus Elfring wrote: > > > > If someone wants something mor complicated, they can use indent regularly > > > on their code, or this tool that you mention. > > > > Would you like to be able to generate patches without reformatting by other > > code beautifiers? > > It is a very hard problem to beautify code. I don't see any reason for > Coccinelle to do that as well. Coccinelle needs to make the code readable > and to try to respect the existing style. But if someone wants something > more exotic, they should use some tool that is designed for that.
It seems to me that Coccinelle should not beautify code, however, maybe it could be one stage in a pipeline that beautifies code. It seems to me that you could specify many of the popular styles of C indentation/line-breaking in terms of the boxes, glue, and penalties that Knuth & Plass's line-breaking algorithm operates on. Knuth & Plass's paper, "Breaking Paragraphs Into Lines", mentions a program called Blaise that compiled Pascal programs into boxes/glue/penalties for typesetting. Perhaps some Coccinelle script could compile C into boxes/glue/penalties? I guess that if the transformation will be C->C as Coccinelle requires, it may be necessary to put box/glue/penalty annotations into comments, e.g.: static int/*-*-*penalty(x, y, z)glue(p, q, r)*-*-*/ ath_pci_match(/*-*-*penalty(g, h, j)glue(k, m, n)*-*-*/device_t/*-*-*penalty(a, b, c)glue(d, e, f)*-*-*/parent, ... Another pipeline stage would transform the code so annotated into the most beautiful form for a given page width. Maybe Coccinelle is not most suitable for this, however, it does seem like a Coccinelle script is more nearly the right level of abstraction than, say, some C/C++ code that operates on an AST. Dave -- David Young OJC Technologies [email protected] Urbana, IL * (217) 344-0444 x24 _______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
