1/// Move constants to the right of binary operators. 2//# Depends on personal taste in some cases. 3/// 4// Confidence: Moderate 5// Copyright: (C) 2015 Copyright: (C) 2015 Julia Lawall, Inria. GPLv2. 6// URL: http://coccinelle.lip6.fr/ 7// Options: --no-includes --include-headers 8 9virtual patch 10virtual context 11virtual org 12virtual report 13 14@r1 depends on patch && !context && !org && !report 15 disable bitor_comm, neg_if_exp@ 16constant c,c1; 17local idexpression i; 18expression e,e1,e2; 19binary operator b = {==,!=,&,|}; 20type t; 21@@ 22 23( 24c b (c1) 25| 26sizeof(t) b e1 27| 28sizeof e b e1 29| 30i b e1 31| 32c | e1 | e2 | ... 33| 34c | (e ? e1 : e2) 35| 36- c 37+ e 38b 39- e 40+ c 41) 42 43@r2 depends on patch && !context && !org && !report 44 disable gtr_lss, gtr_lss_eq, not_int2@ 45constant c,c1; 46expression e,e1,e2; 47binary operator b; 48binary operator b1 = {<,<=},b2 = {<,<=}; 49binary operator b3 = {>,>=},b4 = {>,>=}; 50local idexpression i; 51type t; 52@@ 53 54( 55c b c1 56| 57sizeof(t) b e1 58| 59sizeof e b e1 60| 61 (e1 b1 e) && (e b2 e2) 62| 63 (e1 b3 e) && (e b4 e2) 64| 65i b e 66| 67- c < e 68+ e > c 69| 70- c <= e 71+ e >= c 72| 73- c > e 74+ e < c 75| 76- c >= e 77+ e <= c 78) 79 80// ---------------------------------------------------------------------------- 81 82@r1_context depends on !patch && (context || org || report) 83 disable bitor_comm, neg_if_exp exists@ 84type t; 85binary operator b = {==,!=,&,|}; 86constant c, c1; 87expression e, e1, e2; 88local idexpression i; 89position j0; 90@@ 91 92( 93c b (c1) 94| 95sizeof(t) b e1 96| 97sizeof e b e1 98| 99i b e1 100| 101c | e1 | e2 | ... 102| 103c | (e ? e1 : e2) 104| 105* c@j0 b e 106) 107 108@r2_context depends on !patch && (context || org || report) 109 disable gtr_lss, gtr_lss_eq, not_int2 exists@ 110type t; 111binary operator b, b1 = {<,<=}, b2 = {<,<=}, b3 = {>,>=}, b4 = {>,>=}; 112constant c, c1; 113expression e, e1, e2; 114local idexpression i; 115position j0; 116@@ 117 118( 119c b c1 120| 121sizeof(t) b e1 122| 123sizeof e b e1 124| 125 (e1 b1 e) && (e b2 e2) 126| 127 (e1 b3 e) && (e b4 e2) 128| 129i b e 130| 131* c@j0 < e 132| 133* c@j0 <= e 134| 135* c@j0 > e 136| 137* c@j0 >= e 138) 139 140// ---------------------------------------------------------------------------- 141 142@script:python r1_org depends on org@ 143j0 << r1_context.j0; 144@@ 145 146msg = "Move constant to right." 147coccilib.org.print_todo(j0[0], msg) 148 149@script:python r2_org depends on org@ 150j0 << r2_context.j0; 151@@ 152 153msg = "Move constant to right." 154coccilib.org.print_todo(j0[0], msg) 155 156// ---------------------------------------------------------------------------- 157 158@script:python r1_report depends on report@ 159j0 << r1_context.j0; 160@@ 161 162msg = "Move constant to right." 163coccilib.report.print_report(j0[0], msg) 164 165@script:python r2_report depends on report@ 166j0 << r2_context.j0; 167@@ 168 169msg = "Move constant to right." 170coccilib.report.print_report(j0[0], msg) 171 172