-
Notifications
You must be signed in to change notification settings - Fork 39
/
ser_names.ml
284 lines (204 loc) · 7.18 KB
/
ser_names.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
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)
(* <O___,, * (see CREDITS file for the list of authors) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
(************************************************************************)
(* Coq serialization API/Plugin *)
(* Copyright 2016-2018 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)
(* Written by: Emilio J. Gallego Arias *)
(************************************************************************)
(* Status: Very Experimental *)
(************************************************************************)
open Sexplib.Std
open Ppx_hash_lib.Std.Hash.Builtin
open Ppx_compare_lib.Builtin
open Names
module Int = Ser_int
module CAst = Ser_cAst
(************************************************************************)
(* Serialization of Names.mli *)
(************************************************************************)
module Id = struct
(* Id.t: private *)
module Id_ = struct
type t = Names.Id.t
type _t = Id of string [@@deriving sexp, yojson, hash, compare]
let of_t id = Id (Id.to_string id)
let to_t (Id id) = Id.of_string_soft id
end
module Self = SerType.Biject(Id_)
include Self
module Set = Ser_cSet.Make(Names.Id.Set)(Self)
module Map = Ser_cMap.Make(Names.Id.Map)(Self)
end
module Name = struct
(* Name.t: public *)
type t =
[%import: Names.Name.t]
[@@deriving sexp,yojson,hash,compare]
end
module DirPath = struct
(* DirPath.t: private *)
module DirPath_ = struct
type t = Names.DirPath.t
type _t = DirPath of Id.t list
[@@deriving sexp,yojson,hash,compare]
let of_t dp = DirPath (DirPath.repr dp)
let to_t (DirPath dpl) = DirPath.make dpl
end
include SerType.Biject(DirPath_)
end
module DPmap = Ser_cMap.Make(DPmap)(DirPath)
module Label = struct
(* Label.t: private *)
module Label_= struct
type t = [%import: Names.Label.t]
(* XXX: This will miss the tag *)
type _t = Id.t
[@@deriving sexp,yojson,hash,compare]
let to_t = Label.of_id
let of_t = Label.to_id
end
include SerType.Biject(Label_)
end
module MBId = struct
(* MBId.t: private *)
module MBIdBij = struct
type t = [%import: Names.MBId.t]
type _t = Mbid of int * Id.t * DirPath.t
[@@deriving sexp,yojson,hash,compare]
end
include SerType.Pierce(MBIdBij)
end
module ModPath = struct
(* ModPath.t: public *)
type t = [%import: Names.ModPath.t]
[@@deriving sexp,yojson,hash,compare]
end
module MPmap = Ser_cMap.Make(MPmap)(ModPath)
(* KerName: private *)
module KerName = struct
type t = [%import: Names.KerName.t]
type _t = KerName of ModPath.t * Label.t
[@@deriving sexp,yojson,hash,compare]
let _t_put kn =
let mp, l = KerName.repr kn in KerName (mp,l)
let _kername_get (KerName (mp,l)) = KerName.make mp l
let t_of_sexp sexp = _kername_get (_t_of_sexp sexp)
let sexp_of_t kn = sexp_of__t (_t_put kn)
let of_yojson json = Ppx_deriving_yojson_runtime.(_t_of_yojson json >|= _kername_get)
let to_yojson kn = _t_to_yojson (_t_put kn)
let hash x = hash__t (_t_put x)
let hash_fold_t st id = hash_fold__t st (_t_put id)
let compare x y = compare__t (_t_put x) (_t_put y)
let equal = KerName.equal
end
module KNmap = Ser_cMap.Make(Names.KNmap)(KerName)
module Constant = struct
(* Constant.t: private *)
type t = [%import: Names.Constant.t]
type _t = Constant of KerName.t * KerName.t option
[@@deriving sexp,yojson,hash,compare]
let _t_put cs =
let cu, cc = Constant.(user cs, canonical cs) in
if KerName.equal cu cc then Constant (cu, None) else Constant (cu, Some cc)
let _t_get = function
| Constant (cu, None) -> Constant.make1 cu
| Constant (cu, Some cc) -> Constant.make cu cc
let t_of_sexp sexp = _t_get (_t_of_sexp sexp)
let sexp_of_t dp = sexp_of__t (_t_put dp)
let of_yojson json = Ppx_deriving_yojson_runtime.(_t_of_yojson json >|= _t_get)
let to_yojson level = _t_to_yojson (_t_put level)
let hash x = hash__t (_t_put x)
let hash_fold_t st id = hash_fold__t st (_t_put id)
let compare x y = compare__t (_t_put x) (_t_put y)
end
module Cset_env = Ser_cSet.Make(Cset_env)(Constant)
module Cmap = Ser_cMap.Make(Cmap)(Constant)
module Cmap_env = Ser_cMap.Make(Cmap_env)(Constant)
module MutInd = struct
(* MutInd.t: private *)
module BijectSpec = struct
type t = [%import: Names.MutInd.t]
type _t = MutInd of KerName.t * KerName.t option
[@@deriving sexp,yojson,hash,compare]
let of_t cs =
let cu, cc = MutInd.(user cs, canonical cs) in
if KerName.equal cu cc then MutInd (cu, None) else MutInd (cu, Some cc)
let to_t = function
| MutInd (cu, None) -> MutInd.make1 cu
| MutInd (cu, Some cc) -> MutInd.make cu cc
end
include SerType.Biject(BijectSpec)
end
module Mindmap = Ser_cMap.Make(Mindmap)(MutInd)
module Mindmap_env = Ser_cMap.Make(Mindmap_env)(MutInd)
type 'a tableKey =
[%import: 'a Names.tableKey]
[@@deriving sexp]
type variable =
[%import: Names.variable]
[@@deriving sexp,yojson,hash,compare]
(* Inductive and constructor = public *)
module Ind = struct
type t =
[%import: Names.Ind.t]
[@@deriving sexp,yojson,hash,compare]
end
module Indset_env = Ser_cSet.Make(Indset_env)(Ind)
module Indmap_env = Ser_cMap.Make(Indmap_env)(Ind)
type inductive =
[%import: Names.inductive]
[@@deriving sexp,yojson,hash,compare]
module Construct = struct
type t =
[%import: Names.Construct.t]
[@@deriving sexp,yojson,hash,compare]
end
type constructor =
[%import: Names.constructor]
[@@deriving sexp,yojson,hash,compare]
(* Projection: private *)
module Projection = struct
module Repr = struct
module PierceSpec = struct
type t = Names.Projection.Repr.t
type _t =
{ proj_ind : inductive
; proj_relevant : bool
; proj_npars : int
; proj_arg : int
; proj_name : Label.t
} [@@deriving sexp,yojson,hash,compare]
end
include SerType.Pierce(PierceSpec)
end
module PierceSpec = struct
type t = [%import: Names.Projection.t]
type _t = Repr.t * bool
[@@deriving sexp,yojson,hash,compare]
end
include SerType.Pierce(PierceSpec)
end
module GlobRef = struct
type t = [%import: Names.GlobRef.t]
[@@deriving sexp,yojson,hash,compare]
end
(* Evaluable global reference: public *)
(* type evaluable_global_reference =
* [%import: Names.evaluable_global_reference]
* [@@deriving sexp] *)
type lident =
[%import: Names.lident]
[@@deriving sexp,yojson,hash,compare]
type lname =
[%import: Names.lname]
[@@deriving sexp,yojson,hash,compare]
type lstring =
[%import: Names.lstring]
[@@deriving sexp,yojson,hash,compare]