public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
* [Cocci] how to consider castings in semantic patchs
@ 2013-03-12 13:51 Andrés More
  2013-03-13  8:43 ` Julia Lawall
  2013-03-13  8:49 ` Lars-Peter Clausen
  0 siblings, 2 replies; 3+ messages in thread
From: Andrés More @ 2013-03-12 13:51 UTC (permalink / raw)
  To: cocci

Hi, I've been playing with Coccinele, I find it really useful.

I'm trying to create a semantic patch to rename a structure (and its
fields).
I could get almost everything in place in several patches: the structure
gets renamed, also variables of that type, also their attributes. However,
the code (not mine) uses some explicit castings and I couldn't find a way
to cover those cases also.

I've tried to follow the documented grammar but I think I got lost without
finding how to declare such castings.

I'm appending the last version of the semantic patch I've been working on
just to give the rough idea how what I am trying to describe. The code is a
Linux kernel staging driver (VIA VT6656), using their own Ethernet packet
struct.

Thanks, I will really appreciate any hints on how to consider explicit
casting.

-- Andres

Sample Line not covered
pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);

Semantic patch I could get done
$ cat test.cocci
@rule1@
identifier h;
@@
-PSEthernetHeader h;
+struct ethhdr * h;

@rule2@
identifier h;
@@
-PS802_11Header h;
+struct ieee80211_hdr *h;

@rule5@
identifier h;
@@
-SEthernetHeader h;
+struct ethhdr h;

@rule6@
identifier h;
@@
-S802_11Header h;
+struct ieee80211_hdr h;

@rule3@
struct ethhdr *h;
@@
(
-h->abyDstAddr
+h->h_dest
|
-h->abySrcAddr
+h->h_source
|
-h->wType
+h->h_proto
)

@rule4@
struct ieee80211_hdr *h;
@@
(
-h->wFrameCtl
+h->frame_control
|
-h->wDurationID
+h->duration_id
|
-h->abyAddr1
+h->addr1
|
-h->abyAddr2
+h->addr2
|
-h->abyAddr3
+h->addr3
|
-h->wSeqCtl
+h->seq_ctrl
|
-h->abyAddr4
+h->addr4
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130312/497e76ed/attachment.html>

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

* [Cocci] how to consider castings in semantic patchs
  2013-03-12 13:51 [Cocci] how to consider castings in semantic patchs Andrés More
@ 2013-03-13  8:43 ` Julia Lawall
  2013-03-13  8:49 ` Lars-Peter Clausen
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2013-03-13  8:43 UTC (permalink / raw)
  To: cocci

On Tue, 12 Mar 2013, Andr?s More wrote:

> Hi, I've been playing with Coccinele, I find it really useful.
>
> I'm trying to create a semantic patch to rename a structure (and its
> fields).
> I could get almost everything in place in several patches: the structure
> gets renamed, also variables of that type, also their attributes. However,
> the code (not mine) uses some explicit castings and I couldn't find a way to
> cover those cases also.
>
> I've tried to follow the documented grammar but I think I got lost without
> finding how to declare such castings.?
>
> I'm appending the last version of the semantic patch I've been working on
> just to give the rough idea how what I am trying to describe. The code is a
> Linux kernel staging driver (VIA VT6656), using their own Ethernet packet
> struct.
>
> Thanks, I will really appreciate any hints on how to consider explicit
> casting.
>
> -- Andres
> Sample Line not covered
> pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);

What would you like to generate in this case?  Is it just to change the
cast name?  In that case, what you are missing is probably the typedef
declaration.  You could say:

@@
typedef PS802_11Header, newtype;
expression e;
@@

 (
- PS802_11Header
+ newtype
 )
 e

You only need to declare a type using typedef once.  It is remembered for
subsequent rules.

julia

>
> Semantic patch I could get done
> $ cat test.cocci
> @rule1@
> identifier h;
> @@
> -PSEthernetHeader h;
> +struct ethhdr * h;
>
> @rule2@
> identifier h;
> @@
> -PS802_11Header h;
> +struct ieee80211_hdr *h;
>
> @rule5@
> identifier h;
> @@
> -SEthernetHeader h;
> +struct ethhdr h;
>
> @rule6@
> identifier h;
> @@
> -S802_11Header h;
> +struct ieee80211_hdr h;
>
> @rule3@
> struct ethhdr *h;
> @@
> (
> -h->abyDstAddr
> +h->h_dest
> |
> -h->abySrcAddr
> +h->h_source
> |
> -h->wType
> +h->h_proto
> )
>
> @rule4@
> struct ieee80211_hdr *h;
> @@
> (
> -h->wFrameCtl
> +h->frame_control
> |
> -h->wDurationID
> +h->duration_id
> |
> -h->abyAddr1
> +h->addr1
> |
> -h->abyAddr2
> +h->addr2
> |
> -h->abyAddr3
> +h->addr3
> |
> -h->wSeqCtl
> +h->seq_ctrl
> |
> -h->abyAddr4
> +h->addr4
> )
>
>
>

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

* [Cocci] how to consider castings in semantic patchs
  2013-03-12 13:51 [Cocci] how to consider castings in semantic patchs Andrés More
  2013-03-13  8:43 ` Julia Lawall
@ 2013-03-13  8:49 ` Lars-Peter Clausen
  1 sibling, 0 replies; 3+ messages in thread
From: Lars-Peter Clausen @ 2013-03-13  8:49 UTC (permalink / raw)
  To: cocci

On 03/12/2013 02:51 PM, Andr?s More wrote:
> Hi, I've been playing with Coccinele, I find it really useful.
> 
> I'm trying to create a semantic patch to rename a structure (and its
> fields).
> I could get almost everything in place in several patches: the structure
> gets renamed, also variables of that type, also their attributes. However,
> the code (not mine) uses some explicit castings and I couldn't find a way
> to cover those cases also.
> 
> I've tried to follow the documented grammar but I think I got lost without
> finding how to declare such castings.
> 
> I'm appending the last version of the semantic patch I've been working on
> just to give the rough idea how what I am trying to describe. The code is a
> Linux kernel staging driver (VIA VT6656), using their own Ethernet packet
> struct.
> 
> Thanks, I will really appreciate any hints on how to consider explicit
> casting.
> 
> -- Andres
> 

Hi,

If you typedef PS802_11Header coccinelle will also be able to handle the cast.

@@
typedef PS802_11Header;
@@
-PS802_11Header
+struct ieee80211_hdr

- Lars

> Sample Line not covered
> pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
> 
> Semantic patch I could get done
> $ cat test.cocci
> @rule1@
> identifier h;
> @@
> -PSEthernetHeader h;
> +struct ethhdr * h;
> 
> @rule2@
> identifier h;
> @@
> -PS802_11Header h;
> +struct ieee80211_hdr *h;
> 
> @rule5@
> identifier h;
> @@
> -SEthernetHeader h;
> +struct ethhdr h;
> 
> @rule6@
> identifier h;
> @@
> -S802_11Header h;
> +struct ieee80211_hdr h;
> 
> @rule3@
> struct ethhdr *h;
> @@
> (
> -h->abyDstAddr
> +h->h_dest
> |
> -h->abySrcAddr
> +h->h_source
> |
> -h->wType
> +h->h_proto
> )
> 
> @rule4@
> struct ieee80211_hdr *h;
> @@
> (
> -h->wFrameCtl
> +h->frame_control
> |
> -h->wDurationID
> +h->duration_id
> |
> -h->abyAddr1
> +h->addr1
> |
> -h->abyAddr2
> +h->addr2
> |
> -h->abyAddr3
> +h->addr3
> |
> -h->wSeqCtl
> +h->seq_ctrl
> |
> -h->abyAddr4
> +h->addr4
> )
> 
> 
> 
> 
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2013-03-13  8:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-12 13:51 [Cocci] how to consider castings in semantic patchs Andrés More
2013-03-13  8:43 ` Julia Lawall
2013-03-13  8:49 ` Lars-Peter Clausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox