types.mli 6.04 KB
Newer Older
1 2
open Ident

3 4 5 6 7 8 9 10 11
type const = 
  | Integer of Intervals.V.t
  | Atom of Atoms.V.t 
  | 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
module CompUnit : sig
  include Custom.T

18
  val get_current: unit -> t
19 20
  val mk: U.t -> t
  val value: t -> U.t
21
  val print_qual: Format.formatter -> t -> unit
22 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
module Abstract : sig
33 34
  module T : Custom.T with type t = string
  type abs = T.t
35 36 37
  type t
  val any: t
  val atom: abs -> t
38
  val compare: t -> t -> int
39 40 41 42 43 44 45 46

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

  val contains: abs -> t -> bool
end

47 48
(** Algebra **)

49 50
include Custom.T
module Node : Custom.T
51

52
type descr = t
53

54 55
val make: unit -> Node.t
val define: Node.t -> t -> unit
56

57 58
val cons: t -> Node.t
val internalize: Node.t -> Node.t
59

60 61
val id: Node.t -> int
val descr: Node.t -> t
62

63 64 65
val caml_mode : bool ref
val clear_deserialize_table: unit -> unit

66 67
(** Boolean connectives **)

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

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

78
val non_constructed : t
79
val non_constructed_or_absent : t
80

81 82
(** Constructors **)

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

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

97 98
(** Helpers *)

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

101
val rec_of_list: bool -> (bool * Ns.qname * t) list -> t
102

103
val empty_closed_record: t
104
val empty_open_record: t
105

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

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

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

(** Normalization **)

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

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

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

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


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

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

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

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

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

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

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


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

187
  val empty_cases: t -> bool * bool
188

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

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

195
module Arrow : sig
196
  val any : t
197

198
  val sample: t -> t
199

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

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

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

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

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


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

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

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

246 247
val get_abstract: t -> Abstract.t

248
val normalize : t -> t
249

250
(** Subtyping  **)
251

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

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


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

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

278