1 /// Detect BQ27XXX_DATA structures with identical registers, dm registers or
3 //# Doesn't unfold macros used in register or property fields.
4 //# Requires OCaml scripting
7 // Copyright: (C) 2017 Julia Lawall, Inria/LIP6, GPLv2.
8 // URL: http://coccinelle.lip6.fr/
10 // Keywords: BQ27XXX_DATA
17 let print_report p msg =
19 Printf.printf "%s:%d:%d-%d: %s" p.file p.line p.col p.col_end msg
21 @str depends on report@
29 [e1] = BQ27XXX_DATA(i1,...),
31 [e2] = BQ27XXX_DATA(i2,...),
35 @script:ocaml tocheck@
46 i1regs := make_ident (i1 ^ "_regs");
47 i2regs := make_ident (i2 ^ "_regs");
48 i1dmregs := make_ident (i1 ^ "_dm_regs");
49 i2dmregs := make_ident (i2 ^ "_dm_regs");
50 i1props := make_ident (i1 ^ "_props");
51 i2props := make_ident (i2 ^ "_props")
54 (* ---------------------------------------------------------------- *)
58 identifier tocheck.i1regs;
59 initializer list i1regs_vals;
63 u8 i1regs@p1[...] = { i1regs_vals, };
66 identifier tocheck.i2regs;
67 initializer list i2regs_vals;
71 u8 i2regs@p2[...] = { i2regs_vals, };
74 (_,i1regs_vals) << getregs1.i1regs_vals;
75 (_,i2regs_vals) << getregs2.i2regs_vals;
76 i1regs << tocheck.i1regs;
77 i2regs << tocheck.i2regs;
83 List.sort compare i1regs_vals = List.sort compare i2regs_vals
87 "WARNING %s and %s (line %d) are identical\n"
88 i1regs i2regs (List.hd p2).line in
91 (* ---------------------------------------------------------------- *)
94 identifier tocheck.i1dmregs;
95 initializer list i1dmregs_vals;
99 struct bq27xxx_dm_reg i1dmregs@p1[] = { i1dmregs_vals, };
102 identifier tocheck.i2dmregs;
103 initializer list i2dmregs_vals;
107 struct bq27xxx_dm_reg i2dmregs@p2[] = { i2dmregs_vals, };
110 (_,i1dmregs_vals) << getdmregs1.i1dmregs_vals;
111 (_,i2dmregs_vals) << getdmregs2.i2dmregs_vals;
112 i1dmregs << tocheck.i1dmregs;
113 i2dmregs << tocheck.i2dmregs;
118 if i1dmregs < i2dmregs &&
119 List.sort compare i1dmregs_vals = List.sort compare i2dmregs_vals
123 "WARNING %s and %s (line %d) are identical\n"
124 i1dmregs i2dmregs (List.hd p2).line in
127 (* ---------------------------------------------------------------- *)
130 identifier tocheck.i1props;
131 initializer list[n1] i1props_vals;
135 enum power_supply_property i1props@p1[] = { i1props_vals, };
138 identifier tocheck.i2props;
139 initializer list[n2] i2props_vals;
143 enum power_supply_property i2props@p2[] = { i2props_vals, };
146 (_,i1props_vals) << getprops1.i1props_vals;
147 (_,i2props_vals) << getprops2.i2props_vals;
148 i1props << tocheck.i1props;
149 i2props << tocheck.i2props;
154 if i1props < i2props &&
155 List.sort compare i1props_vals = List.sort compare i2props_vals
159 "WARNING %s and %s (line %d) are identical\n"
160 i1props i2props (List.hd p2).line in