Explicit types in the generator.
[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 =
24   | TFilePerm
25   | TInt32
26   | TInt64
27   | TPathname
28   | TUInt32
29   | TUInt64
30
31 type parameter = string * any_type
32
33 type return_type = RErr | Return of any_type
34
35 type c_code = string
36
37 type entry_point = {
38   ep_loc : Camlp4.PreCast.Loc.t;
39   ep_name : string;
40   ep_params : parameter list;
41   ep_return : return_type;
42   ep_code : c_code option;
43 }
44
45 type api = {
46   api_entry_points : entry_point list;
47 }
48
49 let string_of_any_type = function
50   | TFilePerm -> "fileperm"
51   | TInt32 -> "int32"
52   | TInt64 -> "int64"
53   | TPathname -> "pathname"
54   | TUInt32 -> "uint32"
55   | TUInt64 -> "uint64"
56 let string_of_return_type = function
57   | RErr -> "err"
58   | Return t -> string_of_any_type t
59 let string_of_parameter (name, t) =
60   sprintf "%s %s" (string_of_any_type t) name
61 let string_of_parameters params =
62   "(" ^ String.concat ", " (List.map string_of_parameter params) ^ ")"
63 let string_of_c_code code = code
64 let string_of_entry_point ep =
65   sprintf "entry_point %s %s %s <<%s>>"
66     (*(Loc.to_string ep.ep_loc)*)
67     (string_of_return_type ep.ep_return)
68     ep.ep_name
69     (string_of_parameters ep.ep_params)
70     (match ep.ep_code with
71     | None -> "/* implicit */"
72     | Some code -> string_of_c_code code)