Repository navigation
Expand file tree
/
Copy pathasttypes.ml
More file actions
95 lines (77 loc) · 3.48 KB
/
Copy pathasttypes.ml
File metadata and controls
95 lines (77 loc) · 3.48 KB
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
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(** Auxiliary AST types used by parsetree and typedtree. *)
type constant =
| Const_int of int
| Const_char of int
(** The decoded Unicode code point of a character literal. For example,
['\u{1F600}'] is represented as [Const_char 0x1F600]. Source spelling
has been discarded after type checking. *)
| Const_string of string
(** The decoded runtime value of an ordinary string literal. For example,
["a\\n"] is represented by a string containing an actual newline.
Source spelling has been discarded after type checking. *)
| Const_float of string
| Const_bigint of bool * string
type template_segment = String_literal.template_segment
(** A segment of an ordinary backquoted template after validation. [source]
preserves its spelling for JavaScript output; [semantic] is its decoded
runtime string value. For example, the final segment of [`a ${value}\n`]
preserves ["\\n"] as its source and contains an actual newline as its
semantic value. Construct segments through [String_literal]. *)
type rec_flag = Nonrecursive | Recursive
type direction_flag = Upto | Downto
(* Order matters, used in polymorphic comparison *)
type private_flag = Private | Public
type mutable_flag = Immutable | Mutable
type override_flag = Override | Fresh
type closed_flag = Closed | Open
type label = string
type 'a loc = 'a Location.loc = {txt: 'a; loc: Location.t}
type variance = Covariant | Contravariant | Invariant
type arg_label =
| Nolabel (* x => ...*)
| Labelled of string loc (* ~label => ... *)
| Optional of string loc (* ~(label=e) => ... *)
module Noloc = struct
type arg_label =
| Nolabel (* x => ...*)
| Labelled of string (* ~label => ... *)
| Optional of string (* ~(label=e) => ... *)
end
let to_arg_label lbl =
let loc = Location.none in
match lbl with
| Noloc.Nolabel -> Nolabel
| Labelled s -> Labelled {loc; txt = s}
| Optional s -> Optional {loc; txt = s}
let to_noloc = function
| Nolabel -> Noloc.Nolabel
| Labelled {txt} -> Labelled txt
| Optional {txt} -> Optional txt
let same_arg_label (x : arg_label) y =
match x with
| Nolabel -> y = Nolabel
| Labelled {txt = s} -> (
match y with
| Labelled {txt = s0} -> s = s0
| _ -> false)
| Optional {txt = s} -> (
match y with
| Optional {txt = s0} -> s = s0
| _ -> false)
let get_lbl_loc = function
| Nolabel -> Location.none
| Labelled {loc} | Optional {loc} -> loc