8dfa31b6ad02ad35d8399719766a096b68b44504
[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 type api = {
40   api_entry_points : entry_point list;
41 }
42
43 let string_of_any_type = function
44   | TInt32 -> "int32"
45   | TInt64 -> "int64"
46   | Type s -> s
47 let string_of_return_type = function
48   | RErr -> "err"
49   | Return t -> string_of_any_type t
50 let string_of_parameter (name, t) =
51   sprintf "%s %s" (string_of_any_type t) name
52 let string_of_parameters params =
53   "(" ^ String.concat ", " (List.map string_of_parameter params) ^ ")"
54 let string_of_c_code code = code
55 let string_of_entry_point ep =
56   sprintf "entry_point %s %s %s <<%s>>"
57     (*(Loc.to_string ep.ep_loc)*)
58     (string_of_return_type ep.ep_return)
59     ep.ep_name
60     (string_of_parameters ep.ep_params)
61     (match ep.ep_code with
62     | None -> "/* implicit */"
63     | Some code -> string_of_c_code code)