Commit 8008854b authored by POTTIER Francois's avatar POTTIER Francois

Use ppx_deriving to test for attributes.

parent 649556a0
......@@ -2181,6 +2181,9 @@ whether this behavior is appropriate.
In \polymorphic mode (\sref{sec:intro:parameterized:poly}), a type variable
must not occur under an \oc|[@opaque]| annotation.
If desired, instead of \oc|[@opaque]|, one can use the more verbose forms
\oc|[@visitors.opaque]| and \oc|[@deriving.visitors.opaque]|.
% ------------------------------------------------------------------------------
\bibliographystyle{plain}
......
......@@ -17,6 +17,22 @@ type tyvars = tyvar list
(* Testing for the presence of attributes. *)
(* We use [Ppx_deriving] to extract attributes. By convention, an attribute
named [name] can also be referred to as [visitors.name] or
[deriving.visitors.name]. *)
(* [select name attrs] extracts the attribute named [name] from the attribute
list [attrs]. *)
let select (name : string) (attrs : attribute list) : attribute option =
attr ~deriver:plugin name attrs
(* [present name attrs] tests whether an attribute named [name] is present
(with no argument) in the list [attrs]. *)
let present (name : string) (attrs : attribute list) : bool =
Arg.get_flag ~deriver:plugin (select name attrs)
(* [opacity attrs] tests whether the attribute list [attrs] contains an
[@opaque] attribute. *)
......@@ -24,12 +40,8 @@ type opacity =
| Opaque
| NonOpaque
let is_opaque (attr : attribute) : bool =
let { txt = name; _ }, _payload = attr in
name = "opaque"
let opacity (attrs : attributes) : opacity =
if List.exists is_opaque attrs then Opaque else NonOpaque
if present "opaque" attrs then Opaque else NonOpaque
(* -------------------------------------------------------------------------- *)
......
......@@ -11,4 +11,5 @@ test01
test02
test03
test04
test05
testallprims
(* Testing that @opaque is properly detected. *)
module T = struct
type t = A of ((int -> int)[@deriving.visitors.opaque])
[@@deriving visitors { variety = "map" }]
end
module U = struct
type u = B of ((int -> int)[@visitors.opaque])
[@@deriving visitors { variety = "map" }]
end
module V = struct
type w = C of ((int -> int)[@opaque])
[@@deriving visitors { variety = "map" }]
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment