cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] modifying C99 initializers?
@ 2019-03-21 13:15 Johannes Berg
  2019-03-21 13:40 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2019-03-21 13:15 UTC (permalink / raw)
  To: cocci

Hi all,

I'm trying to do something like this:

@@
identifier list;
@@
struct my_struct list[] = {
<...
 {
+       .field = 27,
 },
...>
};


where "field" is a new struct member and I want it initialized
everywhere.

The above doesn't parse, but is there another way of doing it?

The expected output would be

struct my_struct xyz[] = {
	{
+		.field = 27,
		.other_field = 7,
	},
	{
+		.field = 27,
		.third_field = 8,
	},
};

Thanks,

johannes

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

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

* Re: [Cocci] modifying C99 initializers?
  2019-03-21 13:15 [Cocci] modifying C99 initializers? Johannes Berg
@ 2019-03-21 13:40 ` Julia Lawall
  2019-03-21 14:04   ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2019-03-21 13:40 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Thu, 21 Mar 2019, Johannes Berg wrote:

> Hi all,
>
> I'm trying to do something like this:
>
> @@
> identifier list;
> @@
> struct my_struct list[] = {
> <...
>  {
> +       .field = 27,
>  },
> ...>
> };
>
>
> where "field" is a new struct member and I want it initialized
> everywhere.
>
> The above doesn't parse, but is there another way of doing it?
>
> The expected output would be
>
> struct my_struct xyz[] = {
> 	{
> +		.field = 27,
> 		.other_field = 7,
> 	},
> 	{
> +		.field = 27,
> 		.third_field = 8,
> 	},
> };

Try without the <... ...>.

julia

>
> 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] 6+ messages in thread

* Re: [Cocci] modifying C99 initializers?
  2019-03-21 13:40 ` Julia Lawall
@ 2019-03-21 14:04   ` Johannes Berg
  2019-03-21 19:33     ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2019-03-21 14:04 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Thu, 2019-03-21 at 14:40 +0100, Julia Lawall wrote:
> 
> > @@
> > identifier list;
> > @@
> > struct my_struct list[] = {
> > <...
> >  {
> > +       .field = 27,
> >  },
> > ...>
> > };

> Try without the <... ...>.

I did :-)

If I just remove the <... ...> then it only changes an array that has a
single entry. If I add ... at the end, it only changes the first entry.

johannes

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

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

* Re: [Cocci] modifying C99 initializers?
  2019-03-21 14:04   ` Johannes Berg
@ 2019-03-21 19:33     ` Julia Lawall
  2019-03-21 20:08       ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2019-03-21 19:33 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Thu, 21 Mar 2019, Johannes Berg wrote:

> On Thu, 2019-03-21 at 14:40 +0100, Julia Lawall wrote:
> >
> > > @@
> > > identifier list;
> > > @@
> > > struct my_struct list[] = {
> > > <...
> > >  {
> > > +       .field = 27,
> > >  },
> > > ...>
> > > };
>
> > Try without the <... ...>.
>
> I did :-)
>
> If I just remove the <... ...> then it only changes an array that has a
> single entry. If I add ... at the end, it only changes the first entry.

OK, how about ... before and after?

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

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

* Re: [Cocci] modifying C99 initializers?
  2019-03-21 19:33     ` Julia Lawall
@ 2019-03-21 20:08       ` Johannes Berg
  2019-03-21 20:22         ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Berg @ 2019-03-21 20:08 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Thu, 2019-03-21 at 20:33 +0100, Julia Lawall wrote:
> 
> On Thu, 21 Mar 2019, Johannes Berg wrote:
> 
> > On Thu, 2019-03-21 at 14:40 +0100, Julia Lawall wrote:
> > > 
> > > > @@
> > > > identifier list;
> > > > @@
> > > > struct my_struct list[] = {
> > > > <...
> > > >  {
> > > > +       .field = 27,
> > > >  },
> > > > ...>
> > > > };
> > > Try without the <... ...>.
> > 
> > I did :-)
> > 
> > If I just remove the <... ...> then it only changes an array that has a
> > single entry. If I add ... at the end, it only changes the first entry.
> 
> OK, how about ... before and after?

Huh. I was going to say I tried this, but apparently I didn't since it
actually works!

Thanks!

johannes

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

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

* Re: [Cocci] modifying C99 initializers?
  2019-03-21 20:08       ` Johannes Berg
@ 2019-03-21 20:22         ` Julia Lawall
  0 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2019-03-21 20:22 UTC (permalink / raw)
  To: Johannes Berg; +Cc: cocci



On Thu, 21 Mar 2019, Johannes Berg wrote:

> On Thu, 2019-03-21 at 20:33 +0100, Julia Lawall wrote:
> >
> > On Thu, 21 Mar 2019, Johannes Berg wrote:
> >
> > > On Thu, 2019-03-21 at 14:40 +0100, Julia Lawall wrote:
> > > >
> > > > > @@
> > > > > identifier list;
> > > > > @@
> > > > > struct my_struct list[] = {
> > > > > <...
> > > > >  {
> > > > > +       .field = 27,
> > > > >  },
> > > > > ...>
> > > > > };
> > > > Try without the <... ...>.
> > >
> > > I did :-)
> > >
> > > If I just remove the <... ...> then it only changes an array that has a
> > > single entry. If I add ... at the end, it only changes the first entry.
> >
> > OK, how about ... before and after?
>
> Huh. I was going to say I tried this, but apparently I didn't since it
> actually works!

If it is .x = e, I think it would have worked without any kind of ... at
all.  But array elements are ordered, so the ... are needed.  The pattern
matches multiple times, one time for each array element.

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

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

end of thread, other threads:[~2019-03-21 20:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-21 13:15 [Cocci] modifying C99 initializers? Johannes Berg
2019-03-21 13:40 ` Julia Lawall
2019-03-21 14:04   ` Johannes Berg
2019-03-21 19:33     ` Julia Lawall
2019-03-21 20:08       ` Johannes Berg
2019-03-21 20:22         ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).