[Pkg-ocaml-maint-commits] [atdgen] 07/16: Imported Upstream version 1.7.0

Stéphane Glondu glondu at moszumanska.debian.org
Thu Jan 28 10:29:23 UTC 2016


This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository atdgen.

commit f856aea1e2d42559b57e8baa724c1fa65d58dc98
Author: Stephane Glondu <steph at glondu.net>
Date:   Thu Jan 28 09:51:51 2016 +0100

    Imported Upstream version 1.7.0
---
 .merlin                       |  4 ++--
 Makefile                      |  3 +++
 src/Makefile                  |  2 +-
 src/ag_main.ml                |  9 +++++++++
 src/ag_ob_emit.ml             |  3 ++-
 src/ag_ocaml.ml               | 31 ++++++++++++++++---------------
 src/ag_oj_emit.ml             |  3 ++-
 src/ag_ov_emit.ml             |  3 ++-
 test/.gitignore               |  3 +++
 test/Makefile                 | 15 +++++++++++++++
 test/test_atdgen_type_conv.ml | 19 +++++++++++++++++++
 test/test_type_conv.atd       | 13 +++++++++++++
 12 files changed, 87 insertions(+), 21 deletions(-)

diff --git a/.merlin b/.merlin
index e03a487..0611ebb 100644
--- a/.merlin
+++ b/.merlin
@@ -1,4 +1,4 @@
 PKG yojson atd
 
-B .
-S .
+B ./**
+S ./**
diff --git a/Makefile b/Makefile
index 868a035..c9d5c19 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,9 @@ reinstall:
 test:
 	$(MAKE) -C test
 
+test-all:
+	$(MAKE) -C test test-all
+
 clean:
 	rm -f *~ util/*~ example/*~
 	$(MAKE) -C src clean
diff --git a/src/Makefile b/src/Makefile
index 0b064dd..4181c64 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
-VERSION = 1.6.1
+VERSION = 1.7.0
 ifeq "$(shell ocamlc -config |grep os_type)" "os_type: Win32"
 EXE=.exe
 else
diff --git a/src/ag_main.ml b/src/ag_main.ml
index 133688e..5080bdd 100644
--- a/src/ag_main.ml
+++ b/src/ag_main.ml
@@ -78,7 +78,15 @@ let main () =
     let l = Str.split (Str.regexp " *, *\\| +") s in
     opens := List.rev_append l !opens
   in
+  let type_convs = ref [] in
   let options = [
+    "-type-conv", Arg.String (fun s ->
+      type_convs := Str.split (Str.regexp ",") s),
+    "
+    GEN1,GEN2,...
+         Insert 'with GEN1, GEN2, ...' after OCaml type definitions for the
+         type-conv preprocessor
+    ";
     "-t", Arg.Unit (fun () ->
                       set_once "output type" mode `T;
                       set_once "no function definitions" with_fundefs false),
@@ -406,6 +414,7 @@ Recommended usage: %s (-t|-b|-j|-v|-dep|-list) example.atd" Sys.argv.(0) in
         let with_default default = function None -> default | Some x -> x in
 
         make_ocaml_files
+          ~type_convs: !type_convs
           ~opens
           ~with_typedefs: (with_default true !with_typedefs)
           ~with_create
diff --git a/src/ag_ob_emit.ml b/src/ag_ob_emit.ml
index d07feaf..449d08d 100644
--- a/src/ag_ob_emit.ml
+++ b/src/ag_ob_emit.ml
@@ -1479,6 +1479,7 @@ let make_ocaml_files
     ~type_aliases
     ~force_defaults
     ~name_overlap
+    ~type_convs
     atd_file out =
   let ((head, m0), _) =
     match atd_file with
@@ -1511,7 +1512,7 @@ let make_ocaml_files
      m1 = original type definitions after dependency analysis
      m2 = monomorphic type definitions after dependency analysis *)
   let ocaml_typedefs =
-    Ag_ocaml.ocaml_of_atd ~target:`Biniou ~type_aliases (head, m1) in
+    Ag_ocaml.ocaml_of_atd ~type_convs ~target:`Biniou ~type_aliases (head, m1) in
   let defs = translate_mapping m2 in
   let header =
     let src =
diff --git a/src/ag_ocaml.ml b/src/ag_ocaml.ml
index 41ba52b..f0003a4 100644
--- a/src/ag_ocaml.ml
+++ b/src/ag_ocaml.ml
@@ -1,3 +1,4 @@
+
 (*
   Translation from ATD types into OCaml types and pretty-printing.
 
@@ -596,7 +597,13 @@ let append_ocamldoc_comment x doc =
         let comment = make_ocamldoc_comment y in
         Label ((x, label), comment)
 
-let rec format_module_item
+let format_type_conv_node node = function
+  | [] -> node
+  | converters ->
+    let converters = "with " ^ (String.concat ", " converters) in
+    Label ((node, label), make_atom converters)
+
+let rec format_module_item type_convs
     is_first (`Type def : ocaml_module_item) =
   let type_ = if is_first then "type" else "and" in
   let s, param = def.o_def_name in
@@ -639,7 +646,7 @@ let rec format_module_item
             format_type_expr t
           )
   in
-  prepend_ocamldoc_comment doc part123
+  format_type_conv_node (prepend_ocamldoc_comment doc part123) type_convs
 
 
 and prepend_type_param l tl =
@@ -737,21 +744,15 @@ and format_variant kind (s, o, doc) =
   in
   append_ocamldoc_comment variant doc
 
-let format_module_items is_rec (l : ocaml_module_body) =
+let format_module_items type_convs is_rec (l : ocaml_module_body) =
   match l with
       x :: l ->
-        format_module_item true x ::
-          List.map (fun x -> format_module_item false x) l
+        format_module_item type_convs true x ::
+          List.map (fun x -> format_module_item type_convs false x) l
     | [] -> []
 
-let format_module_body is_rec (l : ocaml_module_body) =
-  List (
-    ("", "", "", rlist),
-    format_module_items is_rec l
-  )
-
-let format_module_bodies (l : (bool * ocaml_module_body) list) =
-  List.flatten (List.map (fun (is_rec, x) -> format_module_items is_rec x) l)
+let format_module_bodies type_conv (l : (bool * ocaml_module_body) list) =
+  List.flatten (List.map (fun (is_rec, x) -> format_module_items type_conv is_rec x) l)
 
 let format_head (loc, an) =
   match Ag_doc.get_doc loc an with
@@ -765,14 +766,14 @@ let format_all l =
 let ocaml_of_expr x : string =
   Easy_format.Pretty.to_string (format_type_expr x)
 
-let ocaml_of_atd ~target ~type_aliases
+let ocaml_of_atd ?(type_convs=[]) ~target ~type_aliases
     (head, (l : (bool * module_body) list)) : string =
   let head = format_head head in
   let bodies =
     List.map (fun (is_rec, m) ->
                 (is_rec, map_module ~target ~type_aliases m)) l
   in
-  let body = format_module_bodies bodies in
+  let body = format_module_bodies type_convs bodies in
   let x = format_all (head @ body) in
   Easy_format.Pretty.to_string x
 
diff --git a/src/ag_oj_emit.ml b/src/ag_oj_emit.ml
index b63a322..c84088a 100644
--- a/src/ag_oj_emit.ml
+++ b/src/ag_oj_emit.ml
@@ -1722,6 +1722,7 @@ let make_ocaml_files
     ~force_defaults
     ~preprocess_input
     ~name_overlap
+    ~type_convs
     atd_file out =
   let ((head, m0), _) =
     match atd_file with
@@ -1753,7 +1754,7 @@ let make_ocaml_files
      m1 = original type definitions after dependency analysis
      m2 = monomorphic type definitions after dependency analysis *)
   let ocaml_typedefs =
-    Ag_ocaml.ocaml_of_atd ~target:`Json ~type_aliases (head, m1) in
+    Ag_ocaml.ocaml_of_atd ~type_convs ~target:`Json ~type_aliases (head, m1) in
   let defs = translate_mapping m2 in
   let header =
     let src =
diff --git a/src/ag_ov_emit.ml b/src/ag_ov_emit.ml
index d884130..0066774 100644
--- a/src/ag_ov_emit.ml
+++ b/src/ag_ov_emit.ml
@@ -472,6 +472,7 @@ let make_ocaml_files
     ~type_aliases
     ~force_defaults
     ~name_overlap
+    ~type_convs
     atd_file out =
   let ((head, m0), _) =
     match atd_file with
@@ -504,7 +505,7 @@ let make_ocaml_files
      m1 = original type definitions after dependency analysis
      m2 = monomorphic type definitions after dependency analysis *)
   let ocaml_typedefs =
-    Ag_ocaml.ocaml_of_atd ~target:`Validate ~type_aliases (head, m1) in
+    Ag_ocaml.ocaml_of_atd ~type_convs ~target:`Validate ~type_aliases (head, m1) in
   let defs = translate_mapping m2 in
   let header =
     let src =
diff --git a/test/.gitignore b/test/.gitignore
index 9485e7d..b589b56 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -31,3 +31,6 @@ testjstd.ml
 testjstd.mli
 testv.ml
 testv.mli
+test3j_*.ml*
+test_type_conv_*.ml*
+test_atdgen_type_conv
diff --git a/test/Makefile b/test/Makefile
index 7b3809b..1520d82 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -30,6 +30,7 @@ really-test:
 	$(ATDGEN) -o-name-overlap -t test5.atd
 	$(ATDGEN) -o-name-overlap -j test5.atd
 	$(ATDGEN) -o-name-overlap -b test5.atd
+	$(ATDGEN) -t test_type_conv.atd -type-conv sexp -open "Sexplib.Std"
 	ocamlfind ocamlc -c -package atdgen \
 		test5_t.mli test5_t.ml test5_j.mli test5_j.ml
 	ocamlfind ocamlc -c -package atdgen \
@@ -64,6 +65,20 @@ really-test:
 		test3j_t.mli test4.mli test4j.mli testv.mli
 	./test_atdgen
 
+.PHONY: test-all
+test-all: really-test
+	ocamlfind ocamlc -c -g -syntax camlp4o -package camlp4 \
+	  -package sexplib -package sexplib.syntax \
+	  test_type_conv_t.mli
+	ocamlfind ocamlopt -c -g -syntax camlp4o -package camlp4 \
+	  -package sexplib -package sexplib.syntax \
+	  test_type_conv_t.ml
+	ocamlfind ocamlopt -c -g test_atdgen_type_conv.ml -package atdgen -package sexplib
+	ocamlfind ocamlopt -o test_atdgen_type_conv$(EXE) -g -linkpkg \
+	  -syntax camlp4o -package camlp4 \
+	  -package sexplib -package sexplib.syntax \
+	  test_type_conv_t.cmx test_atdgen_type_conv.cmx
+	./test_atdgen_type_conv
 
 # Benchmarking and more testing
 
diff --git a/test/test_atdgen_type_conv.ml b/test/test_atdgen_type_conv.ml
new file mode 100644
index 0000000..6b5b2fd
--- /dev/null
+++ b/test/test_atdgen_type_conv.ml
@@ -0,0 +1,19 @@
+open Sexplib.Std
+
+let my_record = Test_type_conv_t.({ fst=123; snd="testing" })
+
+let cmrs : (float Test_type_conv_t.contains_my_record) list =
+  let open Test_type_conv_t in
+  [ `C1 123
+  ; `C2 123.0
+  ; `C3 my_record ]
+
+let sexps =
+  [my_record |> Test_type_conv_t.sexp_of_my_record] @
+  (List.map (Test_type_conv_t.sexp_of_contains_my_record sexp_of_float) cmrs)
+
+let () =
+  sexps
+  |> sexp_of_list (fun x -> x)
+  |> Sexplib.Sexp.to_string
+  |> print_endline
diff --git a/test/test_type_conv.atd b/test/test_type_conv.atd
new file mode 100644
index 0000000..bde8b49
--- /dev/null
+++ b/test/test_type_conv.atd
@@ -0,0 +1,13 @@
+<doc text="testing -type-conv.">
+
+type my_record = {
+  fst: int;
+  snd: string;
+}
+
+
+type 'a contains_my_record = [
+  | C1 of int
+  | C2 of 'a
+  | C3 of my_record
+]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/atdgen.git



More information about the Pkg-ocaml-maint-commits mailing list