2 (****************************************************************************)
6 (* INRIA Rocquencourt *)
8 (* Copyright 2007 Institut National de Recherche en Informatique et *)
9 (* en Automatique. All rights reserved. This file is distributed under *)
10 (* the terms of the GNU Library General Public License, with the special *)
11 (* exception on linking described in LICENSE at the top of the Objective *)
12 (* Caml source tree. *)
14 (****************************************************************************)
17 * - Nicolas Pouillard: initial version
20 module Make (Ast : Sig.Ast) : Sig.DynAst with module Ast = Ast = struct
39 | Tag_module_binding ];
46 | Tag_module_type -> "module_type"
47 | Tag_sig_item -> "sig_item"
48 | Tag_with_constr -> "with_constr"
49 | Tag_module_expr -> "module_expr"
50 | Tag_str_item -> "str_item"
51 | Tag_class_type -> "class_type"
52 | Tag_class_sig_item -> "class_sig_item"
53 | Tag_class_expr -> "class_expr"
54 | Tag_class_str_item -> "class_str_item"
55 | Tag_match_case -> "match_case"
56 | Tag_ident -> "ident"
57 | Tag_binding -> "binding"
58 | Tag_rec_binding -> "rec_binding"
59 | Tag_module_binding -> "module_binding" ];
61 value ctyp_tag = Tag_ctyp;
62 value patt_tag = Tag_patt;
63 value expr_tag = Tag_expr;
64 value module_type_tag = Tag_module_type;
65 value sig_item_tag = Tag_sig_item;
66 value with_constr_tag = Tag_with_constr;
67 value module_expr_tag = Tag_module_expr;
68 value str_item_tag = Tag_str_item;
69 value class_type_tag = Tag_class_type;
70 value class_sig_item_tag = Tag_class_sig_item;
71 value class_expr_tag = Tag_class_expr;
72 value class_str_item_tag = Tag_class_str_item;
73 value match_case_tag = Tag_match_case;
74 value ident_tag = Tag_ident;
75 value binding_tag = Tag_binding;
76 value rec_binding_tag = Tag_rec_binding;
77 value module_binding_tag = Tag_module_binding;
80 external dyn_tag : tag 'a -> tag dyn = "%identity";
82 module Pack(X : sig type t 'a; end) = struct
83 (* These Obj.* hacks should be avoided with GADTs *)
84 type pack = (tag dyn * Obj.t);
86 value pack tag v = (dyn_tag tag, Obj.repr v);
87 value unpack (tag : tag 'a) (tag', obj) =
88 if dyn_tag tag = tag' then (Obj.obj obj : X.t 'a) else raise Pack_error;
89 value print_tag f (tag, _) = Format.pp_print_string f (string_of_tag tag);