Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Changing function pointer typedef
@ 2019-03-08 18:19 Jerome Glisse
  2019-03-08 18:57 ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Jerome Glisse @ 2019-03-08 18:19 UTC (permalink / raw)
  To: cocci

Coccinelle seems to have issue with function pointer. For instance
if i want to add a new argument to a function pointer typdef i need
to replace the whole typedef as one line. For instance:

test.c:
typedef int (*filler_t)(void *, struct page *);

test.spatch:
@@
type T1, T2;
@@
-typedef int (*filler_t)(T1, T2);
+typedef int (*filler_t)(T1, struct address_space *, T2);

Anything else will not work and also if the function pointer typedef
spread accross multiple line then the above does not work, in fact
i have not found a work around for that case.

I am missing some syntax that make this work with coccinelle ?

Cheers,
Jérôme
_______________________________________________
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] Changing function pointer typedef
  2019-03-08 18:19 [Cocci] Changing function pointer typedef Jerome Glisse
@ 2019-03-08 18:57 ` Julia Lawall
  2019-03-08 19:11   ` Jerome Glisse
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2019-03-08 18:57 UTC (permalink / raw)
  To: Jerome Glisse; +Cc: cocci



On Fri, 8 Mar 2019, Jerome Glisse wrote:

> Coccinelle seems to have issue with function pointer. For instance
> if i want to add a new argument to a function pointer typdef i need
> to replace the whole typedef as one line. For instance:
>
> test.c:
> typedef int (*filler_t)(void *, struct page *);
>
> test.spatch:
> @@
> type T1, T2;
> @@
> -typedef int (*filler_t)(T1, T2);
> +typedef int (*filler_t)(T1, struct address_space *, T2);
>
> Anything else will not work and also if the function pointer typedef
> spread accross multiple line then the above does not work, in fact
> i have not found a work around for that case.
>
> I am missing some syntax that make this work with coccinelle ?

Thanks for the report.  Is the error you got something like:

error in collection of - tokens: line 4 less than line 6

I will have to look into it.

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] Changing function pointer typedef
  2019-03-08 18:57 ` Julia Lawall
@ 2019-03-08 19:11   ` Jerome Glisse
  2019-03-08 19:23     ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Jerome Glisse @ 2019-03-08 19:11 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Fri, Mar 08, 2019 at 07:57:08PM +0100, Julia Lawall wrote:
> 
> 
> On Fri, 8 Mar 2019, Jerome Glisse wrote:
> 
> > Coccinelle seems to have issue with function pointer. For instance
> > if i want to add a new argument to a function pointer typdef i need
> > to replace the whole typedef as one line. For instance:
> >
> > test.c:
> > typedef int (*filler_t)(void *, struct page *);
> >
> > test.spatch:
> > @@
> > type T1, T2;
> > @@
> > -typedef int (*filler_t)(T1, T2);
> > +typedef int (*filler_t)(T1, struct address_space *, T2);
> >
> > Anything else will not work and also if the function pointer typedef
> > spread accross multiple line then the above does not work, in fact
> > i have not found a work around for that case.
> >
> > I am missing some syntax that make this work with coccinelle ?
> 
> Thanks for the report.  Is the error you got something like:
> 
> error in collection of - tokens: line 4 less than line 6
> 
> I will have to look into it.

With:
@@
type T1, T2;
@@
typedef int (*filler_t)(T1,
+struct address_space *,
T2);

I get:
error in collection of - tokens: line 4 less than line 6

The error message depends on the semantic patch i tried several
variation hopping to find some syntax that would work but failed
so far.


In case of multiline typdef:
minus: parse error: 
  File "typedef-func.spatch", line 6, column 0, charpos = 101
  around = '',
  whole content = 

test.c:
typedef int (*filler_t)(void *,
    struct page *);

test.spatch
@@
type T1, T2;
@@
-typedef int (*filler_t)(T1,
+typedef int (*filler_t)(T1, struct address_space *,
_______________________________________________
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] Changing function pointer typedef
  2019-03-08 19:11   ` Jerome Glisse
@ 2019-03-08 19:23     ` Julia Lawall
  2019-03-08 19:32       ` Jerome Glisse
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2019-03-08 19:23 UTC (permalink / raw)
  To: Jerome Glisse; +Cc: cocci

> test.spatch
> @@
> type T1, T2;
> @@
> -typedef int (*filler_t)(T1,
> +typedef int (*filler_t)(T1, struct address_space *,

If this is the whole rule, it is clear that it will not work.  A semantic
patch rule has to e a complete syntactic unit.  So something with an open
parenthesis and no corresponding close parenthesis will not be accepted.

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] Changing function pointer typedef
  2019-03-08 19:23     ` Julia Lawall
@ 2019-03-08 19:32       ` Jerome Glisse
  2019-03-17 18:43         ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Jerome Glisse @ 2019-03-08 19:32 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

On Fri, Mar 08, 2019 at 08:23:48PM +0100, Julia Lawall wrote:
> > test.spatch
> > @@
> > type T1, T2;
> > @@
> > -typedef int (*filler_t)(T1,
> > +typedef int (*filler_t)(T1, struct address_space *,
> 
> If this is the whole rule, it is clear that it will not work.  A semantic
> patch rule has to e a complete syntactic unit.  So something with an open
> parenthesis and no corresponding close parenthesis will not be accepted.

Yeah and adding "T2);" to the rule does not help either it error to
error in collection of - tokens: line 4 less than line 6

Any variation really do error in some way or another.

Cheers,
Jérôme
_______________________________________________
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] Changing function pointer typedef
  2019-03-08 19:32       ` Jerome Glisse
@ 2019-03-17 18:43         ` Julia Lawall
  0 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2019-03-17 18:43 UTC (permalink / raw)
  To: Jerome Glisse; +Cc: cocci



On Fri, 8 Mar 2019, Jerome Glisse wrote:

> On Fri, Mar 08, 2019 at 08:23:48PM +0100, Julia Lawall wrote:
> > > test.spatch
> > > @@
> > > type T1, T2;
> > > @@
> > > -typedef int (*filler_t)(T1,
> > > +typedef int (*filler_t)(T1, struct address_space *,
> >
> > If this is the whole rule, it is clear that it will not work.  A semantic
> > patch rule has to e a complete syntactic unit.  So something with an open
> > parenthesis and no corresponding close parenthesis will not be accepted.
>
> Yeah and adding "T2);" to the rule does not help either it error to
> error in collection of - tokens: line 4 less than line 6
>
> Any variation really do error in some way or another.

This problem is fixed.  Thanks for the report.

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, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 18:19 [Cocci] Changing function pointer typedef Jerome Glisse
2019-03-08 18:57 ` Julia Lawall
2019-03-08 19:11   ` Jerome Glisse
2019-03-08 19:23     ` Julia Lawall
2019-03-08 19:32       ` Jerome Glisse
2019-03-17 18:43         ` Julia Lawall

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