* [Cocci] Matching function pointer typedef @ 2018-05-15 20:36 Jerome Glisse 2018-05-15 20:50 ` Håkon Løvdal 2018-05-17 19:28 ` Julia Lawall 0 siblings, 2 replies; 10+ messages in thread From: Jerome Glisse @ 2018-05-15 20:36 UTC (permalink / raw) To: cocci Hello, I am trying to modify an function pointer typedef something like: @@ @@ - typedef void (*toto_t)(int a, int b); + typedef void (*toto_t)(int a, int b, int c); But it seems spatch or the semantic does not handle function pointer. Or simply that typedef is not well handled in the first place. Thing like: @@ @@ - typedef int nombre; + typedef unsigned nombre; also fails to work. But if typedef is use with struct then it works. For instance: @@ @@ - typedef struct {int a;} nombre; + typedef struct {unsigned a;} nombre; Do work. Looking at declaration grammar i do not see why the former does not work. I am using fedora 27 coccinelle 1.0.6 if that matters. Is this a known limitation or am i writting it wrong ? Thank you for any input on this, J?r?me ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-15 20:36 [Cocci] Matching function pointer typedef Jerome Glisse @ 2018-05-15 20:50 ` Håkon Løvdal 2018-05-15 20:53 ` Julia Lawall 2018-05-17 19:28 ` Julia Lawall 1 sibling, 1 reply; 10+ messages in thread From: Håkon Løvdal @ 2018-05-15 20:50 UTC (permalink / raw) To: cocci It's been a while since I used coccinelle, but I think to remember that you must (and in any case should) keep the non-changing parts outside of the +/- lines, e.g. @@ @@ typedef void (*toto_t)(int a, int b + , int c ); etc BR H?kon L?vdal On 15 May 2018 at 22:36, Jerome Glisse <jglisse@redhat.com> wrote: > Hello, > > I am trying to modify an function pointer typedef something like: > > @@ > @@ > - typedef void (*toto_t)(int a, int b); > + typedef void (*toto_t)(int a, int b, int c); > > But it seems spatch or the semantic does not handle function pointer. > Or simply that typedef is not well handled in the first place. Thing > like: > > @@ > @@ > - typedef int nombre; > + typedef unsigned nombre; > > also fails to work. But if typedef is use with struct then it works. > For instance: > > @@ > @@ > - typedef struct {int a;} nombre; > + typedef struct {unsigned a;} nombre; > > Do work. Looking at declaration grammar i do not see why the former > does not work. I am using fedora 27 coccinelle 1.0.6 if that matters. > > Is this a known limitation or am i writting it wrong ? > > Thank you for any input on this, > J?r?me > _______________________________________________ > Cocci mailing list > Cocci at systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-15 20:50 ` Håkon Løvdal @ 2018-05-15 20:53 ` Julia Lawall 2018-05-15 21:26 ` Jerome Glisse 0 siblings, 1 reply; 10+ messages in thread From: Julia Lawall @ 2018-05-15 20:53 UTC (permalink / raw) To: cocci On Tue, 15 May 2018, H?kon L?vdal wrote: > It's been a while since I used coccinelle, but I think to remember that you must > (and in any case should) keep the non-changing parts outside of the > +/- lines, e.g. > > @@ > @@ > typedef void (*toto_t)(int a, int b > + , int c > ); I think that typedefs of function pointers just don't work. It is looking for typedef type name;. I can try to fix this. julia > > etc > > BR H?kon L?vdal > > On 15 May 2018 at 22:36, Jerome Glisse <jglisse@redhat.com> wrote: > > Hello, > > > > I am trying to modify an function pointer typedef something like: > > > > @@ > > @@ > > - typedef void (*toto_t)(int a, int b); > > + typedef void (*toto_t)(int a, int b, int c); > > > > But it seems spatch or the semantic does not handle function pointer. > > Or simply that typedef is not well handled in the first place. Thing > > like: > > > > @@ > > @@ > > - typedef int nombre; > > + typedef unsigned nombre; > > > > also fails to work. But if typedef is use with struct then it works. > > For instance: > > > > @@ > > @@ > > - typedef struct {int a;} nombre; > > + typedef struct {unsigned a;} nombre; > > > > Do work. Looking at declaration grammar i do not see why the former > > does not work. I am using fedora 27 coccinelle 1.0.6 if that matters. > > > > Is this a known limitation or am i writting it wrong ? > > > > Thank you for any input on this, > > J?r?me > > _______________________________________________ > > Cocci mailing list > > Cocci at systeme.lip6.fr > > https://systeme.lip6.fr/mailman/listinfo/cocci > _______________________________________________ > Cocci mailing list > Cocci at systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-15 20:53 ` Julia Lawall @ 2018-05-15 21:26 ` Jerome Glisse 2018-05-16 15:13 ` Jerome Glisse 0 siblings, 1 reply; 10+ messages in thread From: Jerome Glisse @ 2018-05-15 21:26 UTC (permalink / raw) To: cocci On Tue, May 15, 2018 at 10:53:36PM +0200, Julia Lawall wrote: > > > On Tue, 15 May 2018, H?kon L?vdal wrote: > > > It's been a while since I used coccinelle, but I think to remember that you must > > (and in any case should) keep the non-changing parts outside of the > > +/- lines, e.g. > > > > @@ > > @@ > > typedef void (*toto_t)(int a, int b > > + , int c > > ); > > I think that typedefs of function pointers just don't work. It is looking > for typedef type name;. I can try to fix this. > Above does not work either. The error is same roughly spatch complains that it matches whole content ... I have a workaround, namely abusing gcc which accept: typedef void toto_t(int a, int b); For function pointer typedef and then coccinelle on function declaration do work. Still it would be nice if coccinelle can understand function pointer typedef. J?r?me ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-15 21:26 ` Jerome Glisse @ 2018-05-16 15:13 ` Jerome Glisse 2018-05-16 18:35 ` Julia Lawall 0 siblings, 1 reply; 10+ messages in thread From: Jerome Glisse @ 2018-05-16 15:13 UTC (permalink / raw) To: cocci On Tue, May 15, 2018 at 05:26:59PM -0400, Jerome Glisse wrote: > On Tue, May 15, 2018 at 10:53:36PM +0200, Julia Lawall wrote: > > > > > > On Tue, 15 May 2018, H?kon L?vdal wrote: > > > > > It's been a while since I used coccinelle, but I think to remember that you must > > > (and in any case should) keep the non-changing parts outside of the > > > +/- lines, e.g. > > > > > > @@ > > > @@ > > > typedef void (*toto_t)(int a, int b > > > + , int c > > > ); > > > > I think that typedefs of function pointers just don't work. It is looking > > for typedef type name;. I can try to fix this. > > > > Above does not work either. The error is same roughly spatch complains > that it matches whole content ... I have a workaround, namely abusing > gcc which accept: > > typedef void toto_t(int a, int b); > > For function pointer typedef and then coccinelle on function declaration > do work. Still it would be nice if coccinelle can understand function > pointer typedef. Ok my work around does work that well, it seems gcc allow this abuse only for function parameter type, it can not be use as a type inside a structure and so it doesn't cover all cases i am dealing with. Is there a way to modify code using python inside coccinelle ? I have seen example that print thing inside coccinelle but i haven't not seen an example that use coccinelle to match something and then do changes to the code using python. I am guessing i can open the file and use the position information to do that but was wondering if there is already helper provided for that. Cheers, J?r?me ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-16 15:13 ` Jerome Glisse @ 2018-05-16 18:35 ` Julia Lawall 0 siblings, 0 replies; 10+ messages in thread From: Julia Lawall @ 2018-05-16 18:35 UTC (permalink / raw) To: cocci On Wed, 16 May 2018, Jerome Glisse wrote: > On Tue, May 15, 2018 at 05:26:59PM -0400, Jerome Glisse wrote: > > On Tue, May 15, 2018 at 10:53:36PM +0200, Julia Lawall wrote: > > > > > > > > > On Tue, 15 May 2018, H?kon L?vdal wrote: > > > > > > > It's been a while since I used coccinelle, but I think to remember that you must > > > > (and in any case should) keep the non-changing parts outside of the > > > > +/- lines, e.g. > > > > > > > > @@ > > > > @@ > > > > typedef void (*toto_t)(int a, int b > > > > + , int c > > > > ); > > > > > > I think that typedefs of function pointers just don't work. It is looking > > > for typedef type name;. I can try to fix this. > > > > > > > Above does not work either. The error is same roughly spatch complains > > that it matches whole content ... I have a workaround, namely abusing > > gcc which accept: > > > > typedef void toto_t(int a, int b); > > > > For function pointer typedef and then coccinelle on function declaration > > do work. Still it would be nice if coccinelle can understand function > > pointer typedef. > > Ok my work around does work that well, it seems gcc allow this abuse > only for function parameter type, it can not be use as a type inside > a structure and so it doesn't cover all cases i am dealing with. > > Is there a way to modify code using python inside coccinelle ? I have > seen example that print thing inside coccinelle but i haven't not seen > an example that use coccinelle to match something and then do changes > to the code using python. > > I am guessing i can open the file and use the position information to > do that but was wondering if there is already helper provided for that. No, python code doesn't have access to the ast, which is an ocaml structure. julia > > Cheers, > J?r?me > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-15 20:36 [Cocci] Matching function pointer typedef Jerome Glisse 2018-05-15 20:50 ` Håkon Løvdal @ 2018-05-17 19:28 ` Julia Lawall 2018-05-17 19:48 ` Jerome Glisse [not found] ` <51d95102-78ad-b56b-c470-c83d3f6c6b9b@users.sourceforge.net> 1 sibling, 2 replies; 10+ messages in thread From: Julia Lawall @ 2018-05-17 19:28 UTC (permalink / raw) To: cocci On Tue, 15 May 2018, Jerome Glisse wrote: > Hello, > > I am trying to modify an function pointer typedef something like: > > @@ > @@ > - typedef void (*toto_t)(int a, int b); > + typedef void (*toto_t)(int a, int b, int c); This now works. Currently, you need to remove the whole typedef and add it back, not just add the third argument as H?kon suggested. > > But it seems spatch or the semantic does not handle function pointer. > Or simply that typedef is not well handled in the first place. Thing > like: > > @@ > @@ > - typedef int nombre; > + typedef unsigned nombre; Was this just an experiment, or is it something you need? I would imagine that the problem is that "unsigned" as a type by itself is not well supported. julia > also fails to work. But if typedef is use with struct then it works. > For instance: > > @@ > @@ > - typedef struct {int a;} nombre; > + typedef struct {unsigned a;} nombre; > > Do work. Looking at declaration grammar i do not see why the former > does not work. I am using fedora 27 coccinelle 1.0.6 if that matters. > > Is this a known limitation or am i writting it wrong ? > > Thank you for any input on this, > J?r?me > _______________________________________________ > Cocci mailing list > Cocci at systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [Cocci] Matching function pointer typedef 2018-05-17 19:28 ` Julia Lawall @ 2018-05-17 19:48 ` Jerome Glisse [not found] ` <51d95102-78ad-b56b-c470-c83d3f6c6b9b@users.sourceforge.net> 1 sibling, 0 replies; 10+ messages in thread From: Jerome Glisse @ 2018-05-17 19:48 UTC (permalink / raw) To: cocci On Thu, May 17, 2018 at 09:28:00PM +0200, Julia Lawall wrote: > > > On Tue, 15 May 2018, Jerome Glisse wrote: > > > Hello, > > > > I am trying to modify an function pointer typedef something like: > > > > @@ > > @@ > > - typedef void (*toto_t)(int a, int b); > > + typedef void (*toto_t)(int a, int b, int c); > > This now works. Currently, you need to remove the whole typedef and add > it back, not just add the third argument as H?kon suggested. Awesome ! :) Thank you for working on that. > > > > > But it seems spatch or the semantic does not handle function pointer. > > Or simply that typedef is not well handled in the first place. Thing > > like: > > > > @@ > > @@ > > - typedef int nombre; > > + typedef unsigned nombre; > > Was this just an experiment, or is it something you need? I would imagine > that the problem is that "unsigned" as a type by itself is not well > supported. This was just an experiment i did while trying to understand why my function pointer typedef changes did not work. If i use long or any basic ctype then it works. Cheers, J?r?me ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <51d95102-78ad-b56b-c470-c83d3f6c6b9b@users.sourceforge.net>]
* [Cocci] Matching function pointer typedef [not found] ` <51d95102-78ad-b56b-c470-c83d3f6c6b9b@users.sourceforge.net> @ 2018-05-18 16:53 ` Julia Lawall [not found] ` <c3c0b202-ad2c-b53e-f73c-acc2baba9279@users.sourceforge.net> 0 siblings, 1 reply; 10+ messages in thread From: Julia Lawall @ 2018-05-18 16:53 UTC (permalink / raw) To: cocci On Fri, 18 May 2018, SF Markus Elfring wrote: > >> I am trying to modify an function pointer typedef something like: > >> > >> @@ > >> @@ > >> - typedef void (*toto_t)(int a, int b); > >> + typedef void (*toto_t)(int a, int b, int c); > > > > This now works. > > Thanks for another software improvement. > https://github.com/coccinelle/coccinelle/commit/80dcf751e411f1421fdcdb7119a95e50b841609c > > > > Currently, you need to remove the whole typedef and add it back, > > I find this information inappropriate because such a source code replacement > was attempted. It was attempted before the change was made. julia > > > > not just add the third argument as H?kon suggested. > > It can be clearer to limit changes precisely while it can be also occasionally nice > to extend the adjustment a bit so that the affected source code will be > hopefully reformatted by the Coccinelle software in a desired way. > https://github.com/coccinelle/coccinelle/issues/37 > > Regards, > Markus > ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <c3c0b202-ad2c-b53e-f73c-acc2baba9279@users.sourceforge.net>]
* [Cocci] Matching function pointer typedef [not found] ` <c3c0b202-ad2c-b53e-f73c-acc2baba9279@users.sourceforge.net> @ 2018-05-18 17:54 ` Julia Lawall 0 siblings, 0 replies; 10+ messages in thread From: Julia Lawall @ 2018-05-18 17:54 UTC (permalink / raw) To: cocci On Fri, 18 May 2018, SF Markus Elfring wrote: > >>> Currently, you need to remove the whole typedef and add it back, > >> > >> I find this information inappropriate because such a source code replacement > >> was attempted. > > > > It was attempted before the change was made. > > I get the impression from such feedback that another clarification > would be useful about the granularity if each function parameter can be > adjusted in data type definitions finally. Concretely, the typedef name has to appear on the same line as all the parameters. julia ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-05-18 17:54 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-05-15 20:36 [Cocci] Matching function pointer typedef Jerome Glisse 2018-05-15 20:50 ` Håkon Løvdal 2018-05-15 20:53 ` Julia Lawall 2018-05-15 21:26 ` Jerome Glisse 2018-05-16 15:13 ` Jerome Glisse 2018-05-16 18:35 ` Julia Lawall 2018-05-17 19:28 ` Julia Lawall 2018-05-17 19:48 ` Jerome Glisse [not found] ` <51d95102-78ad-b56b-c470-c83d3f6c6b9b@users.sourceforge.net> 2018-05-18 16:53 ` Julia Lawall [not found] ` <c3c0b202-ad2c-b53e-f73c-acc2baba9279@users.sourceforge.net> 2018-05-18 17:54 ` 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.