types.mli 6.31 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 18 19 20 21 22 23 24 25 26 27 28 29 30

module CompUnit : sig
  include Custom.T

  val mk: U.t -> t
  val value: t -> U.t

  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

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

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

  val contains: abs -> t -> bool
end

46 47
(** Algebra **)

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

51
type descr = t
52

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

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

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

62 63
(** Boolean connectives **)

64 65 66 67 68 69
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
70

71
val any_node : Node.t
72
val empty_node : Node.t
73

74
val non_constructed : t
75
val non_constructed_or_absent : t
76

77 78
(** Constructors **)

79 80
type pair_kind = [ `Normal | `XML ]

81 82 83 84 85 86
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
87
  (* bool = true -> open record; bool = false -> closed record *)
88 89 90
val record'  : bool * Node.t label_map -> t
val char     : Chars.t -> t
val constant : const -> t
91
val abstract : Abstract.t -> t
92

93 94
(** Helpers *)

95 96
val tuple : Node.t list -> t

97
  (** given a list of descrs create an OR type including all descrs *)
98
val choice_of_list: t list -> t
99 100 101

  (** do it yourself: create an Xml type from three types (tag type, attribute
  type, content type) *)
102
val xml': t -> t -> t -> t
103

104
  (** Build a record from a list of <name,t> pairs. Open defaults to true.
105
  All specified fields are required. *)
106
val rec_of_list: ?opened:bool -> (Ns.qname * t) list -> t
107 108 109

  (** Similiar to rec_of_list, the additional boolean value specify whether the
  specified field is optional (true) or not (false. *)
110
val rec_of_list': ?opened:bool -> (bool * Ns.qname * t) list -> t
111

112 113
val empty_closed_record: t
val empty_opened_record: t
114

115 116 117 118 119 120 121
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
122
  val ty: t -> v
123 124
  val cup: v list -> v
  val times: v -> v -> v
125
  val xml: v -> v -> v
126

127
  val solve: v -> Node.t
128 129 130 131 132
end

(** Normalization **)

module Product : sig
133 134
  val any : t
  val any_xml : t
135
  val any_of: pair_kind -> t
136 137
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
138 139 140

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
141
  val is_empty: t -> bool
142
  val get: ?kind:pair_kind -> descr -> t
143 144
  val pi1: t -> descr
  val pi2: t -> descr
145
  val pi2_restricted: descr -> t -> descr
146 147 148 149 150 151 152
    
  (* 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
153
  val normal: ?kind:pair_kind -> descr -> normal
154

155 156 157 158
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

159 160
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
161 162 163 164


  val clean_normal: t -> t
    (* Merge rectangles with same second component *)
165 166 167
end

module Record : sig
168
  val any : t
169 170
  val absent : t
  val absent_node : Node.t
171 172
  val or_absent: t -> t
  val any_or_absent: t
173
  val any_or_absent_node : Node.t
174

175 176
  val has_absent: t -> bool
  val has_record: t -> bool
177

178 179
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
180

181 182 183
  val pi : label -> t -> t
    (* May contain absent *)

184
  val project : t -> label -> t
185 186
    (* Raise Not_found if label is not necessarily present *)

187
  val condition : t -> label -> t -> t
188
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
189 190
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
191 192


193
  val first_label: t -> label
194
  val all_labels: t -> LabelSet.t
195

196
  val empty_cases: t -> bool * bool
197

198 199
  val merge: t -> t -> t
  val remove_field: t -> label -> t
200

201
  val get: t -> ((bool * t) label_map * bool * bool) list
202 203
end

204
module Arrow : sig
205
  val any : t
206

207
  val sample: t -> t
208

209
  val check_strenghten: t -> t -> t
210 211 212 213 214 215 216
    (* [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.
    *)

217
  val check_iface: (t * t) list -> t -> bool
218

219
  type t
220
  val is_empty: t -> bool
221 222
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
223

224 225 226
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
227 228 229 230 231 232

  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
233 234 235
end


236
module Int : sig
237
  val has_int : t -> Intervals.V.t -> bool
238 239
  val get: t -> Intervals.t
  val any : t
240 241
end

242
module Atom : sig
243
  val has_atom : t -> Atoms.V.t -> bool
244 245
  val get: t -> Atoms.t
  val any : t
246 247
end

248
module Char : sig
249
  val has_char : t -> Chars.V.t -> bool
250 251 252
  val is_empty : t -> bool
  val get: t -> Chars.t
  val any : t
253 254
end

255 256
val get_abstract: t -> Abstract.t

257
val normalize : t -> t
258

259
(** Subtyping  **)
260

261 262 263
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
264
val disjoint : t -> t -> bool
265
val equiv : t -> t -> bool
266

267 268 269 270 271 272 273 274 275
(** 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. *)


276 277
module Print :
sig
278
  val register_global : U.t -> t -> unit
279
  val print_const : Format.formatter -> const -> unit
280
  val print: Format.formatter -> t -> unit
281
  val print_node: Format.formatter -> Node.t -> unit
282
end
283

284