cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] Converting compound statement after if to single statement with SmPL?
@ 2024-02-29 14:55 Markus Elfring
  0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2024-02-29 14:55 UTC (permalink / raw)
  To: cocci

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-29 14:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 14:55 [cocci] Converting compound statement after if to single statement with SmPL? Markus Elfring

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 NNTP newsgroup(s).