Combine generator subdirectories into one.
[wrappi.git] / generator / 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 | RStaticString | Return of ptype
45 (** API return type.  A superset of {!ptype} because we allow the
46     some special return-only types. *)
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 = {
53   cc_loc : Camlp4.PreCast.Loc.t;
54   cc_code : string;
55 }
56 (** C code. *)
57
58 type entry_point = {
59   ep_loc : Camlp4.PreCast.Loc.t;
60   ep_local : bool;
61   ep_name : string;
62   ep_ftype : ftype;
63   ep_code : c_code option;
64   ep_includes : string list;
65 }
66 (** An API entry point. *)
67
68 type typedef = {
69   td_loc : Camlp4.PreCast.Loc.t;
70   td_name : string;
71   td_type : ptype;
72 }
73 (** A typedef. *)
74
75 type enum = {
76   en_loc : Camlp4.PreCast.Loc.t;
77   en_name : string;
78   en_identifiers : string array;
79 }
80 (** An enum. *)
81
82 type struct_decl = {
83   sd_loc : Camlp4.PreCast.Loc.t;
84   sd_name : string;
85   sd_fields : (string * ptype) array;
86 }
87 (** A struct declaration. *)
88
89 type union = {
90   un_loc : Camlp4.PreCast.Loc.t;
91   un_name : string;
92   un_fields : (string * ptype) array;
93 }
94 (** A qualified union declaration. *)
95
96 type api = {
97   api_typedefs : typedef Wrappi_utils.StringMap.t;
98   api_enums : enum Wrappi_utils.StringMap.t;
99   api_structs : struct_decl Wrappi_utils.StringMap.t;
100   api_unions : union Wrappi_utils.StringMap.t;
101   api_entry_points : entry_point Wrappi_utils.StringMap.t;
102 }
103 (** This single structure describes the whole API.  Each map is from
104     name of thing -> thing. *)
105
106 val iter_typedefs : api -> (typedef -> unit) -> unit
107 val iter_enums : api -> (enum -> unit) -> unit
108 val iter_structs : api -> (struct_decl -> unit) -> unit
109 val iter_unions : api -> (union -> unit) -> unit
110 val iter_entry_points : api -> (entry_point -> unit) -> unit
111 (** For convenience, iteration always presents the objects in name order. *)
112
113 val string_of_ptype : ptype -> string
114 val string_of_rtype : rtype -> string
115 val string_of_parameter : parameter -> string
116 val string_of_parameters : parameter list -> string
117 val string_of_ftype : ftype -> string
118 val string_of_c_code : c_code -> string
119 val string_of_typedef : typedef -> string
120 val string_of_enum : enum -> string
121 val string_of_struct : struct_decl -> string
122 val string_of_union : union -> string
123 val string_of_entry_point : entry_point -> string
124 (** Convert structures to strings for printing, debugging etc. *)