3 # Generate a Coccinelle semantic patch to remove pointless QOM cast.
7 # $ qom-cast-macro-clean-cocci-gen.py $(git ls-files) > qom_pointless_cast.cocci
9 # --macro-file scripts/cocci-macro-file.h \
10 # --sp-file qom_pointless_cast.cocci \
16 # SPDX-FileContributor: Philippe Mathieu-Daudé <philmd@linaro.org>
17 # SPDX-FileCopyrightText: 2023 Linaro Ltd.
18 # SPDX-License-Identifier: GPL-2.0-or-later
23 assert len(sys
.argv
) > 0
25 def print_cocci_rule(qom_typedef
, qom_cast_macro
):
27 typedef {qom_typedef};
30 - {qom_cast_macro}(obj)
35 r
'DECLARE_INSTANCE_CHECKER\((\w+),\W*(\w+),\W*TYPE_\w+\)',
36 r
'DECLARE_OBJ_CHECKERS\((\w+),\W*\w+,\W*(\w+),\W*TYPE_\w+\)',
37 r
'OBJECT_DECLARE_TYPE\((\w+),\W*\w+,\W*(\w+)\)',
38 r
'OBJECT_DECLARE_SIMPLE_TYPE\((\w+),\W*(\w+)\)',
39 r
'INTERFACE_CHECK\((\w+),\W*\(\w+\),\W*TYPE_(\w+)\)',
42 for fn
in sys
.argv
[1:]:
44 content
= open(fn
, 'rt').read()
47 for pattern
in patterns
:
48 for match
in re
.findall(pattern
, content
):
49 print_cocci_rule(match
[0], match
[1])