Import Upstream version 20180207
[hcoop/debian/mlton.git] / mlton / xml / xml-tree.sig
1 (* Copyright (C) 2009,2017 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 *)
9
10 (* binding occurences:
11 * 1. lambda arg
12 * 2. pattern arg
13 * 3. MonoVal dec
14 * 4. PolyVal dec
15 * 5. Fun dec
16 * 6. Handle catch
17 *)
18
19 signature XML_TREE_STRUCTS =
20 sig
21 include ATOMS
22 end
23
24 signature XML_TREE =
25 sig
26 include XML_TREE_STRUCTS
27
28 structure Type: XML_TYPE
29 sharing Atoms = Type.Atoms
30
31 structure Pat:
32 sig
33 datatype t = T of {arg: (Var.t * Type.t) option,
34 con: Con.t,
35 targs: Type.t vector}
36
37 val falsee: t
38 val truee: t
39 val con: t -> Con.t
40 val layout: t -> Layout.t
41 end
42
43 structure Cases:
44 sig
45 datatype 'a t =
46 Con of (Pat.t * 'a) vector
47 | Word of WordSize.t * (WordX.t * 'a) vector
48
49 val fold: 'a t * 'b * ('a * 'b -> 'b) -> 'b
50 val foreach: 'a t * ('a -> unit) -> unit
51 val foreach': 'a t * ('a -> unit) * (Pat.t -> unit) -> unit
52 val map: 'a t * ('a -> 'b) -> 'b t
53 end
54
55 structure Lambda:
56 sig
57 type exp
58 type t
59
60 val arg: t -> Var.t
61 val body: t -> exp
62 val dest: t -> {arg: Var.t,
63 argType: Type.t,
64 body: exp,
65 mayInline: bool}
66 val equals: t * t -> bool
67 val layout: t -> Layout.t
68 val make: {arg: Var.t,
69 argType: Type.t,
70 body: exp,
71 mayInline: bool} -> t
72 val mayInline: t -> bool
73 val plist: t -> PropertyList.t
74 end
75
76 (* VarExp is a type application, variable applied to type args. *)
77 structure VarExp:
78 sig
79 datatype t = T of {var: Var.t,
80 targs: Type.t vector}
81
82 val equals: t * t -> bool
83 val layout: t -> Layout.t
84 val mono: Var.t -> t
85 val var: t -> Var.t
86 end
87
88 structure PrimExp:
89 sig
90 type exp = Lambda.exp
91 datatype t =
92 App of {arg: VarExp.t,
93 func: VarExp.t}
94 | Case of {cases: exp Cases.t,
95 default: (exp * Region.t) option,
96 test: VarExp.t}
97 | ConApp of {arg: VarExp.t option,
98 con: Con.t,
99 targs: Type.t vector}
100 | Const of Const.t
101 | Handle of {(* catch binds the exception in the handler. *)
102 catch: Var.t * Type.t,
103 handler: exp,
104 try: exp}
105 | Lambda of Lambda.t
106 | PrimApp of {args: VarExp.t vector,
107 prim: Type.t Prim.t,
108 targs: Type.t vector}
109 | Profile of ProfileExp.t
110 | Raise of {exn: VarExp.t, extend: bool}
111 | Select of {offset: int,
112 tuple: VarExp.t}
113 | Tuple of VarExp.t vector
114 | Var of VarExp.t
115
116 val layout: t -> Layout.t
117 end
118
119 structure Dec:
120 sig
121 type exp = Lambda.exp
122
123 datatype t =
124 Exception of {arg: Type.t option,
125 con: Con.t}
126 | Fun of {decs: {lambda: Lambda.t,
127 ty: Type.t,
128 var: Var.t} vector,
129 tyvars: Tyvar.t vector}
130 | MonoVal of {exp: PrimExp.t,
131 ty: Type.t,
132 var: Var.t}
133 | PolyVal of {exp: exp,
134 ty: Type.t,
135 tyvars: Tyvar.t vector,
136 var: Var.t}
137
138 val layout: t -> Layout.t
139 end
140
141 structure Exp:
142 sig
143 type t = Lambda.exp
144
145 val clear: t -> unit
146 val decs: t -> Dec.t list
147 val dest: t -> {decs: Dec.t list, result: VarExp.t}
148 val enterLeave: t * Type.t * SourceInfo.t -> t
149 (* foreach {exp, handleExp, handleBoundVar, handleVarExp}
150 * applies handleExp to each subexpresison of e (including e)
151 * applies handleBoundVar to each variable bound in e
152 * applies handleVarExp to each variable expression in e
153 * handleBoundVar will be called on a variable binding before
154 * handleVarExp is called on any occurrences
155 * handleExp is called on an expression after it is called on
156 * all of its subexpressions
157 *)
158 val foreach:
159 {exp: t,
160 handleExp: t -> unit,
161 handlePrimExp: Var.t * Type.t * PrimExp.t -> unit,
162 handleBoundVar: Var.t * Tyvar.t vector * Type.t -> unit,
163 handleVarExp: VarExp.t -> unit} -> unit
164 val foreachBoundVar:
165 t * (Var.t * Tyvar.t vector * Type.t -> unit) -> unit
166 val foreachExp: t * (t -> unit) -> unit
167 val foreachPrimExp: t * (Var.t * Type.t * PrimExp.t -> unit) -> unit
168 val foreachVarExp: t * (VarExp.t -> unit) -> unit
169 val fromPrimExp: PrimExp.t * Type.t -> t
170 val hasPrim: t * (Type.t Prim.t -> bool) -> bool
171 val layout: t -> Layout.t
172 val make: {decs: Dec.t list, result: VarExp.t} -> t
173 val prefix: t * Dec.t -> t
174 val result: t -> VarExp.t
175 val size: t -> int
176 end
177
178 structure DirectExp:
179 sig
180 type t
181
182 val app: {func: t, arg: t, ty: Type.t} -> t
183 val bug: string -> t
184 val casee:
185 {cases: t Cases.t,
186 default: (t * Region.t) option,
187 test: t,
188 ty: Type.t} (* type of entire case expression *)
189 -> t
190 val conApp: {arg: t option,
191 con: Con.t,
192 targs: Type.t vector,
193 ty: Type.t} -> t
194 val const: Const.t -> t
195 val deref: t -> t
196 val detuple: {tuple: t, body: (VarExp.t * Type.t) vector -> t} -> t
197 val detupleBind: {tuple: t, components: Var.t vector, body: t} -> t
198 val devector: {vector: t, length: int, body: (VarExp.t * Type.t) vector -> t} -> t
199 val equal: t * t -> t
200 val falsee: unit -> t
201 val fromExp: Exp.t * Type.t -> t
202 val fromLambda: Lambda.t * Type.t -> t
203 val handlee: {catch: Var.t * Type.t,
204 handler: t,
205 try: t,
206 ty: Type.t} -> t
207 val iff: {test: t, thenn: t, elsee: t, ty: Type.t} -> t
208 val lambda: {arg: Var.t,
209 argType: Type.t,
210 body: t,
211 bodyType: Type.t,
212 mayInline: bool} -> t
213 val let1: {var: Var.t, exp: t, body: t} -> t
214 val lett: {decs: Dec.t list, body: t} -> t
215 val monoVar: Var.t * Type.t -> t
216 val primApp: {args: t vector,
217 prim: Type.t Prim.t,
218 targs: Type.t vector,
219 ty: Type.t} -> t
220 val raisee: {exn: t, extend: bool, ty: Type.t} -> t
221 val reff: t -> t
222 val select: {tuple: t, offset: int, ty: Type.t} -> t
223 val seq: t vector * (t vector -> t) -> t
224 val sequence: t vector -> t
225 val string: string -> t
226 val toExp: t -> Exp.t
227 val truee: unit -> t
228 val tuple: {exps: t vector, ty: Type.t} -> t
229 val unit: unit -> t
230 val vall: {var: Var.t, exp: t} -> Dec.t list
231 val var: {targs: Type.t vector,
232 ty: Type.t,
233 var: Var.t} -> t
234 val varExp: VarExp.t * Type.t -> t
235 val vectorLength: t -> t
236 end
237
238 structure Program:
239 sig
240 datatype t =
241 T of {body: Exp.t,
242 datatypes: {cons: {arg: Type.t option,
243 con: Con.t} vector,
244 tycon: Tycon.t,
245 tyvars: Tyvar.t vector} vector,
246 (* overflow is SOME only after exceptions have been
247 * implemented.
248 *)
249 overflow: Var.t option}
250
251 val clear: t -> unit (* clear all property lists *)
252 val layout: t -> Layout.t
253 val layouts: t * (Layout.t -> unit) -> unit
254 val layoutStats: t -> Layout.t
255 end
256 end