types.mli 4.91 KB
Newer Older
1
2
open Ident

3
4
5
type const = | Integer of Intervals.v
	     | Atom of Atoms.v 
	     | Char of Chars.v
6

7
8
val compare_const: const -> const -> int
val hash_const: const -> int
9
val equal_const: const -> const -> bool
10

11
12
(** Algebra **)

13
14
15
include Custom.T
module Node : Custom.T
type descr = t
16

17
18
val make: unit -> Node.t
val define: Node.t -> t -> unit
19

20
21
val cons: t -> Node.t
val internalize: Node.t -> Node.t
22

23
24
val id: Node.t -> int
val descr: Node.t -> t
25

26
27
(** Boolean connectives **)

28
29
30
31
32
33
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
34

35
val any_node : Node.t
36

37
val non_constructed : t
38

39
40
(** Constructors **)

41
42
type pair_kind = [ `Normal | `XML ]

43
44
45
46
47
48
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
49
  (* bool = true -> open record; bool = false -> closed record *)
50
51
52
val record'  : bool * Node.t label_map -> t
val char     : Chars.t -> t
val constant : const -> t
53

54
55
56
(** Helpers *)

  (** given a list of descrs create an OR type including all descrs *)
57
val choice_of_list: t list -> t
58
59
60

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

63
  (** Build a record from a list of <name,t> pairs. Open defaults to true.
64
  All specified fields are required. *)
65
val rec_of_list: ?opened:bool -> (string * t) list -> t
66
67
68

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

71
72
val empty_closed_record: t
val empty_opened_record: t
73

74
75
76
77
78
79
80
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
81
  val ty: t -> v
82
83
  val cup: v list -> v
  val times: v -> v -> v
84
  val xml: v -> v -> v
85

86
  val solve: v -> Node.t
87
88
89
90
91
end

(** Normalization **)

module Product : sig
92
93
94
95
  val any : t
  val any_xml : t
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
96
97
98

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
99
  val is_empty: t -> bool
100
  val get: ?kind:pair_kind -> descr -> t
101
102
  val pi1: t -> descr
  val pi2: t -> descr
103
  val pi2_restricted: descr -> t -> descr
104
105
106
107
108
109
110
    
  (* 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
111
  val normal: ?kind:pair_kind -> descr -> normal
112

113
114
115
116
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

117
118
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
119
120
121
end

module Record : sig
122
123
124
  val any : t
  val or_absent: t -> t
  val any_or_absent: t
125

126
127
  val has_absent: t -> bool
  val has_record: t -> bool
128

129
130
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
131

132
  val project : t -> label -> t
133
134
    (* Raise Not_found if label is not necessarily present *)

135
  val condition : t -> label -> t -> t
136
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
137
138
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
139
140


141
  val first_label: t -> label
142

143
  val empty_cases: t -> bool * bool
144

145
146
  val merge: t -> t -> t
  val remove_field: t -> label -> t
147

148
  val get: t -> ((bool * t) label_map * bool * bool) list
149
150
end

151
module Arrow : sig
152
  val any : t
153

154
  val sample: t -> t
155

156
  val check_strenghten: t -> t -> t
157
158
159
160
161
162
163
    (* [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.
    *)

164
  val check_iface: (t * t) list -> t -> bool
165

166
  type t
167
  val is_empty: t -> bool
168
169
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
170

171
172
173
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
174
175
176
177
178
179

  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
180
181
182
end


183
module Int : sig
184
185
186
  val has_int : t -> Intervals.v -> bool
  val get: t -> Intervals.t
  val any : t
187
188
end

189
module Atom : sig
190
191
192
  val has_atom : t -> Atoms.v -> bool
  val get: t -> Atoms.t
  val any : t
193
194
end

195
module Char : sig
196
197
198
199
  val has_char : t -> Chars.v -> bool
  val is_empty : t -> bool
  val get: t -> Chars.t
  val any : t
200
201
end

202
val normalize : t -> t
203

204
(** Subtyping  **)
205

206
207
208
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
209
210
211

module Print :
sig
212
  val register_global : U.t -> t -> unit
213
  val print_const : Format.formatter -> const -> unit
214
  val print: Format.formatter -> t -> unit
215
216
end