All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Matching if a function parameter is used at all
@ 2016-04-19 21:14 Kieran Bingham
  2016-04-20  5:17 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Kieran Bingham @ 2016-04-19 21:14 UTC (permalink / raw)
  To: cocci

Hi All,

I would like to match on when a function *doesn't* use a parameter, so that
those use-cases can be swapped to new function prototype, as an interim -
leaving code which needs fixing up still compiling successfully.
To do this, I believe I need to identify the functions that use that
parameter, and then make the conversion dependant upon that hunk.

I've been trying various combinations of below:

======================================

// Detect if id is used in the probe function

@ probe_id_used depends on driver @
identifier driver.probefunc;
identifier client;
identifier idt;
@@
static int probefunc( struct i2c_client *client, const struct i2c_device_id
*idt)
 {
 ...
 idt
 ...
 }

//
// Then, only if requirements are met, start making adjustments
//

// Convert the probe function

@ convert depends on driver && !probe_id_used @
identifier driver.probefunc;
identifier client;
identifier id;
@@
static int probefunc(
    struct i2c_client *client
-    , const struct i2c_device_id *id
    )
    { ... }
======================================

However, I can't get the probe_id_used to match correctly for the idt
identifier. I'd like it to match if it is mentioned at all in the function,
but I have also tried mapping a disjunction on known conditionals to no
avail:

======================================
// Detect if id is used in the probe function

@ probe_id_used depends on driver @
identifier driver.probefunc;
identifier client;
identifier idt;
expression e;
statement S;
@@
static int probefunc( struct i2c_client *client, const struct i2c_device_id
*idt)
 {
 ...
(
  if(idt) S;
|
  if (idt) { ... }
|
  e = idt->name
|
  e = idt->driver_data
)
 ...
 }
======================================

And that still doesn't match

Is there an easier / correct way to achieve what I'm trying to do ? Or am I
missing something obvious?

--
Regards

Kieran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20160419/68910dee/attachment.html>

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

* [Cocci] Matching if a function parameter is used at all
  2016-04-19 21:14 [Cocci] Matching if a function parameter is used at all Kieran Bingham
@ 2016-04-20  5:17 ` Julia Lawall
  2016-04-20 12:42   ` Kieran Bingham
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2016-04-20  5:17 UTC (permalink / raw)
  To: cocci



On Tue, 19 Apr 2016, Kieran Bingham wrote:

> Hi All,
> 
> I would like to match on when a function *doesn't* use a parameter, so that
> those use-cases can be swapped to new function prototype, as an interim -
> leaving code which needs fixing up still compiling successfully.
> To do this, I believe I need to identify the functions that use that
> parameter, and then make the conversion dependant upon that hunk.
> 
> I've been trying various combinations of below:
> 
> ======================================
> 
> // Detect if id is used in the probe function
> 
> @ probe_id_used depends on driver @
> identifier driver.probefunc;
> identifier client;
> identifier idt;
> @@
> static int probefunc( struct i2c_client *client, const struct i2c_device_id
> *idt)
> ?{
> ?...
> ?idt
> ?...
> ?}
> 
> //
> // Then, only if requirements are met, start making adjustments
> //
> 
> // Convert the probe function
> 
> @ convert depends on driver && !probe_id_used @
> identifier driver.probefunc;
> identifier client;
> identifier id;
> @@
> static int probefunc(
> ??? struct i2c_client *client
> -??? , const struct i2c_device_id *id
> ??? )
> ??? { ... }
> ======================================
> 
> However, I can't get the probe_id_used to match correctly for the idt
> identifier. I'd like it to match if it is mentioned at all in the function,
> but I have also tried mapping a disjunction on known conditionals to no
> avail:
> 
> ======================================
> // Detect if id is used in the probe function
> 
> @ probe_id_used depends on driver @
> identifier driver.probefunc;
> identifier client;
> identifier idt;
> expression e;
> statement S;
> @@
> static int probefunc( struct i2c_client *client, const struct i2c_device_id
> *idt)
> ?{
> ?...
> (
> ? if(idt) S;
> |
> ? if (idt) { ... }
> |
> ? e = idt->name
> |
> ? e = idt->driver_data
> )
> ?...
> ?}
> ======================================
> 
> And that still doesn't match
> 
> Is there an easier / correct way to achieve what I'm trying to do ? Or am I
> missing something obvious?

I think that

f(...,T i,...) { ... when != i
}

would do what you want?

julia

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

* [Cocci] Matching if a function parameter is used at all
  2016-04-20  5:17 ` Julia Lawall
@ 2016-04-20 12:42   ` Kieran Bingham
  0 siblings, 0 replies; 3+ messages in thread
From: Kieran Bingham @ 2016-04-20 12:42 UTC (permalink / raw)
  To: cocci

On 20 April 2016 at 06:17, Julia Lawall <julia.lawall@lip6.fr> wrote:

>
> On Tue, 19 Apr 2016, Kieran Bingham wrote:
>
> > Hi All,
> >
> > I would like to match on when a function *doesn't* use a parameter, so
> that
> > those use-cases can be swapped to new function prototype, as an interim -
> > leaving code which needs fixing up still compiling successfully.
> > To do this, I believe I need to identify the functions that use that
> > parameter, and then make the conversion dependant upon that hunk.
> >
> > I've been trying various combinations of below:
> >
> > ======================================
> >
> > // Detect if id is used in the probe function
> >
> > @ probe_id_used depends on driver @
> > identifier driver.probefunc;
> > identifier client;
> > identifier idt;
> > @@
> > static int probefunc( struct i2c_client *client, const struct
> i2c_device_id
> > *idt)
> >  {
> >  ...
> >  idt
> >  ...
> >  }
> >
> > //
> > // Then, only if requirements are met, start making adjustments
> > //
> >
> > // Convert the probe function
> >
> > @ convert depends on driver && !probe_id_used @
> > identifier driver.probefunc;
> > identifier client;
> > identifier id;
> > @@
> > static int probefunc(
> >     struct i2c_client *client
> > -    , const struct i2c_device_id *id
> >     )
> >     { ... }
> > ======================================
> >
> > However, I can't get the probe_id_used to match correctly for the idt
> > identifier. I'd like it to match if it is mentioned at all in the
> function,
> > but I have also tried mapping a disjunction on known conditionals to no
> > avail:
> >
> > ======================================
> > // Detect if id is used in the probe function
> >
> > @ probe_id_used depends on driver @
> > identifier driver.probefunc;
> > identifier client;
> > identifier idt;
> > expression e;
> > statement S;
> > @@
> > static int probefunc( struct i2c_client *client, const struct
> i2c_device_id
> > *idt)
> >  {
> >  ...
> > (
> >   if(idt) S;
> > |
> >   if (idt) { ... }
> > |
> >   e = idt->name
> > |
> >   e = idt->driver_data
> > )
> >  ...
> >  }
> > ======================================
> >
> > And that still doesn't match
> >
> > Is there an easier / correct way to achieve what I'm trying to do ? Or
> am I
> > missing something obvious?
>
> I think that
>
> f(...,T i,...) { ... when != i
> }
>
> would do what you want?
>

Aha - yes, I believe this did match as I needed, with the hunk renamed for
the inversion

// Detect if id is used in the probe function

@ probe_id_unused depends on driver @
identifier driver.probefunc;
identifier client;
identifier idt;
@@
static int probefunc( struct i2c_client *client, const struct i2c_device_id
*idt)
 {
 ...
 when != idt
 }

but I think I now understand that the root of my issue as being something
different. It looks like I had got the match working in other ways but the
depends chain wasn't working.
Your version is cleaner though - so thank-you for that!

I will post a new thread for the depends issue, as I think that is separate
--
Regards

Kieran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20160420/e678b653/attachment.html>

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

end of thread, other threads:[~2016-04-20 12:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-19 21:14 [Cocci] Matching if a function parameter is used at all Kieran Bingham
2016-04-20  5:17 ` Julia Lawall
2016-04-20 12:42   ` Kieran Bingham

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.