[22/33] cocci: Split min()/max() rules out

Submitted by Lyude Paul on June 7, 2019, 11:08 p.m.

Details

Message ID 20190607230821.4488-22-lyude@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 2 1 ) in IGT - Trybot

Not browsing as part of any series.

Commit Message

Lyude Paul June 7, 2019, 11:08 p.m.
From: Lyude Paul <lyude@redhat.com>

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 scripts/cocci/igt.cocci         | 41 ------------------------------
 scripts/cocci/igt_min_max.cocci | 44 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 41 deletions(-)
 create mode 100644 scripts/cocci/igt_min_max.cocci

Patch hide | download patch | download mbox

diff --git a/scripts/cocci/igt.cocci b/scripts/cocci/igt.cocci
index ef3a5a40..7a369a6a 100644
--- a/scripts/cocci/igt.cocci
+++ b/scripts/cocci/igt.cocci
@@ -31,47 +31,6 @@  def warn_cmp_macro(p, type_prefix, op, e1, e2):
     msg = 'WARNING: igt_assert_%s%s(%s, %s) should be used instead' % args
     coccilib.report.print_report(p[0], msg)
 
-// So we don't complain about #define min(), #define max(), etc.
-@min_max_ignore@
-identifier i =~ "^m(in|ax)$";
-expression E;
-position p;
-@@
-#define i(...) <+...E@p...+>
-
-// Replace open-coded min/max()
-@depends on patch@
-position p != min_max_ignore.p;
-expression a;
-expression b;
-binary operator lt_op = {<,<=};
-binary operator gt_op = {>,>=};
-@@
-(
-- ((a) lt_op (b) ? (a) : (b@p))
-+ min(a, b)
-|
-- ((a) gt_op (b) ? (a) : (b@p))
-+ max(a, b)
-)
-
-@no_opencoded_min_max_report depends on report@
-position p != min_max_ignore.p;
-expression a, b;
-binary operator op = {<,<=,>,>=};
-@@
- (a op b) ? a : b@p
-
-@script:python depends on report@
-a << no_opencoded_min_max_report.a;
-b << no_opencoded_min_max_report.b;
-p << no_opencoded_min_max_report.p;
-op << no_opencoded_min_max_report.op;
-@@
-should_use = "min" if op.strip().startswith("<") else "max"
-msg = "WARNING: %s(%s, %s) should be used instead" % (should_use, a, b)
-coccilib.report.print_report(p[0], msg)
-
 // Use comparison macros instead of raw igt_assert when possible
 @depends on patch@
 typedef uint32_t;
diff --git a/scripts/cocci/igt_min_max.cocci b/scripts/cocci/igt_min_max.cocci
new file mode 100644
index 00000000..f525428c
--- /dev/null
+++ b/scripts/cocci/igt_min_max.cocci
@@ -0,0 +1,44 @@ 
+// Enforce usage of min/max() macros
+
+virtual report
+virtual patch
+
+// So we don't complain about #define min(), #define max(), etc.
+@min_max_ignore@
+identifier i =~ "^m(in|ax)$";
+expression E;
+position p;
+@@
+#define i(...) <+...E@p...+>
+
+@depends on patch@
+position p != min_max_ignore.p;
+expression a;
+expression b;
+binary operator lt_op = {<,<=};
+binary operator gt_op = {>,>=};
+@@
+(
+- ((a) lt_op (b) ? (a) : (b@p))
++ min(a, b)
+|
+- ((a) gt_op (b) ? (a) : (b@p))
++ max(a, b)
+)
+
+@no_opencoded_min_max_report depends on report@
+position p != min_max_ignore.p;
+expression a, b;
+binary operator op = {<,<=,>,>=};
+@@
+ (a op b) ? a : b@p
+
+@script:python depends on report@
+a << no_opencoded_min_max_report.a;
+b << no_opencoded_min_max_report.b;
+p << no_opencoded_min_max_report.p;
+op << no_opencoded_min_max_report.op;
+@@
+should_use = "min" if op.strip().startswith("<") else "max"
+msg = "WARNING: %s(%s, %s) should be used instead" % (should_use, a, b)
+coccilib.report.print_report(p[0], msg)