Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 175 lines (136 sloc) 6.703 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 Managment of tags for a bypass in a specific implementation.
21
22 @author Mathieu Barbin
23 *)
24
25 (**
26 This module contains a type [BslTags.t] to represent bypass tags,
27 with a documentation of what are tags for, and a easy way to extend them.
28 *)
29
30 (** {6 Tags : Attributes for bypases} *)
31
32 (** The type, as it is parsed by bslregister *)
33 type parsed_t = ( string * string option ) list
34
35 (**
36 The type for bsltags.
37
38 + [backend:restriction] : UNDOCUMENTED -- default is [None]
39 + [internal_first] : HACK will be removed. internal tag of BslRegisterLib.
40 is true if the function is the first of its module-record (js) -- default is [false]
41 + [js_module_representation] : the way module are produced in js.
42 new_object seems to be deprecated -- default is [None]
43 + [no_projection] : [None]: this bypass should never be projected, [Some stringset]:
44 this bypass should be projected for everybody but inhabitants of the set
45 <!> use at your own risk ! -- default is [false]
46 + [opaname] : tag for type definition, meant not to apply the standardization
47 on the name of the type.
48 + [restricted] : the bypass is not meant to be used by a user, but only generated in a compiler pass.
49 The optional string list bring some more restriction.
50 If the bypass has been taged with [restricted:toto],
51 only a pass insering a [Directive (`restricted_bypass "toto", [Bypass _], _)] is authorized to use it.
52 Beware, [Some (Some []) <> Some None]. -- default is [None]
53 + [second_order] is a tag for bypass which contains an arrow type in one of their argument, or the returned type.
54 + [cps_bypass] is a tag for bypass that take explicitly the cps continuation.
55 + [opacapi] says that this bypass is part of the compiler interface (inserted by some pass)
56
57 This tag is added by the bslregister process, so that the type should not be inspected each time we may need to
58 get this information.
59 *)
60 type t =
61 {
62 backend_restriction : StringSet.t option ;
63 no_projection : StringSet.t option ;
64 opaname : bool ;
65 raise_ : bool ;
66 restricted : string list option option ;
67 second_order : bool ;
68 cps_bypass : bool ;
69 opacapi : bool ;
70 }
71
72 (** The default tags. See default values in the definition of the type [t] *)
73 val default : t
74
75 (** Test if a value of type [t] is physically equal to the [default] value
76 ( computed with [t == default] )
77 this is used to optimize the generated code of loaders *)
78 val is_default : t -> bool
79
80 (** {6 Printing} *)
81
82 type 'a pprinter = 'a LangPrint.pprinter
83 val pp : t pprinter
84 val pp_tag : (string * string option) pprinter
85
86 (**
87 Meta printing, for code generation.
88 Print as Ocaml concrete syntax
89 *)
90 val pp_meta_tag : (string * string option) pprinter
91 val pp_meta : parsed_t pprinter
92
93 (** {6 Error reporting } *)
94
95 (** Error during parsing of tags *)
96 type error
97 exception Exception of error
98 val pp_error : error pprinter
99
100 (** {6 Parsing} *)
101
102 (**
103 The tags are found with the implementation, in the file processed by {b bslregister}.
104 The syntax to insert tags is the following :
105 [##register [mytag, myothertag, mytagwith:an_argument] etc...]
106
107 In {b bslregister}, the parser does not try to parse explicitly the tags. It builds just
108 a row type from all tags read in the files : [ (string * string option) list ] : tag * optional argument.
109
110 Then, the [parse] function of this module is called to build a element of type [BslTags.t].
111
112 That means that you can easily extend the type [BslTags.t] by modifying only this module.
113 *)
114
115 (**
116 Parse the given list of tags.
117
118 If a pos is provided, do not raise the error, but directly fails with OManager.
119 if not,
120 @raise Error with an appropriate error message, in case of unbound tags, conflict, etc.. *)
121 val parse : ?pos:FilePos.pos -> parsed_t -> t
122
123 (**
124 Reversing the parsing, returns back the parsed_t
125 *)
126 val parsed_t : t -> parsed_t
127
128 (** {6 Helpers for projection semantic} *)
129
130 type passname = string
131
132 (** Given the name of a pass, and a [BslTags.t], says if the projection should be done *)
133 val do_projection : t -> passname -> bool
134
135 (** Given a [BslTags.t], says if the projection cannot be projected
136 (ie declared as [no_projection]) *)
137 val never_projected : t -> bool
138
139 (** A pretty message to get in mind the complex semantic of the field [no_projection] of a [BslTags.t].
140 @param no_projection The field [no_projection] as it is in the tags [BslTags.t] corresponding to this bypass
141 *)
142 val string_of_no_projection : StringSet.t option -> string
143
144 (** {6 Helpers for checking bypass restriction} *)
145
146 (**
147 The bypass restriction is used to check whenever a bypass is used outside of
148 the context it is meant to be :
149 + if a user try to use a bypass reserved for an internal use only (inserted by the compiler)
150 + if a pass try to insert a bypass restricted for an other pass.
151 *)
152
153 (** A pretty message to get in mind the complex semantic of the field [restricted] of a [BslTags.t].
154 @param restricted The field [restricted] as it is in the tags [BslTags.t] corresponding to this bypass
155 *)
156 val string_of_restricted : string list option option -> string
157
158 (** This function implements the semantic of bypass restriction.
159
160 @param restriction The restriction of the bypass. This is [None] if the bypass is represented
161 with [Bypass] in the ast, and [Some pass] if it is [Directive (`restricted_bypass pass, _, _)]
162 @param tags The tags [BslTags.t] corresponding to this bypass
163 @return [true] if and only if the bypass is authorized
164 *)
165 val authorized_bypass : restriction:string option -> t -> bool
166
167 (** Same than [authorized_bypass] but with an other interface for commodity :
168 [authorized_bypass_as_expr restricted bypass]
169 @param tags The tags [BslTags.t] corresponding to this bypass
170 @param bypass A [QmlAst.expr] which must be either [Directive (`restricted_bypass _, [Bypass _], _)]
171 or [Bypass _]
172 @return [true] if and only if the bypass is authorized
173 *)
174 val authorized_bypass_as_expr : t -> QmlAst.expr -> bool
Something went wrong with that request. Please try again.