/usr/lib/ocaml/deriving/default_class.ml is in libderiving-ocsigen-ocaml-dev 0.7.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | open Pa_deriving_common
open Utils
module Description : Defs.ClassDescription = struct
let classname = "Default"
let default_module = None
let runtimename = "Deriving_Default"
let alpha = None
let allow_private = true
let predefs = [
["int" ], ["Deriving_Default";"int"];
["bool" ], ["Deriving_Default";"bool"];
["unit" ], ["Deriving_Default";"unit"];
["char" ], ["Deriving_Default";"char"];
["int32" ], ["Deriving_Default";"int32"];
["Int32";"t"], ["Deriving_Default";"int32"];
["int64" ], ["Deriving_Default";"int64"];
["Int64";"t"], ["Deriving_Default";"int64"];
["nativeint"], ["Deriving_Default";"nativeint"];
["float" ], ["Deriving_Default";"float"];
["string" ], ["Deriving_Default";"string"];
["list" ], ["Deriving_Default";"list"];
["ref" ], ["Deriving_Default";"ref"];
["option" ], ["Deriving_Default";"option"];
["array" ], ["Deriving_Default";"array"];
]
let depends = []
end
module Builder(Generator : Defs.Generator) = struct
open Generator.Loc
open Camlp4.PreCast
open Description
module Helpers = Generator.AstHelpers
let wrap expr = [ <:str_item< let default () = $expr$ >> ]
let generator = (object (self)
inherit Generator.generator
method proxy unit =
None, [ <:ident< default >> ]
method tuple ctxt args =
let l : Ast.expr list = List.map (fun ty -> <:expr<$self#call_expr ctxt ty "default"$ () >>) args
in
wrap (Helpers.tuple_expr l)
method case ctxt (name, args) =
match args with
| [] -> <:expr< $uid:name$ >>
| _ ->
let tuple = List.map (fun ty -> <:expr<$self#call_expr ctxt ty "default"$ () >>) args in
<:expr< $uid:name$ $Helpers.tuple_expr tuple$ >>
method sum ?eq ctxt tname params constraints summands =
wrap (self#case ctxt (List.hd summands))
method record ?eq ctxt tname params constraints fields =
let contents = List.map (fun (name, (_,ty), _) ->
name,
<:expr< $ self # call_expr ctxt ty "default"$ ()>> ) fields in
wrap (Helpers.record_expr contents)
method polycase ctxt = function
| Type.Tag (name, []) ->
<:expr< `$name$ >>
| Type.Tag (name, [ty]) ->
let c = self#call_expr ctxt ty "default" in
<:expr<`$name$ ($c$ ()) >>
| Type.Tag (name, tys) ->
let ty = `Tuple tys in
let c = self#call_expr ctxt ty "default" in
<:expr<`$name$ ($c$ ()) >>
| Type.Extends t -> <:expr< assert false >>
method variant ctxt tname params constraints (_,tags) =
wrap (self#polycase ctxt (List.hd tags))
end :> Generator.generator)
let classname = Description.classname
let runtimename = Description.runtimename
let generate = Generator.generate generator
let generate_sigs = Generator.generate_sigs generator
let generate_expr = Generator.generate_expr generator
end
include Base.RegisterFullClass(Description)(Builder)
|