Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Add code after local variable declarations ?
@ 2019-04-16 22:11 Jerome Glisse
  2019-04-17  5:14 ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Jerome Glisse @ 2019-04-16 22:11 UTC (permalink / raw)
  To: cocci

I would like to add code after local variable declaration but there
is nothing particular to match there for me. Roughly i want to do:

    void FooFun(..., struct fooicareabout *identifier, ...)
    {
        // bunch of local variable

        // I want to add code here after all local variables
    }

The thing i match on is one of the function argument. So is that do-
able ? If so any pointer on how to do this would be much appreciated.

Thank you
Jérôme
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Add code after local variable declarations ?
  2019-04-16 22:11 [Cocci] Add code after local variable declarations ? Jerome Glisse
@ 2019-04-17  5:14 ` Julia Lawall
  2019-04-17  9:10   ` [Cocci] Add code after local variable declarations? Markus Elfring
  2019-04-17 14:14   ` [Cocci] Add code after local variable declarations ? Jerome Glisse
  0 siblings, 2 replies; 9+ messages in thread
From: Julia Lawall @ 2019-04-17  5:14 UTC (permalink / raw)
  To: Jerome Glisse; +Cc: cocci



On Tue, 16 Apr 2019, Jerome Glisse wrote:

> I would like to add code after local variable declaration but there
> is nothing particular to match there for me. Roughly i want to do:
>
>     void FooFun(..., struct fooicareabout *identifier, ...)
>     {
>         // bunch of local variable
>
>         // I want to add code here after all local variables
>     }

@@
statement S,S1;
@@

foo(...) {
  ... when != S
+ added code
  S1
  ...
}

A declaration doesn't match S.

>
> The thing i match on is one of the function argument. So is that do-
> able ? If so any pointer on how to do this would be much appreciated.

I'm not sure what you are trying to do here.  You can certainly make a
pattern for your parameters like you have shown in the example.  Do you
mean that you want to go find the argument value at the call site?

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

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

* Re: [Cocci] Add code after local variable declarations?
  2019-04-17  5:14 ` Julia Lawall
@ 2019-04-17  9:10   ` Markus Elfring
  2019-04-17  9:12     ` Julia Lawall
  2019-04-17 14:14   ` [Cocci] Add code after local variable declarations ? Jerome Glisse
  1 sibling, 1 reply; 9+ messages in thread
From: Markus Elfring @ 2019-04-17  9:10 UTC (permalink / raw)
  To: Julia Lawall, Jerome Glisse; +Cc: cocci

> @@
> statement S,S1;
> @@
>
> foo(...) {
>   ... when != S
> + added code
>   S1
>   ...
> }
>
> A declaration doesn't match S.

Can this information trigger additional considerations for the handling
of variable definitions?

Would you like to add any source code only after a variable declaration
(or definition) block?

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

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

* Re: [Cocci] Add code after local variable declarations?
  2019-04-17  9:10   ` [Cocci] Add code after local variable declarations? Markus Elfring
@ 2019-04-17  9:12     ` Julia Lawall
  2019-04-17  9:42       ` Markus Elfring
  2019-04-17  9:42       ` Markus Elfring
  0 siblings, 2 replies; 9+ messages in thread
From: Julia Lawall @ 2019-04-17  9:12 UTC (permalink / raw)
  To: Markus Elfring; +Cc: cocci



On Wed, 17 Apr 2019, Markus Elfring wrote:

> > @@
> > statement S,S1;
> > @@
> >
> > foo(...) {
> >   ... when != S
> > + added code
> >   S1
> >   ...
> > }
> >
> > A declaration doesn't match S.
>
> Can this information trigger additional considerations for the handling
> of variable definitions?
>
> Would you like to add any source code only after a variable declaration

Coccinelle doesn't allow this.  It has no way of knowing whether other
declarations come afterwards, and in the Linux kernel it is not allowed to
mix statements and declarations.

julia

> (or definition) block?
>
> Regards,
> Markus
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Add code after local variable declarations?
  2019-04-17  9:12     ` Julia Lawall
  2019-04-17  9:42       ` Markus Elfring
@ 2019-04-17  9:42       ` Markus Elfring
  1 sibling, 0 replies; 9+ messages in thread
From: Markus Elfring @ 2019-04-17  9:42 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

>> Would you like to add any source code only after a variable declaration
>
> Coccinelle doesn't allow this.  It has no way of knowing whether other
> declarations come afterwards,

I suggest to reconsider this quick response.
Are there approximations supported for such a source code search approach?


> and in the Linux kernel it is not allowed to mix statements and declarations.

There are adjustments possible for the desired scopes, aren't there?


>> (or definition) block?

Which details will become more interesting for corresponding
transformation patterns?

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

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

* Re: [Cocci] Add code after local variable declarations?
  2019-04-17  9:12     ` Julia Lawall
@ 2019-04-17  9:42       ` Markus Elfring
  2019-04-17  9:42       ` Markus Elfring
  1 sibling, 0 replies; 9+ messages in thread
From: Markus Elfring @ 2019-04-17  9:42 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

>> Would you like to add any source code only after a variable declaration
>
> Coccinelle doesn't allow this.  It has no way of knowing whether other
> declarations come afterwards,

I suggest to reconsider this quick response.
Are there approximations supported for such a source code search approach?


> and in the Linux kernel it is not allowed to mix statements and declarations.

There are adjustments possible for the desired scopes, aren't there?


>> (or definition) block?

Which details will become more interesting for corresponding
transformation patterns?

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

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

* Re: [Cocci] Add code after local variable declarations ?
  2019-04-17  5:14 ` Julia Lawall
  2019-04-17  9:10   ` [Cocci] Add code after local variable declarations? Markus Elfring
@ 2019-04-17 14:14   ` Jerome Glisse
  2019-04-17 14:32     ` Julia Lawall
  2019-04-17 16:42     ` [Cocci] Add code after local variable declarations? Markus Elfring
  1 sibling, 2 replies; 9+ messages in thread
From: Jerome Glisse @ 2019-04-17 14:14 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Wed, Apr 17, 2019 at 07:14:29AM +0200, Julia Lawall wrote:
> 
> 
> On Tue, 16 Apr 2019, Jerome Glisse wrote:
> 
> > I would like to add code after local variable declaration but there
> > is nothing particular to match there for me. Roughly i want to do:
> >
> >     void FooFun(..., struct fooicareabout *identifier, ...)
> >     {
> >         // bunch of local variable
> >
> >         // I want to add code here after all local variables
> >     }
> 
> @@
> statement S,S1;
> @@
> 
> foo(...) {
>   ... when != S
> + added code
>   S1
>   ...
> }
> 
> A declaration doesn't match S.

Oh cool did not think of that thanks. What happens if some of the
declaration also have initializer that are statement ie for instance:

foobar(int a, int b, int c, struct fooicareabout *id)
{
    int toto = funbar(a, b);
    int k, l, m;

    ...
}


> 
> >
> > The thing i match on is one of the function argument. So is that do-
> > able ? If so any pointer on how to do this would be much appreciated.
> 
> I'm not sure what you are trying to do here.  You can certainly make a
> pattern for your parameters like you have shown in the example.  Do you
> mean that you want to go find the argument value at the call site?

No i want to add some code to _all_ function that have a specific
structure as one of their argument. Thus i match on the function
parameter list for the struct i am interested in and then after
all the declaration i add a code snippet.

Cheers,
Jérôme
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Add code after local variable declarations ?
  2019-04-17 14:14   ` [Cocci] Add code after local variable declarations ? Jerome Glisse
@ 2019-04-17 14:32     ` Julia Lawall
  2019-04-17 16:42     ` [Cocci] Add code after local variable declarations? Markus Elfring
  1 sibling, 0 replies; 9+ messages in thread
From: Julia Lawall @ 2019-04-17 14:32 UTC (permalink / raw)
  To: Jerome Glisse; +Cc: cocci



On Wed, 17 Apr 2019, Jerome Glisse wrote:

> On Wed, Apr 17, 2019 at 07:14:29AM +0200, Julia Lawall wrote:
> >
> >
> > On Tue, 16 Apr 2019, Jerome Glisse wrote:
> >
> > > I would like to add code after local variable declaration but there
> > > is nothing particular to match there for me. Roughly i want to do:
> > >
> > >     void FooFun(..., struct fooicareabout *identifier, ...)
> > >     {
> > >         // bunch of local variable
> > >
> > >         // I want to add code here after all local variables
> > >     }
> >
> > @@
> > statement S,S1;
> > @@
> >
> > foo(...) {
> >   ... when != S
> > + added code
> >   S1
> >   ...
> > }
> >
> > A declaration doesn't match S.
>
> Oh cool did not think of that thanks. What happens if some of the
> declaration also have initializer that are statement ie for instance:

No difference.

> foobar(int a, int b, int c, struct fooicareabout *id)
> {
>     int toto = funbar(a, b);
>     int k, l, m;
>
>     ...
> }
>
>
> >
> > >
> > > The thing i match on is one of the function argument. So is that do-
> > > able ? If so any pointer on how to do this would be much appreciated.
> >
> > I'm not sure what you are trying to do here.  You can certainly make a
> > pattern for your parameters like you have shown in the example.  Do you
> > mean that you want to go find the argument value at the call site?
>
> No i want to add some code to _all_ function that have a specific
> structure as one of their argument. Thus i match on the function
> parameter list for the struct i am interested in and then after
> all the declaration i add a code snippet.

OK, you should be fine with the pattern you wrote.

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

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

* Re: [Cocci] Add code after local variable declarations?
  2019-04-17 14:14   ` [Cocci] Add code after local variable declarations ? Jerome Glisse
  2019-04-17 14:32     ` Julia Lawall
@ 2019-04-17 16:42     ` Markus Elfring
  1 sibling, 0 replies; 9+ messages in thread
From: Markus Elfring @ 2019-04-17 16:42 UTC (permalink / raw)
  To: Jérôme Glisse; +Cc: cocci

> No i want to add some code to _all_ function that have a specific
> structure as one of their argument. Thus i match on the function
> parameter list for the struct i am interested in

This source code search approach is generally fine.


> and then after all the declaration i add a code snippet.

Our programmer eyes are trained for pattern recognition according to
such a software transformation.

* How many efforts would you like to invest into the development
  for the automation of this refactoring (together with
  the semantic patch language)?

* Would you like to determine the source code positions between
  variable declaration (or definition) blocks and other statements safely?

* Will any additional constraints become relevant for this change attempt?

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

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

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16 22:11 [Cocci] Add code after local variable declarations ? Jerome Glisse
2019-04-17  5:14 ` Julia Lawall
2019-04-17  9:10   ` [Cocci] Add code after local variable declarations? Markus Elfring
2019-04-17  9:12     ` Julia Lawall
2019-04-17  9:42       ` Markus Elfring
2019-04-17  9:42       ` Markus Elfring
2019-04-17 14:14   ` [Cocci] Add code after local variable declarations ? Jerome Glisse
2019-04-17 14:32     ` Julia Lawall
2019-04-17 16:42     ` [Cocci] Add code after local variable declarations? Markus Elfring

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox