瀏覽代碼

function_call_termination_condition.cocci: add a patch mode.

Cyril Roelandt 13 年之前
父節點
當前提交
795aab35ea

+ 29 - 19
tools/dev/experimental/function_call_termination_condition.cocci

@@ -1,7 +1,7 @@
 /*
  * StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2012 INRIA
+ * Copyright (C) 2012 inria
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -25,49 +25,59 @@
  * unsigned int max = foo(...);
  * for (i = 0; i < max; i++) { ... }
  *
- * This semantic patch does not automagically generate a patch, but still
- * points out that kind of code so that it can be fixed (if necesary) by
- * programmers.
  */
 
-/*
- * You may want to run spatch(1) with either -D report or -D org.
- * Otherwise, a context output will be generated.
- */
-virtual report
+virtual context
 virtual org 
+virtual patch
+virtual report
 
 @initialize:python depends on report || org@
 msg="Function call in the termination condition of a for loop"
 
 @r@
+type t;
 identifier f;
 identifier it; 
-expression E;
+expression E1;
 position p;
 @@
-for (it = E; it < f@p(...); ...)
+t it;
+...
+for@p (it = E1; it < f(...); ...)
 {
 ...
 }
 
-@script:python depends on r && report@
-p << r.p;
+@depends on r && context@
+identifier r.f;
+identifier r.it;
+expression r.E1;
 @@
-coccilib.report.print_report(p[0], msg)
+* for (it = E1; it < f(...); ...)
+{
+...
+}
 
 @script:python depends on r && org@
 p << r.p;
 @@
-msg="Function call in the termination condition of a for loop"
 coccilib.org.print_todo(p[0], msg)
 
-@depends on !report && !org && r@
-identifier r.f;
+@depends on r && patch@
+type r.t;
+expression r.E1, E2, E3;
 identifier r.it;
-expression r.E;
+position r.p;
 @@
-* for (it = E; it < f(...); ...)
+-for@p(it = E1; it < E3; E2) 
++t max = E3;
++for(it = E1; i < max; E2) 
 {
 ...
 }
+
+@script:python depends on r && report@
+p << r.p;
+@@
+coccilib.report.print_report(p[0], msg)

+ 7 - 9
tools/dev/experimental/function_call_termination_condition_test.c

@@ -18,19 +18,14 @@ void
 bad_1(void)
 {
 	int i;
-	for (i = 0; i < bar(); i++)
+	for (i = 0; i < bar(a,b); i++)
 	{
 		do_stg();
 	}
-}
 
-void
-bad_2(void)
-{
-	int i;
-	for (i = foo(); i < bar(); i++)
+	for (i = 0; i < foo(); i++)
 	{
-		do_stg();
+		do_stg_else();
 	}
 }
 
@@ -38,6 +33,9 @@ void
 good_1(void)
 {
 	int i, max;
-	for (i = foo(), max = bar(); i < max; i++)
+	max = bar();
+	for (i = foo(); i < max; i++)
+	{
 		do_stg();
+	}
 }