permit multiline comments and strings in macros
[bpt/coccinelle.git] / demos / iteration.cocci
CommitLineData
3a314143
C
1// run with the options -no_show_diff and -dir {directory}
2
3virtual after_start
4
5@initialize:ocaml@
6
7let tbl = Hashtbl.create(100)
8
9let add_if_not_present from f file =
10try let _ = Hashtbl.find tbl (f,file) in ()
11with Not_found ->
12 Hashtbl.add tbl (f,file) file;
13 let it = new iteration() in
14 (match file with
15 Some fl -> it#set_files [fl]
16 | None -> ());
17 it#add_virtual_rule After_start;
18 it#add_virtual_identifier Err_ptr_function f;
19 it#register()
20
21@r depends on !after_start exists@
22identifier fn;
23position p;
24@@
25
26fn@p(...) { <+... return (ERR_PTR(...)); ...+> }
27
28@statfns@
29identifier r.fn;
30position r.p;
31@@
32
33static fn@p(...) { ... }
34
35@script:ocaml depends on statfns@
36fn << r.fn;
37p << r.p;
38@@
39
40add_if_not_present "ERR_PTR" fn (Some ((List.hd p).file))
41
42@script:ocaml depends on !statfns@
43fn << r.fn;
44p << r.p;
45@@
46
47add_if_not_present "ERR_PTR" fn None
48
49// -----------------------------------------------------------------------
50// iterate
51
52@s depends on after_start exists@
53identifier virtual.err_ptr_function, fn;
54position p;
55@@
56
57fn@p(...) { <+... return err_ptr_function(...); ...+> }
58
59@statfns_call@
60identifier s.fn;
61position s.p;
62@@
63
64static fn@p(...) { ... }
65
66@script:ocaml depends on statfns_call@
67fn << s.fn;
68p << s.p;
69err_ptr_function << virtual.err_ptr_function;
70@@
71
72add_if_not_present err_ptr_function fn (Some ((List.hd p).file))
73
74@script:ocaml depends on !statfns_call@
75fn << s.fn;
76p << s.p;
77err_ptr_function << virtual.err_ptr_function;
78@@
79
80add_if_not_present err_ptr_function fn None
81
82// -----------------------------------------------------------------------
83// find bugs
84
85@e depends on after_start exists@
86identifier virtual.err_ptr_function;
87expression x;
88identifier fld;
89position p1,p2;
90@@
91
92(
93IS_ERR(x = err_ptr_function(...))
94|
95x@p1 = err_ptr_function(...)
96)
97... when != IS_ERR(x)
98(
99 (IS_ERR(x) ||...)
100|
101x@p2->fld
102)
103
104@script:python@
105p1 << e.p1;
106p2 << e.p2;
107@@
108
109cocci.print_main("def",p1)
110cocci.print_secs("ref",p2)