All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Adding a newline after a variable definition
@ 2021-06-23  8:38 Fuad Tabba
  2021-06-23  8:54 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Fuad Tabba @ 2021-06-23  8:38 UTC (permalink / raw)
  To: cocci

Hi,

I have a semantic patch that inserts a new variable definition into a
function. I would like it if that variable definition is the only one
in the function, then it should add a new line to separate the
definition from following statements (Linux code formatting style).

I thought that doing this in two steps might be easier, i.e., add the
definition, then check and add a newline if a statement follows:

@@
identifier x;
identifier func;
statement S;
@@
func(...)
 {
struct kvm_cpu_context *x = ...;
+ newline;
S
...
 }

The above works as expected, and it adds "newline;" after the
definition of x. The thing is, is it possible to add an actual new
line, as opposed to a non-whitespace string? I tried just using a +
but that didn't work.

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

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

* Re: [Cocci] Adding a newline after a variable definition
  2021-06-23  8:38 [Cocci] Adding a newline after a variable definition Fuad Tabba
@ 2021-06-23  8:54 ` Julia Lawall
  2021-06-23  9:03   ` Fuad Tabba
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2021-06-23  8:54 UTC (permalink / raw)
  To: Fuad Tabba; +Cc: cocci



On Wed, 23 Jun 2021, Fuad Tabba wrote:

> Hi,
>
> I have a semantic patch that inserts a new variable definition into a
> function. I would like it if that variable definition is the only one
> in the function, then it should add a new line to separate the
> definition from following statements (Linux code formatting style).
>
> I thought that doing this in two steps might be easier, i.e., add the
> definition, then check and add a newline if a statement follows:
>
> @@
> identifier x;
> identifier func;
> statement S;
> @@
> func(...)
>  {
> struct kvm_cpu_context *x = ...;
> + newline;
> S
> ...
>  }
>
> The above works as expected, and it adds "newline;" after the
> definition of x. The thing is, is it possible to add an actual new
> line, as opposed to a non-whitespace string? I tried just using a +
> but that didn't work.

I think that the problem is not that the change is not being made, but
that spatch doesn't think it's worth showing you the change, since the
only change is in the whitespace.  Try adding the argument --force-diff

Note that you can cause this argument to always be used with your semantic
patch by putting

#spatch --force-diff

at the top of the file.

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

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

* Re: [Cocci] Adding a newline after a variable definition
  2021-06-23  8:54 ` Julia Lawall
@ 2021-06-23  9:03   ` Fuad Tabba
  0 siblings, 0 replies; 3+ messages in thread
From: Fuad Tabba @ 2021-06-23  9:03 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

That works, thank you!

Cheers,
/fuad

On Wed, Jun 23, 2021 at 9:54 AM Julia Lawall <julia.lawall@inria.fr> wrote:
>
>
>
> On Wed, 23 Jun 2021, Fuad Tabba wrote:
>
> > Hi,
> >
> > I have a semantic patch that inserts a new variable definition into a
> > function. I would like it if that variable definition is the only one
> > in the function, then it should add a new line to separate the
> > definition from following statements (Linux code formatting style).
> >
> > I thought that doing this in two steps might be easier, i.e., add the
> > definition, then check and add a newline if a statement follows:
> >
> > @@
> > identifier x;
> > identifier func;
> > statement S;
> > @@
> > func(...)
> >  {
> > struct kvm_cpu_context *x = ...;
> > + newline;
> > S
> > ...
> >  }
> >
> > The above works as expected, and it adds "newline;" after the
> > definition of x. The thing is, is it possible to add an actual new
> > line, as opposed to a non-whitespace string? I tried just using a +
> > but that didn't work.
>
> I think that the problem is not that the change is not being made, but
> that spatch doesn't think it's worth showing you the change, since the
> only change is in the whitespace.  Try adding the argument --force-diff
>
> Note that you can cause this argument to always be used with your semantic
> patch by putting
>
> #spatch --force-diff
>
> at the top of the file.
>
> julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, other threads:[~2021-06-23  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23  8:38 [Cocci] Adding a newline after a variable definition Fuad Tabba
2021-06-23  8:54 ` Julia Lawall
2021-06-23  9:03   ` Fuad Tabba

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.