All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] moving variable declarations up
@ 2020-06-17 20:54 Johannes Berg
  2020-06-17 21:15 ` Julia Lawall
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2020-06-17 20:54 UTC (permalink / raw)
  To: cocci

Hi spatchers,

I've been working on an old code base, and toying with something like
this:

@@
type T;
identifier x;
expression E, F;
@@
{
+T x;
+
 E;
...
-T x;
...
}

(and also a variant with "T x = F;" where F is an expression).


That works OK if there's only a single variable, but...

First, it only moves a single variable up, even if I run it multiple
times (I think)?

Secondly, sometimes it says something like:

previous modification:

  <<< T x;
      
CONTEXT
According to environment 2:
   rule starting on line 15.x -> id var1
   rule starting on line 15.T -> u32

current modification:

  <<< T x;
      
CONTEXT
According to environment 2:
   rule starting on line 15.x -> id var2
   rule starting on line 15.T -> u32

EXN:Failure("rule starting on line 15: already tagged token:\nC code context\nFile \"/tmp/cocci_small_output-170001-6edb7c.c\", line 150, column 4,  charpos = 8969\n    around = 'DEBUG_PRINT', whole content =     DEBUG_PRINT(...omitted...);")


That's basically what I saw, something like

DEBUG_PRINT(...);
u32 var1 = ...;
u32 var2 = ...;


Any ideas how I can make it move more variable declarations up?

Thanks,
johannes

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 20:54 [Cocci] moving variable declarations up Johannes Berg
@ 2020-06-17 21:15 ` Julia Lawall
  2020-06-17 21:19   ` Johannes Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2020-06-17 21:15 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Wed, 17 Jun 2020, Johannes Berg wrote:

> Hi spatchers,
>
> I've been working on an old code base, and toying with something like
> this:
>
> @@
> type T;
> identifier x;
> expression E, F;
> @@
> {
> +T x;

Change the + to ++

There is no guarantee on the order in which the variables will appear.

> +
>  E;
> ...

Add when any after the ...

julia

> -T x;
> ...
> }
>
> (and also a variant with "T x = F;" where F is an expression).
>
>
> That works OK if there's only a single variable, but...
>
> First, it only moves a single variable up, even if I run it multiple
> times (I think)?
>
> Secondly, sometimes it says something like:
>
> previous modification:
>
>   <<< T x;
>
> CONTEXT
> According to environment 2:
>    rule starting on line 15.x -> id var1
>    rule starting on line 15.T -> u32
>
> current modification:
>
>   <<< T x;
>
> CONTEXT
> According to environment 2:
>    rule starting on line 15.x -> id var2
>    rule starting on line 15.T -> u32
>
> EXN:Failure("rule starting on line 15: already tagged token:\nC code context\nFile \"/tmp/cocci_small_output-170001-6edb7c.c\", line 150, column 4,  charpos = 8969\n    around = 'DEBUG_PRINT', whole content =     DEBUG_PRINT(...omitted...);")
>
>
> That's basically what I saw, something like
>
> DEBUG_PRINT(...);
> u32 var1 = ...;
> u32 var2 = ...;
>
>
> Any ideas how I can make it move more variable declarations up?
>
> Thanks,
> johannes
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 21:15 ` Julia Lawall
@ 2020-06-17 21:19   ` Johannes Berg
  2020-06-17 21:47     ` Johannes Berg
  2020-06-18  5:59     ` Julia Lawall
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Berg @ 2020-06-17 21:19 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Wed, 2020-06-17 at 23:15 +0200, Julia Lawall wrote:
> 
> > +T x;
> 
> Change the + to ++

Hah, I think you mentioned that to me before, but I can never remember
what it does ...

> There is no guarantee on the order in which the variables will appear.

That's ok, I don't really care :)

> > +
> >  E;
> > ...
> 
> Add when any after the ...

What's the difference between "..." and "... when any"?

johannes

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 21:19   ` Johannes Berg
@ 2020-06-17 21:47     ` Johannes Berg
  2020-06-18 15:25       ` Julia Lawall
  2020-06-18 15:49       ` Julia Lawall
  2020-06-18  5:59     ` Julia Lawall
  1 sibling, 2 replies; 10+ messages in thread
From: Johannes Berg @ 2020-06-17 21:47 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Wed, 2020-06-17 at 23:19 +0200, Johannes Berg wrote:
> On Wed, 2020-06-17 at 23:15 +0200, Julia Lawall wrote:
> > > +T x;
> > 
> > Change the + to ++

Heh, something funny happened

+ u16 *foo;
+ u16[2] bar;

... some code ...

-u16 *foo;
-u16 *bar[2];


What happened to the array index?

I guess ... at some level I even understand it, that's a property of the
type, and I was moving the type around. But I really didn't expect that
:)

johannes

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 21:19   ` Johannes Berg
  2020-06-17 21:47     ` Johannes Berg
@ 2020-06-18  5:59     ` Julia Lawall
  2020-06-18  7:37       ` Johannes Berg
  1 sibling, 1 reply; 10+ messages in thread
From: Julia Lawall @ 2020-06-18  5:59 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Wed, 17 Jun 2020, Johannes Berg wrote:

> On Wed, 2020-06-17 at 23:15 +0200, Julia Lawall wrote:
> >
> > > +T x;
> >
> > Change the + to ++
>
> Hah, I think you mentioned that to me before, but I can never remember
> what it does ...
>
> > There is no guarantee on the order in which the variables will appear.
>
> That's ok, I don't really care :)
>
> > > +
> > >  E;
> > > ...
> >
> > Add when any after the ...
>
> What's the difference between "..." and "... when any"?

A ... B connects an A to the closest B, as you might like in some code
with lots of locks and unlocks.  When any picks up any subsequent B, even
if there is another B between the matched A and B.

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-18  5:59     ` Julia Lawall
@ 2020-06-18  7:37       ` Johannes Berg
  0 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2020-06-18  7:37 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Thu, 2020-06-18 at 07:59 +0200, Julia Lawall wrote:

> > What's the difference between "..." and "... when any"?
> 
> A ... B connects an A to the closest B, as you might like in some code
> with lots of locks and unlocks.  When any picks up any subsequent B, even
> if there is another B between the matched A and B.

OK, great, thanks for the explanation.

Thanks a lot for your help!

johannes

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 21:47     ` Johannes Berg
@ 2020-06-18 15:25       ` Julia Lawall
  2020-06-18 15:49       ` Julia Lawall
  1 sibling, 0 replies; 10+ messages in thread
From: Julia Lawall @ 2020-06-18 15:25 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Wed, 17 Jun 2020, Johannes Berg wrote:

> On Wed, 2020-06-17 at 23:19 +0200, Johannes Berg wrote:
> > On Wed, 2020-06-17 at 23:15 +0200, Julia Lawall wrote:
> > > > +T x;
> > >
> > > Change the + to ++
>
> Heh, something funny happened
>
> + u16 *foo;
> + u16[2] bar;
>
> ... some code ...
>
> -u16 *foo;
> -u16 *bar[2];
>
>
> What happened to the array index?
>
> I guess ... at some level I even understand it, that's a property of the
> type, and I was moving the type around. But I really didn't expect that
> :)

What version of Coccinelle do you have?

There has been a lot of work on types recently that may have affected
this.

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

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

* Re: [Cocci] moving variable declarations up
  2020-06-17 21:47     ` Johannes Berg
  2020-06-18 15:25       ` Julia Lawall
@ 2020-06-18 15:49       ` Julia Lawall
  1 sibling, 0 replies; 10+ messages in thread
From: Julia Lawall @ 2020-06-18 15:49 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Wed, 17 Jun 2020, Johannes Berg wrote:

> On Wed, 2020-06-17 at 23:19 +0200, Johannes Berg wrote:
> > On Wed, 2020-06-17 at 23:15 +0200, Julia Lawall wrote:
> > > > +T x;
> > >
> > > Change the + to ++
>
> Heh, something funny happened
>
> + u16 *foo;
> + u16[2] bar;
>
> ... some code ...
>
> -u16 *foo;
> -u16 *bar[2];
>
>
> What happened to the array index?
>
> I guess ... at some level I even understand it, that's a property of the
> type, and I was moving the type around. But I really didn't expect that
> :)

If you get the latest version from github, everything should be ok.

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

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

* Re: [Cocci] moving variable declarations up
       [not found]   ` <b6ded75b-c4fe-dab6-b50a-d8ce55793b97@web.de>
@ 2020-06-18  7:34     ` Johannes Berg
  0 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2020-06-18  7:34 UTC (permalink / raw)
  To: Markus Elfring, Julia Lawall; +Cc: cocci

On Thu, 2020-06-18 at 09:33 +0200, Markus Elfring wrote:
> > > You tried it out to move the variable “bar” which is an array of two pointers.
> > 
> > Oops. I just mistyped that when transcribing it to email... It was 'u16
> > bar[2];' in the original.
> 
> The intended absence of asterisks can make the clarification a bit easier.
> Are there still any software development challenges to consider for
> the movement of corresponding array sizes?

Well, it's surprising that it went there? And it doesn't compile?

johannes

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

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

* Re: [Cocci] moving variable declarations up
       [not found] <50990ed6-f5b7-c031-a5df-bdaa6863baa8@web.de>
@ 2020-06-18  7:20 ` Johannes Berg
       [not found]   ` <b6ded75b-c4fe-dab6-b50a-d8ce55793b97@web.de>
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2020-06-18  7:20 UTC (permalink / raw)
  To: Markus Elfring, Julia Lawall; +Cc: cocci

On Thu, 2020-06-18 at 09:19 +0200, Markus Elfring wrote:
> > > > > +T x;
> > > > 
> > > > Change the + to ++
> > 
> > Heh, something funny happened
> > 
> > + u16 *foo;
> > + u16[2] bar;
> > 
> > ... some code ...
> > 
> > -u16 *foo;
> > -u16 *bar[2];
> > 
> > 
> > What happened to the array index?
> > 
> > I guess ... at some level I even understand it, that's a property of the
> > type, and I was moving the type around. But I really didn't expect that
> 
> I find that there are further software development challenges to clarify.
> 
> You tried it out to move the variable “bar” which is an array of two pointers.

Oops. I just mistyped that when transcribing it to email... It was 'u16
bar[2];' in the original.

johannes

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

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

end of thread, other threads:[~2020-06-18 15:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 20:54 [Cocci] moving variable declarations up Johannes Berg
2020-06-17 21:15 ` Julia Lawall
2020-06-17 21:19   ` Johannes Berg
2020-06-17 21:47     ` Johannes Berg
2020-06-18 15:25       ` Julia Lawall
2020-06-18 15:49       ` Julia Lawall
2020-06-18  5:59     ` Julia Lawall
2020-06-18  7:37       ` Johannes Berg
     [not found] <50990ed6-f5b7-c031-a5df-bdaa6863baa8@web.de>
2020-06-18  7:20 ` Johannes Berg
     [not found]   ` <b6ded75b-c4fe-dab6-b50a-d8ce55793b97@web.de>
2020-06-18  7:34     ` Johannes Berg

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.