Skip to content
Permalink
Browse files

scripts/coccinelle: Add script for counting identifier length

Add a simple Coccinelle script that counts identifier lengths and
prints out a warning if it is longer than 31 characters.

The script can be run with:
spatch -D report --very-quiet \
--include-headers --recursive-includes \
--cocci-file $ZEPHYR_BASE/scripts/coccinelle/identifier_length.cocci \
--dir $ZEPHYR_BASE \
kernel/

Where '--include-headers' and '--recursive-includes' can be omitted
if neede.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
  • Loading branch information...
Patrik Flykt authored and nashif committed Mar 5, 2019
1 parent 3fa9093 commit 83de530d5a36c3399cc9575d9a61e3a532dc29ba
Showing with 30 additions and 0 deletions.
  1. +30 −0 scripts/coccinelle/identifier_length.cocci
@@ -0,0 +1,30 @@
// Copyright: (C) 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

virtual report

@r_idlen@
type T;
identifier I;
constant C;
position p;
@@

(
T I@p (...);
|
I@p (...)
|
T I@p = C;
|
T I@p;
)

@script:python depends on report@
id << r_idlen.I;
pos << r_idlen.p;
@@

if (len(id) > 31):
msg="WARNING: Identifier %s length %d > 31" % (id, len(id))
coccilib.report.print_report(pos[0], msg)

0 comments on commit 83de530

Please sign in to comment.
You can’t perform that action at this time.