cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] struct replacement
@ 2018-12-12 18:39 Max
  2018-12-13  6:24 ` Julia Lawall
  0 siblings, 1 reply; 12+ messages in thread
From: Max @ 2018-12-12 18:39 UTC (permalink / raw)
  To: cocci

Hi.

I have been trying to use spatch to update c struct but haven't found a 
way to do so yet.

For example, we have

struct old_thing {

uint8_t a;

uint16_t b[5];

};

which I'd like to replace with

struct new_thing {

uint8_t x1;

uint32_t x2;

uint8_t x3[11];

};

So pretty much replace every function parameter:

f1(... struct old_thing *t...) => f1(... struct new_thing *t...)

Replace the field access and variable definitions:

...

struct old_thing t1; => struct new_thing t1;

struct old_thing *t2; => struct new_thing *t2;

...

t1.a => t1.x1

t2->b => t2->x3

...

The thing which escapes me is how to make coccinelle treat it like a type?

Do I need to use @@typedef struct old_thing@@? Do I use it as 
@@identifier old_stuff@@ or @@identifier struct old_stuff@@?

Doesn't seem to work for me.

Any links to .spatch examples playing around with structs would be 
greatly appreciated.

-- 
- Max Suraev <msuraev@sysmocom.de>       http://www.sysmocom.de/
=======================================================================
* sysmocom - systems for mobile communications GmbH
* Alt-Moabit 93
* 10559 Berlin, Germany
* Sitz / Registered office: Berlin, HRB 134158 B
* Geschaeftsfuehrer / Managing Directors: Harald Welte

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2018-12-18 18:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 18:39 [Cocci] struct replacement Max
2018-12-13  6:24 ` Julia Lawall
2018-12-13 16:43   ` Max
2018-12-13 20:01     ` Julia Lawall
     [not found]       ` <c8041b90-d4e9-a9a6-603d-7f5498fe081c@users.sourceforge.net>
2018-12-15 13:49         ` Julia Lawall
2018-12-18 16:15       ` Max
2018-12-18 16:19         ` Julia Lawall
2018-12-18 16:44           ` Max
2018-12-18 16:54             ` Julia Lawall
2018-12-18 17:12               ` Max
2018-12-18 17:18                 ` Julia Lawall
2018-12-18 18:13                   ` Max

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).