On Sun, Aug 21, 2011 at 10:21 PM, Julia Lawall <[email protected]> wrote:

> 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.
>

Thanks, Julia. This is definitely going in the direction of what I'm after
but I need it richer :-)
Is it possible to output the character position on a line of statements?
Is it possible to output info about the position of individual arguments in
a function call? Or parameters in a function declaration?
Is it possible to identify particular statements? E.g. This statement is a
function declaration, this statement is a function definition, etc?
If a statement is a stack variable definition then is it possible to show
the position of the type, name and option assignment operator, and then show
separate sub-statements for the assignment right hand value?

Thanks,
Simon

julia
>
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to