* [Cocci] How to write a pattern which crosses two functions?
@ 2019-07-16 2:36 Will Lester
2019-07-20 10:11 ` Julia Lawall
0 siblings, 1 reply; 2+ messages in thread
From: Will Lester @ 2019-07-16 2:36 UTC (permalink / raw)
To: cocci
[-- Attachment #1.1: Type: text/plain, Size: 474 bytes --]
Hello,
I want to write a script to solve problems of such pattern.
func_a () {
x = .*alloc();
}
func_b () {
foo(..., x, ...);
}
That is, a variable x is allocated by func_a and used by func_b in a file.
I wrote a script like this:
fn_a (...) {
...
- X = fn1(...);
...
}
...
fn_b (...) {
...
- fn2 (..., X, ...);
...
}
But an error was reported between two functions, "..." cannot be used there.
Therefore, what is the correct solution to this problem?
Thanks,
Will
[-- Attachment #1.2: Type: text/html, Size: 802 bytes --]
[-- 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] 2+ messages in thread
* Re: [Cocci] How to write a pattern which crosses two functions?
2019-07-16 2:36 [Cocci] How to write a pattern which crosses two functions? Will Lester
@ 2019-07-20 10:11 ` Julia Lawall
0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2019-07-20 10:11 UTC (permalink / raw)
To: Will Lester; +Cc: cocci
[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]
On Tue, 16 Jul 2019, Will Lester wrote:
> Hello,
> I want to write a script to solve problems of such pattern.
> func_a () {
> x = .*alloc();
> }
> func_b () {
> foo(..., x, ...);
> }
> That is, a variable x is allocated by func_a and used by func_b in a file.
> I wrote a script like this:
> fn_a (...) {
> ...
> - X = fn1(...);
> ...
> }
> ...
> fn_b (...) {
> ...
> - fn2 (..., X, ...);
> ...
> }
> But an error was reported between two functions, "..." cannot be used there.
> Therefore, what is the correct solution to this problem?
Just make two separate rules. You can put a name for a rule between the
initial @@ and then you can refer to the name in the second rule to
obtain the value of a metavariable from the first one. For example:
@r@
identifier x;
@@
x = fn1(...)
@@
identifier r.x;
@@
fn2(...,x,...)
In your example, fn1 should end with alloc. If you want to declare a
metavariable like that you can use a regular expression:
identifier alloc =~ "alloc$";
I guess this should match names that end with alloc.
julia
[-- 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] 2+ messages in thread
end of thread, other threads:[~2019-07-20 10:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 2:36 [Cocci] How to write a pattern which crosses two functions? Will Lester
2019-07-20 10:11 ` 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).