Project

General

Profile

Download (1.62 KB) Statistics
| Branch: | Tag: | Revision:
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
open Utils
13
(** Generic inference environments. Used both for typing and clock-calculus. *)
14

    
15
type 'a t = 'a IMap.t
16

    
17
(* Same namespace for nodes, variables and constants *)
18
let initial = IMap.empty
19

    
20
let add_value env ident ty = IMap.add ident ty env
21

    
22
let lookup_value env ident = IMap.find ident env
23

    
24
let exists_value env ident = IMap.mem ident env
25

    
26
let iter env f = IMap.iter f env
27

    
28
let fold = IMap.fold
29

    
30
(* Merges x and y. In case of conflicting definitions, overwrites definitions in
31
   x by definitions in y *)
32
let overwrite x y =
33
  IMap.merge
34
    (fun _ _old _new -> match _new with Some _ -> _new | _ -> _old)
35
    x y
36

    
37
let pp_env pp_fun fmt env =
38
  let lid, lty = list_of_imap env in
39
  let l' = List.combine lid lty in
40
  let pp_fun fmt (id, value) = Format.fprintf fmt "%s |-> %a" id pp_fun value in
41
  Format.fprintf fmt "{ @[<v 2>%a@] }" (fprintf_list ~sep:"@," pp_fun) l'
42

    
43
(* Local Variables: *)
44
(* compile-command:"make -C .." *)
45
(* End: *)
(3-3/7)