2010-07-09 11:33:17 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
(* Generic mapred over Minils Ast *)
|
|
|
|
open Misc
|
2010-09-15 09:38:52 +02:00
|
|
|
open Errors
|
2010-07-09 11:33:17 +02:00
|
|
|
open Global_mapfold
|
|
|
|
open Minils
|
|
|
|
|
2010-09-30 21:44:18 +02:00
|
|
|
(* /!\ do not ever, NEVER put in your funs record one
|
2010-08-17 18:30:37 +02:00
|
|
|
of the generic iterator function (_it),
|
|
|
|
either yours either the default version named according to the type. *)
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
type 'a mls_it_funs = {
|
2011-04-14 18:06:54 +02:00
|
|
|
app: 'a mls_it_funs -> 'a -> Minils.app -> Minils.app * 'a;
|
|
|
|
edesc: 'a mls_it_funs -> 'a -> Minils.edesc -> Minils.edesc * 'a;
|
|
|
|
eq: 'a mls_it_funs -> 'a -> Minils.eq -> Minils.eq * 'a;
|
|
|
|
eqs: 'a mls_it_funs -> 'a -> Minils.eq list -> Minils.eq list * 'a;
|
|
|
|
exp: 'a mls_it_funs -> 'a -> Minils.exp -> Minils.exp * 'a;
|
|
|
|
extvalue: 'a mls_it_funs -> 'a -> Minils.extvalue -> Minils.extvalue * 'a;
|
|
|
|
extvalue_desc: 'a mls_it_funs -> 'a -> Minils.extvalue_desc -> Minils.extvalue_desc * 'a;
|
|
|
|
pat: 'a mls_it_funs -> 'a -> Minils.pat -> Minils.pat * 'a;
|
|
|
|
var_dec: 'a mls_it_funs -> 'a -> Minils.var_dec -> Minils.var_dec * 'a;
|
|
|
|
var_decs: 'a mls_it_funs -> 'a -> Minils.var_dec list -> Minils.var_dec list * 'a;
|
|
|
|
contract: 'a mls_it_funs -> 'a -> Minils.contract -> Minils.contract * 'a;
|
|
|
|
node_dec: 'a mls_it_funs -> 'a -> Minils.node_dec -> Minils.node_dec * 'a;
|
|
|
|
const_dec: 'a mls_it_funs -> 'a -> Minils.const_dec -> Minils.const_dec * 'a;
|
|
|
|
type_dec: 'a mls_it_funs -> 'a -> Minils.type_dec -> Minils.type_dec * 'a;
|
|
|
|
tdesc: 'a mls_it_funs -> 'a -> Minils.tdesc -> Minils.tdesc * 'a;
|
|
|
|
program: 'a mls_it_funs -> 'a -> Minils.program -> Minils.program * 'a;
|
2011-04-19 18:45:56 +02:00
|
|
|
program_desc: 'a mls_it_funs -> 'a -> Minils.program_desc -> Minils.program_desc * 'a;
|
2011-04-14 18:06:54 +02:00
|
|
|
global_funs: 'a Global_mapfold.global_it_funs }
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
let rec exp_it funs acc e = funs.exp funs acc e
|
|
|
|
and exp funs acc e =
|
2010-08-17 23:26:20 +02:00
|
|
|
let e_ty, acc = ty_it funs.global_funs acc e.e_ty in
|
2011-11-14 15:29:31 +01:00
|
|
|
let e_level_ck, acc = ck_it funs.global_funs acc e.e_level_ck in
|
|
|
|
let e_base_ck, acc = ck_it funs.global_funs acc e.e_base_ck in
|
|
|
|
let e_ct, acc = ct_it funs.global_funs acc e.e_ct in
|
2010-07-09 11:33:17 +02:00
|
|
|
let ed, acc = edesc_it funs acc e.e_desc in
|
2011-11-14 15:29:31 +01:00
|
|
|
{ e with e_desc = ed; e_ty = e_ty; e_level_ck = e_level_ck;
|
|
|
|
e_base_ck = e_base_ck; e_ct = e_ct }, acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
2011-04-14 18:06:54 +02:00
|
|
|
and extvalue_it funs acc w = funs.extvalue funs acc w
|
|
|
|
and extvalue funs acc w =
|
|
|
|
let w_ty, acc = ty_it funs.global_funs acc w.w_ty in
|
2011-11-14 15:29:31 +01:00
|
|
|
let w_ck, acc = ck_it funs.global_funs acc w.w_ck in
|
2011-04-14 18:06:54 +02:00
|
|
|
let wd, acc = extvalue_desc_it funs acc w.w_desc in
|
2011-11-14 15:29:31 +01:00
|
|
|
{ w with w_desc = wd; w_ty = w_ty; w_ck = w_ck }, acc
|
2011-04-14 18:06:54 +02:00
|
|
|
|
|
|
|
and extvalue_desc_it funs acc wd =
|
|
|
|
try funs.extvalue_desc funs acc wd
|
|
|
|
with Fallback -> extvalue_desc funs acc wd
|
|
|
|
and extvalue_desc funs acc wd = match wd with
|
|
|
|
| Wconst se ->
|
|
|
|
let se, acc = static_exp_it funs.global_funs acc se in
|
|
|
|
Wconst se, acc
|
2011-11-14 15:29:31 +01:00
|
|
|
| Wvar v ->
|
|
|
|
let v, acc = var_ident_it funs.global_funs acc v in
|
|
|
|
Wvar v, acc
|
2011-04-14 18:06:54 +02:00
|
|
|
| Wfield (w,f) ->
|
|
|
|
let w, acc = extvalue_it funs acc w in
|
|
|
|
Wfield (w,f), acc
|
|
|
|
| Wwhen (w, c, v) ->
|
|
|
|
let w, acc = extvalue_it funs acc w in
|
2011-11-14 15:29:31 +01:00
|
|
|
let v, acc = var_ident_it funs.global_funs acc v in
|
2011-04-14 18:06:54 +02:00
|
|
|
Wwhen (w,c,v), acc
|
2011-10-17 15:28:04 +02:00
|
|
|
| Wreinit (w1, w2) ->
|
|
|
|
let w1, acc = extvalue_it funs acc w1 in
|
|
|
|
let w2, acc = extvalue_it funs acc w2 in
|
|
|
|
Wreinit (w1, w2), acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
and edesc_it funs acc ed =
|
|
|
|
try funs.edesc funs acc ed
|
|
|
|
with Fallback -> edesc funs acc ed
|
|
|
|
and edesc funs acc ed = match ed with
|
2011-04-14 18:06:54 +02:00
|
|
|
| Eextvalue w ->
|
|
|
|
let w, acc = extvalue_it funs acc w in
|
|
|
|
Eextvalue w, acc
|
|
|
|
| Efby (se, w) ->
|
2010-07-09 11:33:17 +02:00
|
|
|
let se, acc = optional_wacc (static_exp_it funs.global_funs) acc se in
|
2011-04-14 18:06:54 +02:00
|
|
|
let w, acc = extvalue_it funs acc w in
|
2011-11-14 15:29:31 +01:00
|
|
|
Efby (se, w), acc
|
2010-07-09 11:33:17 +02:00
|
|
|
| Eapp(app, args, reset) ->
|
|
|
|
let app, acc = app_it funs acc app in
|
2011-04-14 18:06:54 +02:00
|
|
|
let args, acc = mapfold (extvalue_it funs) acc args in
|
2011-11-14 15:29:31 +01:00
|
|
|
let reset, acc = optional_wacc (var_ident_it funs.global_funs) acc reset in
|
|
|
|
Eapp (app, args, reset), acc
|
2011-04-14 18:06:54 +02:00
|
|
|
| Emerge(x, c_w_list) ->
|
|
|
|
let aux acc (c,w) =
|
|
|
|
let w, acc = extvalue_it funs acc w in
|
2011-11-14 15:29:31 +01:00
|
|
|
(c,w), acc
|
|
|
|
in
|
2011-04-14 18:06:54 +02:00
|
|
|
let c_w_list, acc = mapfold aux acc c_w_list in
|
2011-11-14 15:29:31 +01:00
|
|
|
let x, acc = var_ident_it funs.global_funs acc x in
|
|
|
|
Emerge(x, c_w_list), acc
|
2011-05-18 09:59:21 +02:00
|
|
|
| Ewhen(e,c,x) ->
|
|
|
|
let e, acc = exp_it funs acc e in
|
2011-11-14 15:29:31 +01:00
|
|
|
let x, acc = var_ident_it funs.global_funs acc x in
|
2011-05-18 09:59:21 +02:00
|
|
|
Ewhen(e,c,x), acc
|
2011-04-14 18:06:54 +02:00
|
|
|
| Estruct n_w_list ->
|
|
|
|
let aux acc (n,w) =
|
|
|
|
let w, acc = extvalue_it funs acc w in
|
2011-11-14 15:29:31 +01:00
|
|
|
(n,w), acc
|
|
|
|
in
|
2011-04-14 18:06:54 +02:00
|
|
|
let n_w_list, acc = mapfold aux acc n_w_list in
|
2011-11-14 15:29:31 +01:00
|
|
|
Estruct n_w_list, acc
|
2011-06-27 10:58:14 +02:00
|
|
|
| Eiterator (i, app, params, pargs, args, reset) ->
|
2010-07-09 11:33:17 +02:00
|
|
|
let app, acc = app_it funs acc app in
|
2011-06-27 10:58:14 +02:00
|
|
|
let params, acc = mapfold (static_exp_it funs.global_funs) acc params in
|
2011-04-14 18:06:54 +02:00
|
|
|
let pargs, acc = mapfold (extvalue_it funs) acc pargs in
|
|
|
|
let args, acc = mapfold (extvalue_it funs) acc args in
|
2011-11-14 15:29:31 +01:00
|
|
|
let reset, acc = optional_wacc (var_ident_it funs.global_funs) acc reset in
|
|
|
|
Eiterator (i, app, params, pargs, args, reset), acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
and app_it funs acc a = funs.app funs acc a
|
|
|
|
and app funs acc a =
|
|
|
|
let p, acc = mapfold (static_exp_it funs.global_funs) acc a.a_params in
|
|
|
|
{ a with a_params = p }, acc
|
|
|
|
|
|
|
|
|
|
|
|
and pat_it funs acc p =
|
|
|
|
try funs.pat funs acc p
|
|
|
|
with Fallback -> pat funs acc p
|
|
|
|
and pat funs acc p = match p with
|
|
|
|
| Etuplepat pl ->
|
|
|
|
let pl, acc = mapfold (pat_it funs) acc pl in
|
|
|
|
Etuplepat pl, acc
|
2011-11-14 15:29:31 +01:00
|
|
|
| Evarpat v ->
|
|
|
|
let v, acc = var_ident_it funs.global_funs acc v in
|
|
|
|
Evarpat v, acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
and eq_it funs acc eq = funs.eq funs acc eq
|
|
|
|
and eq funs acc eq =
|
|
|
|
let eq_lhs, acc = pat_it funs acc eq.eq_lhs in
|
|
|
|
let eq_rhs, acc = exp_it funs acc eq.eq_rhs in
|
|
|
|
{ eq with eq_lhs = eq_lhs; eq_rhs = eq_rhs }, acc
|
|
|
|
|
2010-07-14 03:45:38 +02:00
|
|
|
and eqs_it funs acc eqs = funs.eqs funs acc eqs
|
|
|
|
and eqs funs acc eqs = mapfold (eq_it funs) acc eqs
|
|
|
|
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
and var_dec_it funs acc vd = funs.var_dec funs acc vd
|
|
|
|
and var_dec funs acc vd =
|
|
|
|
let v_type, acc = ty_it funs.global_funs acc vd.v_type in
|
2011-11-14 15:29:31 +01:00
|
|
|
let v, acc = var_ident_it funs.global_funs acc vd.v_ident in
|
|
|
|
let v_clock, acc = ck_it funs.global_funs acc vd.v_clock in
|
|
|
|
{ vd with v_type = v_type; v_clock = v_clock; v_ident = v }, acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
2010-07-14 03:45:38 +02:00
|
|
|
and var_decs_it funs acc vds = funs.var_decs funs acc vds
|
|
|
|
and var_decs funs acc vds = mapfold (var_dec_it funs) acc vds
|
|
|
|
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
and contract_it funs acc c = funs.contract funs acc c
|
|
|
|
and contract funs acc c =
|
2011-05-09 19:32:12 +02:00
|
|
|
let c_assume, acc = extvalue_it funs acc c.c_assume in
|
|
|
|
let c_enforce, acc = extvalue_it funs acc c.c_enforce in
|
2010-07-14 03:45:38 +02:00
|
|
|
let c_local, acc = var_decs_it funs acc c.c_local in
|
|
|
|
let c_eq, acc = eqs_it funs acc c.c_eq in
|
2010-07-09 11:33:17 +02:00
|
|
|
{ c with
|
|
|
|
c_assume = c_assume; c_enforce = c_enforce; c_local = c_local; c_eq = c_eq }
|
|
|
|
, acc
|
|
|
|
|
|
|
|
|
2010-12-14 18:29:55 +01:00
|
|
|
and node_dec_it funs acc nd =
|
|
|
|
Idents.enter_node nd.n_name;
|
|
|
|
funs.node_dec funs acc nd
|
2010-07-09 11:33:17 +02:00
|
|
|
and node_dec funs acc nd =
|
2010-07-14 03:45:38 +02:00
|
|
|
let n_input, acc = var_decs_it funs acc nd.n_input in
|
|
|
|
let n_output, acc = var_decs_it funs acc nd.n_output in
|
|
|
|
let n_local, acc = var_decs_it funs acc nd.n_local in
|
2010-07-09 11:33:17 +02:00
|
|
|
let n_params, acc = mapfold (param_it funs.global_funs) acc nd.n_params in
|
|
|
|
let n_contract, acc = optional_wacc (contract_it funs) acc nd.n_contract in
|
2010-07-14 03:45:38 +02:00
|
|
|
let n_equs, acc = eqs_it funs acc nd.n_equs in
|
2010-07-09 11:33:17 +02:00
|
|
|
{ nd with
|
|
|
|
n_input = n_input; n_output = n_output;
|
|
|
|
n_local = n_local; n_params = n_params;
|
|
|
|
n_contract = n_contract; n_equs = n_equs }
|
|
|
|
, acc
|
|
|
|
|
|
|
|
|
|
|
|
and const_dec_it funs acc c = funs.const_dec funs acc c
|
|
|
|
and const_dec funs acc c =
|
|
|
|
let ty, acc = ty_it funs.global_funs acc c.c_type in
|
|
|
|
let se, acc = static_exp_it funs.global_funs acc c.c_value in
|
|
|
|
{ c with c_type = ty; c_value = se }, acc
|
|
|
|
|
|
|
|
|
|
|
|
and type_dec_it funs acc t = funs.type_dec funs acc t
|
|
|
|
and type_dec funs acc t =
|
|
|
|
let tdesc, acc = tdesc_it funs acc t.t_desc in
|
|
|
|
{ t with t_desc = tdesc }, acc
|
|
|
|
|
|
|
|
|
|
|
|
and tdesc_it funs acc td =
|
|
|
|
try funs.tdesc funs acc td
|
|
|
|
with Fallback -> tdesc funs acc td
|
|
|
|
and tdesc funs acc td = match td with
|
|
|
|
| Type_struct s ->
|
|
|
|
let s, acc = structure_it funs.global_funs acc s in
|
|
|
|
Type_struct s, acc
|
2010-08-17 23:26:20 +02:00
|
|
|
| Type_alias ty ->
|
|
|
|
let ty, acc = ty_it funs.global_funs acc ty in
|
|
|
|
Type_alias ty, acc
|
|
|
|
| Type_abs | Type_enum _ -> td, acc
|
2010-07-09 11:33:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
and program_it funs acc p = funs.program funs acc p
|
|
|
|
and program funs acc p =
|
2011-04-18 19:20:03 +02:00
|
|
|
let p_desc, acc = mapfold (program_desc_it funs) acc p.p_desc in
|
|
|
|
{ p with p_desc = p_desc }, acc
|
|
|
|
|
|
|
|
and program_desc_it funs acc pd =
|
|
|
|
try funs.program_desc funs acc pd
|
|
|
|
with Fallback -> program_desc funs acc pd
|
|
|
|
and program_desc funs acc pd = match pd with
|
2011-04-19 18:45:56 +02:00
|
|
|
| Pconst cd -> let cd, acc = const_dec_it funs acc cd in Pconst cd, acc
|
|
|
|
| Ptype td -> let td, acc = type_dec_it funs acc td in Ptype td, acc
|
|
|
|
| Pnode n -> let n, acc = node_dec_it funs acc n in Pnode n, acc
|
2011-04-18 19:20:03 +02:00
|
|
|
|
2010-07-09 11:33:17 +02:00
|
|
|
|
2010-07-14 02:31:31 +02:00
|
|
|
let defaults = {
|
2010-07-09 11:33:17 +02:00
|
|
|
app = app;
|
|
|
|
edesc = edesc;
|
|
|
|
eq = eq;
|
2010-07-14 03:45:38 +02:00
|
|
|
eqs = eqs;
|
2010-07-09 11:33:17 +02:00
|
|
|
exp = exp;
|
2011-04-14 18:06:54 +02:00
|
|
|
extvalue = extvalue;
|
|
|
|
extvalue_desc = extvalue_desc;
|
2010-07-09 11:33:17 +02:00
|
|
|
pat = pat;
|
|
|
|
var_dec = var_dec;
|
2010-07-14 03:45:38 +02:00
|
|
|
var_decs = var_decs;
|
2010-07-09 11:33:17 +02:00
|
|
|
contract = contract;
|
|
|
|
node_dec = node_dec;
|
|
|
|
const_dec = const_dec;
|
|
|
|
type_dec = type_dec;
|
|
|
|
tdesc = tdesc;
|
|
|
|
program = program;
|
2011-04-19 18:45:56 +02:00
|
|
|
program_desc = program_desc;
|
2010-07-14 02:31:31 +02:00
|
|
|
global_funs = Global_mapfold.defaults }
|