mirror of https://lore.kernel.org/lkml/
 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: Improving output for single characters (with SmPL)?
Date: Thu, 23 Jul 2026 21:26:15 +0200	[thread overview]
Message-ID: <406093f5-ee7d-4ae9-808b-2b42d4846eab@web.de> (raw)
In-Reply-To: <202dfb21-f5a2-4550-8a1f-aa07d84db345@web.de>

> I would like to achieve further source code adjustments by the means of
> the following script variant for the semantic patch language.

Unfortunately, the SmPL code needs to be corrected a bit in the final
replacement rule.
The parameter order should be reversed from selected fprintf() to fputc() calls.

@initialize:python@
@@
input = ''

def convert(item):
   mark = ["'", item, "'"]
   coccinelle.text = cocci.make_expr(''.join(mark))

def common_checks(unescaped):
   if input[1] == '"':
      if input[2:] == '':
         convert(input[0] if unescaped else '\\' + input[0])
      else:
         cocci.include_match(False)
   else:
      cocci.include_match(False)

@find_update_candidate@
constant char[] input_string;
expression input_context;
position pos;
@@
 fprintf@pos(input_context, input_string);

@script:python selection@
param << find_update_candidate.input_string;
text;
@@
if param[0] == '"':
   input = param[1:]
   if input[0] == '\\':
      input = input[1:]
      if input[0] == '"':
         if input[1] == '"':
            if input[2:] == '':
               convert('"')
            else:
               cocci.include_match(False)
         else:
            cocci.include_match(False)
      else:
         common_checks(False)
   else:
      common_checks(True)
else:
   cocci.include_match(False)

@replacement@
constant char[] find_update_candidate.input_string, selection.text;
expression find_update_candidate.input_context;
position find_update_candidate.pos;
@@
(
-fprintf@pos
+putchar
 (
-stdout,
-input_string
+text
 )
|
-fprintf@pos
+fputc
 (
-input_context
+text
 ,
-input_string
+input_context
 )
)


Another test result (according to the software combination “Coccinelle 1.3.1”):
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --timeout 23  -j4 --chunksize 1 --no-loops --include-headers -dir tools …/Projekte/Coccinelle/janitor/use_fputc-20260723.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff
…
548 files match
…
real    0m35,324s
user    1m54,532s
sys     0m3,473s
Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Linux/next-analyses> lsdiff /home/altes_Heim2/elfring/Projekte/Bau/Linux/scripts/Coccinelle/tuning1/next/20260721/use_fputc.diff | wc -l
50



I hope that demonstrated data processing possibilities can influence further
development ideas in constructive ways besides hints that some compilers
can also perform such a source code transformation already.

Regards,
Markus

  reply	other threads:[~2026-07-23 19:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 17:03 Markus Elfring
2026-07-23 19:26 ` Markus Elfring [this message]
2026-07-24  9:02 ` Markus Elfring
2026-08-01  8:10   ` Markus Elfring
2026-08-01  8:18     ` Julia Lawall
2026-08-01 12:00       ` [cocci] " Markus Elfring
2026-08-02 10:06       ` Markus Elfring
2026-08-03  5:40         ` [cocci] Improving parallel data processing for hierarchical structures? 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=406093f5-ee7d-4ae9-808b-2b42d4846eab@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

all inboxes | Powered by JetHome®