Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Find duplicate field initializations.  This has a high rate of false
0003 /// positives due to #ifdefs, which Coccinelle is not aware of in a structure
0004 /// initialization.
0005 ///
0006 // Confidence: Low
0007 // Copyright: (C) 2010-2012 Nicolas Palix.
0008 // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
0009 // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
0010 // URL: https://coccinelle.gitlabpages.inria.fr/website
0011 // Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
0012 // Options: --no-includes --include-headers
0013 
0014 virtual org
0015 virtual report
0016 
0017 @r@
0018 identifier I, s, fld;
0019 position p0,p;
0020 expression E;
0021 @@
0022 
0023 struct I s =@p0 { ..., .fld@p = E, ...};
0024 
0025 @s@
0026 identifier I, s, r.fld;
0027 position r.p0,p;
0028 expression E;
0029 @@
0030 
0031 struct I s =@p0 { ..., .fld@p = E, ...};
0032 
0033 @script:python depends on org@
0034 p0 << r.p0;
0035 fld << r.fld;
0036 ps << s.p;
0037 pr << r.p;
0038 @@
0039 
0040 if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
0041   cocci.print_main(fld,p0)
0042   cocci.print_secs("s",ps)
0043   cocci.print_secs("r",pr)
0044 
0045 @script:python depends on report@
0046 p0 << r.p0;
0047 fld << r.fld;
0048 ps << s.p;
0049 pr << r.p;
0050 @@
0051 
0052 if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
0053   msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line)
0054   coccilib.report.print_report(p0[0],msg)