types.mli 4.81 KB
Newer Older
1
2
open Ident

3
4
5
type const = | Integer of Intervals.v
	     | Atom of Atoms.v 
	     | Char of Chars.v
6

7
8
9
val compare_const: const -> const -> int
val hash_const: const -> int

10
11
(** Algebra **)

12
13
type node
type descr
14

15
16
val make: unit -> node
val define: node -> descr -> unit
17

18
19
val cons: descr -> node
val internalize: node -> node
20

21
22
val id: node -> int
val descr: node -> descr
23

24
25
val equal_descr: descr -> descr -> bool
val hash_descr: descr -> int
26
val compare_descr: descr -> descr -> int
27

28
module DescrHash: Hashtbl.S with type key = descr
29
module DescrSList: SortedList.S with type 'a elem = descr
30
31
32
33
module DescrMap: Map.S with type key = descr

(* Note: it seems that even for non-functional data, DescrMap
is more efficient than DescrHash ... *)
34

35
36
(** Boolean connectives **)

37
38
39
40
41
42
val cup    : descr -> descr -> descr
val cap    : descr -> descr -> descr
val diff   : descr -> descr -> descr
val neg    : descr -> descr
val empty  : descr
val any    : descr
43

44
45
val any_node : node

46
47
(** Constructors **)

48
49
type pair_kind = [ `Normal | `XML ]

50
val interval : Intervals.t -> descr
51
val atom     : Atoms.t -> descr
52
val times    : node -> node -> descr
53
val xml      : node -> node -> descr
54
val arrow    : node -> node -> descr
55
val record   : label -> node -> descr
56
val record'  : bool * node label_map -> descr
57
val char     : Chars.t -> descr
58
val constant : const -> descr
59

60
61
62
63
64
65
66
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
67
  val ty: descr -> v
68
69
  val cup: v list -> v
  val times: v -> v -> v
70
  val xml: v -> v -> v
71

72
  val solve: v -> node
73
74
75
76
77
end

(** Normalization **)

module Product : sig
78
  val any : descr
79
80
81
  val any_xml : descr
  val other : ?kind:pair_kind -> descr -> descr
  val is_product : ?kind:pair_kind -> descr -> bool
82
83
84

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
85
  val is_empty: t -> bool
86
  val get: ?kind:pair_kind -> descr -> t
87
88
  val pi1: t -> descr
  val pi2: t -> descr
89
  val pi2_restricted: descr -> t -> descr
90
91
92
93
94
95
96
    
  (* Intersection with (pi1,Any) *)
  val restrict_1: t -> descr -> t

  (* List of non-empty rectangles whose first projection
     are pair-wise disjunct *)
  type normal = t
97
  val normal: ?kind:pair_kind -> descr -> normal
98
99
100

  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
101
102
103
end

module Record : sig
104
105
106
107
108
109
110
111
112
113
114
115
116
  val any : descr
  val or_absent: descr -> descr
  val any_or_absent: descr

  val has_absent: descr -> bool
  val has_record: descr -> bool

  val split : descr -> label -> Product.t
  val split_normal : descr -> label -> Product.normal

  val project : descr -> label -> descr
    (* Raise Not_found if label is not necessarily present *)

117
118
119
120
121
122
  val condition : descr -> label -> descr -> descr
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
  val project_opt : descr -> label -> descr
  val has_empty_record: descr -> bool


123
124
125
126
  val first_label: descr -> label

  val empty_cases: descr -> bool * bool

127
128
  val merge: descr -> descr -> descr
  val remove_field: descr -> label -> descr
129
130
end

131
132
module Arrow : sig
  val any : descr
133

134
135
136
137
138
139
140
141
  val check_strenghten: descr -> descr -> descr
    (* [check_strenghten t s]
       Assume that [t] is an intersection of arrow types
       representing the interface of an abstraction;
       check that this abstraction has type [s] (otherwise raise Not_found)
       and returns a refined type for this abstraction.
    *)

142
143
  val check_iface: (descr * descr) list -> descr -> bool

144
  type t
145
  val is_empty: t -> bool
146
147
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
148

149
150
151
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
152
153
154
155
156
157

  val need_arg : t -> bool
    (* True if the type of the argument is needed to obtain
       the type of the result (must use [apply]; otherwise,
       [apply_noarg] is enough *)
  val apply_noarg : t -> descr
158
159
160
end


161
module Int : sig
162
  val has_int : descr -> Intervals.v -> bool
163

164
165
166
167
168
169
170
  val any : descr

  val is_int : descr -> bool
  val get: descr -> Intervals.t
  val put: Intervals.t -> descr
end

171
module Atom : sig
172
  val has_atom : descr -> Atoms.v -> bool
173
  val get: descr -> Atoms.t
174
175
end

176
module Char : sig
177
  val has_char : descr -> Chars.v -> bool
178
  val any : descr
179
  val get: descr -> Chars.t
180
181
end

182
val normalize : descr -> descr
183

184
(** Subtyping and sample values **)
185

186
187
188
val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool
189

190
191
module Sample :
sig
192
  type t 
193
194
195
196
197
198

  val get : descr -> t
	(** 
	  Extract a sample value from a non empty type;
	  raise Not_found for an empty type
	**)
199
200

  val print : Format.formatter -> t -> unit
201
202
end

203
204
module Print :
sig
205
  val register_global : string -> descr -> unit
206
  val print_const : Format.formatter -> const -> unit
207
208
  val print : Format.formatter -> node -> unit
  val print_descr: Format.formatter -> descr -> unit
209
end
210

211
val print_stat: Format.formatter -> unit