Re: [cocci] Moving string literals with SmPL?
Markus Elfring <[email protected]>
| Newsgroups | fr.inria.cocci |
|---|---|
| Message-ID | <[email protected]> |
> I would appreciate if another source code transformation can be achieved
> also by the means of the semantic patch language.
Will another SmPL script example trigger constructive development discussions?
@searching@
constant char[] last_literal, literal;
expression context;
@@
seq_printf(context, literal);
seq_printf(context, last_literal, ...);
@script:python recombination@
x << searching.literal;
y << searching.last_literal;
text;
@@
coccinelle.text = cocci.make_ident(x + "\n" + y)
@movement@
constant char[] searching.last_literal, searching.literal;
expression searching.context;
identifier recombination.text;
@@
-seq_printf(context, literal);
seq_printf(context,
- last_literal
+ text
,
...);
Questionable test result (according to the software combination “Coccinelle 1.3.0”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --no-loops crypto/rng.c …/Projekte/Coccinelle/janitor/combine_selected_seq_printf_calls2.cocci
…
@@ -81,8 +81,8 @@ static void crypto_rng_show(struct seq_f
__maybe_unused;
static void crypto_rng_show(struct seq_file *m, struct crypto_alg *alg)
{
- seq_printf(m, "type : rng\n");
- seq_printf(m, "seedsize : %u\n", seedsize(alg));
+ seq_printf(m, "type : rng\n"
+"seedsize : %u\n", seedsize(alg));
}
…
real 0m0,493s
user 0m0,249s
sys 0m0,109s
See also:
* Clarification approach
Propagating values back from Python script to SmPL rule with other metavariable type than “identifier”
2016-10-22
* Contribution
[PATCH] crypto: rng - Combine two seq_printf() calls into one in crypto_rng_show()
https://lore.kernel.org/linux-crypto/[email protected]/
https://lkml.org/lkml/2025/11/10/1357
Regards,
Markus