Coccinelle: Script to remove unnecessary static on local variables
PATCH 1/1 Coccinelle: Script to remove unnecessary static on local variables
Coccinelle script to remove unnecessary static on local variables when the variables are not used before update.
Signed-off-by Gustavo A. R. Silva <[email protected]>
--- scripts/coccinelle/misc/static_unnecessary.cocci | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/coccinelle/misc/static_unnecessary.cocci
scripts/coccinelle/misc/static_unnecessary.cocci new file +89 -0
@@ -0,0 +1,89 @@ +/// Drop static on local variable when the variable is not used before update. +//# NOTE: Be aware that if a large object is initialized all at once, it might +//# not be wise to remove the static because that would increase the risk of a +//# stack overflow. +/// +// Confidence: Moderate +// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2. +// Copyright: (C) 2017 Gustavo A. R. Silva, Core Infrastructure Initiative. +// Copyright: (C) 2017 GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Options: --no-includes --include-headers +// Keywords: static + +virtual patch +virtual context +virtual org +virtual report + +// <smpl> + at bad exists@ +position p; +identifier x; +expression e; +type T; +@@ + +static T x at p; +... when != x = e +x = <+...x...+> + + at worse exists@ +position p; +identifier x; +type T; +@@ + +static T x at p; +... + &x + + at modify depends on patch && !context && !org && !report@ +identifier x; +expression e; +type T; +position p != {bad.p,worse.p}; +@@ + +-static + T x at p; + ... when != x + when strict +?x = e; +// </smpl> + + +// ---------------------------------------------------------------------------- + + at modify_context depends on !patch && (context || org || report) forall@ +type T; +identifier x; +expression e; +position p != {bad.p,worse.p}; +position j0; +@@ + +* static + T x at j0@p; + ... when != x + when strict +?x = e; + +// ---------------------------------------------------------------------------- + + at script:python modify_org depends on org@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.org.print_todo(j0[0], msg) + +// ---------------------------------------------------------------------------- + +@script:python modify_report depends on report@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.report.print_report(j0[0], msg) +
Signature · 1 line
2.5.0
Quoted 4 lines · Gustavo A. R. Silva
Coccinelle script to remove unnecessary static on local variables when the variables are not used before update.
Signed-off-by Gustavo A. R. Silva <[email protected]>
Acked-by Julia Lawall <[email protected]>
Quoted 104 lines
--- scripts/coccinelle/misc/static_unnecessary.cocci | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/coccinelle/misc/static_unnecessary.cocciscripts/coccinelle/misc/static_unnecessary.cocci new file +89
-1@@ -0,0 +1,89 @@ +/// Drop static on local variable when the variable is not used before update. +//# NOTE: Be aware that if a large object is initialized all at once, it might +//# not be wise to remove the static because that would increase the risk of a +//# stack overflow. +/// +// Confidence: Moderate +// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2. +// Copyright: (C) 2017 Gustavo A. R. Silva, Core Infrastructure Initiative. +// Copyright: (C) 2017 GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Options: --no-includes --include-headers +// Keywords: static + +virtual patch +virtual context +virtual org +virtual report + +// <smpl> + at bad exists@ +position p; +identifier x; +expression e; +type T; +@@ + +static T x at p; +... when != x = e +x = <+...x...+> + + at worse exists@ +position p; +identifier x; +type T; +@@ + +static T x at p; +... + &x + + at modify depends on patch && !context && !org && !report@ +identifier x; +expression e; +type T; +position p != {bad.p,worse.p}; +@@ + +-static + T x at p; + ... when != x + when strict +?x = e; +// </smpl> + + +// ---------------------------------------------------------------------------- + + at modify_context depends on !patch && (context || org || report) forall@ +type T; +identifier x; +expression e; +position p != {bad.p,worse.p}; +position j0; +@@ + +* static + T x at j0@p; + ... when != x + when strict +?x = e; + +// ---------------------------------------------------------------------------- + + at script:python modify_org depends on org@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.org.print_todo(j0[0], msg) + +// ---------------------------------------------------------------------------- + + at script:python modify_report depends on report@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.report.print_report(j0[0], msg) + --2.5.0
PATCH v2 1/1 Coccinelle: Script to remove unnecessary static on local variables
In reply to Gustavo A. R. SilvaCoccinelle script to remove unnecessary static on local variables when the variables are not used before update.
Signed-off-by Gustavo A. R. Silva <[email protected]>
---
Changes in v2:
Update header and Copyright note.
scripts/coccinelle/misc/static_unnecessary.cocci | 96 ++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 scripts/coccinelle/misc/static_unnecessary.cocci
scripts/coccinelle/misc/static_unnecessary.cocci new file +96 -0
@@ -0,0 +1,96 @@ +/// Drop static on local variable when the variable is not used before update. +//# +//# Removing unnecessary static on local variables reduces the code +//# size and increases maintainability. +//# +//# On the other hand, even though it is rare, be aware that if a +//# large object is initialized all at once, it might not be wise +//# to remove the static because that would increase the risk of a +//# stack overflow. +/// +// Confidence: Moderate +// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Copyright: (C) 2017 Gustavo A. R. Silva. GPLv2. +// Work supported by a grant from +// The Linux Foundation's Core Infrastructure Initiative. +// URL: https://www.coreinfrastructure.org/ +// Options: --no-includes --include-headers +// Keywords: static + +virtual patch +virtual context +virtual org +virtual report + +// <smpl> + at bad exists@ +position p; +identifier x; +expression e; +type T; +@@ + +T x at p; +... when != x = e +x = <+...x...+> + + at worse exists@ +position p; +identifier x; +type T; +@@ + +T x at p; +... + &x + + at modify depends on patch && !context && !org && !report@ +identifier x; +expression e; +type T; +position p != {bad.p,worse.p}; +@@ + +-static + T x at p; + ... when != x + when strict +?x = e; +// </smpl> + + +// ---------------------------------------------------------------------------- + + at modify_context depends on !patch && (context || org || report) forall@ +type T; +identifier x; +expression e; +position p != {bad.p,worse.p}; +position j0; +@@ + +* static + T x at j0@p; + ... when != x + when strict +?x = e; + +// ---------------------------------------------------------------------------- + + at script:python modify_org depends on org@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.org.print_todo(j0[0], msg) + +// ---------------------------------------------------------------------------- + +@script:python modify_report depends on report@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.report.print_report(j0[0], msg) +
Signature · 1 line
2.5.0
Acked-by Julia Lawall <[email protected]>
Quoted 118 lines · Gustavo A. R. Silva
Coccinelle script to remove unnecessary static on local variables when the variables are not used before update.
Signed-off-by Gustavo A. R. Silva <[email protected]>---
Changes in v2:
Update header and Copyright note.scripts/coccinelle/misc/static_unnecessary.cocci | 96 ++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 scripts/coccinelle/misc/static_unnecessary.cocciscripts/coccinelle/misc/static_unnecessary.cocci new file +96
-1@@ -0,0 +1,96 @@ +/// Drop static on local variable when the variable is not used before update. +//# +//# Removing unnecessary static on local variables reduces the code +//# size and increases maintainability. +//# +//# On the other hand, even though it is rare, be aware that if a +//# large object is initialized all at once, it might not be wise +//# to remove the static because that would increase the risk of a +//# stack overflow. +/// +// Confidence: Moderate +// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Copyright: (C) 2017 Gustavo A. R. Silva. GPLv2. +// Work supported by a grant from +// The Linux Foundation's Core Infrastructure Initiative. +// URL: https://www.coreinfrastructure.org/ +// Options: --no-includes --include-headers +// Keywords: static + +virtual patch +virtual context +virtual org +virtual report + +// <smpl> + at bad exists@ +position p; +identifier x; +expression e; +type T; +@@ + +T x at p; +... when != x = e +x = <+...x...+> + + at worse exists@ +position p; +identifier x; +type T; +@@ + +T x at p; +... + &x + + at modify depends on patch && !context && !org && !report@ +identifier x; +expression e; +type T; +position p != {bad.p,worse.p}; +@@ + +-static + T x at p; + ... when != x + when strict +?x = e; +// </smpl> + + +// ---------------------------------------------------------------------------- + + at modify_context depends on !patch && (context || org || report) forall@ +type T; +identifier x; +expression e; +position p != {bad.p,worse.p}; +position j0; +@@ + +* static + T x at j0@p; + ... when != x + when strict +?x = e; + +// ---------------------------------------------------------------------------- + + at script:python modify_org depends on org@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.org.print_todo(j0[0], msg) + +// ---------------------------------------------------------------------------- + + at script:python modify_report depends on report@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.report.print_report(j0[0], msg) + --2.5.0