Debian Codegraph @

lib/dAst.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open CAst
12
13 type ('a, _) thunk =
14 | Value : 'a -> ('a, 'b) thunk
15 | Thunk : 'a Lazy.t -> ('a, [ `thunk ]) thunk
16
17 type ('a, 'b) t = ('a, 'b) thunk CAst.t
18
19 let map_thunk (type s) f : (_, s) thunk -> (_, s) thunk = function
20 | Value x -> Value (f x)
21 | Thunk k -> Thunk (lazy (f (Lazy.force k)))
22
23 let get_thunk (type s) : ('a, s) thunk -> 'a = function
24 | Value x -> x
25 | Thunk k -> Lazy.force k
26
27 let get x = get_thunk x.v
28
29 let make ?loc v = CAst.make ?loc (Value v)
30
31 let delay ?loc v = CAst.make ?loc (Thunk (Lazy.from_fun v))
32
33 let force x = CAst.make ?loc:x.CAst.loc (Value (get_thunk x.v))
34
35 let map f n = CAst.map (fun x -> map_thunk f x) n
36
37 let map_with_loc f n =
38 CAst.map_with_loc (fun ?loc x -> map_thunk (fun x -> f ?loc x) x) n
39
40 let map_from_loc f (loc, x) =
41 make ?loc (f ?loc x)
42
43 let with_val f n = f (get n)
44
45 let with_loc_val f n = f ?loc:n.CAst.loc (get n)