Debian Codegraph @

tools/spgen/examples/inherited_.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 /// This is a Coccinelle script to test inheritance between rules.
6 //# Only works for functions with exact names f, g, h, hh.
7 //# Not really useful.
8 ///
9 // Confidence: High
10 // Copyright: (C) 2015 Author1, affiliation. License1
11 // Copyright: (C) 2015 Author2, affiliation. License2
12 // Copyright: (C) 2015 Author3.
13 // URL: http://coccinelle.lip6.fr/
14 // Comments: Additional comments.
15 // Options: --a-flag, --another-flag, --a-third-flag.
16 // Keywords: inheritance, test.
17
18 virtual patch
19 virtual context
20 virtual org
21 virtual report
22
23 @r@
24 expression x;
25 @@
26
27 (
28 f(x);
29 |
30 g(1);
31 )
32
33 @rule_h depends on patch && !context && !org && !report@
34 expression r.x;
35 @@
36
37 - h(x);
38 + hh(x);
39
40
41 @rule_h2 depends on patch && !context && !org && !report@
42 expression r.x;
43 @@
44 - h2(x);
45 + hh22(x);
46
47 @rule_0 depends on patch && !context && !org && !report@
48 @@
49
50 - foo(1);
51 + bar(1);
52
53 // ----------------------------------------------------------------------------
54
55 @rule_h_context depends on !patch && (context || org || report)@
56 expression r.x;
57 position j0;
58 @@
59
60 * h@j0(x);
61
62 @rule_h2_context depends on !patch && (context || org || report)@
63 expression r.x;
64 position j0;
65 @@
66
67 * h2@j0(x);
68
69 @rule_0_context depends on !patch && (context || org || report)@
70 position j0;
71 @@
72
73 * foo@j0(1);
74
75 // ----------------------------------------------------------------------------
76
77 @script:python rule_h_org depends on org@
78 x << r.x;
79 j0 << rule_h_context.j0;
80 @@
81
82 msg = "Replace call to h with call to hh on expression %s. " % (x)
83 coccilib.org.print_safe_todo(j0[0], msg)
84
85 @script:python rule_h2_org depends on org@
86 j0 << rule_h2_context.j0;
87 @@
88
89 msg = "This is a message for rule_h2 in org mode.."
90 coccilib.org.print_todo(j0[0], msg)
91
92 @script:python rule_0_org depends on org@
93 j0 << rule_0_context.j0;
94 @@
95
96 msg = "found a match around here ...."
97 coccilib.org.print_todo(j0[0], msg)
98
99 // ----------------------------------------------------------------------------
100
101 @script:python rule_h_report depends on report@
102 x << r.x;
103 j0 << rule_h_context.j0;
104 @@
105
106 msg = "Replace call to h with call to hh on expression %s. " % (x)
107 coccilib.report.print_report(j0[0], msg)
108
109 @script:python rule_h2_report depends on report@
110 j0 << rule_h2_context.j0;
111 @@
112
113 msg = "This is a message for rule_h2 in report mode.."
114 coccilib.report.print_report(j0[0], msg)
115
116 @script:python rule_0_report depends on report@
117 j0 << rule_0_context.j0;
118 @@
119
120 msg = "found a match around here ...."
121 coccilib.report.print_report(j0[0], msg)
122