types.mli 5.47 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 32 33 34 35 36 37 38 39 40 41 42 43
module Abstract : sig
  type abs = CompUnit.t * Ident.id
  type t
  val any: t
  val atom: abs -> t

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

  val contains: abs -> t -> bool
end

44 45
(** Algebra **)

46 47
include Custom.T
module Node : Custom.T
48

49
type descr = t
50

51 52
val make: unit -> Node.t
val define: Node.t -> t -> unit
53

54 55
val cons: t -> Node.t
val internalize: Node.t -> Node.t
56

57 58
val id: Node.t -> int
val descr: Node.t -> t
59

60 61
(** Boolean connectives **)

62 63 64 65 66 67
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
68

69
val any_node : Node.t
70

71
val non_constructed : t
72

73 74
(** Constructors **)

75 76
type pair_kind = [ `Normal | `XML ]

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

89 90 91
(** Helpers *)

  (** given a list of descrs create an OR type including all descrs *)
92
val choice_of_list: t list -> t
93 94 95

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

98
  (** Build a record from a list of <name,t> pairs. Open defaults to true.
99
  All specified fields are required. *)
100
val rec_of_list: ?opened:bool -> (Ns.qname * t) list -> t
101 102 103

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

106 107
val empty_closed_record: t
val empty_opened_record: t
108

109 110 111 112 113 114 115
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
116
  val ty: t -> v
117 118
  val cup: v list -> v
  val times: v -> v -> v
119
  val xml: v -> v -> v
120

121
  val solve: v -> Node.t
122 123 124 125 126
end

(** Normalization **)

module Product : sig
127 128 129 130
  val any : t
  val any_xml : t
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
131 132 133

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

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

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

module Record : sig
157 158 159
  val any : t
  val or_absent: t -> t
  val any_or_absent: t
160

161 162
  val has_absent: t -> bool
  val has_record: t -> bool
163

164 165
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
166

167
  val project : t -> label -> t
168 169
    (* Raise Not_found if label is not necessarily present *)

170
  val condition : t -> label -> t -> t
171
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
172 173
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
174 175


176
  val first_label: t -> label
177

178
  val empty_cases: t -> bool * bool
179

180 181
  val merge: t -> t -> t
  val remove_field: t -> label -> t
182

183
  val get: t -> ((bool * t) label_map * bool * bool) list
184 185
end

186
module Arrow : sig
187
  val any : t
188

189
  val sample: t -> t
190

191
  val check_strenghten: t -> t -> t
192 193 194 195 196 197 198
    (* [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.
    *)

199
  val check_iface: (t * t) list -> t -> bool
200

201
  type t
202
  val is_empty: t -> bool
203 204
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
205

206 207 208
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
209 210 211 212 213 214

  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
215 216 217
end


218
module Int : sig
219
  val has_int : t -> Intervals.V.t -> bool
220 221
  val get: t -> Intervals.t
  val any : t
222 223
end

224
module Atom : sig
225
  val has_atom : t -> Atoms.V.t -> bool
226 227
  val get: t -> Atoms.t
  val any : t
228 229
end

230
module Char : sig
231
  val has_char : t -> Chars.V.t -> bool
232 233 234
  val is_empty : t -> bool
  val get: t -> Chars.t
  val any : t
235 236
end

237 238
val get_abstract: t -> Abstract.t

239
val normalize : t -> t
240

241
(** Subtyping  **)
242

243 244 245
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
246

247 248
module Print :
sig
249
  val register_global : U.t -> t -> unit
250
  val print_const : Format.formatter -> const -> unit
251
  val print: Format.formatter -> t -> unit
252
end
253