149ab7a39SNicolas Palix/// Find confusingly indented code in or after an if. An if branch should 249ab7a39SNicolas Palix/// be indented. The code following an if should not be indented. 349ab7a39SNicolas Palix/// Sometimes, code after an if that is indented is actually intended to be 449ab7a39SNicolas Palix/// part of the if branch. 549ab7a39SNicolas Palix/// 649ab7a39SNicolas Palix/// This has a high rate of false positives, because Coccinelle's column 749ab7a39SNicolas Palix/// calculation does not distinguish between spaces and tabs, so code that 849ab7a39SNicolas Palix/// is not visually aligned may be considered to be in the same column. 949ab7a39SNicolas Palix/// 1049ab7a39SNicolas Palix// Confidence: Low 1149ab7a39SNicolas Palix// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. 1249ab7a39SNicolas Palix// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. 1349ab7a39SNicolas Palix// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 1449ab7a39SNicolas Palix// URL: http://coccinelle.lip6.fr/ 1549ab7a39SNicolas Palix// Comments: 16*93f14468SNicolas Palix// Options: --no-includes --include-headers 1749ab7a39SNicolas Palix 1849ab7a39SNicolas Palixvirtual org 1949ab7a39SNicolas Palixvirtual report 2049ab7a39SNicolas Palix 2149ab7a39SNicolas Palix@r disable braces4@ 2249ab7a39SNicolas Palixposition p1,p2; 2349ab7a39SNicolas Palixstatement S1,S2; 2449ab7a39SNicolas Palix@@ 2549ab7a39SNicolas Palix 2649ab7a39SNicolas Palix( 2749ab7a39SNicolas Palixif (...) { ... } 2849ab7a39SNicolas Palix| 2949ab7a39SNicolas Palixif (...) S1@p1 S2@p2 3049ab7a39SNicolas Palix) 3149ab7a39SNicolas Palix 3249ab7a39SNicolas Palix@script:python depends on org@ 3349ab7a39SNicolas Palixp1 << r.p1; 3449ab7a39SNicolas Palixp2 << r.p2; 3549ab7a39SNicolas Palix@@ 3649ab7a39SNicolas Palix 3749ab7a39SNicolas Palixif (p1[0].column == p2[0].column): 3849ab7a39SNicolas Palix cocci.print_main("branch",p1) 3949ab7a39SNicolas Palix cocci.print_secs("after",p2) 4049ab7a39SNicolas Palix 4149ab7a39SNicolas Palix@script:python depends on report@ 4249ab7a39SNicolas Palixp1 << r.p1; 4349ab7a39SNicolas Palixp2 << r.p2; 4449ab7a39SNicolas Palix@@ 4549ab7a39SNicolas Palix 4649ab7a39SNicolas Palixif (p1[0].column == p2[0].column): 4749ab7a39SNicolas Palix msg = "code aligned with following code on line %s" % (p2[0].line) 4849ab7a39SNicolas Palix coccilib.report.print_report(p1[0],msg) 49