lustrec / src / env.ml @ 3b2bd83d
History | View | Annotate | Download (1.64 KB)
1 |
(********************************************************************) |
---|---|
2 |
(* *) |
3 |
(* The LustreC compiler toolset / The LustreC Development Team *) |
4 |
(* Copyright 2012 - -- ONERA - CNRS - INPT *) |
5 |
(* *) |
6 |
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *) |
7 |
(* under the terms of the GNU Lesser General Public License *) |
8 |
(* version 2.1. *) |
9 |
(* *) |
10 |
(********************************************************************) |
11 |
|
12 |
(** Generic inference environments. Used both for typing and |
13 |
clock-calculus. *) |
14 |
open Utils |
15 |
|
16 |
type 'a t = 'a IMap.t |
17 |
(* Same namespace for nodes, variables and constants *) |
18 |
let initial = IMap.empty |
19 |
|
20 |
let add_value env ident ty = |
21 |
IMap.add ident ty env |
22 |
|
23 |
let lookup_value env ident = |
24 |
IMap.find ident env |
25 |
|
26 |
let exists_value env ident = |
27 |
IMap.mem ident env |
28 |
|
29 |
let iter env f = IMap.iter f env |
30 |
|
31 |
(* Merges x and y. In case of conflicting definitions, |
32 |
overwrites definitions in x by definitions in y *) |
33 |
let overwrite x y = |
34 |
IMap.merge ( |
35 |
fun k _old _new -> match _new with |
36 |
| Some _ -> _new |
37 |
| _ -> _old |
38 |
) x y |
39 |
|
40 |
open Format |
41 |
|
42 |
let pp_env pp_fun fmt env = |
43 |
let (lid,lty) = list_of_imap env in |
44 |
let l' = List.combine lid lty in |
45 |
let pp_fun fmt (id,value) = |
46 |
Format.fprintf fmt "%s |-> %a" id pp_fun value |
47 |
in |
48 |
Format.fprintf fmt "{ @[<v 2>%a@] }" (fprintf_list ~sep:"@," pp_fun) l' |
49 |
|
50 |
(* Local Variables: *) |
51 |
(* compile-command:"make -C .." *) |
52 |
(* End: *) |