On Tue, 30 Jul 2019, Chuhong Yuan wrote:
> Hi all,
> I want to write a script to match a pattern of conditional statement.
> However, I find that I can only match the first "if" in the block.
> The script is like this:
> fn(...) {
> ...
> - f(arg1, arg2, arg3)
> ...
> }
> where f returns the condition check result.
... means that what is before and after should not appear in the code
matched by ... This is useful for patterns like
A
...
B
when you want the closest A and B.
You can remove this restriction using
... when any
However that will not completely solve your problem, because when
transformation is used with ..., the patterns have to appear on every
control-flow path.
To eliminate this constraint, you can use
fn(...) {
<...
- f(...)
...> }
The <... ...> allows the pattern to appear 0 or more times in the matched
region. If you want to be sure that it appears one or more times, you can
use <+... ...+>. But the latter is more expensive and may not be
necessary.
On the other hand, if the name of the function is not very important, it
would be much more efficient to just match the function call that you are
interested in directly, without putting the function definition pattern
around it.
julia
>
> But when I apply to source code like this:
> if (f(a1, a2, a3)) {
> ...
> } else if (f(a4, a5, a6)) {
> ...
> }
> I find it can only match f(a1, a2, a3).
> So how to fix this problem?
>
> Thanks,
> Chuhong
> _______________________________________________
> Cocci mailing list
> [email protected]
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci