| 1 |
// This file is part of Coccinelle, lincensed under the terms of the GPL v2. |
| 2 |
// See copyright.txt in the Coccinelle source code for more information. |
| 3 |
// The Coccinelle source code can be obtained at http://coccinelle.lip6.fr |
| 4 |
|
| 5 |
/// Description for the disj script. |
| 6 |
//# This is a limitation. |
| 7 |
//# This is another limitation. |
| 8 |
/// |
| 9 |
// Confidence: Moderate |
| 10 |
// Comments: This is to test disjunction generation. |
| 11 |
|
| 12 |
virtual patch |
| 13 |
virtual context |
| 14 |
virtual org |
| 15 |
virtual report |
| 16 |
|
| 17 |
@disj depends on patch && !context && !org && !report@ |
| 18 |
expression E1, E2, E3; |
| 19 |
identifier x; |
| 20 |
@@ |
| 21 |
|
| 22 |
if (E2 < |
| 23 |
- E3 |
| 24 |
+ E1 |
| 25 |
) { ... |
| 26 |
( |
| 27 |
some_function(0); |
| 28 |
x = 30; |
| 29 |
| |
| 30 |
some_function(1); |
| 31 |
x = 30; |
| 32 |
| |
| 33 |
- this(E1); |
| 34 |
+ that(E2); |
| 35 |
| |
| 36 |
- some_function(E1) |
| 37 |
+ another_function(E2) |
| 38 |
; |
| 39 |
- x = 30; |
| 40 |
) |
| 41 |
... } |
| 42 |
|
| 43 |
// ---------------------------------------------------------------------------- |
| 44 |
|
| 45 |
@disj_context depends on !patch && (context || org || report) exists@ |
| 46 |
identifier x; |
| 47 |
expression E1, E2, E3; |
| 48 |
position j0, j1; |
| 49 |
@@ |
| 50 |
|
| 51 |
if (E2@j0 < |
| 52 |
E3 |
| 53 |
) { ... |
| 54 |
( |
| 55 |
some_function(0); |
| 56 |
x = 30; |
| 57 |
| |
| 58 |
some_function(1); |
| 59 |
x = 30; |
| 60 |
| |
| 61 |
this@j1(E1); |
| 62 |
| |
| 63 |
some_function@j1(E1) |
| 64 |
; |
| 65 |
x = 30; |
| 66 |
) |
| 67 |
... } |
| 68 |
|
| 69 |
@disj_disj depends on !patch && (context || org || report)@ |
| 70 |
identifier x; |
| 71 |
expression E1, E2, E3; |
| 72 |
position disj_context.j0, disj_context.j1; |
| 73 |
@@ |
| 74 |
|
| 75 |
if (E2@j0 < |
| 76 |
* E3 |
| 77 |
) { ... |
| 78 |
( |
| 79 |
* this@j1(E1); |
| 80 |
| |
| 81 |
* some_function@j1(E1) |
| 82 |
; |
| 83 |
* x = 30; |
| 84 |
) |
| 85 |
... } |
| 86 |
|
| 87 |
// ---------------------------------------------------------------------------- |
| 88 |
|
| 89 |
@script:python disj_org depends on org@ |
| 90 |
j0 << disj_context.j0; |
| 91 |
j1 << disj_context.j1; |
| 92 |
@@ |
| 93 |
|
| 94 |
msg = "Org message. Found a match in disj rule.." |
| 95 |
coccilib.org.print_todo(j0[0], msg) |
| 96 |
coccilib.org.print_link(j1[0], "") |
| 97 |
|
| 98 |
// ---------------------------------------------------------------------------- |
| 99 |
|
| 100 |
@script:python disj_report depends on report@ |
| 101 |
E1 << disj_context.E1; |
| 102 |
E2 << disj_context.E2; |
| 103 |
j0 << disj_context.j0; |
| 104 |
j1 << disj_context.j1; |
| 105 |
@@ |
| 106 |
|
| 107 |
msg = "Report message. Remove call to this(%s) and replace with call to that(%s) around line %s." % (E1,E2,j1[0].line) |
| 108 |
coccilib.report.print_report(j0[0], msg) |
| 109 |
|