Revision 15003796 src/corelang.ml
src/corelang.ml  

856  856  
857  857 
(* Replace any occurence of a var in vars_to_replace by its associated 
858  858 
expression in defs until e does not contain any such variables *) 
859 
let rec substitute_expr vars_to_replace defs e = 

860 
let se = substitute_expr vars_to_replace defs in 

861 
{ e with expr_desc = 

859 
let substitute_expr ?(open_pre=true) vars_to_replace defs e = 

860 
Format.eprintf "substitution in %a@." Printers.pp_expr e; 

861 
let normalized = ref [] in 

862 
let rec se vars_to_replace defs e = 

863 
let se = se vars_to_replace defs in 

864 
{ e with expr_desc = 

862  865 
let ed = e.expr_desc in 
863  866 
match ed with 
864  867 
 Expr_const _ > ed 
...  ...  
869  872 
 Expr_ite (c, t, e) > Expr_ite (se c, se t, se e) 
870  873 
 Expr_arrow (e1, e2)> Expr_arrow (se e1, se e2) 
871  874 
 Expr_fby (e1, e2) > Expr_fby (se e1, se e2) 
872 
 Expr_pre e' > Expr_pre (se e')


875 
 Expr_pre e' > if open_pre then Expr_pre (se e') else ed


873  876 
 Expr_when (e', i, l)> Expr_when (se e', i, l) 
874  877 
 Expr_merge (i, hl) > Expr_merge (i, List.map (fun (t, h) > (t, se h)) hl) 
875  878 
 Expr_appl (i, e', i') > Expr_appl (i, se e', i') 
876  879 
 Expr_ident i > 
877 
if List.exists (fun v > v.var_id = i) vars_to_replace then ( 

880 
if List.exists (fun vid > vid = i) vars_to_replace then ( 

881 
Format.eprintf "computation substitution in %a@." Printers.pp_expr e; 

878  882 
let eq_i eq = eq.eq_lhs = [i] in 
879 
if List.exists eq_i defs then 

883 
if List.mem_assoc i !normalized then ( 

884 
Format.eprintf "substitution of variable %a already computed. getting it: %a@." Printers.pp_expr e Printers.pp_expr (List.assoc i !normalized); 

885 
(List.assoc i !normalized).expr_desc 

886 
) 

887 
else if List.exists eq_i defs then ( 

888 
Format.eprintf "substitution of variable %a not computed.@." Printers.pp_expr e; 

880  889 
let sub = List.find eq_i defs in 
890 
Format.eprintf "definition is %a@." Printers.pp_expr (sub.eq_rhs); 

881  891 
let sub' = se sub.eq_rhs in 
892 
Format.eprintf "substitution of variable %a just computed.@." Printers.pp_expr e; 

893 
normalized := (i, sub')::!normalized; 

882  894 
sub'.expr_desc 
895 
) 

883  896 
else 
884  897 
assert false 
885  898 
) 
...  ...  
887  900 
ed 
888  901  
889  902 
} 
903 
in 

904 
se vars_to_replace defs e 

890  905 
(* FAUT IL RETIRER ? 
891  906 

892  907 
let rec expr_to_eexpr expr = 
Also available in: Unified diff