types.mli 9.72 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
type type_kind = [ `atoms | `intervals | `chars | `times | `xml | `arrow | `record | `abstracts ]
81

82
val pp_type_kind : Format.formatter -> type_kind -> unit
83 84 85
module type VarType = sig
    include Bool.V
    type descr = Descr.t
86
    val kind : type_kind
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    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



112 113
val make: unit -> Node.t
val define: Node.t -> t -> unit
114

115 116
val cons: t -> Node.t
val internalize: Node.t -> Node.t
117

118 119
val id: Node.t -> int
val descr: Node.t -> t
120

121 122
(** Boolean connectives **)

123 124 125 126 127 128
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
129

Pietro Abate's avatar
Pietro Abate committed
130 131
val no_var  : t -> bool
val is_var  : t -> bool
132
val has_tlv : t -> bool
Pietro Abate's avatar
Pietro Abate committed
133
val is_closed : Var.Set.t -> t -> bool
134

135
val any_node : Node.t
136
val empty_node : Node.t
137

138
val non_constructed : t
139
val non_constructed_or_absent : t
140

141 142
(** Constructors **)

143 144
type pair_kind = [ `Normal | `XML ]

145
val var      : Var.t -> t
146 147
val interval : Intervals.t -> t
val atom     : Atoms.t -> t
148 149 150 151
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
152
  (** bool = true -> open record; bool = false -> closed record *)
153
val record_fields : bool * Node.t label_map -> t
154
val char     : Chars.t -> t
155
val constant : const -> t
156
val abstract : Abstracts.t -> t
157

158 159
(** Helpers *)

160
val all_vars : t -> Var.Set.t
161 162
val tuple : Node.t list -> t

163
val rec_of_list: bool -> (bool * Ns.Label.t * t) list -> t
164

165
val empty_closed_record: t
166
val empty_open_record: t
167

168 169 170 171 172 173 174 175 176


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
end

177 178
(** Positive systems and least solutions **)

179
module Positive : sig
180 181 182
  type v
  val forward: unit -> v
  val define: v -> v -> unit
183
  val ty: t -> v
184 185
  val cup: v list -> v
  val times: v -> v -> v
186
  val xml: v -> v -> v
187
  val solve: v -> Node.t
188
end
189

190
module Variable : sig
191
    val extract : t -> Var.t * bool
192 193
end

194 195 196 197 198 199 200 201 202 203 204
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
205 206
end

207 208 209 210

(** Normalization **)

module Product : sig
211 212
  val any : t
  val any_xml : t
213
  val any_of: pair_kind -> t
214 215
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
216 217 218

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
219
  val is_empty: t -> bool
220
  val get: ?kind:pair_kind -> descr -> t
221 222
  val pi1: t -> descr
  val pi2: t -> descr
223
  val pi2_restricted: descr -> t -> descr
224

225 226 227 228 229 230
  (* 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
231
  val normal: ?kind:pair_kind -> descr -> normal
232

233 234 235 236
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

237 238
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
239 240 241

  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
242 243 244
end

module Record : sig
245
  val any : t
246 247
  val absent : t
  val absent_node : Node.t
248 249
  val or_absent: t -> t
  val any_or_absent: t
250
  val any_or_absent_node : Node.t
251

252 253
  val has_absent: t -> bool
  val has_record: t -> bool
254

255 256
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
257

258 259 260
  val pi : label -> t -> t
    (* May contain absent *)

261
  val project : t -> label -> t
262 263
    (* Raise Not_found if label is not necessarily present *)

264
  val condition : t -> label -> t -> t
265
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
266 267
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
268

269
  val first_label: t -> label
270
  val all_labels: t -> LabelSet.t
271

272
  val empty_cases: t -> bool * bool
273

274 275
  val merge: t -> t -> t
  val remove_field: t -> label -> t
276

277
  val get: t -> ((bool * t) label_map * bool * bool) list
278 279 280 281 282 283

  type t
  val focus: descr -> label -> t
  val get_this: t -> descr
  val need_others: t -> bool
  val constraint_on_others: t -> descr -> descr
284 285
end

286
module Arrow : sig
287
  val any : t
288

289
  val sample: t -> t
290

Pietro Abate's avatar
Pietro Abate committed
291 292 293 294 295 296
  (** [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.
  *)
297
  val check_strenghten: t -> t -> t
298

299
  val check_iface: (t * t) list -> t -> bool
300

301
  type t = descr * (descr * descr) list list
302
  val is_empty: t -> bool
303 304
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
305

306
  val domain: t -> descr
Pietro Abate's avatar
Pietro Abate committed
307 308

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

Pietro Abate's avatar
Pietro Abate committed
311 312 313
  (** True if the type of the argument is needed to obtain
     the type of the result (must use [apply]; otherwise,
     [apply_noarg] is enough *)
314
  val need_arg : t -> bool
Pietro Abate's avatar
Pietro Abate committed
315

316
  val apply_noarg : t -> descr
317

Pietro Abate's avatar
Pietro Abate committed
318
end
319

320
module Int : sig
321
  val has_int : t -> Intervals.V.t -> bool
322
  val get: t -> VarIntervals.t
323
  val any : t
324 325
end

326
module Atom : sig
327
  val has_atom : t -> Atoms.V.t -> bool
328
  val get: t -> VarAtoms.t
329
  val any : t
330 331
end

332
module Char : sig
333
  val has_char : t -> Chars.V.t -> bool
334
  val is_empty : t -> bool
335
  val get: t -> VarChars.t
336
  val any : t
337 338
end

339 340
module Abstract : sig
  val has_abstract : t -> Abstracts.T.t -> bool
341
  val get: t -> VarAbstracts.t
342 343 344 345 346
  val any : t
end
(*
val get_abstract: t -> Abstracts.t
*)
347

348
val normalize : t -> t
349

350
(** Subtyping  **)
351

352 353 354
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
355
val disjoint : t -> t -> bool
356
val equiv : t -> t -> bool
357

358 359 360 361 362 363 364
(** intermediary representation for records *)

(*** TODO : SEAL OFF *)

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


365 366 367 368 369 370 371 372
(** 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
373
module Print : sig
374
  type gname = string * Ns.QName.t * (Var.t * t) list
Pietro Abate's avatar
Pietro Abate committed
375
  val register_global : gname -> t -> unit
376 377 378
  val pp_const : Format.formatter -> const -> unit
  val pp_type: Format.formatter -> t -> unit
  val pp_node: Format.formatter -> Node.t -> unit
379 380

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

383 384
  val string_of_type: t -> string
  val string_of_node: Node.t -> string
385
  val printf : t -> unit
386 387
  val dump: Format.formatter -> t -> unit
  val dump_by_id: Format.formatter -> int -> unit
388
end
389

Pietro Abate's avatar
Pietro Abate committed
390
module Service : sig
Jérôme Maloberti's avatar
Jérôme Maloberti committed
391 392 393 394
  val to_service_params: t -> service_params
  val to_string: service_params -> string
end

395
module Witness : sig
396
  type witness
397 398
  val pp: Format.formatter -> witness -> unit
  val printf : witness -> unit
399 400
end
val witness: t -> Witness.witness
401

402

403
module Cache : sig
404 405 406
  type 'a cache
  val emp: 'a cache
  val find: (t -> 'a) -> t -> 'a cache -> 'a cache * 'a
407
  val lookup : t -> 'a cache -> 'a option
408 409
  val memo: (t -> 'a) -> (t -> 'a)
end
410