Within a function definition, for statement-level things, you can do
something like the following:
@r@
statement S;
position p;
@@
S@p
@script:ocaml s@
p << r.p;
label_start;
label_end;
@@
label_start := Printf.sprintf "// <statement line: %d>" (List.hd p).line;
label_end := Printf.sprintf "// </statement line: %d>" (List.hd p).line
@@
position r.p;
statement S;
identifier s.label_start, s.label_end;
@@
+ label_start;
S@p
+ label_end;
For the C file:
int main () {
foo();
if (y)
x = 12;
if (y) {
x = 12;
}
return 15;
}
You get:
int main () {
// <statement line: 2>;
foo();
// </statement line: 2>;
// <statement line: 3>;
if (y) {
// <statement line: 4>;
x = 12;
// </statement line: 4>;
}
// </statement line: 3>;
// <statement line: 5>;
if (y) {
// <statement line: 5>;
{
// <statement line: 6>;
x = 12;
// </statement line: 6>;
}
// </statement line: 5>;
}
// </statement line: 5>;
// <statement line: 8>;
return 15;
// </statement line: 8>;
}
Note { } were added in the first if branch, because it thinks that newcode
was added so the braces are needed.
This is only possible in cases where it is possible to use an identifier.
So I don't see how it would be possible to do the same for an expression
or for a top-level item. It is, however, possible to add comments around
things. Maybe metavariables could be instantiated within these added
comments.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)