164
165
let check_pos info mck pos =
166
167
| Ast_cocci.PLUS -> raise Impossible
167
| Ast_cocci.CONTEXT (Ast_cocci.FixPos (i1,i2),_)
168
| Ast_cocci.MINUS (Ast_cocci.FixPos (i1,i2),_) ->
168
| Ast_cocci.CONTEXT (Ast_cocci.FixPos (i1,i2),_)
169
| Ast_cocci.MINUS (Ast_cocci.FixPos (i1,i2),_,_,_) ->
169
170
pos <= i2 && pos >= i1
170
| Ast_cocci.CONTEXT (Ast_cocci.DontCarePos,_)
171
| Ast_cocci.MINUS (Ast_cocci.DontCarePos,_) ->
171
| Ast_cocci.CONTEXT (Ast_cocci.DontCarePos,_)
172
| Ast_cocci.MINUS (Ast_cocci.DontCarePos,_,_,_) ->
204
205
match (oldmcode,mck) with
205
| (Ast_cocci.CONTEXT(_,Ast_cocci.NOTHING), _)
206
| (Ast_cocci.CONTEXT(_,Ast_cocci.NOTHING), _)
206
207
| (_, Ast_cocci.CONTEXT(_,Ast_cocci.NOTHING))
208
cocciinforef := (mck, tin.binding);
209
let update_inst inst = function
210
Ast_cocci.MINUS (pos,_,adj,any_xxs) ->
211
Ast_cocci.MINUS (pos,inst,adj,any_xxs)
213
cocciinforef := Some (update_inst tin.extra.index mck, tin.binding);
216
| (Ast_cocci.MINUS(old_pos,old_inst,old_adj,[]),
217
Ast_cocci.MINUS(new_pos,new_inst,new_adj,[]))
218
when old_pos = new_pos && oldenv =*= tin.binding
219
(* no way to combine adjacency information, just drop one *)
223
(old_pos,Common.union_set old_inst new_inst,old_adj,[]),
225
(if !Flag_matcher.show_misc
226
then pr2 "already tagged but only removed, so safe");
212
if (oldmcode, oldenv) =*= (mck, tin.binding)
214
if !Flag_matcher.show_misc
215
then pr2 "already tagged but with same mcode, so safe";
220
231
if !Flag.sgrep_mode2
221
232
then ib (* safe *)
226
Format.set_formatter_out_channel stderr;
227
Common.pr2 "SP mcode ";
228
Pretty_print_cocci.print_mcodekind oldmcode;
229
Format.print_newline();
230
Common.pr2 "C code mcode ";
231
Pretty_print_cocci.print_mcodekind mck;
232
Format.print_newline();
233
Format.print_flush();
237
pad: if dont want cocci write:
236
239
(match Ast_c.pinfo_of_info ib with
237
240
Ast_c.FakeTok _ -> "already tagged fake token"
242
let pm str mcode env =
244
"%s modification:\n%s\nAccording to environment:\n%s\n"
246
(Common.format_to_string
248
Pretty_print_cocci.print_mcodekind mcode))
251
(function ((r,vr),vl) ->
252
Printf.sprintf " %s.%s -> %s" r vr
253
(Common.format_to_string
255
Pretty_print_engine.pp_binding_kind vl)))
257
flush stdout; flush stderr;
259
("\n"^ (pm "previous" oldmcode oldenv) ^ "\n" ^
260
(pm "current" mck tin.binding));
262
(match Ast_c.pinfo_of_info ib with
264
Common.sprintf "%s: already tagged fake token\n"
265
tin.extra.current_rule_name
239
Common.sprintf "%s: already tagged token:\n%s"
268
"%s: already tagged token:\nC code context\n%s"
240
269
tin.extra.current_rule_name
241
270
(Common.error_message (Ast_c.file_of_info ib)
242
271
(Ast_c.str_of_info ib, Ast_c.opos_of_info ib)))
277
306
let distribute_mck mcodekind distributef expr tin =
278
307
match mcodekind with
279
| Ast_cocci.MINUS (pos,any_xxs) ->
308
| Ast_cocci.MINUS (pos,_,adj,any_xxs) ->
309
let inst = tin.extra.index in
281
(fun ib -> tag_with_mck (Ast_cocci.MINUS (pos,any_xxs)) ib tin),
282
(fun ib -> tag_with_mck (Ast_cocci.MINUS (pos,[])) ib tin),
283
(fun ib -> tag_with_mck (Ast_cocci.MINUS (pos,[])) ib tin),
284
(fun ib -> tag_with_mck (Ast_cocci.MINUS (pos,any_xxs)) ib tin)
312
tag_with_mck (Ast_cocci.MINUS (pos,inst,adj,any_xxs)) ib tin),
314
tag_with_mck (Ast_cocci.MINUS (pos,inst,adj,[])) ib tin),
316
tag_with_mck (Ast_cocci.MINUS (pos,inst,adj,[])) ib tin),
318
tag_with_mck (Ast_cocci.MINUS (pos,inst,adj,any_xxs)) ib tin)
286
320
| Ast_cocci.CONTEXT (pos,any_befaft) ->
287
321
(match any_befaft with
382
416
let get_pos mck =
384
418
| Ast_cocci.PLUS -> raise Impossible
385
| Ast_cocci.CONTEXT (Ast_cocci.FixPos (i1,i2),_)
386
| Ast_cocci.MINUS (Ast_cocci.FixPos (i1,i2),_) ->
419
| Ast_cocci.CONTEXT (Ast_cocci.FixPos (i1,i2),_)
420
| Ast_cocci.MINUS (Ast_cocci.FixPos (i1,i2),_,_,_) ->
387
421
Ast_cocci.FixPos (i1,i2)
388
| Ast_cocci.CONTEXT (Ast_cocci.DontCarePos,_)
389
| Ast_cocci.MINUS (Ast_cocci.DontCarePos,_) ->
422
| Ast_cocci.CONTEXT (Ast_cocci.DontCarePos,_)
423
| Ast_cocci.MINUS (Ast_cocci.DontCarePos,_,_,_) ->
390
424
Ast_cocci.DontCarePos
391
425
| _ -> failwith "weird: dont have position info for the mcodekind"
506
540
optional_qualifier_iso = not(List.mem "optional_qualifier" dropped_isos);
507
541
value_format_iso = not(List.mem "value_format" dropped_isos);
508
542
current_rule_name = rule_name;
511
546
(* find the node, transform, update the node, and iter for all elements *)
513
xs +> List.fold_left (fun acc (nodei, binding, rule_elem) ->
548
xs +> List.fold_left (fun acc (index, (nodei, binding, rule_elem)) ->
514
549
(* subtil: not cflow#nodes but acc#nodes *)
515
550
let node = acc#nodes#assoc nodei in
517
552
if !Flag.show_transinfo
518
553
then pr2 "transform one node";
521
XTRANS.extra = extra;
556
XTRANS.extra = {extra with index = index};
522
557
XTRANS.binding = binding0@binding;
523
558
XTRANS.binding0 = []; (* not used - everything constant for trans *)