Passing code replacements by APIs (for SmPL)?
Hello,
The semantic patch language supports the specification of source code replacements. Such replacements are specified within SmPL rules. The evaluation of several SmPL rules would trigger corresponding software run time consequences. Thus it can occasionally be preferred to combine some data processing selections into SmPL disjunctions.
Desirable source code adjustments can also be generated into SmPL script variants. I imagine that it can occasionally be nicer to avoid such script generation because the Coccinelle software can benefit also from source file analyses. How will the chances evolve to extend application programming interfaces accordingly?
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/c52d87d02775dea45d51a3c9440646525e4b5f29/docs/Coccilib.3cocci#L26
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/c52d87d02775dea45d51a3c9440646525e4b5f29/python/python_documentation.md
Regards,
Markus
Quoted 1 line
Desirable source code adjustments can also be generated into SmPL script variants.
Will any more software users get further development ideas from an SmPL script like the following?
// See also:
// https://elixir.bootlin.com/linux/v6.16-rc2/source/include/uapi/linux/usb/ch9.h#L472-L678
@initialize:python@
@@
import sys
x = {}
def store_data(action, input, code):
"""Add information to an internal data structure.""" x[code] = (action, input)
@find@
expression e;
identifier action, input;
type input_type, return_type != void;
@@
static inline return_type action(input_type input) {
return e;
}
@script:python collection@
action << find.action;
input << find.input;
code << find.e;
@@store_data(action, input, code)
@finalize:python@
@@
if x:
sys.stdout.write("@replacements@\nconst struct usb_endpoint_descriptor *epd;\n@@\n(\n") sys.stdout.write("|\n".join("-{}\n+{}({})\n".format(key, value[0], value[1])
for key, value in x.items()))
sys.stdout.write(")\n")
else:
sys.stderr.write("No result for this analysis!\n")
Would you become interested to convert contents from any header (or source) files into more advanced transformation approaches?
Regards,
Markus
Quoted 2 lines
Would you become interested to convert contents from any header (or source) files into more advanced transformation approaches?
I demonstrated that expressions can be extracted from selected function implementations also by the means of the semantic patch language.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2025-06/msg00044.html
Now I am looking again for further software extension possibilities.
1. I would like to sort found expressions by decreasing complexity.
2. Some expressions will probably refer to known function (or macro) calls. How can corresponding identifiers be replaced by previously determined source code?
Regards,
Markus