From: Richard W.M. Jones Date: Fri, 30 Dec 2011 11:58:41 +0000 (+0000) Subject: Explicit types in the generator. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;ds=sidebyside;h=68483fce4f959886866af28c1c3342c2a6fcb410;p=wrappi.git Explicit types in the generator. --- diff --git a/APIs/mknod.api b/APIs/mknod.api index ceedd78..bc0ba02 100644 --- a/APIs/mknod.api +++ b/APIs/mknod.api @@ -1,5 +1,5 @@ entry_point -err mknod_char (pathname path, fileperm perm, int64 major, int64 minor) +err mknod_char (pathname path, fileperm perm, uint64 major, uint64 minor) << return mknod (path, S_IFCHR | perm, makedev (major, minor)); >> diff --git a/generator-lib/wrappi_types.ml b/generator-lib/wrappi_types.ml index 8dfa31b..957d479 100644 --- a/generator-lib/wrappi_types.ml +++ b/generator-lib/wrappi_types.ml @@ -20,7 +20,13 @@ open Camlp4.PreCast open Printf -type any_type = TInt32 | TInt64 | Type of string +type any_type = + | TFilePerm + | TInt32 + | TInt64 + | TPathname + | TUInt32 + | TUInt64 type parameter = string * any_type @@ -41,9 +47,12 @@ type api = { } let string_of_any_type = function + | TFilePerm -> "fileperm" | TInt32 -> "int32" | TInt64 -> "int64" - | Type s -> s + | TPathname -> "pathname" + | TUInt32 -> "uint32" + | TUInt64 -> "uint64" let string_of_return_type = function | RErr -> "err" | Return t -> string_of_any_type t diff --git a/generator-lib/wrappi_types.mli b/generator-lib/wrappi_types.mli index f4b4f66..6bd58f0 100644 --- a/generator-lib/wrappi_types.mli +++ b/generator-lib/wrappi_types.mli @@ -16,7 +16,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) -type any_type = TInt32 | TInt64 | Type of string +type any_type = + | TFilePerm + | TInt32 + | TInt64 + | TPathname + | TUInt32 + | TUInt64 (** Any API parameter or return type. *) type parameter = string * any_type diff --git a/generator-lib/wrappi_utils.ml b/generator-lib/wrappi_utils.ml index 89cc662..4474423 100644 --- a/generator-lib/wrappi_utils.ml +++ b/generator-lib/wrappi_utils.ml @@ -20,6 +20,13 @@ open Printf let failwithf fs = ksprintf failwith fs +let isspace c = + c = ' ' + (* || c = '\f' *) || c = '\n' || c = '\r' || c = '\t' (* || c = '\v' *) + +let isalnum c = + (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') + let files_equal n1 n2 = let cmd = sprintf "cmp -s %s %s" (Filename.quote n1) (Filename.quote n2) in match Sys.command cmd with diff --git a/generator-lib/wrappi_utils.mli b/generator-lib/wrappi_utils.mli index 613394f..c08b402 100644 --- a/generator-lib/wrappi_utils.mli +++ b/generator-lib/wrappi_utils.mli @@ -19,6 +19,12 @@ val failwithf : ('a, unit, string, 'b) format4 -> 'a (** Like [failwith] but supports printf-like arguments. *) +val isspace : char -> bool +(** Return true if char is a whitespace character. *) + +val isalnum : char -> bool +(** Return true if char is an alphanumeric character. *) + val files_equal : string -> string -> bool (** [files_equal filename1 filename2] returns true if the files contain the same content. *) diff --git a/generator-macros/pa_wrap.ml b/generator-macros/pa_wrap.ml index adfd799..a73484a 100644 --- a/generator-macros/pa_wrap.ml +++ b/generator-macros/pa_wrap.ml @@ -90,9 +90,12 @@ EXTEND Gram (* A parameter or return type. *) any_type: [ - [ "int32" -> <:expr< Wrappi_types.TInt32 >> ] + [ "fileperm" -> <:expr< Wrappi_types.TFilePerm >> ] + | [ "int32" -> <:expr< Wrappi_types.TInt32 >> ] | [ "int64" -> <:expr< Wrappi_types.TInt64 >> ] - | [ t = LIDENT -> <:expr< Wrappi_types.Type $str:t$ >> ] + | [ "pathname" -> <:expr< Wrappi_types.TPathname >> ] + | [ "uint32" -> <:expr< Wrappi_types.TUInt32 >> ] + | [ "uint64" -> <:expr< Wrappi_types.TUInt64 >> ] ]; (* A return type. *) diff --git a/generator/Makefile.am b/generator/Makefile.am index 31d1b10..1379f1a 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -47,7 +47,7 @@ generator: $(OBJECTS) ../generator-lib/generator_lib.cma ../APIs/apis.cma $(OBJECTS) \ -o $@ -%.cmi: %.mli +%.cmi: %.mli ../generator-lib/generator_lib.cma $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@ %.cmo: %.ml $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@ diff --git a/generator/wrappi_c.ml b/generator/wrappi_c.ml index f6e9afc..62fb48d 100644 --- a/generator/wrappi_c.ml +++ b/generator/wrappi_c.ml @@ -16,13 +16,34 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) +open Wrappi_types +open Wrappi_utils open Wrappi_pr open Wrappi_boilerplate +open Printf + +let c_of_any_type = function + | TFilePerm -> "int" + | TInt32 -> "int32_t" + | TInt64 -> "int64_t" + | TPathname -> "const char *" + | TUInt32 -> "uint32_t" + | TUInt64 -> "uint64_t" + +let c_of_return_type = function + | RErr -> "int" + | Return t -> c_of_any_type t + let generate_lib_wrappi_h api = generate_header CStyle LGPLv2plus; pr "\ +/* Please read the wrappi(1) man page for full documentation. If you + * are not familiar with man pages or don't have the documentation + * installed, it is also available online at http://wrappi.org/ + */ + #ifndef WRAPPI_H_ #define WRAPPI_H_ @@ -30,10 +51,32 @@ let generate_lib_wrappi_h api = extern \"C\" { #endif -"; +#include + +/* The handle. */ +typedef struct wrap_h wrap_h; +/* Connection management. */ +extern wrap_h *wrap_create (void); +extern void wrap_close (wrap_h *w); +/* API entry points. */ +"; + List.iter ( + fun ep -> + pr "extern %s wrap_%s (wrap_h *w, %s);\n" + (c_of_return_type ep.ep_return) + ep.ep_name + (String.concat ", " + (List.map ( + fun (name, t) -> + let t = c_of_any_type t in + let last_char = t.[String.length t - 1] in + let sep = if isalnum last_char then " " else "" in + sprintf "%s%s%s" t sep name + ) ep.ep_params)) + ) api.api_entry_points; pr "\