Test example program.
[wrappi.git] / generator-lib / wrappi_types.mli
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 type ptype =
20   | TBool                               (** Boolean *)
21   | TBuffer                             (** 8 bit buffer of limited length *)
22   | TEnum of string                     (** Enumerated type *)
23   | TFile                               (** arbitrary length file in/out *)
24   | THash of ptype                      (** Hash of string -> ptype *)
25   | TInt                                (** Integer: MUST have preconditions *)
26   | TInt32                              (** Signed 32 bit integer *)
27   | TInt64                              (** Signed 64 bit integer *)
28   | TList of ptype                      (** List/array of values *)
29   | TNullable of ptype                  (** NULLable type modifier *)
30   | TString                             (** String (non-null) *)
31   | TStruct of string                   (** Struct *)
32   | TTypedef of string                  (** Typedef (before being resolved) *)
33   | TUInt32                             (** Unsigned 32 bit integer *)
34   | TUInt64                             (** Unsigned 64 bit integer *)
35   | TUnion of string                    (** Qualified union *)
36 (** API parameter type. *)
37
38 type prec
39 (** Parameter precondition (XXX not implemented yet). *)
40
41 type parameter = string * ptype * prec option
42 (** API parameter (argument name, type, optional precondition). *)
43
44 type rtype = RVoid | Return of ptype
45 (** API return type.  A superset of {!ptype} because we allow the
46     special value [RVoid] for functions that don't return any value. *)
47
48 type ftype = rtype * parameter list * parameter list
49 (** A function type.  Return type, list of required parameters, list
50     of optional parameters. *)
51
52 type c_code = string
53 (** C code. *)
54
55 type entry_point = {
56   ep_loc : Camlp4.PreCast.Loc.t;
57   ep_local : bool;
58   ep_name : string;
59   ep_ftype : ftype;
60   ep_code : c_code option;
61 }
62 (** An API entry point. *)
63
64 type typedef = {
65   td_loc : Camlp4.PreCast.Loc.t;
66   td_name : string;
67   td_type : ptype;
68 }
69 (** A typedef. *)
70
71 type enum = {
72   en_loc : Camlp4.PreCast.Loc.t;
73   en_name : string;
74   en_identifiers : string array;
75 }
76 (** An enum. *)
77
78 type struct_decl = {
79   sd_loc : Camlp4.PreCast.Loc.t;
80   sd_name : string;
81   sd_identifiers : string array;
82   sd_fields : ptype array;
83 }
84 (** A struct declaration. *)
85
86 type union = {
87   un_loc : Camlp4.PreCast.Loc.t;
88   un_name : string;
89   un_identifiers : string array;
90   un_fields : ptype array;
91 }
92 (** A qualified union declaration. *)
93
94 type api = {
95   api_typedefs : typedef Wrappi_utils.StringMap.t;
96   api_enums : enum Wrappi_utils.StringMap.t;
97   api_structs : struct_decl Wrappi_utils.StringMap.t;
98   api_unions : union Wrappi_utils.StringMap.t;
99   api_entry_points : entry_point Wrappi_utils.StringMap.t;
100 }
101 (** This single structure describes the whole API.  Each map is from
102     name of thing -> thing. *)
103
104 val iter_typedefs : api -> (typedef -> unit) -> unit
105 val iter_enums : api -> (enum -> unit) -> unit
106 val iter_structs : api -> (struct_decl -> unit) -> unit
107 val iter_unions : api -> (union -> unit) -> unit
108 val iter_entry_points : api -> (entry_point -> unit) -> unit
109 (** For convenience, iteration always presents the objects in name order. *)
110
111 val string_of_ptype : ptype -> string
112 val string_of_rtype : rtype -> string
113 val string_of_parameter : parameter -> string
114 val string_of_parameters : parameter list -> string
115 val string_of_ftype : ftype -> string
116 val string_of_c_code : c_code -> string
117 val string_of_typedef : typedef -> string
118 val string_of_enum : enum -> string
119 val string_of_struct : struct_decl -> string
120 val string_of_union : union -> string
121 val string_of_entry_point : entry_point -> string
122 (** Convert structures to strings for printing, debugging etc. *)