On Thu, 2 Aug 2012, Lars-Peter Clausen wrote:
> Hi,
>
> I noticed that coccinelle will that identifiers, which have the same name,
> but live in different scopes, as the same identifier. For example two local
> variables in two different functions with the same name will be seen as the
> same identifier.
>
> E.g. in this simple synthetic example
>
> @r1@
> identifier i;
> @@
> i = 1;
>
> @r2@
> identifier r1.i;
> @@
> -i = 2;
> +i = 3;
>
> void f1(void)
> {
> int i;
>
> i = 1;
> }
>
> void f2(void)
> {
> int i;
>
> i = 2;
> }
>
> it will match r1 on the i in f1, but will replace the assignment to i in f2,
> although it is different i.
>
> Is this a bug or a feature?
>
> In this example I could work around it by e.g. doing something like:
> @r1@
> identifier i;
> identifier fn;
> @@
> fn(...)
> {
> <+...
> i = 1;
> ...+>
> }
>
> @@
> identifier r1.i;
> identifier r1.fn;
> @@
> fn(...)
> {
> <+...
> -i = 2;
> +i = 3;
> ...+>
> }
>
> But this would still leave the issue open for nested scopes inside a
> function. And requires a extra set of rules to match identifiers outside of
> functions.
If the definition of feature is "problem that the developers have decided
is too complicated to work around", then it is a feature :)
Part of the problem is the interaction with transformation. A
transformation could add or remove scoping. So then it is not clear what
keeping track of scopes would mean.
Also, an identifier never has a scope. If you want it to keep track of
scope within a single rule, use an idexpression. But from one rule to the
next all scope information is lost.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)