|
@@ -963,7 +963,7 @@ let rec string_list_of_expr_path (e,p) =
|
|
|
| EField (e,f) -> f :: string_list_of_expr_path e
|
|
|
| _ -> error "Invalid path" p
|
|
|
|
|
|
-let build_module_def ctx mt meta fvars fbuild =
|
|
|
+let build_module_def ctx mt meta fvars context_init fbuild =
|
|
|
let rec loop = function
|
|
|
| (":build",args,p) :: l ->
|
|
|
let epath, el = (match args with
|
|
@@ -974,6 +974,7 @@ let build_module_def ctx mt meta fvars fbuild =
|
|
|
if ctx.in_macro then error "You cannot used :build inside a macro : make sure that your enum is not used in macro" p;
|
|
|
let old = ctx.g.get_build_infos in
|
|
|
ctx.g.get_build_infos <- (fun() -> Some (mt, fvars()));
|
|
|
+ context_init();
|
|
|
let r = try apply_macro ctx MBuild s el p with e -> ctx.g.get_build_infos <- old; raise e in
|
|
|
ctx.g.get_build_infos <- old;
|
|
|
(match r with
|
|
@@ -1004,7 +1005,7 @@ let init_class ctx c p context_init herits fields =
|
|
|
let fields = patch_class ctx c fields in
|
|
|
let fields = ref fields in
|
|
|
let get_fields() = !fields in
|
|
|
- build_module_def ctx (TClassDecl c) c.cl_meta get_fields (fun (e,p) ->
|
|
|
+ build_module_def ctx (TClassDecl c) c.cl_meta get_fields context_init (fun (e,p) ->
|
|
|
match e with
|
|
|
| EVars [_,Some (CTAnonymous f),None] -> fields := f
|
|
|
| _ -> error "Class build macro must return a single variable with anonymous fields" p
|
|
@@ -1684,7 +1685,8 @@ let init_module_type ctx context_init do_init (decl,p) =
|
|
|
}
|
|
|
) (!constructs)
|
|
|
in
|
|
|
- build_module_def ctx (TEnumDecl e) e.e_meta get_constructs (fun (e,p) ->
|
|
|
+ let init () = List.iter (fun f -> f()) !context_init in
|
|
|
+ build_module_def ctx (TEnumDecl e) e.e_meta get_constructs init (fun (e,p) ->
|
|
|
match e with
|
|
|
| EVars [_,Some (CTAnonymous fields),None] ->
|
|
|
constructs := List.map (fun f ->
|