Explicit types in the generator.
[wrappi.git] / generator-macros / pa_wrap.ml
index 54e3676..a73484a 100644 (file)
@@ -39,6 +39,18 @@ let expr_of_option _loc = function
   | None -> <:expr< None >>
   | Some x -> <:expr< Some $x$ >>
 
+(* Convert a _loc to an AST. *)
+let expr_of_loc _loc loc =
+  let file_name,
+    start_line, start_bol, start_off,
+    stop_line, stop_bol, stop_off,
+    ghost = Loc.to_tuple loc in
+  <:expr< Camlp4.PreCast.Loc.of_tuple
+    ($str:file_name$,
+     $`int:start_line$, $`int:start_bol$, $`int:start_off$,
+     $`int:stop_line$, $`int:stop_bol$, $`int:stop_off$,
+     $`bool:ghost$) >>
+
 let add_entry_point _loc name parameters return_type code =
   let parameters = List.map (
     fun (name, t) -> <:expr< ($str:name$, $t$) >>
@@ -47,8 +59,11 @@ let add_entry_point _loc name parameters return_type code =
 
   let code = expr_of_option _loc code in
 
+  let loc = expr_of_loc _loc _loc in
+
   <:str_item<
-    let ep = { Wrappi_types.ep_name = $str:name$;
+    let ep = { Wrappi_types.ep_loc = $loc$;
+               ep_name = $str:name$;
                ep_params = $parameters$;
                ep_return = $return_type$;
                ep_code = $code$ } in
@@ -75,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. *)