Project

General

Profile

Download (1.66 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
(** 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
let fold = IMap.fold
31

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

    
41
open Format
42

    
43
let pp_env pp_fun fmt env =
44
  let (lid,lty) = list_of_imap env in
45
  let l' = List.combine lid lty in
46
  let pp_fun fmt (id,value) =
47
    Format.fprintf fmt "%s |-> %a" id pp_fun value
48
  in
49
  Format.fprintf fmt "{ @[<v 2>%a@] }" (fprintf_list ~sep:"@," pp_fun) l'
50

    
51
(* Local Variables: *)
52
(* compile-command:"make -C .." *)
53
(* End: *)
(22-22/73)