Skip to content

Commit db33a21

Browse files
committed
Preprocess for OxCaml with ocaml-config:ox
1 parent 93a93c2 commit db33a21

File tree

11 files changed

+98
-34
lines changed

11 files changed

+98
-34
lines changed

src/loader/cmi.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ module Compat = struct
6060
let concr_mem = Types.Meths.mem
6161
let csig_concr x = x.Types.csig_meths
6262
let eq_type = Types.eq_type
63-
#if OCAML_VERSION >= (5,4,0)
63+
#if OCAML_VERSION >= (5,4,0) || defined OXCAML
6464
let invisible_wrap ty = newty2 ~level:Btype.generic_level (Ttuple [None,ty])
65-
#elif OCAML_VERSION = (5,2,0)
66-
let invisible_wrap ty = newty2 ~level:Btype.generic_level (Ttuple [None, ty])
6765
#else
6866
let invisible_wrap ty = newty2 ~level:Btype.generic_level (Ttuple [ty])
6967
#endif
@@ -241,12 +239,12 @@ let mark_type ty =
241239
| Tarrow(_, ty1, ty2, _) ->
242240
loop visited ty1;
243241
loop visited ty2
244-
#if OCAML_VERSION >= (5,4,0) || OCAML_VERSION = (5,2,0)
242+
#if OCAML_VERSION >= (5,4,0) || defined OXCAML
245243
| Ttuple tyl -> List.iter (fun (_lbl,x) -> loop visited x) tyl
246244
#else
247245
| Ttuple tyl -> List.iter (loop visited) tyl
248246
#endif
249-
#if OCAML_VERSION = (5,2,0)
247+
#if defined OXCAML
250248
| Tunboxed_tuple tyl -> List.iter (fun (_, ty) -> loop visited ty) tyl
251249
#endif
252250
| Tconstr(_, tyl, _) ->
@@ -285,7 +283,7 @@ let mark_type ty =
285283
| Tpoly (ty, tyl) ->
286284
List.iter (fun t -> add_alias t) tyl;
287285
loop visited ty
288-
#if OCAML_VERSION = (5,2,0)
286+
#if defined OXCAML
289287
| Tunivar { name; _ } -> reserve_name name
290288
#else
291289
| Tunivar name -> reserve_name name
@@ -305,7 +303,7 @@ let mark_type ty =
305303
#else
306304
| Tsubst (ty,_) -> loop visited ty
307305
#endif
308-
#if OCAML_VERSION = (5,2,0)
306+
#if defined OXCAML
309307
| Tquote typ -> loop visited typ
310308
| Tsplice typ -> loop visited typ
311309
#endif
@@ -504,13 +502,13 @@ let rec read_type_expr env typ =
504502
let res = read_type_expr env res in
505503
Arrow(lbl, arg, res)
506504
| Ttuple typs ->
507-
#if OCAML_VERSION >= (5,4,0) || OCAML_VERSION = (5,2,0)
505+
#if OCAML_VERSION >= (5,4,0) || defined OXCAML
508506
let typs = List.map (fun (lbl,x) -> lbl, read_type_expr env x) typs in
509507
#else
510508
let typs = List.map (fun x -> None, read_type_expr env x) typs in
511509
#endif
512510
Tuple typs
513-
#if OCAML_VERSION = (5,2,0)
511+
#if defined OXCAML
514512
| Tunboxed_tuple typs ->
515513
let typs = List.map (fun (l,t) -> l, read_type_expr env t) typs in
516514
Unboxed_tuple typs
@@ -556,7 +554,7 @@ let rec read_type_expr env typ =
556554
#else
557555
| Tsubst (typ,_) -> read_type_expr env typ
558556
#endif
559-
#if OCAML_VERSION = (5,2,0)
557+
#if defined OXCAML
560558
| Tquote typ -> Quote (read_type_expr env typ)
561559
| Tsplice typ -> Splice (read_type_expr env typ)
562560
#endif
@@ -685,7 +683,7 @@ let read_value_description ({ident_env ; warnings_tag} as env) parent id vd =
685683
let type_ = read_type_expr env vd.val_type in
686684
let value =
687685
match vd.val_kind with
688-
#if OCAML_VERSION = (5,2,0)
686+
#if defined OXCAML
689687
| Val_reg _ -> Value.Abstract
690688
#else
691689
| Val_reg -> Value.Abstract

src/loader/cmt.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ let rec read_pattern env parent doc pat =
4242
match pat.pat_desc with
4343
| Tpat_any -> []
4444
#if OCAML_VERSION < (5,2,0)
45-
| Tpat_var(id, _, _, _) ->
46-
#else
45+
| Tpat_var(id, _) ->
46+
#elif defined OXCAML
4747
| Tpat_var(id, _, _uid, _, _) ->
48+
#else
49+
| Tpat_var(id, _, _uid) ->
4850
#endif
4951
let open Value in
5052
let id = Env.find_value_identifier env.ident_env id in
@@ -55,7 +57,7 @@ let rec read_pattern env parent doc pat =
5557
[Value {id; source_loc; doc; type_; value ; source_loc_jane }]
5658
#if OCAML_VERSION < (5,2, 0)
5759
| Tpat_alias(pat, id, _) ->
58-
#elif OCAML_VERSION = (5,2, 0)
60+
#elif defined OXCAML
5961
| Tpat_alias(pat, id, _, _, _, _, _) ->
6062
#elif OCAML_VERSION < (5,4,0)
6163
| Tpat_alias(pat, id, _,_) ->
@@ -71,11 +73,11 @@ let rec read_pattern env parent doc pat =
7173
Value {id; source_loc; doc; type_; value ; source_loc_jane } :: read_pattern env parent doc pat
7274
| Tpat_constant _ -> []
7375
| Tpat_tuple pats ->
74-
#if OCAML_VERSION >= (5, 4, 0) || OCAML_VERSION = (5, 2, 0)
76+
#if OCAML_VERSION >= (5, 4, 0) || defined OXCAML
7577
let pats = List.map snd pats (* remove labels *) in
7678
#endif
7779
List.concat (List.map (read_pattern env parent doc) pats)
78-
#if OCAML_VERSION = (5, 2, 0)
80+
#if defined OXCAML
7981
| Tpat_unboxed_tuple pats ->
8082
List.concat (List.map (fun (_, p, _) -> read_pattern env parent doc p) pats)
8183
#endif
@@ -93,7 +95,7 @@ let rec read_pattern env parent doc pat =
9395
(List.map
9496
(fun (_, _, pat) -> read_pattern env parent doc pat)
9597
pats)
96-
#if OCAML_VERSION = (5, 2, 0)
98+
#if defined OXCAML
9799
| Tpat_record_unboxed_product(pats, _) ->
98100
List.concat
99101
(List.map

src/loader/cmti.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ let rec read_core_type env container ctyp =
6767
let res = read_core_type env container res in
6868
Arrow(lbl, arg, res)
6969
| Ttyp_tuple typs ->
70-
#if OCAML_VERSION >= (5,4,0) || OCAML_VERSION = (5,2,0)
70+
#if OCAML_VERSION >= (5,4,0) || defined OXCAML
7171
let typs = List.map (fun (lbl,x) -> lbl, read_core_type env container x) typs in
7272
#else
7373
let typs = List.map (fun x -> None, read_core_type env container x) typs in
7474
#endif
7575
Tuple typs
76-
#if OCAML_VERSION = (5,2,0)
76+
#if defined OXCAML
7777
| Ttyp_unboxed_tuple typs ->
7878
let typs = List.map (fun (l, t) -> l, read_core_type env container t) typs in
7979
Unboxed_tuple typs
@@ -155,7 +155,7 @@ let rec read_core_type env container ctyp =
155155
in
156156
Polymorphic_variant {kind; elements}
157157
| Ttyp_poly([], typ) -> read_core_type env container typ
158-
#if OCAML_VERSION = (5,2,0)
158+
#if defined OXCAML
159159
| Ttyp_poly(vars, typ) ->
160160
(* TODO: presumably want the layouts, eventually *)
161161
Poly(List.map fst vars, read_core_type env container typ)
@@ -183,7 +183,7 @@ let rec read_core_type env container ctyp =
183183
(* TODO: adjust model *)
184184
read_core_type env container t
185185
#endif
186-
#if OCAML_VERSION = (5,2,0)
186+
#if defined OXCAML
187187
| Ttyp_quote typ -> Quote (read_core_type env container typ)
188188
| Ttyp_splice typ -> Splice (read_core_type env container typ)
189189
#endif

src/loader/dune

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(library
22
(name odoc_loader)
33
(public_name odoc.loader)
4+
(enabled_if
5+
(not %{ocaml-config:ox}))
46
(preprocess
57
(action
68
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{input-file})))
@@ -11,3 +13,18 @@
1113
odoc_document
1214
odoc_utils
1315
compiler-libs.optcomp))
16+
17+
(library
18+
(name odoc_loader)
19+
(public_name odoc.loader)
20+
(enabled_if %{ocaml-config:ox})
21+
(preprocess
22+
(action
23+
(run %{bin:cppo} -V OCAML:%{ocaml_version} -D "OXCAML" %{input-file})))
24+
(libraries
25+
odoc_model
26+
odoc-parser
27+
syntax_highlighter
28+
odoc_document
29+
odoc_utils
30+
compiler-libs.optcomp))

src/loader/ident_env.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,16 @@ let rec read_pattern hide_item pat =
303303
let open Typedtree in
304304
match pat.pat_desc with
305305
#if OCAML_VERSION < (5,2,0)
306-
| Tpat_var(id, loc, _, _) ->
307-
#else
306+
| Tpat_var(id, loc) ->
307+
#elif defined OXCAML
308308
| Tpat_var(id, loc, _, _, _) ->
309+
#else
310+
| Tpat_var(id, loc, _, _) ->
309311
#endif
310312
[`Value(id, hide_item, Some loc.loc)]
311313
#if OCAML_VERSION < (5,2,0)
312314
| Tpat_alias(pat, id, loc) ->
313-
#elif OCAML_VERSION = (5,2,0)
315+
#elif defined OXCAML
314316
| Tpat_alias(pat, id, loc, _, _, _, _) ->
315317
#elif OCAML_VERSION < (5,4,0)
316318
| Tpat_alias(pat, id, loc, _) ->
@@ -327,7 +329,7 @@ let rec read_pattern hide_item pat =
327329
#else
328330
| Tpat_construct(_, _, pats, _)
329331
#endif
330-
#if OCAML_VERSION = (5,2,0)
332+
#if defined OXCAML
331333
| Tpat_array (_, _, pats) ->
332334
List.concat (List.map (fun pat -> read_pattern hide_item pat) pats)
333335
#elif OCAML_VERSION < (5,4,0)
@@ -338,12 +340,12 @@ let rec read_pattern hide_item pat =
338340
List.concat (List.map (fun pat -> read_pattern hide_item pat) pats)
339341
#endif
340342
| Tpat_tuple pats ->
341-
#if OCAML_VERSION >= (5,4,0) || OCAML_VERSION = (5,2,0)
343+
#if OCAML_VERSION >= (5,4,0) || defined OXCAML
342344
List.concat (List.map (fun (_lbl,pat) -> read_pattern hide_item pat) pats)
343345
#else
344346
List.concat (List.map (fun pat -> read_pattern hide_item pat) pats)
345347
#endif
346-
#if OCAML_VERSION = (5,2,0)
348+
#if defined OXCAML
347349
| Tpat_unboxed_tuple pats ->
348350
List.concat (List.map (fun (_, pat, _) -> read_pattern hide_item pat) pats)
349351
#endif

src/model/compat.cppo.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,18 @@ let shape_info_of_cmt_infos : Cmt_format.cmt_infos -> (shape * uid_to_loc) optio
284284

285285
#endif
286286

287-
#if OCAML_VERSION >= (5,2,0)
287+
#if defined OXCAML
288+
288289
let compunit_name : Compilation_unit.t -> string = Compilation_unit.name_as_string
289290

290291
let required_compunit_names x = List.map compunit_name x.Cmo_format.cu_required_compunits
291292

293+
#elif OCAML_VERSION >= (5,2,0)
294+
295+
let compunit_name : Cmo_format.compunit -> string = function | Compunit x -> x
296+
297+
let required_compunit_names x = List.map compunit_name x.Cmo_format.cu_required_compunits
298+
292299
#elif OCAML_VERSION >= (4,04,0)
293300

294301
let compunit_name x = Compilation_unit.name_as_string x

src/model/dune

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
(targets compat.ml)
33
(deps
44
(:x compat.cppo.ml))
5+
(enabled_if
6+
(not %{ocaml-config:ox}))
57
(action
68
(chdir
79
%{workspace_root}
810
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))
911

12+
(rule
13+
(targets compat.ml)
14+
(deps
15+
(:x compat.cppo.ml))
16+
(enabled_if %{ocaml-config:ox})
17+
(action
18+
(chdir
19+
%{workspace_root}
20+
(run %{bin:cppo} -V OCAML:%{ocaml_version} -D "OXCAML" %{x} -o %{targets}))))
21+
1022
(library
1123
(name odoc_model)
1224
(public_name odoc.model)

src/syntax_highlighter/dune

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
(library
22
(name syntax_highlighter)
33
(public_name odoc.syntax_highlighter)
4+
(enabled_if
5+
(not %{ocaml-config:ox}))
46
(preprocess
57
(action
68
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{input-file})))
79
(libraries compiler-libs.common))
10+
11+
(library
12+
(name syntax_highlighter)
13+
(public_name odoc.syntax_highlighter)
14+
(enabled_if %{ocaml-config:ox})
15+
(preprocess
16+
(action
17+
(run %{bin:cppo} -V OCAML:%{ocaml_version} -D OXCAML %{input-file})))
18+
(libraries compiler-libs.common))

src/syntax_highlighter/syntax_highlighter.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ let tag_of_token (tok : Parser.token) =
165165
| ANDOP _ -> "ANDOP"
166166
| LETOP _ -> "LETOP"
167167
#endif
168-
#if OCAML_VERSION = (5,2,0)
169-
(* oxcaml *)
168+
#if defined OXCAML
170169
| RBRACKETGREATER -> "RBRACKETGREATER"
171170
| LESSLBRACKET -> "LESSLBRACKET"
172171
| DOLLAR -> "DOLLAR"

src/xref2/dune

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,25 @@
88
(libraries odoc_model odoc_utils))
99

1010
(rule
11-
(with-stdout-to
12-
shape_tools.ml
13-
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep:shape_tools.cppo.ml})))
11+
(enabled_if
12+
(not %{ocaml-config:ox}))
13+
(action
14+
(with-stdout-to
15+
shape_tools.ml
16+
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{dep:shape_tools.cppo.ml}))))
17+
18+
(rule
19+
(enabled_if %{ocaml-config:ox})
20+
(action
21+
(with-stdout-to
22+
shape_tools.ml
23+
(run
24+
%{bin:cppo}
25+
-V
26+
OCAML:%{ocaml_version}
27+
-D
28+
OXCAML
29+
%{dep:shape_tools.cppo.ml}))))
1430

1531
(rule
1632
(with-stdout-to

0 commit comments

Comments
 (0)