lustrec / src / env.ml @ 38ae7765
History | View | Annotate | Download (1.64 KB)
1 | a2d97a3e | ploc | (********************************************************************) |
---|---|---|---|
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 | 22fe1c93 | ploc | |
12 | (** Generic inference environments. Used both for typing and |
||
13 | clock-calculus. *) |
||
14 | open Utils |
||
15 | |||
16 | 04a63d25 | xthirioux | type 'a t = 'a IMap.t |
17 | 22fe1c93 | ploc | (* 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 | 5c1184ad | ploc | let iter env f = IMap.iter f env |
30 | 12af4908 | xthirioux | |
31 | (* Merges x and y. In case of conflicting definitions, |
||
32 | overwrites definitions in x by definitions in y *) |
||
33 | 22fe1c93 | ploc | 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: *) |