From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-6.1 required=3.0 tests=AWL,BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 686CB1FAAD for ; Mon, 30 Jan 2017 17:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752880AbdA3RsF (ORCPT ); Mon, 30 Jan 2017 12:48:05 -0500 Received: from mout.web.de ([212.227.17.12]:54495 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751645AbdA3RsE (ORCPT ); Mon, 30 Jan 2017 12:48:04 -0500 Received: from [192.168.178.36] ([79.237.55.102]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MCZh8-1cgT9C3vQA-009LgK; Mon, 30 Jan 2017 18:41:17 +0100 Subject: Re: [PATCH 5/5] graph: use SWAP macro To: Johannes Schindelin References: <8ef4c833-45bd-6831-0683-6d01f30aa518@web.de> Cc: Git List , Junio C Hamano From: =?UTF-8?Q?Ren=c3=a9_Scharfe?= Message-ID: <63f1dcc0-729c-955b-63fa-859e441406bd@web.de> Date: Mon, 30 Jan 2017 18:41:01 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:lJ/8VXtr9FuPFktTF1esDJdiNHwaZ8WAMG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el.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 30.01.2017 um 17:16 schrieb Johannes Schindelin: > Hi René, > > On Sat, 28 Jan 2017, René Scharfe wrote: > >> Exchange the values of graph->columns and graph->new_columns using the >> macro SWAP instead of hand-rolled code. The result is shorter and >> easier to read. >> >> This transformation was not done by the semantic patch swap.cocci >> because there's an unrelated statement between the second and the last >> step of the exchange, so it didn't match the expected pattern. > > Is it really true that Coccinelle cannot be told to look for a code block > that declares a variable that is then used *only* in the lines we want to > match and replace? Hope I parsed your question correctly; my answer would be that it can't be true because that's basically what the proposed semantic patch does: @ swap @ type T; T tmp, a, b; @@ - tmp = a; - a = b; - b = tmp; + SWAP(a, b); @ extends swap @ identifier unused; @@ { ... - T unused; ... when != unused } The first part (up to the "+") looks for a opportunities to use SWAP, and the second part looks for blocks where that transformation was done and we declare identifiers that are/became unused. It did not match the code in graph.c because the pattern was basically: tmp = a; a = b; something = totally_different; b = tmp; Coccinelle can be told to ignore such unrelated code by adding "... when != tmp" etc. (which matches context lines that don't reference tmp), but that's slooow. (Perhaps I just did it wrong, though.) René