Skip to content

Commit

Permalink
scripts/coccinelle: Add script for counting identifier length
Browse files Browse the repository at this point in the history
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
pfl authored and nashif committed Apr 18, 2019
1 parent 3fa9093 commit 83de530
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 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.