types.mli 4.98 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
(** Algebra **)

17
18
include Custom.T
module Node : Custom.T
19

20
type descr = t
21

22
23
val make: unit -> Node.t
val define: Node.t -> t -> unit
24

25
26
val cons: t -> Node.t
val internalize: Node.t -> Node.t
27

28
29
val id: Node.t -> int
val descr: Node.t -> t
30

31
32
(** Boolean connectives **)

33
34
35
36
37
38
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
39

40
val any_node : Node.t
41

42
val non_constructed : t
43

44
45
(** Constructors **)

46
47
type pair_kind = [ `Normal | `XML ]

48
49
50
51
52
53
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
54
  (* bool = true -> open record; bool = false -> closed record *)
55
56
57
val record'  : bool * Node.t label_map -> t
val char     : Chars.t -> t
val constant : const -> t
58

59
60
61
(** Helpers *)

  (** given a list of descrs create an OR type including all descrs *)
62
val choice_of_list: t list -> t
63
64
65

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

68
  (** Build a record from a list of <name,t> pairs. Open defaults to true.
69
  All specified fields are required. *)
70
val rec_of_list: ?opened:bool -> (string * t) list -> t
71
72
73

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

76
77
val empty_closed_record: t
val empty_opened_record: t
78

79
80
81
82
83
84
85
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
86
  val ty: t -> v
87
88
  val cup: v list -> v
  val times: v -> v -> v
89
  val xml: v -> v -> v
90

91
  val solve: v -> Node.t
92
93
94
95
96
end

(** Normalization **)

module Product : sig
97
98
99
100
  val any : t
  val any_xml : t
  val other : ?kind:pair_kind -> t -> t
  val is_product : ?kind:pair_kind -> t -> bool
101
102
103

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

118
119
120
121
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

122
123
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
124
125
126
end

module Record : sig
127
128
129
  val any : t
  val or_absent: t -> t
  val any_or_absent: t
130

131
132
  val has_absent: t -> bool
  val has_record: t -> bool
133

134
135
  val split : t -> label -> Product.t
  val split_normal : t -> label -> Product.normal
136

137
  val project : t -> label -> t
138
139
    (* Raise Not_found if label is not necessarily present *)

140
  val condition : t -> label -> t -> t
141
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
142
143
  val project_opt : t -> label -> t
  val has_empty_record: t -> bool
144
145


146
  val first_label: t -> label
147

148
  val empty_cases: t -> bool * bool
149

150
151
  val merge: t -> t -> t
  val remove_field: t -> label -> t
152

153
  val get: t -> ((bool * t) label_map * bool * bool) list
154
155
end

156
module Arrow : sig
157
  val any : t
158

159
  val sample: t -> t
160

161
  val check_strenghten: t -> t -> t
162
163
164
165
166
167
168
    (* [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.
    *)

169
  val check_iface: (t * t) list -> t -> bool
170

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

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

  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
185
186
187
end


188
module Int : sig
189
  val has_int : t -> Intervals.V.t -> bool
190
191
  val get: t -> Intervals.t
  val any : t
192
193
end

194
module Atom : sig
195
  val has_atom : t -> Atoms.V.t -> bool
196
197
  val get: t -> Atoms.t
  val any : t
198
199
end

200
module Char : sig
201
  val has_char : t -> Chars.V.t -> bool
202
203
204
  val is_empty : t -> bool
  val get: t -> Chars.t
  val any : t
205
206
end

207
val normalize : t -> t
208

209
(** Subtyping  **)
210

211
212
213
val is_empty : t -> bool
val non_empty: t -> bool
val subtype  : t -> t -> bool
214

215
216
module Print :
sig
217
  val register_global : U.t -> t -> unit
218
  val print_const : Format.formatter -> const -> unit
219
  val print: Format.formatter -> t -> unit
220
end
221