Discussion:
[Cocci] problem with transform of expression not line-wrapping as expected
Allan, Bruce W
2017-12-11 22:27:26 UTC
Permalink
I'm trying to transform the following piece of code:

int main(int argc, char **argv)
{
pointer_to_foo = (struct long_named_struct *)
func_foo(e1, a_long_expression_e2, (long_part_a_of_exp_3 *
long_part_b_of_exp_3),
nop_expr);
}


with the following cocci script:

@@
expression ptr,e1,e2,e3,nop;
type type;
@@
(
- ptr = (type *)func_foo(e1,e2,e3,nop);
+ ptr = long_func_bar(macro_foobar(e1),e2,e3,SOME_OTHER_DEFINE);
)

to get:

pointer_to_foo = long_func_bar(macro_foobar(e1), a_long_expression_e2,
(long_part_a_of_exp_3 *
long_part_b_of_exp_3),
SOME_OTHER_DEFINE);

but instead end up with:

pointer_to_foo = long_func_bar(macro_foobar(e1), a_long_expression_e2,
(long_part_a_of_exp_3 * long_part_b_of_exp_3),
SOME_OTHER_DEFINE);

The problem is with the (long_part_a_of_exp_3 * long_part_b_of_exp_3) which does not line wrap as I would expect and exceeds 80-columns. Any suggestions?

Thanks,
Bruce.
Julia Lawall
2017-12-11 22:33:51 UTC
Permalink
Post by Allan, Bruce W
int main(int argc, char **argv)
{
pointer_to_foo = (struct long_named_struct *)
func_foo(e1, a_long_expression_e2, (long_part_a_of_exp_3 *
long_part_b_of_exp_3),
nop_expr);
}
@@
expression ptr,e1,e2,e3,nop;
type type;
@@
(
- ptr = (type *)func_foo(e1,e2,e3,nop);
+ ptr = long_func_bar(macro_foobar(e1),e2,e3,SOME_OTHER_DEFINE);
)
pointer_to_foo = long_func_bar(macro_foobar(e1), a_long_expression_e2,
(long_part_a_of_exp_3 *
long_part_b_of_exp_3),
SOME_OTHER_DEFINE);
pointer_to_foo = long_func_bar(macro_foobar(e1), a_long_expression_e2,
(long_part_a_of_exp_3 * long_part_b_of_exp_3),
SOME_OTHER_DEFINE);
The problem is with the (long_part_a_of_exp_3 * long_part_b_of_exp_3) which does not line wrap as I would expect and exceeds 80-columns. Any suggestions?
Coccinelle only contemplates putting newlines after commas.

You may get better results if you do not remove and then put back e2 and
e3, since they don't change. Just put - and + for the things you actually
want to change.

You don't need the () in the leftmost column. That is for a disjunction,
ie a choice between multiple possibilities, and you have only
one possibility.

julia

Continue reading on narkive:
Loading...