cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] Pretty-printing of code for ternary operators?
Date: Thu, 4 Jul 2019 13:40:47 +0200	[thread overview]
Message-ID: <eb4f2434-99cf-e7d5-9f0d-d0c9cc539785@web.de> (raw)
In-Reply-To: <alpine.DEB.2.20.1907041233010.3517@hadrien>

>> Would you like to achieve any improvements for automatic code beautification?
>> https://github.com/coccinelle/coccinelle/issues/37
>
> If you want to report a problem,

I became curious again if more contributors would become interested
to influence a possibly known software situation a bit more.


> you must include a semantic patch

@replacement@
expression check, context, x1, x2;
identifier action;
@@
-if (check)
-   action(context, x1);
-else
-   action(context, x2);
+action(context, (check) ? x1 : x2);


> and C code that gives an unsatisfactory result.

Source file example:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/ksm.c?id=550d1f5bda33fa3b203d8cf8df1396825dbfd213#n2500
https://elixir.bootlin.com/linux/v5.2-rc7/source/mm/ksm.c#L2500


// SPDX-License-Identifier: GPL-2.0-only

// Deleted part

int __ksm_enter(struct mm_struct *mm)
{
	struct mm_slot *mm_slot;
	int needs_wakeup;

	mm_slot = alloc_mm_slot();
	if (!mm_slot)
		return -ENOMEM;

	/* Check ksm_run too?  Would need tighter locking */
	needs_wakeup = list_empty(&ksm_mm_head.mm_list);

	spin_lock(&ksm_mmlist_lock);
	insert_to_mm_slots_hash(mm, mm_slot);

// Deleted part

	if (ksm_run & KSM_RUN_UNMERGE)
		list_add_tail(&mm_slot->mm_list, &ksm_mm_head.mm_list);
	else
		list_add_tail(&mm_slot->mm_list, &ksm_scan.mm_slot->mm_list);
	spin_unlock(&ksm_mmlist_lock);

// Deleted part

	return 0;
}

// Deleted part


Another test result:

elfring@Sonne:~/Projekte/Coccinelle/Probe> spatch ../janitor/use_call_with_ternary_operator1.cocci ksm-excerpt1.c
…
+	list_add_tail(&mm_slot->mm_list,
+		      (ksm_run & KSM_RUN_UNMERGE) ? &ksm_mm_head.mm_list : &ksm_scan.mm_slot->mm_list);
…



How likely is it that the combined source code for a single function parameter
will fit into known line length limitations?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  parent reply	other threads:[~2019-07-04 11:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  7:33 [Cocci] Pretty-printing of code for ternary operators? Markus Elfring
     [not found] ` <alpine.DEB.2.20.1907041233010.3517@hadrien>
2019-07-04 11:40   ` Markus Elfring [this message]
     [not found]     ` <alpine.DEB.2.20.1907041343250.3517@hadrien>
2019-07-04 12:05       ` 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=eb4f2434-99cf-e7d5-9f0d-d0c9cc539785@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@systeme.lip6.fr \
    --cc=julia.lawall@lip6.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 NNTP newsgroup(s).