package zanuda

  1. Overview
  2. Docs
Linter for OCaml+dune projects

Install

dune-project
 Dependency

Authors

Maintainers

Sources

zanuda-2.0.0.tbz
sha256=0108d8d6e6e23bfe5e5cdade27ae434db921ed4b6f522ea71800f14a7662230e
sha512=c8d633f4083867dfc73caf3b51b63c8c01771f5c286aa0a8357861044448e0b55df38eb695b997df470267ec921adae6f86c73d251fb3e965ac83ebb2c6b856c

doc/src/zanuda.tast_pattern/My_printtyped.ml.html

Source file My_printtyped.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
(** These extra functions are an extension of {!Printtyped} module from compiler libs.
    Maybe in new versions of compiler they will be available out of box. *)

[@@@ocaml.text "/*"]

(** Copyright 2021-2025, Kakadu. *)

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

[@@@ocaml.text "/*"]

[@@@coverage off]

(* This are helper functions related to OCaml compiler. Doesn't make sense to seriously test them *)

include Printtyped

[%%if ocaml_version < (4, 11, 0)]

let untype_expression = default_mapper.expr default_mapper

[%%endif]

(** {2 New functions} *)

let expr ppf e =
  let open Typedtree in
  implementation
    ppf
    { str_items =
        [ { str_desc = Tstr_eval (e, []); str_loc = e.exp_loc; str_env = e.exp_env } ]
    ; str_final_env = e.exp_env
    ; str_type = []
    }
;;

[%%if ocaml_version < (5, 0, 0)]

let make_Tstr_module mb_name _presence ~loc me =
  Typedtree.Tstr_module
    { mb_id = None
    ; mb_name
    ; mb_expr = me
    ; mb_attributes = []
    ; mb_presence = Types.Mp_present
    ; mb_loc = loc
    }
;;

[%%else]

let make_Tstr_module mb_name presence ~loc me =
  Typedtree.Tstr_module
    { mb_id = None
    ; mb_uid = Shape.Uid.internal_not_actually_unique
    ; mb_name
    ; mb_expr = me
    ; mb_attributes = []
    ; mb_presence = presence
    ; mb_loc = loc
    }
;;

[%%endif]

let me ppf me =
  let open Typedtree in
  implementation
    ppf
    { str_items =
        [ { str_desc =
              make_Tstr_module (Location.mknoloc None) Types.Mp_present ~loc:me.mod_loc me
          ; str_loc = me.mod_loc
          ; str_env = me.mod_env
          }
        ]
    ; str_final_env = me.mod_env
    ; str_type = []
    }
;;

[%%if ocaml_version < (5, 0, 0)]

let dummy_vb vb_pat vb_expr =
  { Typedtree.vb_pat; vb_loc = Location.none; vb_attributes = []; vb_expr }
;;

[%%else]

let dummy_vb vb_pat vb_expr =
  { Typedtree.vb_pat
  ; vb_loc = Location.none
  ; vb_rec_kind = Dynamic
  ; vb_attributes = []
  ; vb_expr
  }
;;

[%%endif]

let pattern ppf pat =
  let open Typedtree in
  let dummy_expr =
    { exp_desc = Texp_variant ("Dummy", None)
    ; exp_loc = Location.none
    ; exp_env = pat.pat_env
    ; exp_type = pat.pat_type
    ; exp_extra = []
    ; exp_attributes = []
    }
  in
  implementation
    ppf
    { str_items =
        [ { str_desc = Tstr_value (Nonrecursive, [ dummy_vb pat dummy_expr ])
          ; str_loc = pat.pat_loc
          ; str_env = pat.pat_env
          }
        ]
    ; str_final_env = pat.pat_env
    ; str_type = []
    }
;;

[%%if ocaml_version < (5, 0, 0)]

let make_int_const ~loc:_ n = Parsetree.Pconst_integer (string_of_int n, None)

[%%else]

let make_int_const ~loc n =
  { Parsetree.pconst_desc = Pconst_integer (string_of_int n, None); pconst_loc = loc }
;;

[%%endif]

let attrs ppf attrs =
  Pprintast.expression
    ppf
    (Ast_helper.Exp.constant (make_int_const ~loc:Location.none 1) ~attrs)
;;