[Cocci] "TODO: FunCall" in python match printing
Carl-Daniel Hailfinger
c-d.hailfinger.devel.2006 at gmx.net
Fri Mar 6 00:14:10 CET 2009
Hi,
I decided to use spatch for diagnostics on the refactored flashrom code.
flashrom deals with direct memory accesses, so the code is literally
sprinkled with volatile qualifiers for variables. Some of them don't
make sense, especially assignments to variables which are not placed in
mmapped flash ROM space.
The following semantic patch does almost what I want:
@r exists@
expression b;
typedef uint8_t;
volatile uint8_t a;
position p1;
@@
a at p1 = b;
@script:python@
p1 << r.p1;
a << r.a;
b << r.b;
@@
print "* file: %s line %s has assignment to unnecessarily volatile
variable: %s = %s;" % (p1[0].file, p1[0].line, a, b)
Original code:
volatile uint8_t tmp;
tmp = readb(bios + 0x1823);
tmp = readb(bios + 0x1820);
tmp = readb(bios + 0x1822);
tmp = readb(bios + 0x0418);
tmp = readb(bios + 0x041B);
tmp = readb(bios + 0x0419);
tmp = readb(bios + 0x040A);
Generated messages:
* file: sst28sf040.c line 44 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 43 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 42 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 41 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 40 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 39 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
* file: sst28sf040.c line 38 has assignment to unnecessarily volatile
variable: tmp = TODO: FunCall;
I'd prefer to print the whole line, but as long as the TODO remains, the
current output will have to suffice. Actually, the output is good enough
for my purposes.
Just noticed: For some files, the above patch gives a warning:
(ONCE) Missing type information. Certainly a pb in annotate_typer.ml
For some other files, the warning is different:
(ONCE) ast_to_flow: filter a directive
I'll follow up with links to the mailing list post and the commit later.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
More information about the Cocci
mailing list