Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 174 lines (148 sloc) 4.536 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (**
19 Signatures for [QmlPatternAnalysis]
20 @author Rudy Sicard
21 *)
22
23 (**
24 This module contains types and signatures used by [QmlPatternAnalysis].
25 This module has no mli, to avoid code duplication.
26 It does not contain any implementation.
27 *)
28
29 (**
30 A type for indicating if a pattern is complete or not.
31 {[
32 | { a ; b }
33 ]}
34 would be flaged [`closed]
35 {[
36 | { a ; b ; ... }
37 ]}
38 would be flaged [`open_]
39 *)
40 type row_flag = [ `open_ | `closed ]
41
42 (**
43 An alias for manipulating record fields
44 *)
45 type field = string
46
47 (**
48 The interface of the argument module to the Analysis functor
49 *)
50 module type ONIONLANG =
51 sig
52 (** {6 Types} *)
53
54 type ident
55 type const
56 type ty
57 type expr
58
59 (** {6 Mandatory Functions} *)
60
61 (**
62 Comparison on const type.
63 Should return -1, 0, or 1
64 *)
65 val compare_const : const -> const -> int
66
67 (**
68 Generate a new unique ident given a field
69 and the identifier of the top-level declaration
70 containing the processed expression
71
d3757ec [fix] typos: various corrections
Arthur Milchior authored
72 It is possible to return a fresh ident which does not depend on its arguments,
fccc685 Initial open-source release
MLstate authored
73 but is could also be interressant to name identifier depending on the context,
74 for a better debugging.
75 *)
76 val gen_ident : ?ident:ident -> field -> ident
77
78 (**
79 Take a type, the fields appearing in a non strict record pattern, and returns
80 all possible set of fields corresponding to possible sum cases,
81 with a strictness flag ([`closed] means strict which means without [...])
82 precising if the completed field list is still open.
83
84 Some examples:
85
86 Example 1)
87 in this context:
88 {[
89 type toto = { a ; b ; c } / { d }
90 f =
91 | { a ; b ; ... } : toto ->
92 | _ ->
93 ]}
94 a call to:
95 {[
96 strictify_record_ty toto [ "a" ; "b" ]
97 ]}
98 should return:
99 {[
100 [ [ "a" ; "b" ; "c" ], `closed ]
101 ]}
102
103 Example 2)
104 in this context:
105 {[
106 type toto = { a ; b ; c } / { a ; b ; d }
107 f =
108 | { a ; b ; ... } : toto ->
109 | _ ->
110 ]}
111 a call to:
112 {[
113 strictify_record_ty toto [ "a" ; "b" ]
114 ]}
115 should return:
116 {[
117 [ [ "a" ; "b" ; "c" ], `closed ; [ "a" ; "b" ; "d" ], `closed ]
118 ]}
119
120 Example 3)
121 in this context:
122 {[
123 f =
124 | { a ; b ; ... } ->
125 ]}
126 a call to:
127 {[
128 strictify_record_ty { a ; b ; ... } [ "a" ; "b" ]
129 ]}
130 should return:
131 {[
132 [ [ "a" ; "b" ], `open_ ]
133 ]}
134
135 If all flags in the returned list are strict, this will helps pattern to be free
136 of unstrict sub-patterns.
137 *)
138 val strictify_record_ty : ty -> field list -> ((field list) * row_flag) list
139
140 (**
141 Indicate if a type is an open disjuntion.
142 For Qml, this means that the type is a sum type,
143 with an open column variable.
144 *)
145 val is_open_ty : ty option -> bool
146
147 (**
148 Given as context a set of field, and a type, return the type of a given field
149 the set of field is used to select cases for sum types.
150 This function can assume that the field list used for selecting the case in the sum
151 leads to an uniq choice in this sum.
152 *)
153 val strict_get_field_type : ty -> field list -> field -> ty
154
155 (**
156 Get missing constants in a pattern matching, given a list of matched constants.
157 Hypothesis: the input list in sorted, according the [compare_const] function.
158 The function is authorized to contain some jokes.
159 It is used to produce an hint inviting to complete an pattern matching being not exhaustive.
160 *)
161 val get_missing : const list -> const list
162
163
164 (** {6 Printing} *)
165 (**
166 Used for formulating errors/warnings messages
167 *)
168
169 val print_id : Format.formatter -> ident -> unit
170 val print_ty : Format.formatter -> ty -> unit
171 val print_expr : Format.formatter -> expr -> unit
172 val print_const : Format.formatter -> const -> unit
173 end
Something went wrong with that request. Please try again.