coccinelle release 0.2.5
[bpt/coccinelle.git] / commons / sexp_common.ml
1 (* automatically generated by ocamltarzan *)
2
3 open Sexplib
4 open Common
5 let either_of_sexp__ =
6 let _loc = "Xxx.either"
7 in
8 fun _of_a _of_b ->
9 function
10 | (Sexp.List (Sexp.Atom (("left" | "Left" as tag)) :: sexp_args) as
11 sexp) ->
12 (match sexp_args with
13 | [ v1 ] -> let v1 = _of_a v1 in Left v1
14 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
15 | (Sexp.List (Sexp.Atom (("right" | "Right" as tag)) :: sexp_args) as
16 sexp) ->
17 (match sexp_args with
18 | [ v1 ] -> let v1 = _of_b v1 in Right v1
19 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
20 | (Sexp.Atom ("left" | "Left") as sexp) ->
21 Conv_error.stag_takes_args _loc sexp
22 | (Sexp.Atom ("right" | "Right") as sexp) ->
23 Conv_error.stag_takes_args _loc sexp
24 | (Sexp.List (Sexp.List _ :: _) as sexp) ->
25 Conv_error.nested_list_invalid_sum _loc sexp
26 | (Sexp.List [] as sexp) -> Conv_error.empty_list_invalid_sum _loc sexp
27 | sexp -> Conv_error.unexpected_stag _loc sexp
28
29 let either_of_sexp _of_a _of_b sexp = either_of_sexp__ _of_a _of_b sexp
30
31 let sexp_of_either _of_a _of_b =
32 function
33 | Left v1 -> let v1 = _of_a v1 in Sexp.List [ Sexp.Atom "Left"; v1 ]
34 | Right v1 -> let v1 = _of_b v1 in Sexp.List [ Sexp.Atom "Right"; v1 ]
35
36 let either3_of_sexp__ =
37 let _loc = "Xxx.either3"
38 in
39 fun _of_a _of_b _of_c ->
40 function
41 | (Sexp.List (Sexp.Atom (("left3" | "Left3" as tag)) :: sexp_args) as
42 sexp) ->
43 (match sexp_args with
44 | [ v1 ] -> let v1 = _of_a v1 in Left3 v1
45 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
46 | (Sexp.List (Sexp.Atom (("middle3" | "Middle3" as tag)) :: sexp_args)
47 as sexp) ->
48 (match sexp_args with
49 | [ v1 ] -> let v1 = _of_b v1 in Middle3 v1
50 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
51 | (Sexp.List (Sexp.Atom (("right3" | "Right3" as tag)) :: sexp_args) as
52 sexp) ->
53 (match sexp_args with
54 | [ v1 ] -> let v1 = _of_c v1 in Right3 v1
55 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
56 | (Sexp.Atom ("left3" | "Left3") as sexp) ->
57 Conv_error.stag_takes_args _loc sexp
58 | (Sexp.Atom ("middle3" | "Middle3") as sexp) ->
59 Conv_error.stag_takes_args _loc sexp
60 | (Sexp.Atom ("right3" | "Right3") as sexp) ->
61 Conv_error.stag_takes_args _loc sexp
62 | (Sexp.List (Sexp.List _ :: _) as sexp) ->
63 Conv_error.nested_list_invalid_sum _loc sexp
64 | (Sexp.List [] as sexp) -> Conv_error.empty_list_invalid_sum _loc sexp
65 | sexp -> Conv_error.unexpected_stag _loc sexp
66
67 let either3_of_sexp _of_a _of_b _of_c sexp =
68 either3_of_sexp__ _of_a _of_b _of_c sexp
69
70 let sexp_of_either3 _of_a _of_b _of_c =
71 function
72 | Left3 v1 -> let v1 = _of_a v1 in Sexp.List [ Sexp.Atom "Left3"; v1 ]
73 | Middle3 v1 -> let v1 = _of_b v1 in Sexp.List [ Sexp.Atom "Middle3"; v1 ]
74 | Right3 v1 -> let v1 = _of_c v1 in Sexp.List [ Sexp.Atom "Right3"; v1 ]
75
76 let filename_of_sexp__ =
77 let _loc = "Xxx.filename" in fun sexp -> Conv.string_of_sexp sexp
78
79 let filename_of_sexp sexp =
80 try filename_of_sexp__ sexp
81 with
82 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
83
84 let sexp_of_filename v = Conv.sexp_of_string v
85
86 let dirname_of_sexp__ =
87 let _loc = "Xxx.dirname" in fun sexp -> Conv.string_of_sexp sexp
88
89 let dirname_of_sexp sexp =
90 try dirname_of_sexp__ sexp
91 with
92 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
93
94 let sexp_of_dirname v = Conv.sexp_of_string v
95
96 let set_of_sexp__ =
97 let _loc = "Xxx.set" in fun _of_a -> Conv.list_of_sexp _of_a
98
99 let set_of_sexp _of_a sexp =
100 try set_of_sexp__ _of_a sexp
101 with
102 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
103
104 let sexp_of_set _of_a = Conv.sexp_of_list _of_a
105
106 let assoc_of_sexp__ =
107 let _loc = "Xxx.assoc"
108 in
109 fun _of_a _of_b ->
110 Conv.list_of_sexp
111 (function
112 | Sexp.List ([ v1; v2 ]) ->
113 let v1 = _of_a v1 and v2 = _of_b v2 in (v1, v2)
114 | sexp -> Conv_error.tuple_of_size_n_expected _loc 2 sexp)
115
116 let assoc_of_sexp _of_a _of_b sexp =
117 try assoc_of_sexp__ _of_a _of_b sexp
118 with
119 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
120
121 let sexp_of_assoc _of_a _of_b =
122 Conv.sexp_of_list
123 (fun (v1, v2) ->
124 let v1 = _of_a v1 and v2 = _of_b v2 in Sexp.List [ v1; v2 ])
125
126 (*
127 let hashset_of_sexp__ =
128 let _loc = "Xxx.hashset"
129 in fun _of_a -> Conv.hashtbl_of_sexp _of_a Conv.bool_of_sexp
130
131 let hashset_of_sexp _of_a sexp =
132 try hashset_of_sexp__ _of_a sexp
133 with
134 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
135
136 let sexp_of_hashset _of_a = Conv.sexp_of_hashtbl _of_a Conv.sexp_of_bool
137 *)
138
139 let stack_of_sexp__ =
140 let _loc = "Xxx.stack" in fun _of_a -> Conv.list_of_sexp _of_a
141
142 let stack_of_sexp _of_a sexp =
143 try stack_of_sexp__ _of_a sexp
144 with
145 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
146
147 let sexp_of_stack _of_a = Conv.sexp_of_list _of_a
148
149 let parse_info_of_sexp__ =
150 let _loc = "Xxx.parse_info"
151 in
152 function
153 | (Sexp.List field_sexps as sexp) ->
154 let str_field = ref None and charpos_field = ref None
155 and line_field = ref None and column_field = ref None
156 and file_field = ref None and duplicates = ref []
157 and extra = ref [] in
158 let rec iter =
159 (function
160 | Sexp.List ([ Sexp.Atom field_name; field_sexp ]) :: tail ->
161 ((match field_name with
162 | "str" ->
163 (match !str_field with
164 | None ->
165 let fvalue = Conv.string_of_sexp field_sexp
166 in str_field := Some fvalue
167 | Some _ -> duplicates := field_name :: !duplicates)
168 | "charpos" ->
169 (match !charpos_field with
170 | None ->
171 let fvalue = Conv.int_of_sexp field_sexp
172 in charpos_field := Some fvalue
173 | Some _ -> duplicates := field_name :: !duplicates)
174 | "line" ->
175 (match !line_field with
176 | None ->
177 let fvalue = Conv.int_of_sexp field_sexp
178 in line_field := Some fvalue
179 | Some _ -> duplicates := field_name :: !duplicates)
180 | "column" ->
181 (match !column_field with
182 | None ->
183 let fvalue = Conv.int_of_sexp field_sexp
184 in column_field := Some fvalue
185 | Some _ -> duplicates := field_name :: !duplicates)
186 | "file" ->
187 (match !file_field with
188 | None ->
189 let fvalue = filename_of_sexp field_sexp
190 in file_field := Some fvalue
191 | Some _ -> duplicates := field_name :: !duplicates)
192 | _ ->
193 if !Conv.record_check_extra_fields
194 then extra := field_name :: !extra
195 else ());
196 iter tail)
197 | sexp :: _ -> Conv_error.record_only_pairs_expected _loc sexp
198 | [] -> ())
199 in
200 (iter field_sexps;
201 if !duplicates <> []
202 then Conv_error.record_duplicate_fields _loc !duplicates sexp
203 else
204 if !extra <> []
205 then Conv_error.record_extra_fields _loc !extra sexp
206 else
207 (match ((!str_field), (!charpos_field), (!line_field),
208 (!column_field), (!file_field))
209 with
210 | (Some str_value, Some charpos_value, Some line_value,
211 Some column_value, Some file_value) ->
212 {
213 str = str_value;
214 charpos = charpos_value;
215 line = line_value;
216 column = column_value;
217 file = file_value;
218 }
219 | _ ->
220 Conv_error.record_undefined_elements _loc sexp
221 [ ((!str_field = None), "str");
222 ((!charpos_field = None), "charpos");
223 ((!line_field = None), "line");
224 ((!column_field = None), "column");
225 ((!file_field = None), "file") ]))
226 | (Sexp.Atom _ as sexp) -> Conv_error.record_list_instead_atom _loc sexp
227
228 let parse_info_of_sexp sexp = parse_info_of_sexp__ sexp
229
230 let sexp_of_parse_info {
231 str = v_str;
232 charpos = v_charpos;
233 line = v_line;
234 column = v_column;
235 file = v_file
236 } =
237 let bnds = [] in
238 let arg = sexp_of_filename v_file in
239 let bnd = Sexp.List [ Sexp.Atom "file"; arg ] in
240 let bnds = bnd :: bnds in
241 let arg = Conv.sexp_of_int v_column in
242 let bnd = Sexp.List [ Sexp.Atom "column"; arg ] in
243 let bnds = bnd :: bnds in
244 let arg = Conv.sexp_of_int v_line in
245 let bnd = Sexp.List [ Sexp.Atom "line"; arg ] in
246 let bnds = bnd :: bnds in
247 let arg = Conv.sexp_of_int v_charpos in
248 let bnd = Sexp.List [ Sexp.Atom "charpos"; arg ] in
249 let bnds = bnd :: bnds in
250 let arg = Conv.sexp_of_string v_str in
251 let bnd = Sexp.List [ Sexp.Atom "str"; arg ] in
252 let bnds = bnd :: bnds in Sexp.List bnds
253
254
255
256 let score_result_of_sexp__ =
257 let _loc = "Xxx.score_result"
258 in
259 function
260 | Sexp.Atom ("ok" | "Ok") -> Ok
261 | (Sexp.List (Sexp.Atom (("pb" | "Pb" as tag)) :: sexp_args) as sexp) ->
262 (match sexp_args with
263 | [ v1 ] -> let v1 = Conv.string_of_sexp v1 in Pb v1
264 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
265 | (Sexp.List (Sexp.Atom ("ok" | "Ok") :: _) as sexp) ->
266 Conv_error.stag_no_args _loc sexp
267 | (Sexp.Atom ("pb" | "Pb") as sexp) ->
268 Conv_error.stag_takes_args _loc sexp
269 | (Sexp.List (Sexp.List _ :: _) as sexp) ->
270 Conv_error.nested_list_invalid_sum _loc sexp
271 | (Sexp.List [] as sexp) -> Conv_error.empty_list_invalid_sum _loc sexp
272 | sexp -> Conv_error.unexpected_stag _loc sexp
273
274 let score_result_of_sexp sexp = score_result_of_sexp__ sexp
275
276 let sexp_of_score_result =
277 function
278 | Ok -> Sexp.Atom "Ok"
279 | Pb v1 ->
280 let v1 = Conv.sexp_of_string v1 in Sexp.List [ Sexp.Atom "Pb"; v1 ]
281
282 let score_of_sexp__ =
283 let _loc = "Xxx.score"
284 in
285 fun sexp ->
286 Conv.hashtbl_of_sexp Conv.string_of_sexp score_result_of_sexp sexp
287
288 let score_of_sexp sexp =
289 try score_of_sexp__ sexp
290 with
291 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
292
293 let sexp_of_score v =
294 Conv.sexp_of_hashtbl Conv.sexp_of_string sexp_of_score_result v
295
296
297 let score_list_of_sexp__ =
298 let _loc = "Xxx.score_list"
299 in
300 fun sexp ->
301 Conv.list_of_sexp
302 (function
303 | Sexp.List ([ v1; v2 ]) ->
304 let v1 = Conv.string_of_sexp v1
305 and v2 = score_result_of_sexp v2
306 in (v1, v2)
307 | sexp -> Conv_error.tuple_of_size_n_expected _loc 2 sexp)
308 sexp
309
310 let score_list_of_sexp sexp =
311 try score_list_of_sexp__ sexp
312 with
313 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
314
315 let sexp_of_score_list v =
316 Conv.sexp_of_list
317 (fun (v1, v2) ->
318 let v1 = Conv.sexp_of_string v1
319 and v2 = sexp_of_score_result v2
320 in Sexp.List [ v1; v2 ])
321 v