Combine generator subdirectories into one.
[wrappi.git] / generator / wrappi_types.mli
diff --git a/generator/wrappi_types.mli b/generator/wrappi_types.mli
new file mode 100644 (file)
index 0000000..fd276c4
--- /dev/null
@@ -0,0 +1,124 @@
+(* wrappi
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+type ptype =
+  | TBool                               (** Boolean *)
+  | TBuffer                             (** 8 bit buffer of limited length *)
+  | TEnum of string                     (** Enumerated type *)
+  | TFile                               (** arbitrary length file in/out *)
+  | THash of ptype                      (** Hash of string -> ptype *)
+  | TInt                                (** Integer: MUST have preconditions *)
+  | TInt32                              (** Signed 32 bit integer *)
+  | TInt64                              (** Signed 64 bit integer *)
+  | TList of ptype                      (** List/array of values *)
+  | TNullable of ptype                  (** NULLable type modifier *)
+  | TString                             (** String (non-null) *)
+  | TStruct of string                   (** Struct *)
+  | TTypedef of string                  (** Typedef (before being resolved) *)
+  | TUInt32                             (** Unsigned 32 bit integer *)
+  | TUInt64                             (** Unsigned 64 bit integer *)
+  | TUnion of string                    (** Qualified union *)
+(** API parameter type. *)
+
+type prec
+(** Parameter precondition (XXX not implemented yet). *)
+
+type parameter = string * ptype * prec option
+(** API parameter (argument name, type, optional precondition). *)
+
+type rtype = RVoid | RStaticString | Return of ptype
+(** API return type.  A superset of {!ptype} because we allow the
+    some special return-only types. *)
+
+type ftype = rtype * parameter list * parameter list
+(** A function type.  Return type, list of required parameters, list
+    of optional parameters. *)
+
+type c_code = {
+  cc_loc : Camlp4.PreCast.Loc.t;
+  cc_code : string;
+}
+(** C code. *)
+
+type entry_point = {
+  ep_loc : Camlp4.PreCast.Loc.t;
+  ep_local : bool;
+  ep_name : string;
+  ep_ftype : ftype;
+  ep_code : c_code option;
+  ep_includes : string list;
+}
+(** An API entry point. *)
+
+type typedef = {
+  td_loc : Camlp4.PreCast.Loc.t;
+  td_name : string;
+  td_type : ptype;
+}
+(** A typedef. *)
+
+type enum = {
+  en_loc : Camlp4.PreCast.Loc.t;
+  en_name : string;
+  en_identifiers : string array;
+}
+(** An enum. *)
+
+type struct_decl = {
+  sd_loc : Camlp4.PreCast.Loc.t;
+  sd_name : string;
+  sd_fields : (string * ptype) array;
+}
+(** A struct declaration. *)
+
+type union = {
+  un_loc : Camlp4.PreCast.Loc.t;
+  un_name : string;
+  un_fields : (string * ptype) array;
+}
+(** A qualified union declaration. *)
+
+type api = {
+  api_typedefs : typedef Wrappi_utils.StringMap.t;
+  api_enums : enum Wrappi_utils.StringMap.t;
+  api_structs : struct_decl Wrappi_utils.StringMap.t;
+  api_unions : union Wrappi_utils.StringMap.t;
+  api_entry_points : entry_point Wrappi_utils.StringMap.t;
+}
+(** This single structure describes the whole API.  Each map is from
+    name of thing -> thing. *)
+
+val iter_typedefs : api -> (typedef -> unit) -> unit
+val iter_enums : api -> (enum -> unit) -> unit
+val iter_structs : api -> (struct_decl -> unit) -> unit
+val iter_unions : api -> (union -> unit) -> unit
+val iter_entry_points : api -> (entry_point -> unit) -> unit
+(** For convenience, iteration always presents the objects in name order. *)
+
+val string_of_ptype : ptype -> string
+val string_of_rtype : rtype -> string
+val string_of_parameter : parameter -> string
+val string_of_parameters : parameter list -> string
+val string_of_ftype : ftype -> string
+val string_of_c_code : c_code -> string
+val string_of_typedef : typedef -> string
+val string_of_enum : enum -> string
+val string_of_struct : struct_decl -> string
+val string_of_union : union -> string
+val string_of_entry_point : entry_point -> string
+(** Convert structures to strings for printing, debugging etc. *)