7c3dfdedbe603dd41e73ab05eda4303c31cc96d1
[wrappi.git] / generator-lib / wrappi_types.ml
1 (* wrappi
2  * Copyright (C) 2011 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *)
18
19 open Camlp4.PreCast
20
21 open Printf
22
23 type any_type = TInt32 | TInt64 | Type of string
24
25 type parameter = string * any_type
26
27 type return_type = RErr | Return of any_type
28
29 type c_code = string
30
31 type entry_point = {
32   (*ep_loc : Camlp4.PreCast.Loc.t;*)
33   ep_name : string;
34   ep_params : parameter list;
35   ep_return : return_type;
36   ep_code : c_code option;
37 }
38
39 let string_of_any_type = function
40   | TInt32 -> "int32"
41   | TInt64 -> "int64"
42   | Type s -> s
43 let string_of_return_type = function
44   | RErr -> "err"
45   | Return t -> string_of_any_type t
46 let string_of_parameter (name, t) =
47   sprintf "%s %s" (string_of_any_type t) name
48 let string_of_parameters params =
49   "(" ^ String.concat ", " (List.map string_of_parameter params) ^ ")"
50 let string_of_c_code code = code
51 let string_of_entry_point ep =
52   sprintf "entry_point %s %s %s <<%s>>"
53     (*(Loc.to_string ep.ep_loc)*)
54     (string_of_return_type ep.ep_return)
55     ep.ep_name
56     (string_of_parameters ep.ep_params)
57     (match ep.ep_code with
58     | None -> "/* implicit */"
59     | Some code -> string_of_c_code code)