forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_record_map.ml
304 lines (274 loc) · 9.58 KB
/
js_record_map.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
(* Copyright (C) 2015- Hongbo Zhang, Authors of ReScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
open J
let[@inline] unknown _ x = x
let[@inline] option sub self v =
match v with None -> None | Some v -> Some (sub self v)
let rec list sub self x =
match x with
| [] -> []
| x :: xs ->
let v = sub self x in
v :: list sub self xs
type iter = {
ident : ident fn;
module_id : module_id fn;
vident : vident fn;
exception_ident : exception_ident fn;
for_ident : for_ident fn;
expression : expression fn;
statement : statement fn;
variable_declaration : variable_declaration fn;
block : block fn;
program : program fn;
}
and 'a fn = iter -> 'a -> 'a
let label : label fn = unknown
let ident : ident fn = unknown
let module_id : module_id fn =
fun _self { id = _x0; kind = _x1 } ->
let _x0 = _self.ident _self _x0 in
{ id = _x0; kind = _x1 }
let required_modules : required_modules fn =
fun _self arg -> list _self.module_id _self arg
let vident : vident fn =
fun _self -> function
| Id _x0 ->
let _x0 = _self.ident _self _x0 in
Id _x0
| Qualified (_x0, _x1) ->
let _x0 = _self.module_id _self _x0 in
Qualified (_x0, _x1)
let exception_ident : exception_ident fn =
fun _self arg -> _self.ident _self arg
let for_ident : for_ident fn = fun _self arg -> _self.ident _self arg
let for_direction : for_direction fn = unknown
let property_map : property_map fn =
fun _self arg ->
list
(fun _self (_x0, _x1) ->
let _x1 = _self.expression _self _x1 in
(_x0, _x1))
_self arg
let length_object : length_object fn = unknown
let expression_desc : expression_desc fn =
fun _self -> function
| Length (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = length_object _self _x1 in
Length (_x0, _x1)
| Is_null_or_undefined _x0 ->
let _x0 = _self.expression _self _x0 in
Is_null_or_undefined _x0
| String_append (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
String_append (_x0, _x1)
| Bool _ as v -> v
| Typeof _x0 ->
let _x0 = _self.expression _self _x0 in
Typeof _x0
| Js_not _x0 ->
let _x0 = _self.expression _self _x0 in
Js_not _x0
| Seq (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
Seq (_x0, _x1)
| Cond (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
let _x2 = _self.expression _self _x2 in
Cond (_x0, _x1, _x2)
| Bin (_x0, _x1, _x2) ->
let _x1 = _self.expression _self _x1 in
let _x2 = _self.expression _self _x2 in
Bin (_x0, _x1, _x2)
| FlatCall (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
FlatCall (_x0, _x1)
| Call (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
let _x1 = list _self.expression _self _x1 in
Call (_x0, _x1, _x2)
| String_index (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
String_index (_x0, _x1)
| Array_index (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.expression _self _x1 in
Array_index (_x0, _x1)
| Static_index (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
Static_index (_x0, _x1, _x2)
| New (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
let _x1 =
option (fun _self arg -> list _self.expression _self arg) _self _x1
in
New (_x0, _x1)
| Var _x0 ->
let _x0 = _self.vident _self _x0 in
Var _x0
| Fun (_x0, _x1, _x2, _x3, _x4) ->
let _x1 = list _self.ident _self _x1 in
let _x2 = _self.block _self _x2 in
Fun (_x0, _x1, _x2, _x3, _x4)
| Str _ as v -> v
| Unicode _ as v -> v
| Raw_js_code _ as v -> v
| Array (_x0, _x1) ->
let _x0 = list _self.expression _self _x0 in
Array (_x0, _x1)
| Optional_block (_x0, _x1) ->
let _x0 = _self.expression _self _x0 in
Optional_block (_x0, _x1)
| Caml_block (_x0, _x1, _x2, _x3) ->
let _x0 = list _self.expression _self _x0 in
let _x2 = _self.expression _self _x2 in
Caml_block (_x0, _x1, _x2, _x3)
| Caml_block_tag _x0 ->
let _x0 = _self.expression _self _x0 in
Caml_block_tag _x0
| Number _ as v -> v
| Object _x0 ->
let _x0 = property_map _self _x0 in
Object _x0
| Undefined as v -> v
| Null as v -> v
let for_ident_expression : for_ident_expression fn =
fun _self arg -> _self.expression _self arg
let finish_ident_expression : finish_ident_expression fn =
fun _self arg -> _self.expression _self arg
let case_clause : case_clause fn =
fun _self { switch_body = _x0; should_break = _x1; comment = _x2 } ->
let _x0 = _self.block _self _x0 in
{ switch_body = _x0; should_break = _x1; comment = _x2 }
let string_clause : string_clause fn =
fun _self (_x0, _x1) ->
let _x1 = case_clause _self _x1 in
(_x0, _x1)
let int_clause : int_clause fn =
fun _self (_x0, _x1) ->
let _x1 = case_clause _self _x1 in
(_x0, _x1)
let statement_desc : statement_desc fn =
fun _self -> function
| Block _x0 ->
let _x0 = _self.block _self _x0 in
Block _x0
| Variable _x0 ->
let _x0 = _self.variable_declaration _self _x0 in
Variable _x0
| Exp _x0 ->
let _x0 = _self.expression _self _x0 in
Exp _x0
| If (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
let _x1 = _self.block _self _x1 in
let _x2 = _self.block _self _x2 in
If (_x0, _x1, _x2)
| While (_x0, _x1, _x2, _x3) ->
let _x0 = option label _self _x0 in
let _x1 = _self.expression _self _x1 in
let _x2 = _self.block _self _x2 in
While (_x0, _x1, _x2, _x3)
| ForRange (_x0, _x1, _x2, _x3, _x4, _x5) ->
let _x0 = option for_ident_expression _self _x0 in
let _x1 = finish_ident_expression _self _x1 in
let _x2 = _self.for_ident _self _x2 in
let _x3 = for_direction _self _x3 in
let _x4 = _self.block _self _x4 in
ForRange (_x0, _x1, _x2, _x3, _x4, _x5)
| Continue _x0 ->
let _x0 = label _self _x0 in
Continue _x0
| Break as v -> v
| Return _x0 ->
let _x0 = _self.expression _self _x0 in
Return _x0
| Int_switch (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
let _x1 = list int_clause _self _x1 in
let _x2 = option _self.block _self _x2 in
Int_switch (_x0, _x1, _x2)
| String_switch (_x0, _x1, _x2) ->
let _x0 = _self.expression _self _x0 in
let _x1 = list string_clause _self _x1 in
let _x2 = option _self.block _self _x2 in
String_switch (_x0, _x1, _x2)
| Throw _x0 ->
let _x0 = _self.expression _self _x0 in
Throw _x0
| Try (_x0, _x1, _x2) ->
let _x0 = _self.block _self _x0 in
let _x1 =
option
(fun _self (_x0, _x1) ->
let _x0 = _self.exception_ident _self _x0 in
let _x1 = _self.block _self _x1 in
(_x0, _x1))
_self _x1
in
let _x2 = option _self.block _self _x2 in
Try (_x0, _x1, _x2)
| Debugger as v -> v
let expression : expression fn =
fun _self { expression_desc = _x0; comment = _x1 } ->
let _x0 = expression_desc _self _x0 in
{ expression_desc = _x0; comment = _x1 }
let statement : statement fn =
fun _self { statement_desc = _x0; comment = _x1 } ->
let _x0 = statement_desc _self _x0 in
{ statement_desc = _x0; comment = _x1 }
let variable_declaration : variable_declaration fn =
fun _self { ident = _x0; value = _x1; property = _x2; ident_info = _x3 } ->
let _x0 = _self.ident _self _x0 in
let _x1 = option _self.expression _self _x1 in
{ ident = _x0; value = _x1; property = _x2; ident_info = _x3 }
let block : block fn = fun _self arg -> list _self.statement _self arg
let program : program fn =
fun _self { block = _x0; exports = _x1; export_set = _x2 } ->
let _x0 = _self.block _self _x0 in
{ block = _x0; exports = _x1; export_set = _x2 }
let deps_program : deps_program fn =
fun _self { program = _x0; modules = _x1; side_effect = _x2 } ->
let _x0 = _self.program _self _x0 in
let _x1 = required_modules _self _x1 in
{ program = _x0; modules = _x1; side_effect = _x2 }
let super : iter =
{
ident;
module_id;
vident;
exception_ident;
for_ident;
expression;
statement;
variable_declaration;
block;
program;
}