Julia Lawall wrote:
> My thought was to find a field that is declared as const, then find a 
> static initialization of that field, and then convert the initialized 
> value to const.  So it would be something like:
> 
[snip]
>
> You would of course have to check that const is not already there as you 
> have done in your previous rule.
> 
> I have not tested this at all.

Here is the working version based on your one. This one can find the
control descriptor the same like the original SmPL did. The "-all_includes"
option has to be used.

// <smpl>
@r@
identifier I1, I2, x;
@@
        struct I1 {
          ...
          const struct I2 *x;
          ...
        };
@s@
identifier r.I1, y;
identifier r.x, E;
@@
        struct I1 y = {
          .x = E,
        };
@c@
identifier r.I2;
identifier s.E;
@@
        const struct I2 E[] = ... ;
@depends on !c@
identifier r.I2;
identifier s.E;
@@
+       const
        struct I2 E[] = ...;
// </smpl>

I focused on pointer kind of fields and array kind of initializers. Maybe
this point can be more general.

I have a test case also:

---8<---- cut here ---8<---
struct A {
        int aa;
        const int ab;
        int ac;
};

struct B {
        int ba;
        const int bb;
};

struct C {
        const struct A *pa;
        struct B *pb;
};

struct A x[] = {
        {
                0,
                1,
                2
        }
};

struct B z[] = {
        {
                7,
                8,
        }
};

struct C q = {
        .pa = x,
        .pb = z,
};
---8<---- cut here ---8<---

Regards,

        Márton Németh

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to