All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] rework a function to move parameters around ....
@ 2017-01-16  4:44 ron minnich
  2017-01-16  6:18 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: ron minnich @ 2017-01-16  4:44 UTC (permalink / raw
  To: cocci

I have a function like this (in coreboot)
void lb_add_serial(struct lb_serial *new_serial, void *data)
{
struct lb_header *header = (struct lb_header *)data;
struct lb_serial *serial;

serial = (struct lb_serial *)lb_new_record(header);
serial->tag = LB_TAG_SERIAL;
serial->size = sizeof(*serial);
serial->type = new_serial->type;
...
}

This is just one example.

I'd like to do the following:
Get the name of the variable assigned to serial->size (call it S)
Get the name of the variable assigned to serial->type (call it T)
Change the code as follows:
serial = (struct lb_serial *)lb_new_record(header, T, S);
remove the lines where they as assigned to struct.
make sure that the call to lb_new_record is moved after the size is
computed (i.e. after the assignments above).

This exceeds my spatch foo by a fair amount; I'm fooling around with it but
wonder if you all have some pointers.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20170116/c875f102/attachment-0001.html>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] rework a function to move parameters around ....
  2017-01-16  4:44 [Cocci] rework a function to move parameters around ron minnich
@ 2017-01-16  6:18 ` Julia Lawall
  2017-01-16  6:26   ` ron minnich
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2017-01-16  6:18 UTC (permalink / raw
  To: cocci



On Mon, 16 Jan 2017, ron minnich wrote:

> I have a function like this (in coreboot)void lb_add_serial(struct lb_serial
> *new_serial, void *data)
> {
> struct lb_header *header = (struct lb_header *)data;
> struct lb_serial *serial;
>
> serial = (struct lb_serial *)lb_new_record(header);
> serial->tag = LB_TAG_SERIAL;
> serial->size = sizeof(*serial);
> serial->type = new_serial->type;
> ...
> }
>
> This is just one example.?
>
> I'd like to do the following:
> Get the name of the variable assigned to serial->size (call it S)
> Get the name of the variable assigned to serial->type (call it T)
> Change the code as follows:
> serial = (struct lb_serial *)lb_new_record(header, T, S);
> remove the lines where they as assigned to struct.
> make sure that the call to lb_new_record is moved after the size is computed
> (i.e. after the assignments above).
>
> This exceeds my spatch foo by a fair amount; I'm fooling around with it but
> wonder if you all have some pointers.

Will the cast always be there?

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] rework a function to move parameters around ....
  2017-01-16  6:18 ` Julia Lawall
@ 2017-01-16  6:26   ` ron minnich
  2017-01-16  6:31     ` Julia Lawall
  2017-01-16  6:32     ` Julia Lawall
  0 siblings, 2 replies; 5+ messages in thread
From: ron minnich @ 2017-01-16  6:26 UTC (permalink / raw
  To: cocci

yes, it will.


On Sun, Jan 15, 2017 at 10:19 PM Julia Lawall <julia.lawall@lip6.fr> wrote:

>
>
> On Mon, 16 Jan 2017, ron minnich wrote:
>
> > I have a function like this (in coreboot)void lb_add_serial(struct
> lb_serial
> > *new_serial, void *data)
> > {
> > struct lb_header *header = (struct lb_header *)data;
> > struct lb_serial *serial;
> >
> > serial = (struct lb_serial *)lb_new_record(header);
> > serial->tag = LB_TAG_SERIAL;
> > serial->size = sizeof(*serial);
> > serial->type = new_serial->type;
> > ...
> > }
> >
> > This is just one example.
> >
> > I'd like to do the following:
> > Get the name of the variable assigned to serial->size (call it S)
> > Get the name of the variable assigned to serial->type (call it T)
> > Change the code as follows:
> > serial = (struct lb_serial *)lb_new_record(header, T, S);
> > remove the lines where they as assigned to struct.
> > make sure that the call to lb_new_record is moved after the size is
> computed
> > (i.e. after the assignments above).
> >
> > This exceeds my spatch foo by a fair amount; I'm fooling around with it
> but
> > wonder if you all have some pointers.
>
> Will the cast always be there?
>
> julia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20170116/3f904c53/attachment.html>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] rework a function to move parameters around ....
  2017-01-16  6:26   ` ron minnich
@ 2017-01-16  6:31     ` Julia Lawall
  2017-01-16  6:32     ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2017-01-16  6:31 UTC (permalink / raw
  To: cocci

This is not tested.

---

// both field initializations after the original call

@@
struct lb_header *header;
expression e1,e2,e3,sz,ty,serial;
@@

- serial = (struct lb_serial *)lb_new_record(header);
... when != serial = e1
- serial->size = sz;
... when != serial = e2
    when != serial->size = e3
- serial->type = ty;
+ serial = (struct lb_serial *)lb_new_record(header, sz, ty);

@@
struct lb_header *header;
expression e1,e2,e3,sz,ty,serial;
@@

- serial = (struct lb_serial *)lb_new_record(header);
... when != serial = e1
- serial->type = ty;
... when != serial = e2
    when != serial->type = e3
- serial->size = sz;
+ serial = (struct lb_serial *)lb_new_record(header, sz, ty);

// both field initializations before the original call

@@
struct lb_header *header;
expression e1,e2,e3,e4,e5,sz,ty,serial;
@@

- serial->type = ty;
... when != serial = e1
    when != serial->type = e2
- serial->size = sz;
... when != serial = e3
    when != serial->type = e4
    when != serial->size = e5
  serial = (struct lb_serial *)lb_new_record(header
+ , sz, ty
  );

@@
struct lb_header *header;
expression e1,e2,e3,e4,e5,sz,ty,serial;
@@

- serial->size = sz;
... when != serial = e1
    when != serial->size = e2
- serial->type = ty;
... when != serial = e3
    when != serial->size = e4
    when != serial->type = e5
  serial = (struct lb_serial *)lb_new_record(header
+ , sz, ty
  );

// field initializations around the original call

@@
struct lb_header *header;
expression e1,e2,e3,e4,sz,ty,serial;
@@

- serial->size = sz;
... when != serial = e1
    when != serial->size = e2
- serial = (struct lb_serial *)lb_new_record(header);
... when != serial = e3
    when != serial->size = e4
- serial->type = ty;
+ serial = (struct lb_serial *)lb_new_record(header, sz, ty);


@@
struct lb_header *header;
expression e1,e2,e3,e4,sz,ty,serial;
@@

- serial->type = ty;
... when != serial = e1
    when != serial->type = e2
- serial = (struct lb_serial *)lb_new_record(header);
... when != serial = e3
    when != serial->type = e4
- serial->size = sz;
+ serial = (struct lb_serial *)lb_new_record(header, sz, ty);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] rework a function to move parameters around ....
  2017-01-16  6:26   ` ron minnich
  2017-01-16  6:31     ` Julia Lawall
@ 2017-01-16  6:32     ` Julia Lawall
  1 sibling, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2017-01-16  6:32 UTC (permalink / raw
  To: cocci

Basically, I just went for the brute force solution of listing all the
possible orderings of the code.

This is sort of analogous to the semantic patch for adding uses of
setup_timer in the kernel.

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-16  6:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-16  4:44 [Cocci] rework a function to move parameters around ron minnich
2017-01-16  6:18 ` Julia Lawall
2017-01-16  6:26   ` ron minnich
2017-01-16  6:31     ` Julia Lawall
2017-01-16  6:32     ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.