Generator main program.
[wrappi.git] / generator-lib / wrappi_types.ml
index 3f3ca58..7c3dfde 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
+open Camlp4.PreCast
+
+open Printf
+
 type any_type = TInt32 | TInt64 | Type of string
 
+type parameter = string * any_type
+
 type return_type = RErr | Return of any_type
+
+type c_code = string
+
+type entry_point = {
+  (*ep_loc : Camlp4.PreCast.Loc.t;*)
+  ep_name : string;
+  ep_params : parameter list;
+  ep_return : return_type;
+  ep_code : c_code option;
+}
+
+let string_of_any_type = function
+  | TInt32 -> "int32"
+  | TInt64 -> "int64"
+  | Type s -> s
+let string_of_return_type = function
+  | RErr -> "err"
+  | Return t -> string_of_any_type t
+let string_of_parameter (name, t) =
+  sprintf "%s %s" (string_of_any_type t) name
+let string_of_parameters params =
+  "(" ^ String.concat ", " (List.map string_of_parameter params) ^ ")"
+let string_of_c_code code = code
+let string_of_entry_point ep =
+  sprintf "entry_point %s %s %s <<%s>>"
+    (*(Loc.to_string ep.ep_loc)*)
+    (string_of_return_type ep.ep_return)
+    ep.ep_name
+    (string_of_parameters ep.ep_params)
+    (match ep.ep_code with
+    | None -> "/* implicit */"
+    | Some code -> string_of_c_code code)