Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: cocci@inria.fr
Subject: [cocci] Converting compound statement after if to single statement with SmPL?
Date: Thu, 29 Feb 2024 15:55:58 +0100	[thread overview]
Message-ID: <efe10a0a-9ab1-487f-9be7-a992afbc4cbc@web.de> (raw)

Hello,

I would like to share further test results for two simple source code transformations
which could be expressed by the means of the semantic patch language
also together with the software combination “Coccinelle 1.1.1-00739-g68c580f1”.

Source file example:
int my_test(void)
{
 int rc;
// placeholder 1
 rc = my_work(my_input);
 if (rc) {
    last_action(my_data);
    return rc;
 }
// placeholder 2
 return 0;
}


SmPL script variant 1:
@adjustment1@
@@
 if (...)
-{
-   last_action(my_data);
-   return rc;
-}
+   goto do_last_action;


Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch test_last_action_with_return_in_compound_statement.c convert_compound_statement_after_if_to_single_statement1.cocci
…
@@ -3,10 +3,7 @@ int my_test(void)
  int rc;
 // placeholder 1
  rc = my_work(my_input);
- if (rc) {
-    last_action(my_data);
-    return rc;
- }
+ if (rc) goto do_last_action;
 // placeholder 2
  return 0;
 }



SmPL script variant 2:
@adjustment2@
@@
 if (...)
-{
-   last_action(my_data);
-   return rc;
-}
+
+   goto do_last_action;


Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch test_last_action_with_return_in_compound_statement.c convert_compound_statement_after_if_to_single_statement2.cocci
…
@@ -3,10 +3,9 @@ int my_test(void)
  int rc;
 // placeholder 1
  rc = my_work(my_input);
- if (rc) {
-    last_action(my_data);
-    return rc;
- }
+ if (rc)
+
+    goto do_last_action;
 // placeholder 2
  return 0;
 }



Will such diff outputs support any development considerations for tweaks
of code pretty-printing?

Regards,
Markus

                 reply	other threads:[~2024-02-29 14:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=efe10a0a-9ab1-487f-9be7-a992afbc4cbc@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@inria.fr \
    /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).