[Cocci] Embedding Meta-variables in added Comments using semantic patchesز

Julia Lawall julia.lawall at lip6.fr
Wed Aug 29 04:52:36 CEST 2018



On Wed, 29 Aug 2018, Moustafa Mahmoud wrote:

> Thanks alot for your reply. I will look into this option .I was hoping to
> use coccinelle to annotate some c code so that I would later parse it to
> determine the program flow.
>
> Is there a way to get more information from -show-ctrl-flow switch in
> coccinelle ? It only shows "if" nodes without the expression s inside them
> in dot graph ?

No, nothing is provided for that.  I think that the feeling was that the
expressions could be quite big, and the graph would become unreadable.  Of
course, if you want to do some other processing of the graph, you don't
care about that.

If you are willing to write OCaml code, maybe you would be better off to
just run the parser and the construction of the control-flow graph, and
then do what you want with the resulting data structure.  It is possible
to make the implementation of Coccinelle into a library that you can link
your own OCaml code with and then call the functions from the Coccinelle
infrastructure that you want.

julia

>
> Thanks alot
>
>
> On Tue, Aug 28, 2018, 12:53 PM Julia Lawall <julia.lawall at lip6.fr> wrote:
>
>
>       On Tue, 28 Aug 2018, Moustafa Mahmoud wrote:
>
>       > this semantic patch doesn't produce the required behavioir
>       >
>       > @annotate_if_conditions@
>       > expression ex;
>       > @@
>       >
>       > <+...
>       > + /* ex */
>       > if(ex){...}
>       > ...+>
>       >
>       >
>       > it produces the following 
>       >
>       >      int x =5;
>       >      int y =6;
>       >      int m =funct();
>       > +    /* ex */   // the required behavoir I need is  /* x */
>       >      if(x)
>       >      {
>       > +       /* ex */
>       >         if(y)
>       >         {
>       >             return 1;
>
>       Sorry, it doesn't work.  Currently the only tihng you can do is
>       use python
>       to make an identifier metavariable that actually contains a
>       comment, and
>       then add that metavariable where you want your comments.  By
>       your comments
>       will have to have a ; after them, and are thus better made with
>       // than
>       with /* */, because an identifier is not a valid statement by
>       itself.
>       Instead you need an identifier followed by a semicolon.
>
>       For using python to make an identifier metavariable please see
>       demos/pythontococci.{c,cocci,res}.  Please write back if it is
>       not clear.
>
>       julia
>
>
>


More information about the Cocci mailing list