types.mli 9.98 KB
Newer Older
1
2
open Ident

3
type const =
4
  | Integer of Intervals.V.t
5
  | Atom of Atoms.V.t
6
7
8
9
10
11
  | Char of Chars.V.t
  | Pair of const * const
  | Xml of const * const
  | Record of const label_map
  | String of U.uindex * U.uindex * U.t * const

Jérôme Maloberti's avatar
Jérôme Maloberti committed
12
13
type service_params =
  | TProd of service_params * service_params
14
  | TOption of service_params
Jérôme Maloberti's avatar
Jérôme Maloberti committed
15
16
17
18
19
20
21
  | TList of string * service_params
  | TSet of service_params
  | TSum of service_params * service_params
  | TString of string
  | TInt of string
  | TInt32 of string
  | TInt64 of string
22
  | TFloat of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
23
24
25
  | TBool of string
  | TFile of string
      (* | TUserType of string * (string -> 'a) * ('a -> string) *)
26
  | TCoord of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
27
  | TCoordv of service_params * string
28
  | TESuffix of string
Jérôme Maloberti's avatar
Jérôme Maloberti committed
29
30
31
  | TESuffixs of string
      (*  | TESuffixu of (string * (string -> 'a) * ('a -> string)) *)
  | TSuffix of (bool * service_params)
32
  | TUnit
Jérôme Maloberti's avatar
Jérôme Maloberti committed
33
34
  | TAny
  | TConst of string;;
35

36
module Const: Custom.T with type t = const
37

38
(*
39
40
41
module CompUnit : sig
  include Custom.T

42
  val get_current: unit -> t
43
44
  val mk: U.t -> t
  val value: t -> U.t
45
  val print_qual: Format.formatter -> t -> unit
46
47
48
49
50
51
52
53
54

  val enter: t -> unit
  val leave: unit -> unit
  val close_serialize: unit -> t list

  val pervasives: t

  module Tbl : Inttbl.S with type key = t
end
55
*)
56

57
58
module Abstracts :
sig
59
  module T : Custom.T with type t = string
60
61
62
63
64
65
66
67
  include Bool.S with type elem = T.t

  module V : sig type t = T.t * Obj.t end
  val is_empty : t -> bool
  val sample : t -> elem option
  val print : t -> (Format.formatter -> unit) list
  val contains: elem -> t -> bool
  val contains_sample : elem option -> t -> bool
68
69
end

70
71
(** Algebra **)

72

73
module Descr : Custom.T
74

75
include Custom.T with type t = Descr.t
76

77
module Node : Custom.T
78

79
type descr = t
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module type VarType = sig
    include Bool.V
    type descr = Descr.t
    val inj : t -> descr
    val proj : descr -> t
    val update : descr -> t -> descr
end

type var_type = (module VarType)

module VarAtoms : VarType with type Atom.t = Atoms.t

module VarIntervals : VarType with type Atom.t = Intervals.t

module VarChars : VarType with type Atom.t = Chars.t

module VarAbstracts : VarType with type Atom.t = Abstracts.t

module Pair : Bool.S with type elem = Node.t * Node.t
module Rec : Bool.S with type elem = bool * Node.t Ident.LabelMap.map

module VarTimes : VarType with module Atom = Pair
module VarXml : VarType with module Atom = Pair
module VarArrow : VarType with module Atom = Pair
module VarRec : VarType with module Atom = Rec



109
110
val make: unit -> Node.t
val define: Node.t -> t -> unit
111

112
113
val cons: t -> Node.t
val internalize: Node.t -> Node.t
114

115
116
val id: Node.t -> int
val descr: Node.t -> t
117

118
119
(** Boolean connectives **)

120
121
122
123
124
125
val cup    : t -> t -> t
val cap    : t -> t -> t
val diff   : t -> t -> t
val neg    : t -> t
val empty  : t
val any    : t
126

Pietro Abate's avatar
Pietro Abate committed
127
128
val no_var  : t -> bool
val is_var  : t -> bool
129
val has_tlv : t -> bool
Pietro Abate's avatar
Pietro Abate committed
130
val is_closed : Var.Set.t -> t -> bool
131

132
val any_node : Node.t
133
val empty_node : Node.t
134

135
val non_constructed : t
136
val non_constructed_or_absent : t
137

138
139
(** Constructors **)

140
141
type pair_kind = [ `Normal | `XML ]

142
val var      : Var.t -> t
143
144
val interval : Intervals.t -> t
val atom     : Atoms.t -> t
145
146
147
148
val times    : Node.t -> Node.t -> t
val xml      : Node.t -> Node.t -> t
val arrow    : Node.t -> Node.t -> t
val record   : label -> Node.t -> t
149
  (** bool = true -> open record; bool = false -> closed record *)
150
val record_fields : bool * Node.t label_map -> t
151
val char     : Chars.t -> t
152
val constant : const -> t
153
val abstract : Abstracts.t -> t
154

155
156
(** Helpers *)

157
val all_vars : t -> Var.Set.t
158
159
val tuple : Node.t list -> t

160
val rec_of_list: bool -> (bool * Ns.Label.t * t) list -> t
161

162
val empty_closed_record: t
163
val empty_open_record: t
164

165
166
167
168
169
170
171


module Iter : sig
    val simplify : t -> t
    val map : ?abs:(bool -> bool) -> (var_type -> t -> t) -> t -> t
    val iter : ?abs:(bool -> unit) ->(var_type -> t -> unit) -> t -> unit
    val fold : ?abs:(bool -> 'a -> 'a) -> (var_type -> t -> 'a -> 'a) -> t -> 'a -> 'a
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
    module type Ops = sig
	type t
	val cup : t list -> t
	val cap : t list -> t
	val neg : t -> t
	val var : Var.t list * Var.t list -> t
	val atoms : Atoms.t -> t
	val ints : Intervals.t -> t
	val chars : Chars.t -> t
	val times : Pair.t -> t
	val xml : Pair.t -> t
	val arrow : Pair.t -> t
	val record : Rec.t -> t
	val abstract : Abstracts.t -> t
	val absent : bool -> t
    end
    val compute_ops : (module Ops with type t = 'a) -> t -> 'a

190
191
end

192
193
(** Positive systems and least solutions **)

194
module Positive : sig
195
196
197
  type v
  val forward: unit -> v
  val define: v -> v -> unit
198
  val ty: t -> v
199
200
  val cup: v list -> v
  val times: v -> v -> v
201
  val xml: v -> v -> v
202
  val solve: v -> Node.t
203
end
204

205
module Variable : sig
206
    val extract : t -> Var.t * bool
207
208
end

209
210
211
212
213
214
215
216
217
218
219
module Subst : sig
  type t = descr Var.Map.map
  val identity : t
  val print : Format.formatter -> t -> unit
  val full : descr -> t -> descr
  val full_list : descr -> (Var.t * descr) list -> descr
  val single : descr -> (Var.t * descr) -> descr
  val freshen : Var.Set.t -> descr -> descr
  val hide_vars : descr -> descr
  val solve_rectype : descr -> Var.t -> descr
  val clean_type : Var.Set.t -> descr -> descr
220
221
end

222
223
224
225

(** Normalization **)

module Product : sig
226
227
  val any : t
  val any_xml : t
228
  val any_of: pair_kind -> t
229
230
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
231
232
233

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
234
  val is_empty: t -> bool
235
  val get: ?kind:pair_kind -> descr -> t
236
237
  val pi1: t -> descr
  val pi2: t -> descr
238
  val pi2_restricted: descr -> t -> descr
239

240
241
242
243
244
245
  (* 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
246
  val normal: ?kind:pair_kind -> descr -> normal
247

248
249
250
251
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

252
253
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
254
255
256

  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
257
258
259
end

module Record : sig
260
  val any : t
261
262
  val absent : t
  val absent_node : Node.t
263
264
  val or_absent: t -> t
  val any_or_absent: t
265
  val any_or_absent_node : Node.t
266

267
268
  val has_absent: t -> bool
  val has_record: t -> bool
269

270
271
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
272

273
274
275
  val pi : label -> t -> t
    (* May contain absent *)

276
  val project : t -> label -> t
277
278
    (* Raise Not_found if label is not necessarily present *)

279
  val condition : t -> label -> t -> t
280
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
281
282
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
283

284
  val first_label: t -> label
285
  val all_labels: t -> LabelSet.t
286

287
  val empty_cases: t -> bool * bool
288

289
290
  val merge: t -> t -> t
  val remove_field: t -> label -> t
291

292
  val get: t -> ((bool * t) label_map * bool * bool) list
293
294
295
296
297
298

  type t
  val focus: descr -> label -> t
  val get_this: t -> descr
  val need_others: t -> bool
  val constraint_on_others: t -> descr -> descr
299
300
end

301
module Arrow : sig
302
  val any : t
303

304
  val sample: t -> t
305

Pietro Abate's avatar
Pietro Abate committed
306
307
308
309
310
311
  (** [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.
  *)
312
  val check_strenghten: t -> t -> t
313

314
  val check_iface: (t * t) list -> t -> bool
315

316
  type t = descr * (descr * descr) list list
317
  val is_empty: t -> bool
318
319
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
320

321
  val domain: t -> descr
Pietro Abate's avatar
Pietro Abate committed
322
323

  (* Always succeed; no check on the domain *)
324
  val apply: t -> descr -> descr
325

Pietro Abate's avatar
Pietro Abate committed
326
327
328
  (** True if the type of the argument is needed to obtain
     the type of the result (must use [apply]; otherwise,
     [apply_noarg] is enough *)
329
  val need_arg : t -> bool
Pietro Abate's avatar
Pietro Abate committed
330

331
  val apply_noarg : t -> descr
332

Pietro Abate's avatar
Pietro Abate committed
333
end
334

335
module Int : sig
336
  val has_int : t -> Intervals.V.t -> bool
337
  val get: t -> VarIntervals.t
338
  val any : t
339
340
end

341
module Atom : sig
342
  val has_atom : t -> Atoms.V.t -> bool
343
  val get: t -> VarAtoms.t
344
  val any : t
345
346
end

347
module Char : sig
348
  val has_char : t -> Chars.V.t -> bool
349
  val is_empty : t -> bool
350
  val get: t -> VarChars.t
351
  val any : t
352
353
end

354
355
module Abstract : sig
  val has_abstract : t -> Abstracts.T.t -> bool
356
  val get: t -> VarAbstracts.t
357
358
359
360
361
  val any : t
end
(*
val get_abstract: t -> Abstracts.t
*)
362

363
val normalize : t -> t
364

365
(** Subtyping  **)
366

367
368
369
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
370
val disjoint : t -> t -> bool
371
val equiv : t -> t -> bool
372

373
374
375
376
377
378
379
(** intermediary representation for records *)

(*** TODO : SEAL OFF *)

val get_record : Rec.t -> (Label.t list * (bool * t array) * ((bool * t array) list)) list


380
381
382
383
384
385
386
387
(** Tools for compilation of PM **)

val cond_partition: t -> (t * t) list -> t list
  (* The second argument is a list of pair of types (ti,si)
     interpreted as the question "member of ti under the assumption si".
     The result is a partition of the first argument which is precise enough
     to answer all the questions. *)

Pietro Abate's avatar
Pietro Abate committed
388
module Print : sig
389
  type gname = string * Ns.QName.t * (Var.t * t) list
Pietro Abate's avatar
Pietro Abate committed
390
  val register_global : gname -> t -> unit
391
392
393
  val pp_const : Format.formatter -> const -> unit
  val pp_type: Format.formatter -> t -> unit
  val pp_node: Format.formatter -> Node.t -> unit
394
395

  (* Don't try to find a global name at toplevel *)
396
  val pp_noname: Format.formatter -> t -> unit
397

398
399
  val string_of_type: t -> string
  val string_of_node: Node.t -> string
400
  val printf : t -> unit
401
402
  val dump: Format.formatter -> t -> unit
  val dump_by_id: Format.formatter -> int -> unit
403
end
404

Pietro Abate's avatar
Pietro Abate committed
405
module Service : sig
Jérôme Maloberti's avatar
Jérôme Maloberti committed
406
407
408
409
  val to_service_params: t -> service_params
  val to_string: service_params -> string
end

410
module Witness : sig
411
  type witness
412
413
  val pp: Format.formatter -> witness -> unit
  val printf : witness -> unit
414
415
end
val witness: t -> Witness.witness
416

417

418
module Cache : sig
419
420
421
  type 'a cache
  val emp: 'a cache
  val find: (t -> 'a) -> t -> 'a cache -> 'a cache * 'a
422
  val lookup : t -> 'a cache -> 'a option
423
424
  val memo: (t -> 'a) -> (t -> 'a)
end
425