All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] spatch issue with C struct initialization
@ 2014-04-03  8:30 Marcel Apfelbaum
  2014-04-03 10:16 ` Julia Lawall
  0 siblings, 1 reply; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-03  8:30 UTC (permalink / raw)
  To: cocci

Hi,
I tried to use the coccinellery/doubleinit/doubleinit.cocci script
using the latest spatch version (1.0.0-rc20, I tried prev versions too).

I received the following error:
init_defs_builtins: /usr/local/share/coccinelle/standard.h
400 401
Fatal error: exception Failure("minus: parse error: 
 = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
    around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
")

Am I missing something, am I doing something wrong?

I need the following construct to work:
struct I s =
{
...
.fld = E,
...
};

Any help will be appreciated,
Thanks,
Marcel

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03  8:30 [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
@ 2014-04-03 10:16 ` Julia Lawall
  2014-04-03 13:31   ` Marcel Apfelbaum
  0 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-03 10:16 UTC (permalink / raw)
  To: cocci

On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:

> Hi,
> I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> using the latest spatch version (1.0.0-rc20, I tried prev versions too).
>
> I received the following error:
> init_defs_builtins: /usr/local/share/coccinelle/standard.h
> 400 401
> Fatal error: exception Failure("minus: parse error:
>  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
>     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> ")
>
> Am I missing something, am I doing something wrong?
>
> I need the following construct to work:
> struct I s =
> {
> ...
> .fld = E,
> ...
> };

Sorry, coccinellery versions may be out of date.  You need to put a comma
after the first ...

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 10:16 ` Julia Lawall
@ 2014-04-03 13:31   ` Marcel Apfelbaum
  2014-04-03 14:19     ` Julia Lawall
  2014-04-03 14:22     ` Julia Lawall
  0 siblings, 2 replies; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-03 13:31 UTC (permalink / raw)
  To: cocci

On Thu, 2014-04-03 at 12:16 +0200, Julia Lawall wrote:
> On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> 
> > Hi,
> > I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> > using the latest spatch version (1.0.0-rc20, I tried prev versions too).
> >
> > I received the following error:
> > init_defs_builtins: /usr/local/share/coccinelle/standard.h
> > 400 401
> > Fatal error: exception Failure("minus: parse error:
> >  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
> >     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> > ")
> >
> > Am I missing something, am I doing something wrong?
> >
> > I need the following construct to work:
> > struct I s =
> > {
> > ...
> > .fld = E,
> > ...
> > };
> 
> Sorry, coccinellery versions may be out of date.  You need to put a comma
> after the first ...
Hi Julia,
Thank you for your fast response.

I could compile after adding a comma(thanks!), but it still doesn't work.
For example, I am not able to delete a field which is not the first one
in the initialization list.

Ex:
c file:
struct my_struct {
 int fld1;
 int fld2;
 int fld3;
};

static const my_struct m1 = {
 .fld1 = 1,
 .fld2 = 2,
 .fld3 = 3,
}

cocci:
@@
identifier I;
expression E,
@@
struct my_struct I = {
 ...,
 - .fld2 = E,
 ...
};

The above compiles fine but does not remove the field.
I think it should work, any idea why is not working?

Thank you,
Marcel

> 
> julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 13:31   ` Marcel Apfelbaum
@ 2014-04-03 14:19     ` Julia Lawall
  2014-04-03 14:29       ` Marcel Apfelbaum
  2014-04-03 14:22     ` Julia Lawall
  1 sibling, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-03 14:19 UTC (permalink / raw)
  To: cocci



On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:

> On Thu, 2014-04-03 at 12:16 +0200, Julia Lawall wrote:
> > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> >
> > > Hi,
> > > I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> > > using the latest spatch version (1.0.0-rc20, I tried prev versions too).
> > >
> > > I received the following error:
> > > init_defs_builtins: /usr/local/share/coccinelle/standard.h
> > > 400 401
> > > Fatal error: exception Failure("minus: parse error:
> > >  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
> > >     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> > > ")
> > >
> > > Am I missing something, am I doing something wrong?
> > >
> > > I need the following construct to work:
> > > struct I s =
> > > {
> > > ...
> > > .fld = E,
> > > ...
> > > };
> >
> > Sorry, coccinellery versions may be out of date.  You need to put a comma
> > after the first ...
> Hi Julia,
> Thank you for your fast response.
>
> I could compile after adding a comma(thanks!), but it still doesn't work.
> For example, I am not able to delete a field which is not the first one
> in the initialization list.
>
> Ex:
> c file:
> struct my_struct {
>  int fld1;
>  int fld2;
>  int fld3;
> };
>
> static const my_struct m1 = {
>  .fld1 = 1,
>  .fld2 = 2,
>  .fld3 = 3,
> }

Is this your exact program?  Because I think there should be the word
"struct" somewhere?  If code doesn't compile, Coccinelle just ignores it
silently, unless you use the --verbose-parsing option.

I'll double check whether that is the only problem.

julia

> cocci:
> @@
> identifier I;
> expression E,
> @@
> struct my_struct I = {
>  ...,
>  - .fld2 = E,
>  ...
> };
>
> The above compiles fine but does not remove the field.
> I think it should work, any idea why is not working?
>
> Thank you,
> Marcel
>
> >
> > julia
>
>
>
>

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 13:31   ` Marcel Apfelbaum
  2014-04-03 14:19     ` Julia Lawall
@ 2014-04-03 14:22     ` Julia Lawall
  1 sibling, 0 replies; 20+ messages in thread
From: Julia Lawall @ 2014-04-03 14:22 UTC (permalink / raw)
  To: cocci

For me, it worked fine with exactly the following files:

C file:

struct my_struct {
  int fld1;
  int fld2;
  int fld3;
};

static const struct my_struct m1 = {
  .fld1 = 1,
  .fld2 = 2,
  .fld3 = 3,
};

Cocci file:

@@
identifier I;
expression E;
@@
struct my_struct I = {
 ...,
- .fld1 = E,
 ...
};

I tried with fld1, fld2, and fld3, and all were fine.

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 14:19     ` Julia Lawall
@ 2014-04-03 14:29       ` Marcel Apfelbaum
  2014-04-03 14:33         ` Julia Lawall
  2014-04-04 11:21         ` Julia Lawall
  0 siblings, 2 replies; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-03 14:29 UTC (permalink / raw)
  To: cocci

On Thu, 2014-04-03 at 16:19 +0200, Julia Lawall wrote:
> 
> 
> On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> 
> > On Thu, 2014-04-03 at 12:16 +0200, Julia Lawall wrote:
> > > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> > >
> > > > Hi,
> > > > I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> > > > using the latest spatch version (1.0.0-rc20, I tried prev versions too).
> > > >
> > > > I received the following error:
> > > > init_defs_builtins: /usr/local/share/coccinelle/standard.h
> > > > 400 401
> > > > Fatal error: exception Failure("minus: parse error:
> > > >  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
> > > >     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> > > > ")
> > > >
> > > > Am I missing something, am I doing something wrong?
> > > >
> > > > I need the following construct to work:
> > > > struct I s =
> > > > {
> > > > ...
> > > > .fld = E,
> > > > ...
> > > > };
> > >
> > > Sorry, coccinellery versions may be out of date.  You need to put a comma
> > > after the first ...
> > Hi Julia,
> > Thank you for your fast response.
> >
> > I could compile after adding a comma(thanks!), but it still doesn't work.
> > For example, I am not able to delete a field which is not the first one
> > in the initialization list.
> >
> > Ex:
> > c file:
> > struct my_struct {
> >  int fld1;
> >  int fld2;
> >  int fld3;
> > };
> >
> > static const my_struct m1 = {
> >  .fld1 = 1,
> >  .fld2 = 2,
> >  .fld3 = 3,
> > }
> 
> Is this your exact program?  Because I think there should be the word
> "struct" somewhere?  If code doesn't compile, Coccinelle just ignores it
> silently, unless you use the --verbose-parsing option.
> 
> I'll double check whether that is the only problem.

Hi Julia,
No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)

However, using your verbose flag (thanks!!! I was looking for it) I got:

bad: static const VMStateDescription vmstate_stellaris_gptm = {
bad:     .name = "stellaris_gptm",
bad:     .version_id = 1,
bad:     .minimum_version_id = 1,
bad:     .minimum_version_id_old = 1,
BAD:!!!!!     .fields      = (VMStateField[]) {
bad:         VMSTATE_UINT32(config, gptm_state),
bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
bad:         VMSTATE_UINT32(control, gptm_state),
bad:         VMSTATE_UINT32(state, gptm_state),
bad:         VMSTATE_UINT32(mask, gptm_state),
bad:         VMSTATE_UNUSED(8),
bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
bad:         VMSTATE_UINT32(rtc, gptm_state),
bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
bad:         VMSTATE_END_OF_LIST()
bad:     }
bad: };

Judging by the capital "BAD", the ".fields" field is making
the problem. Any way around it?

Appreciate your involvement,
Marcel

> 
> julia
> 
> > cocci:
> > @@
> > identifier I;
> > expression E,
> > @@
> > struct my_struct I = {
> >  ...,
> >  - .fld2 = E,
> >  ...
> > };
> >
> > The above compiles fine but does not remove the field.
> > I think it should work, any idea why is not working?
> >
> > Thank you,
> > Marcel
> >
> > >
> > > julia
> >
> >
> >
> >

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 14:29       ` Marcel Apfelbaum
@ 2014-04-03 14:33         ` Julia Lawall
  2014-04-03 14:38           ` Marcel Apfelbaum
  2014-04-04 11:21         ` Julia Lawall
  1 sibling, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-03 14:33 UTC (permalink / raw)
  To: cocci



On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:

> On Thu, 2014-04-03 at 16:19 +0200, Julia Lawall wrote:
> >
> >
> > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> >
> > > On Thu, 2014-04-03 at 12:16 +0200, Julia Lawall wrote:
> > > > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> > > >
> > > > > Hi,
> > > > > I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> > > > > using the latest spatch version (1.0.0-rc20, I tried prev versions too).
> > > > >
> > > > > I received the following error:
> > > > > init_defs_builtins: /usr/local/share/coccinelle/standard.h
> > > > > 400 401
> > > > > Fatal error: exception Failure("minus: parse error:
> > > > >  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
> > > > >     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> > > > > ")
> > > > >
> > > > > Am I missing something, am I doing something wrong?
> > > > >
> > > > > I need the following construct to work:
> > > > > struct I s =
> > > > > {
> > > > > ...
> > > > > .fld = E,
> > > > > ...
> > > > > };
> > > >
> > > > Sorry, coccinellery versions may be out of date.  You need to put a comma
> > > > after the first ...
> > > Hi Julia,
> > > Thank you for your fast response.
> > >
> > > I could compile after adding a comma(thanks!), but it still doesn't work.
> > > For example, I am not able to delete a field which is not the first one
> > > in the initialization list.
> > >
> > > Ex:
> > > c file:
> > > struct my_struct {
> > >  int fld1;
> > >  int fld2;
> > >  int fld3;
> > > };
> > >
> > > static const my_struct m1 = {
> > >  .fld1 = 1,
> > >  .fld2 = 2,
> > >  .fld3 = 3,
> > > }
> >
> > Is this your exact program?  Because I think there should be the word
> > "struct" somewhere?  If code doesn't compile, Coccinelle just ignores it
> > silently, unless you use the --verbose-parsing option.
> >
> > I'll double check whether that is the only problem.
>
> Hi Julia,
> No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)
>
> However, using your verbose flag (thanks!!! I was looking for it) I got:
>
> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> bad:     .name = "stellaris_gptm",
> bad:     .version_id = 1,
> bad:     .minimum_version_id = 1,
> bad:     .minimum_version_id_old = 1,
> BAD:!!!!!     .fields      = (VMStateField[]) {

I suspect that the parser does not consider the possibility of a cast in
this position.  At the moment, I see no way around it.  I can look into
how to add the possibility of a cast.

julia

> bad:         VMSTATE_UINT32(config, gptm_state),
> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> bad:         VMSTATE_UINT32(control, gptm_state),
> bad:         VMSTATE_UINT32(state, gptm_state),
> bad:         VMSTATE_UINT32(mask, gptm_state),
> bad:         VMSTATE_UNUSED(8),
> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> bad:         VMSTATE_UINT32(rtc, gptm_state),
> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> bad:         VMSTATE_END_OF_LIST()
> bad:     }
> bad: };
>
> Judging by the capital "BAD", the ".fields" field is making
> the problem. Any way around it?
>
> Appreciate your involvement,
> Marcel
>
> >
> > julia
> >
> > > cocci:
> > > @@
> > > identifier I;
> > > expression E,
> > > @@
> > > struct my_struct I = {
> > >  ...,
> > >  - .fld2 = E,
> > >  ...
> > > };
> > >
> > > The above compiles fine but does not remove the field.
> > > I think it should work, any idea why is not working?
> > >
> > > Thank you,
> > > Marcel
> > >
> > > >
> > > > julia
> > >
> > >
> > >
> > >
>
>
>
>

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 14:33         ` Julia Lawall
@ 2014-04-03 14:38           ` Marcel Apfelbaum
  0 siblings, 0 replies; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-03 14:38 UTC (permalink / raw)
  To: cocci

On Thu, 2014-04-03 at 16:33 +0200, Julia Lawall wrote:
> 
> 
> On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> 
> > On Thu, 2014-04-03 at 16:19 +0200, Julia Lawall wrote:
> > >
> > >
> > > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> > >
> > > > On Thu, 2014-04-03 at 12:16 +0200, Julia Lawall wrote:
> > > > > On Thu, 3 Apr 2014, Marcel Apfelbaum wrote:
> > > > >
> > > > > > Hi,
> > > > > > I tried to use the coccinellery/doubleinit/doubleinit.cocci script
> > > > > > using the latest spatch version (1.0.0-rc20, I tried prev versions too).
> > > > > >
> > > > > > I received the following error:
> > > > > > init_defs_builtins: /usr/local/share/coccinelle/standard.h
> > > > > > 400 401
> > > > > > Fatal error: exception Failure("minus: parse error:
> > > > > >  = File "coccinellery/doubleinit/doubleinit.cocci", line 17, column 22,  charpos = 400
> > > > > >     around = '.', whole content = struct I s =@p0 { ... .fld at p = E, ...};
> > > > > > ")
> > > > > >
> > > > > > Am I missing something, am I doing something wrong?
> > > > > >
> > > > > > I need the following construct to work:
> > > > > > struct I s =
> > > > > > {
> > > > > > ...
> > > > > > .fld = E,
> > > > > > ...
> > > > > > };
> > > > >
> > > > > Sorry, coccinellery versions may be out of date.  You need to put a comma
> > > > > after the first ...
> > > > Hi Julia,
> > > > Thank you for your fast response.
> > > >
> > > > I could compile after adding a comma(thanks!), but it still doesn't work.
> > > > For example, I am not able to delete a field which is not the first one
> > > > in the initialization list.
> > > >
> > > > Ex:
> > > > c file:
> > > > struct my_struct {
> > > >  int fld1;
> > > >  int fld2;
> > > >  int fld3;
> > > > };
> > > >
> > > > static const my_struct m1 = {
> > > >  .fld1 = 1,
> > > >  .fld2 = 2,
> > > >  .fld3 = 3,
> > > > }
> > >
> > > Is this your exact program?  Because I think there should be the word
> > > "struct" somewhere?  If code doesn't compile, Coccinelle just ignores it
> > > silently, unless you use the --verbose-parsing option.
> > >
> > > I'll double check whether that is the only problem.
> >
> > Hi Julia,
> > No, this is not "a real" code, only a pseudo code. Indeed, struct is missing :)
> >
> > However, using your verbose flag (thanks!!! I was looking for it) I got:
> >
> > bad: static const VMStateDescription vmstate_stellaris_gptm = {
> > bad:     .name = "stellaris_gptm",
> > bad:     .version_id = 1,
> > bad:     .minimum_version_id = 1,
> > bad:     .minimum_version_id_old = 1,
> > BAD:!!!!!     .fields      = (VMStateField[]) {
> 
> I suspect that the parser does not consider the possibility of a cast in
> this position.  At the moment, I see no way around it.  I can look into
> how to add the possibility of a cast.
Understood,

Thanks Julia!
Marcel
> 
> julia
> 
> > bad:         VMSTATE_UINT32(config, gptm_state),
> > bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> > bad:         VMSTATE_UINT32(control, gptm_state),
> > bad:         VMSTATE_UINT32(state, gptm_state),
> > bad:         VMSTATE_UINT32(mask, gptm_state),
> > bad:         VMSTATE_UNUSED(8),
> > bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> > bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> > bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> > bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> > bad:         VMSTATE_UINT32(rtc, gptm_state),
> > bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> > bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> > bad:         VMSTATE_END_OF_LIST()
> > bad:     }
> > bad: };
> >
> > Judging by the capital "BAD", the ".fields" field is making
> > the problem. Any way around it?
> >
> > Appreciate your involvement,
> > Marcel
> >
> > >
> > > julia
> > >
> > > > cocci:
> > > > @@
> > > > identifier I;
> > > > expression E,
> > > > @@
> > > > struct my_struct I = {
> > > >  ...,
> > > >  - .fld2 = E,
> > > >  ...
> > > > };
> > > >
> > > > The above compiles fine but does not remove the field.
> > > > I think it should work, any idea why is not working?
> > > >
> > > > Thank you,
> > > > Marcel
> > > >
> > > > >
> > > > > julia
> > > >
> > > >
> > > >
> > > >
> >
> >
> >
> >

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

* [Cocci] spatch issue with C struct initialization
  2014-04-03 14:29       ` Marcel Apfelbaum
  2014-04-03 14:33         ` Julia Lawall
@ 2014-04-04 11:21         ` Julia Lawall
  2014-04-05 15:01           ` Michael Stefaniuc
  1 sibling, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-04 11:21 UTC (permalink / raw)
  To: cocci

> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> bad:     .name = "stellaris_gptm",
> bad:     .version_id = 1,
> bad:     .minimum_version_id = 1,
> bad:     .minimum_version_id_old = 1,
> BAD:!!!!!     .fields      = (VMStateField[]) {
> bad:         VMSTATE_UINT32(config, gptm_state),
> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> bad:         VMSTATE_UINT32(control, gptm_state),
> bad:         VMSTATE_UINT32(state, gptm_state),
> bad:         VMSTATE_UINT32(mask, gptm_state),
> bad:         VMSTATE_UNUSED(8),
> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> bad:         VMSTATE_UINT32(rtc, gptm_state),
> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> bad:         VMSTATE_END_OF_LIST()
> bad:     }
> bad: };
>
> Judging by the capital "BAD", the ".fields" field is making
> the problem. Any way around it?

Unfortunately, I'm not sure how to do this without introducing conflicts
in the grammar.  Currently the grammar is roughly of the following form
(copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):

initializer
	: assignment_expression
	| '{' initializer_list '}'
	| '{' initializer_list ',' '}'
	;

A cast on an ordinary expression is a bit deep in assignment_expression.
So the parser is not happy to have the possibility of a cast on { ... } as
well.

The cast seems to be allowed in C99, but I don't know what the grammar
looks like to allow that.

Any suggestions are welcome.

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-04 11:21         ` Julia Lawall
@ 2014-04-05 15:01           ` Michael Stefaniuc
  2014-04-05 15:17             ` Julia Lawall
  0 siblings, 1 reply; 20+ messages in thread
From: Michael Stefaniuc @ 2014-04-05 15:01 UTC (permalink / raw)
  To: cocci

On 04/04/2014 01:21 PM, Julia Lawall wrote:
>> bad: static const VMStateDescription vmstate_stellaris_gptm = {
>> bad:     .name = "stellaris_gptm",
>> bad:     .version_id = 1,
>> bad:     .minimum_version_id = 1,
>> bad:     .minimum_version_id_old = 1,
>> BAD:!!!!!     .fields      = (VMStateField[]) {
>> bad:         VMSTATE_UINT32(config, gptm_state),
>> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
>> bad:         VMSTATE_UINT32(control, gptm_state),
>> bad:         VMSTATE_UINT32(state, gptm_state),
>> bad:         VMSTATE_UINT32(mask, gptm_state),
>> bad:         VMSTATE_UNUSED(8),
>> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
>> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
>> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
>> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
>> bad:         VMSTATE_UINT32(rtc, gptm_state),
>> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
>> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
>> bad:         VMSTATE_END_OF_LIST()
>> bad:     }
>> bad: };
>>
>> Judging by the capital "BAD", the ".fields" field is making
>> the problem. Any way around it?
> 
> Unfortunately, I'm not sure how to do this without introducing conflicts
> in the grammar.  Currently the grammar is roughly of the following form
> (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
> 
> initializer
> 	: assignment_expression
> 	| '{' initializer_list '}'
> 	| '{' initializer_list ',' '}'
> 	;
> 
> A cast on an ordinary expression is a bit deep in assignment_expression.
> So the parser is not happy to have the possibility of a cast on { ... } as
> well.
> 
> The cast seems to be allowed in C99, but I don't know what the grammar
> looks like to allow that.
That's actually not a cast but a compound literal
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html

bye
	micheal

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

* [Cocci] spatch issue with C struct initialization
  2014-04-05 15:01           ` Michael Stefaniuc
@ 2014-04-05 15:17             ` Julia Lawall
  2014-04-06  6:21               ` [Cocci] Handling of compound literals? SF Markus Elfring
  2014-04-06  7:45               ` [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
  0 siblings, 2 replies; 20+ messages in thread
From: Julia Lawall @ 2014-04-05 15:17 UTC (permalink / raw)
  To: cocci



On Sat, 5 Apr 2014, Michael Stefaniuc wrote:

> On 04/04/2014 01:21 PM, Julia Lawall wrote:
> >> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> >> bad:     .name = "stellaris_gptm",
> >> bad:     .version_id = 1,
> >> bad:     .minimum_version_id = 1,
> >> bad:     .minimum_version_id_old = 1,
> >> BAD:!!!!!     .fields      = (VMStateField[]) {
> >> bad:         VMSTATE_UINT32(config, gptm_state),
> >> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> >> bad:         VMSTATE_UINT32(control, gptm_state),
> >> bad:         VMSTATE_UINT32(state, gptm_state),
> >> bad:         VMSTATE_UINT32(mask, gptm_state),
> >> bad:         VMSTATE_UNUSED(8),
> >> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> >> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> >> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> >> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> >> bad:         VMSTATE_UINT32(rtc, gptm_state),
> >> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> >> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> >> bad:         VMSTATE_END_OF_LIST()
> >> bad:     }
> >> bad: };
> >>
> >> Judging by the capital "BAD", the ".fields" field is making
> >> the problem. Any way around it?
> > 
> > Unfortunately, I'm not sure how to do this without introducing conflicts
> > in the grammar.  Currently the grammar is roughly of the following form
> > (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
> > 
> > initializer
> > 	: assignment_expression
> > 	| '{' initializer_list '}'
> > 	| '{' initializer_list ',' '}'
> > 	;
> > 
> > A cast on an ordinary expression is a bit deep in assignment_expression.
> > So the parser is not happy to have the possibility of a cast on { ... } as
> > well.
> > 
> > The cast seems to be allowed in C99, but I don't know what the grammar
> > looks like to allow that.
> That's actually not a cast but a compound literal
> http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html

Thanks for the pointer.  I'm still not sure to see how to solve the 
ambiguity problem.

julia

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

* [Cocci] Handling of compound literals?
  2014-04-05 15:17             ` Julia Lawall
@ 2014-04-06  6:21               ` SF Markus Elfring
  2014-04-06  7:45               ` [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
  1 sibling, 0 replies; 20+ messages in thread
From: SF Markus Elfring @ 2014-04-06  6:21 UTC (permalink / raw)
  To: cocci

>> That's actually not a cast but a compound literal
>> http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
> 
> [...] I'm still not sure to see how to solve the ambiguity problem.

How do you think about to ask any other parser and compiler developers?

Regards,
Markus

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

* [Cocci] spatch issue with C struct initialization
  2014-04-05 15:17             ` Julia Lawall
  2014-04-06  6:21               ` [Cocci] Handling of compound literals? SF Markus Elfring
@ 2014-04-06  7:45               ` Marcel Apfelbaum
  2014-04-06 10:57                 ` Julia Lawall
  2014-04-20 20:29                 ` Julia Lawall
  1 sibling, 2 replies; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-06  7:45 UTC (permalink / raw)
  To: cocci

On Sat, 2014-04-05 at 17:17 +0200, Julia Lawall wrote:
> 
> 
> On Sat, 5 Apr 2014, Michael Stefaniuc wrote:
> 
> > On 04/04/2014 01:21 PM, Julia Lawall wrote:
> > >> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> > >> bad:     .name = "stellaris_gptm",
> > >> bad:     .version_id = 1,
> > >> bad:     .minimum_version_id = 1,
> > >> bad:     .minimum_version_id_old = 1,
> > >> BAD:!!!!!     .fields      = (VMStateField[]) {
> > >> bad:         VMSTATE_UINT32(config, gptm_state),
> > >> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> > >> bad:         VMSTATE_UINT32(control, gptm_state),
> > >> bad:         VMSTATE_UINT32(state, gptm_state),
> > >> bad:         VMSTATE_UINT32(mask, gptm_state),
> > >> bad:         VMSTATE_UNUSED(8),
> > >> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> > >> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> > >> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> > >> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> > >> bad:         VMSTATE_UINT32(rtc, gptm_state),
> > >> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> > >> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> > >> bad:         VMSTATE_END_OF_LIST()
> > >> bad:     }
> > >> bad: };
> > >>
> > >> Judging by the capital "BAD", the ".fields" field is making
> > >> the problem. Any way around it?
> > > 
> > > Unfortunately, I'm not sure how to do this without introducing conflicts
> > > in the grammar.  Currently the grammar is roughly of the following form
> > > (copied from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html):
> > > 
> > > initializer
> > >     : assignment_expression
> > >     | '{' initializer_list '}'
> > >     | '{' initializer_list ',' '}'
> > >     ;
> > > 
> > > A cast on an ordinary expression is a bit deep in assignment_expression.
> > > So the parser is not happy to have the possibility of a cast on { ... } as
> > > well.
> > > 
> > > The cast seems to be allowed in C99, but I don't know what the grammar
> > > looks like to allow that.
> > That's actually not a cast but a compound literal
> > http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
> 
> Thanks for the pointer.  I'm still not sure to see how to solve the 
> ambiguity problem.

Not being an expert on grammar, there is a chance this will work ?

 initializer
    : assignment_expression
       | '{' initializer_list '}'
       | '{' initializer_list ',' '}'
       | ( type-name ) { initializer-list }
       | ( type-name ) { initializer-list , }

If you can point me to the code dealing with it, I can try to play with
it a little bit.

Thanks,
Marcel

> 
> julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-06  7:45               ` [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
@ 2014-04-06 10:57                 ` Julia Lawall
  2014-04-20 20:29                 ` Julia Lawall
  1 sibling, 0 replies; 20+ messages in thread
From: Julia Lawall @ 2014-04-06 10:57 UTC (permalink / raw)
  To: cocci

> Not being an expert on grammar, there is a chance this will work ?
>
>  initializer
>     : assignment_expression
>        | '{' initializer_list '}'
>        | '{' initializer_list ',' '}'
>        | ( type-name ) { initializer-list }
>        | ( type-name ) { initializer-list , }
>
> If you can point me to the code dealing with it, I can try to play with
> it a little bit.

I think I already tried the same thing.  The problem is that ( type-name )
is already buried deep within assignment_expression, for an ordinary cast,
so the parser doesn't know which rule to choose.

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-06  7:45               ` [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
  2014-04-06 10:57                 ` Julia Lawall
@ 2014-04-20 20:29                 ` Julia Lawall
  2014-04-22  8:21                   ` Marcel Apfelbaum
  1 sibling, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-20 20:29 UTC (permalink / raw)
  To: cocci



On Sun, 6 Apr 2014, Marcel Apfelbaum wrote:

> On Sat, 2014-04-05 at 17:17 +0200, Julia Lawall wrote:
> > 
> > 
> > On Sat, 5 Apr 2014, Michael Stefaniuc wrote:
> > 
> > > On 04/04/2014 01:21 PM, Julia Lawall wrote:
> > > >> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> > > >> bad:     .name = "stellaris_gptm",
> > > >> bad:     .version_id = 1,
> > > >> bad:     .minimum_version_id = 1,
> > > >> bad:     .minimum_version_id_old = 1,
> > > >> BAD:!!!!!     .fields      = (VMStateField[]) {
> > > >> bad:         VMSTATE_UINT32(config, gptm_state),
> > > >> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> > > >> bad:         VMSTATE_UINT32(control, gptm_state),
> > > >> bad:         VMSTATE_UINT32(state, gptm_state),
> > > >> bad:         VMSTATE_UINT32(mask, gptm_state),
> > > >> bad:         VMSTATE_UNUSED(8),
> > > >> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> > > >> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> > > >> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> > > >> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> > > >> bad:         VMSTATE_UINT32(rtc, gptm_state),
> > > >> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> > > >> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> > > >> bad:         VMSTATE_END_OF_LIST()
> > > >> bad:     }
> > > >> bad: };
> > > >>
> > > >> Judging by the capital "BAD", the ".fields" field is making
> > > >> the problem. Any way around it?

In the end, the problem turned out to be not all what I thought.  
Actually, the Coccinelle C parser already accepts constructor expressions.  
The problem is that VMStateField is not recognized as a type.  One 
approach is to find the header file that defines this type and then give 
Coccinelle enough information to find it.  There are various options for 
that:

--all-includes: include all header files that are mentioned in the C file
--recursive-includes: include also header files that are included from 
other header files
--relax-include-path: include a header file that has a unique name, no 
matter where it is defined in the source tree
-I path: give the name of a directory in which to search for header files.  
It is possilble to have more than one -I argument.

If none of this works, then you can also cause it to consider VMStateField 
to be a macro by adding eg #define VMStateField int to the macro 
file standard.h.

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-20 20:29                 ` Julia Lawall
@ 2014-04-22  8:21                   ` Marcel Apfelbaum
  0 siblings, 0 replies; 20+ messages in thread
From: Marcel Apfelbaum @ 2014-04-22  8:21 UTC (permalink / raw)
  To: cocci

On Sun, 2014-04-20 at 22:29 +0200, Julia Lawall wrote:
> 
> 
> On Sun, 6 Apr 2014, Marcel Apfelbaum wrote:
> 
> > On Sat, 2014-04-05 at 17:17 +0200, Julia Lawall wrote:
> > > 
> > > 
> > > On Sat, 5 Apr 2014, Michael Stefaniuc wrote:
> > > 
> > > > On 04/04/2014 01:21 PM, Julia Lawall wrote:
> > > > >> bad: static const VMStateDescription vmstate_stellaris_gptm = {
> > > > >> bad:     .name = "stellaris_gptm",
> > > > >> bad:     .version_id = 1,
> > > > >> bad:     .minimum_version_id = 1,
> > > > >> bad:     .minimum_version_id_old = 1,
> > > > >> BAD:!!!!!     .fields      = (VMStateField[]) {
> > > > >> bad:         VMSTATE_UINT32(config, gptm_state),
> > > > >> bad:         VMSTATE_UINT32_ARRAY(mode, gptm_state, 2),
> > > > >> bad:         VMSTATE_UINT32(control, gptm_state),
> > > > >> bad:         VMSTATE_UINT32(state, gptm_state),
> > > > >> bad:         VMSTATE_UINT32(mask, gptm_state),
> > > > >> bad:         VMSTATE_UNUSED(8),
> > > > >> bad:         VMSTATE_UINT32_ARRAY(load, gptm_state, 2),
> > > > >> bad:         VMSTATE_UINT32_ARRAY(match, gptm_state, 2),
> > > > >> bad:         VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2),
> > > > >> bad:         VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2),
> > > > >> bad:         VMSTATE_UINT32(rtc, gptm_state),
> > > > >> bad:         VMSTATE_INT64_ARRAY(tick, gptm_state, 2),
> > > > >> bad:         VMSTATE_TIMER_ARRAY(timer, gptm_state, 2),
> > > > >> bad:         VMSTATE_END_OF_LIST()
> > > > >> bad:     }
> > > > >> bad: };
> > > > >>
> > > > >> Judging by the capital "BAD", the ".fields" field is making
> > > > >> the problem. Any way around it?
> 
> In the end, the problem turned out to be not all what I thought.  
> Actually, the Coccinelle C parser already accepts constructor expressions.  
> The problem is that VMStateField is not recognized as a type.  One 
> approach is to find the header file that defines this type and then give 
> Coccinelle enough information to find it.  There are various options for 
> that:
> 
> --all-includes: include all header files that are mentioned in the C file
> --recursive-includes: include also header files that are included from 
> other header files
> --relax-include-path: include a header file that has a unique name, no 
> matter where it is defined in the source tree
> -I path: give the name of a directory in which to search for header files.  
> It is possilble to have more than one -I argument.
> 
> If none of this works, then you can also cause it to consider VMStateField 
> to be a macro by adding eg #define VMStateField int to the macro 
> file standard.h.

Hi Julia,

Thanks again for the detailed analysis. I will try the options you mentioned.
Marcel
 
> 
> julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-07 13:27   ` Nic Volanschi (R&D)
@ 2014-04-07 13:48     ` Julia Lawall
  0 siblings, 0 replies; 20+ messages in thread
From: Julia Lawall @ 2014-04-07 13:48 UTC (permalink / raw)
  To: cocci



On Mon, 7 Apr 2014, Nic Volanschi (R&D) wrote:

> On Mon, 2014-04-07 at 14:54 +0200, Julia Lawall wrote:
> > On Mon, 7 Apr 2014, Nic Volanschi (R&D) wrote:
> > > I agree that the "initializer" nonterminal is not the right place to
> > > extend the grammar, because it would not allow legal statements such as:
> > >
> > >   structure = ((struct foo) {x + y, 'a', 0});
> > >
> > > the example coming from:
> > > http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
> > >
> > > Rather, it seems to me that the right place to extend the grammar is the
> > > "cast_expression" nonterminal:
> > >
> > > > cast_expression
> > > > 	: unary_expression
> > > > 	| '(' type_name ')' cast_expression
> > >           | '(' type_name ')' '{' initializer_list '}'
> > > > 	;
> > >
> > > This would not only allow the above legal expression, but should also
> > > avoid to introduce a conflict in the grammar.
> >
> > I can try this.  So the point is that if a type is present, then { ... }
> > is a legal expression in any context?
>
> This is how I understand the above web page about compound literals.
> Indeed, I tried the following code in gcc and it works fine:
>
> int main() {
>   struct s { int i; int j; } s1;
>   printf("{%d, %d}\n", (struct s){ 44, 55}.i, (struct s){ 66, 77}.j);
>   printf("%d\n", (int[]){12,13,14}[1] + 10);
> }
>
> So it seems that a compound literal can be used in any place where an
> lvalue of the corresponding type is legal.
>
> > On the other hand, Coccinelle is
> > not a syntax checker.  It is fine for it to accept syntax that is invalid,
> > as long as the effect in terms of metavariables etc is expectable to the
> > user.
>
> Sure. But in the given case, I'm not sure you create illegal uses,
> anyways.

OK, interesting.  Thanks.

Maybe they made it an expression to avoid the parsing problem :)

Anyway, I will update Coccinelle shortly.

julia

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

* [Cocci] spatch issue with C struct initialization
  2014-04-07 12:54 ` Julia Lawall
@ 2014-04-07 13:27   ` Nic Volanschi (R&D)
  2014-04-07 13:48     ` Julia Lawall
  0 siblings, 1 reply; 20+ messages in thread
From: Nic Volanschi (R&D) @ 2014-04-07 13:27 UTC (permalink / raw)
  To: cocci

On Mon, 2014-04-07 at 14:54 +0200, Julia Lawall wrote:
> On Mon, 7 Apr 2014, Nic Volanschi (R&D) wrote:
> > I agree that the "initializer" nonterminal is not the right place to
> > extend the grammar, because it would not allow legal statements such as:
> >
> >   structure = ((struct foo) {x + y, 'a', 0});
> >
> > the example coming from:
> > http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
> >
> > Rather, it seems to me that the right place to extend the grammar is the
> > "cast_expression" nonterminal:
> >
> > > cast_expression
> > > 	: unary_expression
> > > 	| '(' type_name ')' cast_expression
> >           | '(' type_name ')' '{' initializer_list '}'
> > > 	;
> >
> > This would not only allow the above legal expression, but should also
> > avoid to introduce a conflict in the grammar.
> 
> I can try this.  So the point is that if a type is present, then { ... }
> is a legal expression in any context?  

This is how I understand the above web page about compound literals.
Indeed, I tried the following code in gcc and it works fine:

int main() { 
  struct s { int i; int j; } s1;
  printf("{%d, %d}\n", (struct s){ 44, 55}.i, (struct s){ 66, 77}.j);
  printf("%d\n", (int[]){12,13,14}[1] + 10);
} 

So it seems that a compound literal can be used in any place where an
lvalue of the corresponding type is legal.

> On the other hand, Coccinelle is
> not a syntax checker.  It is fine for it to accept syntax that is invalid,
> as long as the effect in terms of metavariables etc is expectable to the
> user.

Sure. But in the given case, I'm not sure you create illegal uses,
anyways.

Nic.

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

* [Cocci] spatch issue with C struct initialization
  2014-04-07 10:37 Nic Volanschi (R&D)
@ 2014-04-07 12:54 ` Julia Lawall
  2014-04-07 13:27   ` Nic Volanschi (R&D)
  0 siblings, 1 reply; 20+ messages in thread
From: Julia Lawall @ 2014-04-07 12:54 UTC (permalink / raw)
  To: cocci



On Mon, 7 Apr 2014, Nic Volanschi (R&D) wrote:

> On Mon, 2014-04-07 at 12:00 +0200, cocci-request at systeme.lip6.fr wrote:
> > Not being an expert on grammar, there is a chance this will work ?
> > >
> > >  initializer
> > >     : assignment_expression
> > >        | '{' initializer_list '}'
> > >        | '{' initializer_list ',' '}'
> > >        | ( type-name ) { initializer-list }
> > >        | ( type-name ) { initializer-list , }
> > >
> > > If you can point me to the code dealing with it, I can try to play
> > with
> > > it a little bit.
> >
> > I think I already tried the same thing.  The problem is that
> > ( type-name )
> > is already buried deep within assignment_expression, for an ordinary
> > cast,
> > so the parser doesn't know which rule to choose.
> >
> > julia
>
> I agree that the "initializer" nonterminal is not the right place to
> extend the grammar, because it would not allow legal statements such as:
>
>   structure = ((struct foo) {x + y, 'a', 0});
>
> the example coming from:
> http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
>
> Rather, it seems to me that the right place to extend the grammar is the
> "cast_expression" nonterminal:
>
> > cast_expression
> > 	: unary_expression
> > 	| '(' type_name ')' cast_expression
>           | '(' type_name ')' '{' initializer_list '}'
> > 	;
>
> This would not only allow the above legal expression, but should also
> avoid to introduce a conflict in the grammar.

I can try this.  So the point is that if a type is present, then { ... }
is a legal expression in any context?  On the other hand, Coccinelle is
not a syntax checker.  It is fine for it to accept syntax that is invalid,
as long as the effect in terms of metavariables etc is expectable to the
user.

julia

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

* [Cocci] spatch issue with C struct initialization
@ 2014-04-07 10:37 Nic Volanschi (R&D)
  2014-04-07 12:54 ` Julia Lawall
  0 siblings, 1 reply; 20+ messages in thread
From: Nic Volanschi (R&D) @ 2014-04-07 10:37 UTC (permalink / raw)
  To: cocci

On Mon, 2014-04-07 at 12:00 +0200, cocci-request at systeme.lip6.fr wrote:
> Not being an expert on grammar, there is a chance this will work ?
> >
> >  initializer
> >     : assignment_expression
> >        | '{' initializer_list '}'
> >        | '{' initializer_list ',' '}'
> >        | ( type-name ) { initializer-list }
> >        | ( type-name ) { initializer-list , }
> >
> > If you can point me to the code dealing with it, I can try to play
> with
> > it a little bit.
> 
> I think I already tried the same thing.  The problem is that
> ( type-name )
> is already buried deep within assignment_expression, for an ordinary
> cast,
> so the parser doesn't know which rule to choose.
> 
> julia

I agree that the "initializer" nonterminal is not the right place to
extend the grammar, because it would not allow legal statements such as:

  structure = ((struct foo) {x + y, 'a', 0});

the example coming from:
http://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html

Rather, it seems to me that the right place to extend the grammar is the
"cast_expression" nonterminal:

> cast_expression
> 	: unary_expression
> 	| '(' type_name ')' cast_expression
          | '(' type_name ')' '{' initializer_list '}'
> 	;

This would not only allow the above legal expression, but should also 
avoid to introduce a conflict in the grammar.

Hope this helps.

Nic.

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

end of thread, other threads:[~2014-04-22  8:21 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-03  8:30 [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
2014-04-03 10:16 ` Julia Lawall
2014-04-03 13:31   ` Marcel Apfelbaum
2014-04-03 14:19     ` Julia Lawall
2014-04-03 14:29       ` Marcel Apfelbaum
2014-04-03 14:33         ` Julia Lawall
2014-04-03 14:38           ` Marcel Apfelbaum
2014-04-04 11:21         ` Julia Lawall
2014-04-05 15:01           ` Michael Stefaniuc
2014-04-05 15:17             ` Julia Lawall
2014-04-06  6:21               ` [Cocci] Handling of compound literals? SF Markus Elfring
2014-04-06  7:45               ` [Cocci] spatch issue with C struct initialization Marcel Apfelbaum
2014-04-06 10:57                 ` Julia Lawall
2014-04-20 20:29                 ` Julia Lawall
2014-04-22  8:21                   ` Marcel Apfelbaum
2014-04-03 14:22     ` Julia Lawall
2014-04-07 10:37 Nic Volanschi (R&D)
2014-04-07 12:54 ` Julia Lawall
2014-04-07 13:27   ` Nic Volanschi (R&D)
2014-04-07 13:48     ` Julia Lawall

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.