Debian Codegraph @

tools/spgen/examples/context_.cocci

raw
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 /// A generated context rule! This is a Coccinelle script that tests the use of
6 /// the local function metavariable type in SmPL. This comment is longer than
7 /// 80 characters, so it will be split.
8 ///
9 // Confidence: Low
10
11 virtual context
12 virtual org
13 virtual report
14
15 // ----------------------------------------------------------------------------
16
17 @localf depends on context || org || report@
18 identifier m, x, y;
19 local function f;
20 position j0, j1, j2;
21 @@
22
23 f@j0(
24 * int x,
25 int y
26 ) {
27 int m@j1 = x * y;
28 ...
29 return m@j2;
30 }
31
32 // ----------------------------------------------------------------------------
33
34 @script:python localf_org depends on org@
35 x << localf.x;
36 y << localf.y;
37 j0 << localf.j0;
38 j1 << localf.j1;
39 j2 << localf.j2;
40 @@
41
42 msg = "Found a function with arguments %s and %s that multiplies its arguments " % (x,y)
43 coccilib.org.print_safe_todo(j0[0], msg)
44 coccilib.org.print_link(j1[0], "")
45 coccilib.org.print_link(j2[0], "")
46
47 // ----------------------------------------------------------------------------
48
49 @script:python localf_report depends on report@
50 x << localf.x;
51 y << localf.y;
52 j0 << localf.j0;
53 j1 << localf.j1;
54 j2 << localf.j2;
55 @@
56
57 msg = "ERROR: Found a function with arguments %s and %s that are multiplied around lines %s,%s." % (x,y,j1[0].line,j2[0].line)
58 coccilib.report.print_report(j0[0], msg)
59