Release coccinelle-0.1.11rc1
[bpt/coccinelle.git] / commons / sexp_common.ml
1 (* automatically generated by ocamltarzan *)
2
3 open Common
4
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 let hashset_of_sexp__ =
127 let _loc = "Xxx.hashset"
128 in fun _of_a -> Conv.hashtbl_of_sexp _of_a Conv.bool_of_sexp
129
130 let hashset_of_sexp _of_a sexp =
131 try hashset_of_sexp__ _of_a sexp
132 with
133 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
134
135 let sexp_of_hashset _of_a = Conv.sexp_of_hashtbl _of_a Conv.sexp_of_bool
136
137 let stack_of_sexp__ =
138 let _loc = "Xxx.stack" in fun _of_a -> Conv.list_of_sexp _of_a
139
140 let stack_of_sexp _of_a sexp =
141 try stack_of_sexp__ _of_a sexp
142 with
143 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
144
145 let sexp_of_stack _of_a = Conv.sexp_of_list _of_a
146
147 let parse_info_of_sexp__ =
148 let _loc = "Xxx.parse_info"
149 in
150 function
151 | (Sexp.List field_sexps as sexp) ->
152 let str_field = ref None and charpos_field = ref None
153 and line_field = ref None and column_field = ref None
154 and file_field = ref None and duplicates = ref []
155 and extra = ref [] in
156 let rec iter =
157 (function
158 | Sexp.List ([ Sexp.Atom field_name; field_sexp ]) :: tail ->
159 ((match field_name with
160 | "str" ->
161 (match !str_field with
162 | None ->
163 let fvalue = Conv.string_of_sexp field_sexp
164 in str_field := Some fvalue
165 | Some _ -> duplicates := field_name :: !duplicates)
166 | "charpos" ->
167 (match !charpos_field with
168 | None ->
169 let fvalue = Conv.int_of_sexp field_sexp
170 in charpos_field := Some fvalue
171 | Some _ -> duplicates := field_name :: !duplicates)
172 | "line" ->
173 (match !line_field with
174 | None ->
175 let fvalue = Conv.int_of_sexp field_sexp
176 in line_field := Some fvalue
177 | Some _ -> duplicates := field_name :: !duplicates)
178 | "column" ->
179 (match !column_field with
180 | None ->
181 let fvalue = Conv.int_of_sexp field_sexp
182 in column_field := Some fvalue
183 | Some _ -> duplicates := field_name :: !duplicates)
184 | "file" ->
185 (match !file_field with
186 | None ->
187 let fvalue = filename_of_sexp field_sexp
188 in file_field := Some fvalue
189 | Some _ -> duplicates := field_name :: !duplicates)
190 | _ ->
191 if !Conv.record_check_extra_fields
192 then extra := field_name :: !extra
193 else ());
194 iter tail)
195 | sexp :: _ -> Conv_error.record_only_pairs_expected _loc sexp
196 | [] -> ())
197 in
198 (iter field_sexps;
199 if !duplicates <> []
200 then Conv_error.record_duplicate_fields _loc !duplicates sexp
201 else
202 if !extra <> []
203 then Conv_error.record_extra_fields _loc !extra sexp
204 else
205 (match ((!str_field), (!charpos_field), (!line_field),
206 (!column_field), (!file_field))
207 with
208 | (Some str_value, Some charpos_value, Some line_value,
209 Some column_value, Some file_value) ->
210 {
211 str = str_value;
212 charpos = charpos_value;
213 line = line_value;
214 column = column_value;
215 file = file_value;
216 }
217 | _ ->
218 Conv_error.record_undefined_elements _loc sexp
219 [ ((!str_field = None), "str");
220 ((!charpos_field = None), "charpos");
221 ((!line_field = None), "line");
222 ((!column_field = None), "column");
223 ((!file_field = None), "file") ]))
224 | (Sexp.Atom _ as sexp) -> Conv_error.record_list_instead_atom _loc sexp
225
226 let parse_info_of_sexp sexp = parse_info_of_sexp__ sexp
227
228 let sexp_of_parse_info {
229 str = v_str;
230 charpos = v_charpos;
231 line = v_line;
232 column = v_column;
233 file = v_file
234 } =
235 let bnds = [] in
236 let arg = sexp_of_filename v_file in
237 let bnd = Sexp.List [ Sexp.Atom "file"; arg ] in
238 let bnds = bnd :: bnds in
239 let arg = Conv.sexp_of_int v_column in
240 let bnd = Sexp.List [ Sexp.Atom "column"; arg ] in
241 let bnds = bnd :: bnds in
242 let arg = Conv.sexp_of_int v_line in
243 let bnd = Sexp.List [ Sexp.Atom "line"; arg ] in
244 let bnds = bnd :: bnds in
245 let arg = Conv.sexp_of_int v_charpos in
246 let bnd = Sexp.List [ Sexp.Atom "charpos"; arg ] in
247 let bnds = bnd :: bnds in
248 let arg = Conv.sexp_of_string v_str in
249 let bnd = Sexp.List [ Sexp.Atom "str"; arg ] in
250 let bnds = bnd :: bnds in Sexp.List bnds
251
252
253
254 let score_result_of_sexp__ =
255 let _loc = "Xxx.score_result"
256 in
257 function
258 | Sexp.Atom ("ok" | "Ok") -> Ok
259 | (Sexp.List (Sexp.Atom (("pb" | "Pb" as tag)) :: sexp_args) as sexp) ->
260 (match sexp_args with
261 | [ v1 ] -> let v1 = Conv.string_of_sexp v1 in Pb v1
262 | _ -> Conv_error.stag_incorrect_n_args _loc tag sexp)
263 | (Sexp.List (Sexp.Atom ("ok" | "Ok") :: _) as sexp) ->
264 Conv_error.stag_no_args _loc sexp
265 | (Sexp.Atom ("pb" | "Pb") as sexp) ->
266 Conv_error.stag_takes_args _loc sexp
267 | (Sexp.List (Sexp.List _ :: _) as sexp) ->
268 Conv_error.nested_list_invalid_sum _loc sexp
269 | (Sexp.List [] as sexp) -> Conv_error.empty_list_invalid_sum _loc sexp
270 | sexp -> Conv_error.unexpected_stag _loc sexp
271
272 let score_result_of_sexp sexp = score_result_of_sexp__ sexp
273
274 let sexp_of_score_result =
275 function
276 | Ok -> Sexp.Atom "Ok"
277 | Pb v1 ->
278 let v1 = Conv.sexp_of_string v1 in Sexp.List [ Sexp.Atom "Pb"; v1 ]
279
280 let score_of_sexp__ =
281 let _loc = "Xxx.score"
282 in
283 fun sexp ->
284 Conv.hashtbl_of_sexp Conv.string_of_sexp score_result_of_sexp sexp
285
286 let score_of_sexp sexp =
287 try score_of_sexp__ sexp
288 with
289 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
290
291 let sexp_of_score v =
292 Conv.sexp_of_hashtbl Conv.sexp_of_string sexp_of_score_result v
293
294
295 let score_list_of_sexp__ =
296 let _loc = "Xxx.score_list"
297 in
298 fun sexp ->
299 Conv.list_of_sexp
300 (function
301 | Sexp.List ([ v1; v2 ]) ->
302 let v1 = Conv.string_of_sexp v1
303 and v2 = score_result_of_sexp v2
304 in (v1, v2)
305 | sexp -> Conv_error.tuple_of_size_n_expected _loc 2 sexp)
306 sexp
307
308 let score_list_of_sexp sexp =
309 try score_list_of_sexp__ sexp
310 with
311 | Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
312
313 let sexp_of_score_list v =
314 Conv.sexp_of_list
315 (fun (v1, v2) ->
316 let v1 = Conv.sexp_of_string v1
317 and v2 = sexp_of_score_result v2
318 in Sexp.List [ v1; v2 ])
319 v