From patchwork Tue Jun 6 05:56:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 689683 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp2462146wru; Mon, 5 Jun 2023 23:00:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gxCffrHu0JMXxOregR5+pmuu7gDBMb18m6EdCBAp8K2/SgpzWwAOHp/FLzMuFp1dOKQ7s X-Received: by 2002:ad4:5b85:0:b0:626:1b13:34a9 with SMTP id 5-20020ad45b85000000b006261b1334a9mr995506qvp.54.1686031210500; Mon, 05 Jun 2023 23:00:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686031210; cv=none; d=google.com; s=arc-20160816; b=FwPsCbL+oxGh7EddjewdKpQ2jxP3yb9Xx5OA64Tn0zNRws/Eu/0+jD0y/kmQGMY1fZ JNQiSj9OebQsIn704hbrKm/i/Zdu2jq7d3DKHTTFHfq80sKf9oBZBPriYY1CBYXW2zho qI0+rB5PYTsA9ofR6HFC2jmbgkfjLlueHP4AOeF63sUZE1mQB7OUOv8RPpNm1PhZXGF9 /oryIN3QylhIn21j66kD0lvA1DACJ0v6QX+QvucSoaKSDFBXhkDdTQm4YbJrrAQesaTr ouYAxVo9isoLi5FjWoK1njSYxsX6VruS/VDSvSDQGKBnMgIzIwpVfkMdTIWSn4EU6X/W FSMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DMQO0TnJoS6hEZikAOD2aAaF6PaDGIaaThsJFz5o7vI=; b=PaXWOeOQYHiyJW0SCsk2BLHc7URGE0/73UgHwirTpMm6y/VGNM7J8LF60JU88jWLJj sV039ZZo71brp/cZtvLJ+L6hXZ8nNM2sQx9BhZOKzm5mPHO2/o0NK2ntZ3+XqS249jWi WTAgiqIQDbOaU5QFWica6iwOocvxKVQUbB6kLOmI7YW6YDbb8M+tpdirSPq95s2NMU9B JIPrCd8GmJ4EUjP65EPViDInAsYL3C4V0lptyQ5mb4jNeBGLMz5IgKat1jBYDhczdTJI wG9cRj22Ukn/YCO0nj2WIeKohqAI4OHCzMF+h7yqsLgU90fA9fjalYr80ITv3YVVZZ/A J4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MsNbc7p3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gw11-20020a0562140f0b00b00571bb7c3c01si5914058qvb.337.2023.06.05.23.00.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Jun 2023 23:00:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MsNbc7p3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6Pga-0004rq-3h; Tue, 06 Jun 2023 01:56:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6PgY-0004r9-6D for qemu-devel@nongnu.org; Tue, 06 Jun 2023 01:56:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q6PgW-0004Ag-HM for qemu-devel@nongnu.org; Tue, 06 Jun 2023 01:56:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686031007; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DMQO0TnJoS6hEZikAOD2aAaF6PaDGIaaThsJFz5o7vI=; b=MsNbc7p3/Hgv+wM7PY220sJ64QbuzPyFck7KZVFWdZ69Lyte/Or68UJrpLx1l9ylW+zW2B RTGjxMWq5b3jiJ7JhLN24ufgv8yFbuNaErc5bYRDMWu6o6tihMgnt7X5JTL5HkKlzhoCFz Wcup+w73j8wn9bXlTca604ZMslge7rg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-1xvoFSsmMW2PJEnt90HCkQ-1; Tue, 06 Jun 2023 01:56:44 -0400 X-MC-Unique: 1xvoFSsmMW2PJEnt90HCkQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C84585A5AA; Tue, 6 Jun 2023 05:56:44 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 249712166B25; Tue, 6 Jun 2023 05:56:43 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org, Richard Henderson Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Markus Armbruster Subject: [PULL 13/18] scripts: Add qom-cast-macro-clean-cocci-gen.py Date: Tue, 6 Jun 2023 07:56:16 +0200 Message-Id: <20230606055621.523175-14-thuth@redhat.com> In-Reply-To: <20230606055621.523175-1-thuth@redhat.com> References: <20230606055621.523175-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Add a script to generate Coccinelle semantic patch removing all pointless QOM cast macro uses. Suggested-by: Markus Armbruster Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20230601093452.38972-2-philmd@linaro.org> Reviewed-by: Richard Henderson Signed-off-by: Thomas Huth --- MAINTAINERS | 1 + scripts/qom-cast-macro-clean-cocci-gen.py | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 scripts/qom-cast-macro-clean-cocci-gen.py diff --git a/MAINTAINERS b/MAINTAINERS index 89f274f85e..b2137111f1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3045,6 +3045,7 @@ F: include/qom/ F: qapi/qom.json F: qapi/qdev.json F: scripts/coccinelle/qom-parent-type.cocci +F: scripts/qom-cast-macro-clean-cocci-gen.py F: softmmu/qdev-monitor.c F: stubs/qdev.c F: qom/ diff --git a/scripts/qom-cast-macro-clean-cocci-gen.py b/scripts/qom-cast-macro-clean-cocci-gen.py new file mode 100644 index 0000000000..2fa8438a14 --- /dev/null +++ b/scripts/qom-cast-macro-clean-cocci-gen.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Generate a Coccinelle semantic patch to remove pointless QOM cast. +# +# Usage: +# +# $ qom-cast-macro-clean-cocci-gen.py $(git ls-files) > qom_pointless_cast.cocci +# $ spatch \ +# --macro-file scripts/cocci-macro-file.h \ +# --sp-file qom_pointless_cast.cocci \ +# --keep-comments \ +# --use-gitgrep \ +# --in-place \ +# --dir . +# +# SPDX-FileContributor: Philippe Mathieu-Daudé +# SPDX-FileCopyrightText: 2023 Linaro Ltd. +# SPDX-License-Identifier: GPL-2.0-or-later + +import re +import sys + +assert len(sys.argv) > 0 + +def print_cocci_rule(qom_typedef, qom_cast_macro): + print(f'''@@ +typedef {qom_typedef}; +{qom_typedef} *obj; +@@ +- {qom_cast_macro}(obj) ++ obj +''') + +patterns = [ + r'DECLARE_INSTANCE_CHECKER\((\w+),\W*(\w+),\W*TYPE_\w+\)', + r'DECLARE_OBJ_CHECKERS\((\w+),\W*\w+,\W*(\w+),\W*TYPE_\w+\)', + r'OBJECT_DECLARE_TYPE\((\w+),\W*\w+,\W*(\w+)\)', + r'OBJECT_DECLARE_SIMPLE_TYPE\((\w+),\W*(\w+)\)', + r'INTERFACE_CHECK\((\w+),\W*\(\w+\),\W*TYPE_(\w+)\)', +] + +for fn in sys.argv[1:]: + try: + content = open(fn, 'rt').read() + except: + continue + for pattern in patterns: + for match in re.findall(pattern, content): + print_cocci_rule(match[0], match[1])