aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2014-01-19 17:20:58 +0100
committerPierre-Marie Pédrot2014-01-19 17:35:59 +0100
commita532777dcfc59128be2daa7cc74c7881a06f8cb3 (patch)
tree97cde2983485df683a6a82780f1365c47aacadf7 /lib
parent7e6e533b148c9d57251388e9f1646a6829d10bfb (diff)
Adding a default object to generic argument registering mechanism.
Diffstat (limited to 'lib')
-rw-r--r--lib/genarg.ml6
-rw-r--r--lib/genarg.mli3
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/genarg.ml b/lib/genarg.ml
index 3fb8155106..58dfbc91a1 100644
--- a/lib/genarg.ml
+++ b/lib/genarg.ml
@@ -194,6 +194,7 @@ module type GenObj =
sig
type ('raw, 'glb, 'top) obj
val name : string
+ val default : ('raw, 'glb, 'top) genarg_type -> ('raw, 'glb, 'top) obj option
end
module Register (M : GenObj) =
@@ -213,7 +214,10 @@ struct
let get_obj0 name =
try String.Map.find name !arg0_map
with Not_found ->
- Errors.anomaly (str M.name ++ str " function not found: " ++ str name)
+ match M.default (ExtraArgType name) with
+ | None ->
+ Errors.anomaly (str M.name ++ str " function not found: " ++ str name)
+ | Some obj -> obj
(** For now, the following function is quite dummy and should only be applied
to an extra argument type, otherwise, it will badly fail. *)
diff --git a/lib/genarg.mli b/lib/genarg.mli
index f275b0d004..6eea3ac926 100644
--- a/lib/genarg.mli
+++ b/lib/genarg.mli
@@ -227,6 +227,9 @@ sig
val name : string
(** A name for such kind of manipulation, e.g. [interp]. *)
+
+ val default : ('raw, 'glb, 'top) genarg_type -> ('raw, 'glb, 'top) obj option
+ (** A generic object when there is no registered object for this type. *)
end
module Register (M : GenObj) :