* [Cocci] Converting old-style function definitions.
2013-05-29 16:37 ` Julia Lawall
@ 2013-05-29 22:09 ` Ondřej Bílka
2013-06-05 0:37 ` Cyril Roelandt
1 sibling, 0 replies; 4+ messages in thread
From: Ondřej Bílka @ 2013-05-29 22:09 UTC (permalink / raw)
To: cocci
On Wed, May 29, 2013 at 06:37:04PM +0200, Julia Lawall wrote:
> On Wed, 29 May 2013, Ond?ej B?lka wrote:
>
> >
> > Hi,
> >
> > I am interested in common cleanup to convert K&R function
> > definitions to ISO ones (As gcc warning in -Wold-style-definition).
> >
> > Probably someone already wrote spatch so I ask here who?
>
> Unfortunately, it is not supported. The Coccinelle C parser makes at
> least an attempt to parse K&R function definitions, but the SmPL parser,
> ie the parser of the transformation specification language, doesn't accept
> them.
>
Thanks, it looks that I will take plan B, parse -Wold-style-definition
output and try convert corresponding lines by script.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] Converting old-style function definitions.
2013-05-29 16:37 ` Julia Lawall
2013-05-29 22:09 ` Ondřej Bílka
@ 2013-06-05 0:37 ` Cyril Roelandt
1 sibling, 0 replies; 4+ messages in thread
From: Cyril Roelandt @ 2013-06-05 0:37 UTC (permalink / raw)
To: cocci
On 05/29/2013 06:37 PM, Julia Lawall wrote:
> On Wed, 29 May 2013, Ond?ej B?lka wrote:
>
>>
>> Hi,
>>
>> I am interested in common cleanup to convert K&R function
>> definitions to ISO ones (As gcc warning in -Wold-style-definition).
>>
>> Probably someone already wrote spatch so I ask here who?
>
> Unfortunately, it is not supported. The Coccinelle C parser makes at
> least an attempt to parse K&R function definitions, but the SmPL parser,
> ie the parser of the transformation specification language, doesn't accept
> them.
>
Wouldn't it be possible to use a Python/OCaml rule to do this
transformation ? I did not manage to do it, but I think the attached
Coccinelle script might still be useful, since it can probably be used
to "fix" prototypes without having to write a complete C parser first.
The attached Coccinelle script does 3 things:
1) Find all function definitions (the "find" rule);
2) Parse their prototypes in a python rule and compute the "correct"
prototype (the "fix" rule);
3) Write the "correct" prototype in the code.
This does not work well, as it just turns:
void
k_r_function(foo, bar)
int foo; int bar;
{
}
into
void
k_r_function(foo, bar)
int foo; int bar;
{
}
+k_r_function(int foo, int bar);
Even if the third step cannot be fixed, it's probably quite easy to fix
the code in the second step, and to write the whole source file in a new
file.
WDYT ?
Cyril.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: kr.cocci
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130605/d2328d37/attachment.ksh>
^ permalink raw reply [flat|nested] 4+ messages in thread