types.mli 6.24 KB
Newer Older
1 2
open Ident

3 4
type const = 
  | 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

12

13
module Const: Custom.T with type t = const
14

15
(*
16 17 18
module CompUnit : sig
  include Custom.T

19
  val get_current: unit -> t
20 21
  val mk: U.t -> t
  val value: t -> U.t
22
  val print_qual: Format.formatter -> t -> unit
23 24 25 26 27 28 29 30 31

  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
32
*)
33

34
module Abstract : sig
35 36
  module T : Custom.T with type t = string
  type abs = T.t
37 38 39
  type t
  val any: t
  val atom: abs -> t
40
  val compare: t -> t -> int
41 42 43 44 45 46 47 48

  module V : sig
    type t = abs * Obj.t
  end

  val contains: abs -> t -> bool
end

49 50
(** Algebra **)

51 52
include Custom.T
module Node : Custom.T
53

54
type descr = t
55

56 57
val make: unit -> Node.t
val define: Node.t -> t -> unit
58

59 60
val cons: t -> Node.t
val internalize: Node.t -> Node.t
61

62 63
val id: Node.t -> int
val descr: Node.t -> t
64

65 66
(** Boolean connectives **)

67 68 69 70 71 72
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
73

74
val any_node : Node.t
75
val empty_node : Node.t
76

77
val non_constructed : t
78
val non_constructed_or_absent : t
79

80 81
(** Constructors **)

82 83
type pair_kind = [ `Normal | `XML ]

84 85 86 87 88 89
val interval : Intervals.t -> t
val atom     : Atoms.t -> t
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
90
  (* bool = true -> open record; bool = false -> closed record *)
91
val record_fields : bool * Node.t label_map -> t
92 93
val char     : Chars.t -> t
val constant : const -> t
94
val abstract : Abstract.t -> t
95

96 97
(** Helpers *)

98 99
val tuple : Node.t list -> t

100
val rec_of_list: bool -> (bool * Ns.Label.t * t) list -> t
101

102
val empty_closed_record: t
103
val empty_open_record: t
104

105 106 107 108 109 110 111
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
112
  val ty: t -> v
113 114
  val cup: v list -> v
  val times: v -> v -> v
115
  val xml: v -> v -> v
116

117
  val solve: v -> Node.t
118 119 120 121 122
end

(** Normalization **)

module Product : sig
123 124
  val any : t
  val any_xml : t
125
  val any_of: pair_kind -> t
126 127
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
128 129 130

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
131
  val is_empty: t -> bool
132
  val get: ?kind:pair_kind -> descr -> t
133 134
  val pi1: t -> descr
  val pi2: t -> descr
135
  val pi2_restricted: descr -> t -> descr
136 137 138 139 140 141 142
    
  (* 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
143
  val normal: ?kind:pair_kind -> descr -> normal
144

145 146 147 148
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

149 150
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
151 152 153 154


  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
155 156 157
end

module Record : sig
158
  val any : t
159 160
  val absent : t
  val absent_node : Node.t
161 162
  val or_absent: t -> t
  val any_or_absent: t
163
  val any_or_absent_node : Node.t
164

165 166
  val has_absent: t -> bool
  val has_record: t -> bool
167

168 169
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
170

171 172 173
  val pi : label -> t -> t
    (* May contain absent *)

174
  val project : t -> label -> t
175 176
    (* Raise Not_found if label is not necessarily present *)

177
  val condition : t -> label -> t -> t
178
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
179 180
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
181 182


183
  val first_label: t -> label
184
  val all_labels: t -> LabelSet.t
185

186
  val empty_cases: t -> bool * bool
187

188 189
  val merge: t -> t -> t
  val remove_field: t -> label -> t
190

191
  val get: t -> ((bool * t) label_map * bool * bool) list
192 193
end

194
module Arrow : sig
195
  val any : t
196

197
  val sample: t -> t
198

199
  val check_strenghten: t -> t -> t
200 201 202 203 204 205 206
    (* [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.
    *)

207
  val check_iface: (t * t) list -> t -> bool
208

209
  type t
210
  val is_empty: t -> bool
211 212
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
213

214 215 216
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
217 218 219 220 221 222

  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
223 224 225
end


226
module Int : sig
227
  val has_int : t -> Intervals.V.t -> bool
228 229
  val get: t -> Intervals.t
  val any : t
230 231
end

232
module Atom : sig
233
  val has_atom : t -> Atoms.V.t -> bool
234 235
  val get: t -> Atoms.t
  val any : t
236 237
end

238
module Char : sig
239
  val has_char : t -> Chars.V.t -> bool
240 241 242
  val is_empty : t -> bool
  val get: t -> Chars.t
  val any : t
243 244
end

245 246
val get_abstract: t -> Abstract.t

247
val normalize : t -> t
248

249
(** Subtyping  **)
250

251 252 253
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
254
val disjoint : t -> t -> bool
255
val equiv : t -> t -> bool
256

257 258 259 260 261 262 263 264 265
(** 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. *)


266 267
module Print :
sig
268
  val register_global : string -> Ns.QName.t -> t -> unit
269
  val print_const : Format.formatter -> const -> unit
270
  val print: Format.formatter -> t -> unit
271
  val print_node: Format.formatter -> Node.t -> unit
272 273 274

  (* Don't try to find a global name at toplevel *)
  val print_noname: Format.formatter -> t -> unit
275 276

  val to_string: t -> string
277
end
278

279

280 281 282 283 284 285 286 287 288 289 290
type witness
val witness: t -> witness
val print_witness: Format.formatter -> witness -> unit

module Cache: sig
  type 'a cache
  val emp: 'a cache
  val find: (t -> 'a) -> t -> 'a cache -> 'a cache * 'a

  val memo: (t -> 'a) -> (t -> 'a)
end