* [Cocci] Are types re-evaluated between subsequent rules?
@ 2019-05-27 13:32 Christoph Böhmwalder
2019-05-27 14:16 ` [Cocci] Checking change scope for a data type replacement Markus Elfring
2019-05-27 14:28 ` [Cocci] Are types re-evaluated between subsequent rules? Julia Lawall
0 siblings, 2 replies; 8+ messages in thread
From: Christoph Böhmwalder @ 2019-05-27 13:32 UTC (permalink / raw)
To: cocci
Hi,
I'm having trouble understanding coccinelles behaviour here. Consider
the following C code and cocci rules:
#include <stdio.h>
int x;
int main(int argc, char **argv)
{
f(x);
}
@@
identifier x;
@@
- int x;
+ int *x;
@@
int *x;
@@
- f(x)
+ g(x)
Since I read on some slides[0] that "Later rules see the results of
earlier rules", I would assume that this would pick up the type change
introduced by the first rule and replace f by g because it now has an
"int *" parameter. However, spatch merely outputs the patch to change
the type of x. If I change the type of the "expected" x in rule 2 to
"int", cocci picks it up correctly.
Am I missing something?
[0]:
http://events17.linuxfoundation.org/sites/events/files/slides/part1.pdf,
page 43
--
Regards,
Christoph
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 13:32 [Cocci] Are types re-evaluated between subsequent rules? Christoph Böhmwalder
@ 2019-05-27 14:16 ` Markus Elfring
2019-05-27 14:30 ` Christoph Böhmwalder
2019-05-27 14:28 ` [Cocci] Are types re-evaluated between subsequent rules? Julia Lawall
1 sibling, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2019-05-27 14:16 UTC (permalink / raw)
To: Christoph Böhmwalder; +Cc: cocci
> Am I missing something?
It depends on details.
Your initial transformation approach can be written also as follows.
@replacement@
identifier x;
@@
-int
+int*
x;
In which scopes would you like to add the asterisk for the usage of a pointer
data type?
Do you expect that function parameters should be also modified here?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Are types re-evaluated between subsequent rules?
2019-05-27 13:32 [Cocci] Are types re-evaluated between subsequent rules? Christoph Böhmwalder
2019-05-27 14:16 ` [Cocci] Checking change scope for a data type replacement Markus Elfring
@ 2019-05-27 14:28 ` Julia Lawall
1 sibling, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2019-05-27 14:28 UTC (permalink / raw)
To: Christoph Böhmwalder; +Cc: cocci
[-- Attachment #1: Type: text/plain, Size: 1621 bytes --]
On Mon, 27 May 2019, Christoph Böhmwalder wrote:
> Hi,
>
> I'm having trouble understanding coccinelles behaviour here. Consider the
> following C code and cocci rules:
>
>
> #include <stdio.h>
>
> int x;
>
> int main(int argc, char **argv)
> {
> f(x);
> }
>
>
> @@
> identifier x;
> @@
> - int x;
> + int *x;
>
> @@
> int *x;
> @@
> - f(x)
> + g(x)
>
>
>
> Since I read on some slides[0] that "Later rules see the results of earlier
> rules", I would assume that this would pick up the type change introduced by
> the first rule and replace f by g because it now has an "int *" parameter.
> However, spatch merely outputs the patch to change the type of x. If I change
> the type of the "expected" x in rule 2 to "int", cocci picks it up correctly.
>
> Am I missing something?
Your first rule changes only variable declarations, which consist of a
type, a variable and a semicolon. If you want to change all int types to
int *, then you can change the first rule to remove the x and the ;. If
you want to change int x in the parameter list of main, or in the
parameter list of all functions, then you could do
@@
identifier f; // all functions
identifier x;
@@
f(...,
- int x
+ int *x
,...) { ... }
You can factor out the common parts, ie int and x from the transformation,
as Markus suggests, but I doubt this would be useful.
julia
>
>
> [0]: http://events17.linuxfoundation.org/sites/events/files/slides/part1.pdf,
> page 43
>
> --
> Regards,
> Christoph
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
[-- Attachment #2: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 14:16 ` [Cocci] Checking change scope for a data type replacement Markus Elfring
@ 2019-05-27 14:30 ` Christoph Böhmwalder
2019-05-27 15:00 ` Markus Elfring
2019-05-27 17:40 ` Markus Elfring
0 siblings, 2 replies; 8+ messages in thread
From: Christoph Böhmwalder @ 2019-05-27 14:30 UTC (permalink / raw)
To: Markus Elfring; +Cc: cocci
On 27.05.19 16:16, Markus Elfring wrote:
>> Am I missing something?
>
> It depends on details.
>
> Your initial transformation approach can be written also as follows.
>
> @replacement@
> identifier x;
> @@
> -int
> +int*
> x; >
>
> In which scopes would you like to add the asterisk for the usage of a pointer
> data type?
I'm trying to replace a particular function call with a one-liner if the
function is not defined, so I control the scope myself. In other words,
in my original code "int x" is passed to "void f(int)" as a paramter,
and I would like to apply the following transformations:
1) "x" has a type of "int *"
2) the new "int *x" gets passed to a function "void g(int *)" instead.
>
> Do you expect that function parameters should be also modified here?
>
> Regards,
> Markus
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 14:30 ` Christoph Böhmwalder
@ 2019-05-27 15:00 ` Markus Elfring
2019-05-27 17:40 ` Markus Elfring
1 sibling, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2019-05-27 15:00 UTC (permalink / raw)
To: Christoph Böhmwalder; +Cc: cocci
>> @replacement@
>> identifier x;
>> @@
>> -int
>> +int*
>> x; >
>>
>> In which scopes would you like to add the asterisk for the usage of a pointer
>> data type?
…
> 1) "x" has a type of "int *"
The asterisk addition seems to work for (local) variables.
> 2) the new "int *x" gets passed to a function "void g(int *)" instead.
The succinct SmPL change specification looks like it could express
data type adjustments also at other places.
But an additional SmPL rule seems to be needed at the moment.
@replacement2@
identifier f, x;
type t;
@@
t
f(...,
- int
+ int*
x, ...)
{ ... }
Do you distinguish any references to global variables here?
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 14:30 ` Christoph Böhmwalder
2019-05-27 15:00 ` Markus Elfring
@ 2019-05-27 17:40 ` Markus Elfring
2019-05-27 17:46 ` Julia Lawall
1 sibling, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2019-05-27 17:40 UTC (permalink / raw)
To: Christoph Böhmwalder; +Cc: cocci
> In other words, in my original code "int x" is passed to "void f(int)" as a paramter,
> and I would like to apply the following transformations:
How do you think about to try a SmPL change specification out like the following?
@replacement3@
identifier x;
@@
-int
+int*
x;
<+...
-f
+g
(x);
...+>
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 17:40 ` Markus Elfring
@ 2019-05-27 17:46 ` Julia Lawall
2019-05-27 19:12 ` Markus Elfring
0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2019-05-27 17:46 UTC (permalink / raw)
To: Markus Elfring; +Cc: cocci
On Mon, 27 May 2019, Markus Elfring wrote:
> > In other words, in my original code "int x" is passed to "void f(int)" as a paramter,
> > and I would like to apply the following transformations:
>
> How do you think about to try a SmPL change specification out like the following?
>
> @replacement3@
> identifier x;
> @@
> -int
> +int*
> x;
> <+...
> -f
> +g
> (x);
> ...+>
His example shows that he wants to change a parameter type, not a local
variable.
julia
>
>
> Regards,
> Markus
> _______________________________________________
> 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] 8+ messages in thread
* Re: [Cocci] Checking change scope for a data type replacement
2019-05-27 17:46 ` Julia Lawall
@ 2019-05-27 19:12 ` Markus Elfring
0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2019-05-27 19:12 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci
>> @replacement3@
>> identifier x;
>> @@
>> -int
>> +int*
>> x;
>> <+...
>> -f
>> +g
>> (x);
>> ...+>
>
> His example shows that he wants to change a parameter type,
He would like to call a function which gets a single pointer passed
instead of an integer by possibly varying variables.
> not a local variable.
The support for source code transformations together with global variables
might need further software development considerations.
Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-05-27 19:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-27 13:32 [Cocci] Are types re-evaluated between subsequent rules? Christoph Böhmwalder
2019-05-27 14:16 ` [Cocci] Checking change scope for a data type replacement Markus Elfring
2019-05-27 14:30 ` Christoph Böhmwalder
2019-05-27 15:00 ` Markus Elfring
2019-05-27 17:40 ` Markus Elfring
2019-05-27 17:46 ` Julia Lawall
2019-05-27 19:12 ` Markus Elfring
2019-05-27 14:28 ` [Cocci] Are types re-evaluated between subsequent rules? 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).