On Mon, 9 Apr 2012, Jim Cromie wrote:
On Mon, Apr 9, 2012 at 6:43 AM, Julia Lawall <[email protected]> wrote:
For the whole kernel, I get over 32,000 potential added calls. Perhaps
there is some way to better constrain the cases where it should be used?
julia
OOH, THANK YOU for that script.
Now that I see it, I understand it - at least a little bit.
You are a ninja !!
32k is *alot*
and I see youve already constrained it to static defs.
Devs sometimes add comments about keeping A,B in sync if you change...
but the form of comments surely varies, and IIUC, cocci cant look at comments.
No, it doesn't look at comments.
I'll try it out, inspect the results, and see if I can find more constraints.
Actually, the previous results were all backwards. All the constraints
referred to arrays that were declared afterwards. I've attached two new
versions. Tables.cocci collects constraints to all previous arrays of the
same size. Last_tables.cocci puts a constraint only for the most recent
table - if all of the constraints are satisfied it should amount to the
same thing. Last_tables generates less code, but the result is more
fragile because the most recent table is not necessarily the one you want.
julia
@infn@
identifier f,i;
type T;
position p;
@@
f(...) { <...
static const T i@p[] = ...;
...> }
@t1@
type T1;
identifier i1;
initializer list[n] e1;
position p1!=infn.p;
@@
static const T1 i1@p1[] = {e1};
@t2@
type T2;
identifier i2;
initializer list[t1.n] e2;
position p2!=infn.p;
@@
static const T2 i2@p2[] = {e2};
@script:ocaml@
p1 << t1.p1;
p2 << t2.p2;
@@
if (List.hd p1).line >= (List.hd p2).line then include_match(false)
@@
fresh identifier name = t1.i1 ## "_" ## t2.i2 ## "_check";
position t2.p2;
type T2;
identifier t1.i1,t2.i2;
initializer list e2;
declarer name BUILD_BUG_DECL;
@@
static const T2 i2@p2[] = {e2};
++ BUILD_BUG_DECL(name,
++ ARRAY_SIZE(i1) != ARRAY_SIZE(i2));
@initialize:ocaml@
let tbl = Hashtbl.create 101
@infn@
identifier f,i;
type T;
position p;
@@
f(...) { <...
static const T i@p[] = ...;
...> }
@t1@
type T1;
identifier i1;
initializer list[n] e1;
position p1!=infn.p;
@@
static const T1 i1@p1[] = {e1};
@t2@
type T2;
identifier i2;
initializer list[t1.n] e2;
position p2!=infn.p;
@@
static const T2 i2@p2[] = {e2};
@script:ocaml@
i1 << t1.i1;
p1 << t1.p1;
p2 << t2.p2;
@@
let line1 = (List.hd p1).line in
let line2 = (List.hd p2).line in
if line1 >= line2 then include_match(false)
else
try
let cell = Hashtbl.find tbl p2 in
let (ln,_) = !cell in
(if line1 > ln then cell := (line1,i1))
with Not_found -> Hashtbl.add tbl p2 (ref (line1,i1))
@script:ocaml@
p1 << t1.p1;
p2 << t2.p2;
@@
let line1 = (List.hd p1).line in
let cell = Hashtbl.find tbl p2 in
let (ln,_) = !cell in
if not (line1 = ln) then include_match(false)
@@
fresh identifier name = t1.i1 ## "_" ## t2.i2 ## "_check";
position t2.p2;
type T2;
identifier t1.i1,t2.i2;
initializer list e2;
declarer name BUILD_BUG_DECL;
@@
static const T2 i2@p2[] = {e2};
++ BUILD_BUG_DECL(name,
++ ARRAY_SIZE(i1) != ARRAY_SIZE(i2));
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)