Test example program.
[wrappi.git] / generator-lib / wrappi_types.mli
index 6bd58f0..04283d5 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-type any_type =
-  | TFilePerm
-  | TInt32
-  | TInt64
-  | TPathname
-  | TUInt32
-  | TUInt64
-(** Any API parameter or return type. *)
-
-type parameter = string * any_type
-(** API parameter (argument name and type). *)
-
-type return_type = RErr | Return of any_type
-(** API return type.  A superset of {!any_type} because we allow the
-    special value [RErr] for dealing with errno. *)
+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 | Return of ptype
+(** API return type.  A superset of {!ptype} because we allow the
+    special value [RVoid] for functions that don't return any value. *)
+
+type ftype = rtype * parameter list * parameter list
+(** A function type.  Return type, list of required parameters, list
+    of optional parameters. *)
 
 type c_code = string
 (** C code. *)
 
 type entry_point = {
   ep_loc : Camlp4.PreCast.Loc.t;
+  ep_local : bool;
   ep_name : string;
-  ep_params : parameter list;
-  ep_return : return_type;
+  ep_ftype : ftype;
   ep_code : c_code option;
 }
 (** 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_identifiers : string array;
+  sd_fields : ptype array;
+}
+(** A struct declaration. *)
+
+type union = {
+  un_loc : Camlp4.PreCast.Loc.t;
+  un_name : string;
+  un_identifiers : string array;
+  un_fields : ptype array;
+}
+(** A qualified union declaration. *)
+
 type api = {
-  api_entry_points : entry_point list;
+  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. *)
+(** 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_any_type : any_type -> string
-val string_of_return_type : return_type -> string
+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. *)