1 module V0
= Visitor_ast0
2 module VT0
= Visitor_ast0_types
3 module Ast0
= Ast0_cocci
6 (* Detects where position variables can be present in the match of an
7 isomorpshims. This is allowed if all elements of an isomorphism have only
8 one token or if we can somehow match up equal tokens of all of the
9 isomorphic variants. *)
13 (* sort of unpleasant to convert the token representation to a string
14 but we can't make a list of mcodes otherwise because the types are all
16 [(Common.dump
(Ast0.unwrap_mcode x
),Ast0.get_pos_ref x
)] in
17 let donothing r k e
= k e
in
18 let bind x y
= x
@ y
in
19 let option_default = [] in
20 V0.flat_combiner
bind option_default
21 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
22 donothing donothing donothing donothing donothing donothing
24 donothing donothing donothing donothing donothing donothing donothing
26 (* In general, we will get a list of lists:
28 [[tokens1;tokens2;tokens3];[tokens4;tokens5;tokens6];[tokens7;tokens8]]
30 If all of the lists tokens contain only one element, we are done.
32 Otherwise, we focus on tokens1. For each of its elements, if they are
33 present in all of the others, then a position is assigned, and if not then
34 a position is not. The order of the elements in the other lists is
35 irrelevant; we just take the first unannotated element that matches. Once
36 we are done with the elements of tokens1, we skip to tokens 4 and repeat,
37 including considering the one-element special case. *)
43 let name = ("",Printf.sprintf
"p%d" c) in
44 Ast0.MetaPos
(Ast0.make_mcode
name,[],Ast.PER
)
47 let rec loop = function
49 | ((f
::r
)::xs
) as a
->
50 if List.for_all
(List.for_all
(function e
-> List.length e
= 1)) a
53 List.iter
(List.iter
(List.iter
(function (_
,pos
) -> pos
:= p))) a
55 let all = r
@ List.concat xs
in
56 let rec find_first_available a
= function
59 if str
= a
&& !pos
= Ast0.NoMetaPos
61 else find_first_available a xs
in
63 (function (str
,pos
) ->
67 let entries = List.map
(find_first_available str
) all in
70 List.iter
(function pos
-> pos
:= p) entries
72 | _
-> (* already have a variable *) ())
75 | _
-> failwith
"bad iso" in
80 let process (metavars
,alts
,name) =
82 List.map
(List.map
sequence_tokens.VT0.combiner_rec_anything
) alts
in