Explicit types in the generator.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 30 Dec 2011 11:58:41 +0000 (11:58 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 30 Dec 2011 11:58:41 +0000 (11:58 +0000)
APIs/mknod.api
generator-lib/wrappi_types.ml
generator-lib/wrappi_types.mli
generator-lib/wrappi_utils.ml
generator-lib/wrappi_utils.mli
generator-macros/pa_wrap.ml
generator/Makefile.am
generator/wrappi_c.ml

index ceedd78..bc0ba02 100644 (file)
@@ -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));
 >>
index 8dfa31b..957d479 100644 (file)
@@ -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
index f4b4f66..6bd58f0 100644 (file)
  * 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
index 89cc662..4474423 100644 (file)
@@ -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
index 613394f..c08b402 100644 (file)
 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. *)
index adfd799..a73484a 100644 (file)
@@ -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. *)
index 31d1b10..1379f1a 100644 (file)
@@ -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 $@
index f6e9afc..62fb48d 100644 (file)
  * 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 <stdint.h>
+
+/* 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 "\