Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: cocci@inria.fr, kernel-janitors@vger.kernel.org
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [cocci] Passing code replacements by APIs (for SmPL)?
Date: Mon, 23 Jun 2025 10:05:15 +0200	[thread overview]
Message-ID: <481faa1d-7171-4657-8dc0-c37b153e6eaa@web.de> (raw)
In-Reply-To: <2dc257b4-d310-47dd-90ea-9b081727be2a@web.de>

> 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

  reply	other threads:[~2025-06-23  8:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-22  7:30 [cocci] Passing code replacements by APIs (for SmPL)? Markus Elfring
2025-06-23  8:05 ` Markus Elfring [this message]
2025-06-26 11:18   ` Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=481faa1d-7171-4657-8dc0-c37b153e6eaa@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).