@@ -39,6 +39,7 @@ let make_module ctx mpath file loadp =
39
39
m_id = alloc_mid() ;
40
40
m_path = mpath;
41
41
m_types = [] ;
42
+ m_statics = None ;
42
43
m_extra = module_extra (Path. unique_full_path file) (Define. get_signature ctx.com.defines) (file_time file) (if ctx.in_macro then MMacro else MCode ) (get_policy ctx mpath);
43
44
} in
44
45
m
@@ -194,6 +195,7 @@ let module_pass_1 ctx m tdecls loadp =
194
195
if priv then (fst m.m_path @ [" _" ^ snd m.m_path], name) else (fst m.m_path, name)
195
196
in
196
197
let pt = ref None in
198
+ let globals = ref [] in
197
199
let rec make_decl acc decl =
198
200
let p = snd decl in
199
201
let check_type_name type_name meta =
@@ -205,6 +207,9 @@ let module_pass_1 ctx m tdecls loadp =
205
207
(match ! pt with
206
208
| None -> acc
207
209
| Some _ -> error " import and using may not appear after a type declaration" p)
210
+ | EGlobal d ->
211
+ globals := (d,p) :: ! globals;
212
+ acc;
208
213
| EClass d ->
209
214
let name = fst d.d_name in
210
215
pt := Some p;
@@ -341,6 +346,43 @@ let module_pass_1 ctx m tdecls loadp =
341
346
decl :: acc
342
347
in
343
348
let tdecls = List. fold_left make_decl [] tdecls in
349
+ let tdecls =
350
+ match ! globals with
351
+ | [] ->
352
+ tdecls
353
+ | globals ->
354
+ let first_pos = ref null_pos in
355
+ let fields = List. map (fun (d ,p ) ->
356
+ first_pos := p;
357
+ {
358
+ cff_name = d.d_name;
359
+ cff_doc = d.d_doc;
360
+ cff_pos = p;
361
+ cff_meta = d.d_meta;
362
+ cff_access = (AStatic ,null_pos) :: d.d_flags;
363
+ cff_kind = d.d_data;
364
+ }
365
+ ) globals in
366
+ let p = ! first_pos in
367
+ let c = EClass {
368
+ d_name = (snd m.m_path) ^ " _Statics_" , p;
369
+ d_flags = [HPrivate ];
370
+ d_data = fields;
371
+ d_doc = None ;
372
+ d_params = [] ;
373
+ d_meta = []
374
+ } in
375
+ let tdecls = make_decl tdecls (c,p) in
376
+ (match ! decls with
377
+ | (TClassDecl c ,_ ) :: _ ->
378
+ assert (m.m_statics = None );
379
+ m.m_statics < - Some c;
380
+ c.cl_kind < - KModuleStatics m;
381
+ c.cl_final < - true ;
382
+ | _ -> assert false );
383
+ tdecls
384
+
385
+ in
344
386
let decls = List. rev ! decls in
345
387
decls, List. rev tdecls
346
388
@@ -490,7 +532,16 @@ let init_module_type ctx context_init (decl,p) =
490
532
| [] ->
491
533
(match name with
492
534
| None ->
493
- ctx.m.module_types < - List. filter no_private (List. map (fun t -> t,p) types) @ ctx.m.module_types
535
+ ctx.m.module_types < - List. filter no_private (List. map (fun t -> t,p) types) @ ctx.m.module_types;
536
+ Option. may (fun c ->
537
+ context_init#add (fun () ->
538
+ ignore(c.cl_build() );
539
+ List. iter (fun cf ->
540
+ if has_class_field_flag cf CfPublic then
541
+ ctx.m.module_globals < - PMap. add cf.cf_name (TClassDecl c,cf.cf_name,p) ctx.m.module_globals
542
+ ) c.cl_ordered_statics
543
+ );
544
+ ) md.m_statics
494
545
| Some (newname ,pname ) ->
495
546
ctx.m.module_types < - (rebind (get_type tname) newname pname,p) :: ctx.m.module_types);
496
547
| [tsub,p2] ->
@@ -802,6 +853,9 @@ let init_module_type ctx context_init (decl,p) =
802
853
else
803
854
error " Abstract is missing underlying type declaration" a.a_pos
804
855
end
856
+ | EGlobal _ ->
857
+ (* nothing to do here as globals are collected into a special EClass *)
858
+ ()
805
859
806
860
let module_pass_2 ctx m decls tdecls p =
807
861
(* here is an additional PASS 1 phase, which define the type parameters for all module types.
0 commit comments