Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 158 lines (125 sloc) 4.902 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 (**
20 Alpha Conversion representation and computation on QmlAst.
21 @author Mathieu Barbin
22 *)
23
24
25 (** Uses an env to unify every pass of ast with a possible fold_map.
26 The renaming is based on [ExprIdent.next] *)
27
28 (** {6 Error reporting} *)
29
30 (**
31 The module uses QmlError for errors reporting.
32 Depending on the function you use, the module use :
33 + QmlError.error for public errors
34 + QmlError.check_fail for checkers
35 *)
36
37 (** {6 Alpha Conversion representation and options} *)
38
39 (** The abstract type for an alpha conv *)
40 type t
41
42 (**
43 A standard initial value for an alpha conv
44 - refresh only ident name
45 - DOES NOT REFRESH ANNOT
46 *)
47 val empty : t
48
49 (**
50 Initializing a value of type [t] for a new alpha conversion.
51 The option [weak] means that some ident are allowed not to be bound
52 then, they are reproduced as is (no renamed, be carrefull).
53 By default, original names are keeped, for a better tracability of the code.
54 (only the internal int of the [ExprIdent.Internal] is refreshed)
55 *)
56 val next : ?weak:(Ident.t -> bool) -> unit -> t
57
58 (**
59 Construction from two existing map.
60 [map:orig -> final] and [revmap:final -> orig].
61 Not for casual users.
62 *)
63 val create_from_maps : map:Ident.t IdentMap.t -> revmap:Ident.t IdentMap.t -> t
64
65 (** Changing dynamically some of env properties *)
66
67 val env_weak : weak:(Ident.t -> bool) -> t -> t
68
69 (** print the association of the original ident and the new corresponding fresh one (for debug only) *)
70 val to_string : t -> string
71
72 (** {6 Computation} *)
73
74 (** pat can introduce var *)
75 val pat : t -> QmlAst.pat -> t * QmlAst.pat
76
77 (** an expr does not introduce new bindings : simple map *)
78 val expr : t -> QmlAst.expr -> QmlAst.expr
79
80 (** The primary API on top value : they are all fold_map *)
81 val code_elt : t -> QmlAst.code_elt -> t * QmlAst.code_elt
82 val code : t -> QmlAst.code -> t * QmlAst.code
83
84 (** Maping an ident with the current bingings *)
85 val ident : t -> QmlAst.ident -> QmlAst.ident option
86 (** Finding back the origin name *)
87 val rev_ident : t -> QmlAst.ident -> QmlAst.ident option
88
89 (** Higher level API *)
90 val next_code : ?weak:(Ident.t -> bool) -> QmlAst.code -> QmlAst.code
91
92 (** clean t to keep the minimal information *)
93 val clean : t -> t
94 (* this function update the qmlAlphaConv acc to be able to make external first level renaming without losing the succession org -> alpha -> alpha -> ... -> last alpha
95 An alpha convversion must be launched after this
96 *)
97 val update : t -> Ident.t IdentMap.t -> t
98
99 (**
100 Checks related to alpha conversion
101 *)
102 module Check :
103 sig
104 type ('env, 'a) checker = ('env -> 'a) -> 'env PassHandler.cond
105
106 (**
107 The id of all cond related to ident
108 *)
109 val id : PassHandler.cond_id
110
111 (** {6 Alpha-conversion} *)
112 (**
113 Checks that alpha-conversion preconditions are satisfied.
114 The conditions are, e.g., no unbound identifiers and no repeated
115 identifiers in letrecs and patterns.
116 - Condition name : ["cond.ident.alpha"]
117 - Warning class : [cond_ident_alpha]
118 *)
119 val alpha : ('env, QmlAst.annotmap * QmlAst.code) checker
120 val alpha_id : PassHandler.cond_id
121
122 (** {6 Unbound}*)
123 (**
124 Checks that every identifier is in scope when it use
125 - Condition name : ["cond.ident.unbound"]
126 - Warning class : [cond_ident_unbound]
127 For create the checker you must give a function for retrieve an
128 ident from a string.
129
130 *)
131 val unbound : ?weak:(Ident.t -> bool) -> (string -> QmlAst.ident) -> ('env, QmlAst.annotmap * QmlAst.code) checker
132 val unbound_id : PassHandler.cond_id
133
134 (** {6 Unicity} *)
135 (**
136 Checks that every identifier is unique
137 - Condition name : ["cond.ident.unicity"]
138 - Warning class : [cond_ident_unicity]
139 *)
140 val unicity : ('env, QmlAst.annotmap * QmlAst.code) checker
141 val unicity_id : PassHandler.cond_id
142
143 end
144
145 (**
146 Hackish module, should be removed after the refactoring of positions in the AST.
147 *)
148 module HacksForPositions :
149 sig
150 (**
151 Special Hackish annotmap, used for finding positions for error messages.
152 Used for having an annotmap when the module fails, without changing every
153 interfaces by adding an annotmap in argument.
154 *)
155 val set_annotmap : QmlAst.annotmap -> unit
156 val free_annotmap : unit -> unit
157 end
Something went wrong with that request. Please try again.