types.mli 5.82 KB
Newer Older
1
module LabelPool : Pool.T with type value = string and type t = int
2
type label = LabelPool.t
3 4 5
type const = | Integer of Intervals.v
	     | Atom of Atoms.v 
	     | Char of Chars.v
6

7 8
(** Algebra **)

9 10
type node
type descr
11

12 13
val make: unit -> node
val define: node -> descr -> unit
14

15 16
val cons: descr -> node
val internalize: node -> node
17

18 19
val id: node -> int
val descr: node -> descr
20

21 22 23
val equal_descr: descr -> descr -> bool
val hash_descr: descr -> int

24
module DescrHash: Hashtbl.S with type key = descr
25 26 27 28
module DescrMap: Map.S with type key = descr

(* Note: it seems that even for non-functional data, DescrMap
is more efficient than DescrHash ... *)
29

30 31
(** Boolean connectives **)

32 33 34 35 36 37
val cup    : descr -> descr -> descr
val cap    : descr -> descr -> descr
val diff   : descr -> descr -> descr
val neg    : descr -> descr
val empty  : descr
val any    : descr
38

39 40
val any_node : node

41 42
(** Constructors **)

43 44
type pair_kind = [ `Normal | `XML ]

45
val interval : Intervals.t -> descr
46
val atom     : Atoms.t -> descr
47
val times    : node -> node -> descr
48
val xml      : node -> node -> descr
49
val arrow    : node -> node -> descr
50 51
val record   : label -> node -> descr
val record'  : bool * (label, node) SortedMap.t -> descr
52
val char     : Chars.t -> descr
53
val constant : const -> descr
54

55 56 57 58 59 60 61
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
62
  val ty: descr -> v
63 64 65
  val cup: v list -> v
  val times: v -> v -> v

66
  val solve: v -> node
67 68 69 70 71
end

(** Normalization **)

module Product : sig
72
  val any : descr
73 74 75
  val any_xml : descr
  val other : ?kind:pair_kind -> descr -> descr
  val is_product : ?kind:pair_kind -> descr -> bool
76 77 78

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
79
  val is_empty: t -> bool
80
  val get: ?kind:pair_kind -> descr -> t
81 82
  val pi1: t -> descr
  val pi2: t -> descr
83
  val pi2_restricted: descr -> t -> descr
84 85 86 87 88 89 90
    
  (* 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
91
  val normal: ?kind:pair_kind -> descr -> normal
92 93 94

  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
95 96 97
end

module Record : sig
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  val any : descr
  val or_absent: descr -> descr
  val any_or_absent: descr

  val has_absent: descr -> bool
  val has_record: descr -> bool

  val split : descr -> label -> Product.t
  val split_normal : descr -> label -> Product.normal

  val project : descr -> label -> descr
    (* Raise Not_found if label is not necessarily present *)

  val first_label: descr -> label

  val empty_cases: descr -> bool * bool



(*
118 119 120 121
  val restrict_field : t -> label -> descr -> t
  val restrict_label_absent: t -> label -> t
  val restrict_label_present: t -> label -> t
  val label_present: t -> label -> (descr * t) list
122 123
  val somefield_possible: t -> bool
  val nofield_possible: t -> bool
124
  val any : descr
125 126
  val project_field: t -> label -> descr
  val project : descr -> label -> descr
127

128
(*
129
  (* List of maps label -> (optional, content) *)
130
  type t (* = (label, (bool * descr)) SortedMap.t list *)
131
  val get: descr -> t
132
  val descr: t -> descr
133 134 135 136 137
  val is_empty: t -> bool
  val restrict_label_present: t -> label -> t
  val restrict_field: t -> label -> descr -> t
  val restrict_label_absent: t -> label -> t
  val project_field: t -> label -> descr
138
*)
139 140

  type normal = 
141 142 143 144
      [ `Success   (* { } *)
      | `Fail      (* Empty *)
      | `NoField   (* {| |} *)
      | `SomeField (* { } \ {| |} *)
145
      | `Label of label * (descr * normal) list * normal ]
146
	   
147 148
  val normal: descr -> normal

149 150
  val normal': t -> label -> (descr * t) list * t
  val first_label: t -> [ `Success|`Fail|`NoField|`SomeField|`Label of label ]
151

152 153
  val change_field: t -> label -> node -> t

154
(*
155
  val project : descr -> label -> descr
156
    (* Raise Not_found if label is not necessarily present *)
157
*)
158
*)
159 160
end

161 162
module Arrow : sig
  val any : descr
163

164 165 166 167 168 169 170 171
  val check_strenghten: descr -> descr -> descr
    (* [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.
    *)

172 173
  val check_iface: (descr * descr) list -> descr -> bool

174
  type t
175
  val is_empty: t -> bool
176 177
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
178

179 180 181
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
182 183 184 185 186 187

  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
188 189 190
end


191
module Int : sig
192
  val has_int : descr -> Intervals.v -> bool
193

194 195 196 197 198 199 200
  val any : descr

  val is_int : descr -> bool
  val get: descr -> Intervals.t
  val put: Intervals.t -> descr
end

201
module Atom : sig
202
  val has_atom : descr -> Atoms.v -> bool
203 204
end

205
module Char : sig
206
  val has_char : descr -> Chars.v -> bool
207
  val any : descr
208 209
end

210
val normalize : descr -> descr
211

212
(** Subtyping and sample values **)
213

214 215 216
val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool
217

218 219 220
module Sample :
sig
  type t =
221 222 223
    | Int of Intervals.v
    | Atom of Atoms.v
    | Char of Chars.v
224 225
    | Pair of (t * t)
    | Xml of (t * t)
226 227
    | Record of (label * t) list
    | Fun of (node * node) list
228
    | Other
229 230 231 232 233 234

  val get : descr -> t
	(** 
	  Extract a sample value from a non empty type;
	  raise Not_found for an empty type
	**)
235 236

  val print : Format.formatter -> t -> unit
237 238
end

239 240
module Print :
sig
241
  val register_global : string -> descr -> unit
242
  val print_const : Format.formatter -> const -> unit
243 244
  val print : Format.formatter -> node -> unit
  val print_descr: Format.formatter -> descr -> unit
245
end
246

247
val check: descr -> unit
248
val print_stat: Format.formatter -> unit