Coccinelle archive on
 help / color / Atom feed
From: Markus Elfring <>
To: Julia Lawall <>
Cc: Coccinelle <>
Subject: Re: [Cocci] Pretty-printing of code for ternary operators?
Date: Thu, 4 Jul 2019 13:40:47 +0200
Message-ID: <> (raw)
In-Reply-To: <alpine.DEB.2.20.1907041233010.3517@hadrien>

>> Would you like to achieve any improvements for automatic code beautification?
> 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

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

> and C code that gives an unsatisfactory result.

Source file example:

// 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);

	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);
		list_add_tail(&mm_slot->mm_list, &ksm_scan.mm_slot->mm_list);

// 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?

Cocci mailing list

  parent reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  7:33 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 publically 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:

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

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Coccinelle archive on

Archives are clonable:
	git clone --mirror cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ \
	public-inbox-index cocci

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox