Skip to content

Commit feda1ac

Browse files
committed
module-level static declarations (squashed)
1 parent a5cbd5a commit feda1ac

File tree

76 files changed

+1156
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1156
-256
lines changed

src/codegen/gencommon/gencommon.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ let new_ctx con =
620620
gadd_type = (fun md should_filter ->
621621
if should_filter then begin
622622
gen.gtypes_list <- md :: gen.gtypes_list;
623-
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
623+
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_statics = None; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
624624
Hashtbl.add gen.gtypes (t_path md) md;
625625
end else gen.gafter_filters_ended <- (fun () ->
626626
gen.gtypes_list <- md :: gen.gtypes_list;
627-
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
627+
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_statics = None; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
628628
Hashtbl.add gen.gtypes (t_path md) md;
629629
) :: gen.gafter_filters_ended;
630630
);
@@ -685,7 +685,7 @@ let reorder_modules gen =
685685
Hashtbl.iter (fun md_path md ->
686686
if not (Hashtbl.mem processed md_path) then begin
687687
Hashtbl.add processed md_path true;
688-
gen.gmodules <- { m_id = alloc_mid(); m_path = md_path; m_types = List.rev ( Hashtbl.find_all modules md_path ); m_extra = (t_infos md).mt_module.m_extra } :: gen.gmodules
688+
gen.gmodules <- { m_id = alloc_mid(); m_path = md_path; m_types = List.rev ( Hashtbl.find_all modules md_path ); m_statics = None; m_extra = (t_infos md).mt_module.m_extra } :: gen.gmodules
689689
end
690690
) modules
691691

src/codegen/gencommon/overloadingConstructor.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ let ensure_super_is_first com cf =
284284

285285
let init com (empty_ctor_type : t) (empty_ctor_expr : texpr) (follow_type : t -> t) =
286286
let basic = com.basic in
287-
let should_change cl = not cl.cl_interface && (not cl.cl_extern || is_hxgen (TClassDecl cl)) && (match cl.cl_kind with KAbstractImpl _ -> false | _ -> true) in
287+
let should_change cl = not cl.cl_interface && (not cl.cl_extern || is_hxgen (TClassDecl cl)) && (match cl.cl_kind with KAbstractImpl _ | KModuleStatics _ -> false | _ -> true) in
288288
let msize = List.length com.types in
289289
let processed, empty_ctors = Hashtbl.create msize, Hashtbl.create msize in
290290

src/codegen/gencommon/reflectionCFs.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1482,8 +1482,8 @@ struct
14821482
match md with
14831483
| TClassDecl ({ cl_interface = true } as cl) when cl.cl_path <> baseclass.cl_path && cl.cl_path <> baseinterface.cl_path && cl.cl_path <> basedynamic.cl_path ->
14841484
cl.cl_implements <- (baseinterface, []) :: cl.cl_implements
1485-
| TClassDecl ({ cl_kind = KAbstractImpl _ }) ->
1486-
(* don't add any base classes to abstract implementations *)
1485+
| TClassDecl ({ cl_kind = KAbstractImpl _ | KModuleStatics _ }) ->
1486+
(* don't add any base classes to abstract implementations and module statics *)
14871487
()
14881488
| TClassDecl ({ cl_super = None } as cl) when cl.cl_path <> baseclass.cl_path && cl.cl_path <> baseinterface.cl_path && cl.cl_path <> basedynamic.cl_path ->
14891489
cl.cl_super <- Some (baseclass,[])
@@ -1518,7 +1518,7 @@ let has_field_override cl name =
15181518
let configure ctx baseinterface ~slow_invoke =
15191519
let run md =
15201520
(match md with
1521-
| TClassDecl ({ cl_extern = false } as cl) when is_hxgen md && ( not cl.cl_interface || cl.cl_path = baseinterface.cl_path ) && (match cl.cl_kind with KAbstractImpl _ -> false | _ -> true) ->
1521+
| TClassDecl ({ cl_extern = false } as cl) when is_hxgen md && ( not cl.cl_interface || cl.cl_path = baseinterface.cl_path ) && (match cl.cl_kind with KAbstractImpl _ | KModuleStatics _ -> false | _ -> true) ->
15221522
if is_some cl.cl_super then begin
15231523
ignore (has_field_override cl (mk_internal_name "hx" "setField"));
15241524
ignore (has_field_override cl (mk_internal_name "hx" "setField_f"));

src/context/common.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,11 @@ let is_legacy_completion com = match com.json_out with
968968
let get_entry_point com =
969969
Option.map (fun path ->
970970
let m = List.find (fun m -> m.m_path = path) com.modules in
971-
let c = ExtList.List.find_map (fun t -> match t with TClassDecl c when c.cl_path = path -> Some c | _ -> None) m.m_types in
971+
let c =
972+
match m.m_statics with
973+
| Some c when (PMap.mem "main" c.cl_statics) -> c
974+
| _ -> ExtList.List.find_map (fun t -> match t with TClassDecl c when c.cl_path = path -> Some c | _ -> None) m.m_types
975+
in
972976
let e = Option.get com.main in (* must be present at this point *)
973977
(snd path, c, e)
974978
) com.main_class

src/context/display/displayToplevel.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ let collect ctx tk with_type sort =
213213

214214
let add_type mt =
215215
match mt with
216-
| TClassDecl {cl_kind = KAbstractImpl _} -> ()
216+
| TClassDecl {cl_kind = KAbstractImpl _ | KModuleStatics _} -> ()
217217
| _ ->
218218
let path = (t_infos mt).mt_path in
219219
let mname = snd (t_infos mt).mt_module.m_path in

src/context/display/documentSymbols.ml

+21-10
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,42 @@ let collect_module_symbols with_locals (pack,decls) =
4242
expr_opt parent f.f_expr
4343
in
4444
let is_deprecated meta = Meta.has Meta.Deprecated meta in
45-
let field parent parent_kind cff =
46-
let field_parent = parent ^ "." ^ (fst cff.cff_name) in
47-
let add_field kind = add (fst cff.cff_name) kind cff.cff_pos parent (is_deprecated cff.cff_meta) in
48-
match cff.cff_kind with
45+
let field' parent parent_kind cff_name cff_kind cff_access cff_pos cff_meta =
46+
let field_parent = parent ^ "." ^ (fst cff_name) in
47+
let add_field kind = add (fst cff_name) kind cff_pos parent (is_deprecated cff_meta) in
48+
match cff_kind with
4949
| FVar(_,eo) ->
5050
add_field (
51-
if parent_kind = EnumAbstract && not (List.mem_assoc AStatic cff.cff_access) then EnumMember
52-
else if (List.mem_assoc AInline cff.cff_access) then Constant
51+
if parent_kind = EnumAbstract && not (List.mem_assoc AStatic cff_access) then EnumMember
52+
else if (List.mem_assoc AInline cff_access) then Constant
5353
else Field
5454
);
5555
if with_locals then expr_opt field_parent eo
5656
| FFun f ->
5757
add_field (
58-
if fst cff.cff_name = "new" then Constructor
59-
else if ((parent_kind = EnumAbstract or parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff.cff_meta) then Operator
58+
if fst cff_name = "new" then Constructor
59+
else if ((parent_kind = EnumAbstract or parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff_meta) then Operator
6060
else Method
6161
);
6262
if with_locals then func field_parent f
6363
| FProp(_,_,_,eo) ->
6464
add_field Property;
6565
if with_locals then expr_opt field_parent eo
6666
in
67+
let field parent parent_kind cff =
68+
field' parent parent_kind cff.cff_name cff.cff_kind cff.cff_access cff.cff_pos cff.cff_meta
69+
in
6770
List.iter (fun (td,p) ->
68-
let add_type d kind =
69-
let string_of_path l = String.concat "." l in
71+
let get_decl_path d =
7072
let module_name = Path.module_name_of_file p.pfile in
7173
let type_name = fst d.d_name in
7274
let is_primary_type = type_name = module_name in
7375
let type_path = if is_primary_type then pack else pack @ [module_name] in
76+
type_path, type_name
77+
in
78+
let string_of_path l = String.concat "." l in
79+
let add_type d kind =
80+
let type_path, type_name = get_decl_path d in
7481
add type_name kind p (string_of_path type_path) (is_deprecated d.d_meta);
7582
string_of_path (type_path @ [type_name])
7683
in
@@ -98,6 +105,10 @@ let collect_module_symbols with_locals (pack,decls) =
98105
let kind = if Meta.has Meta.Enum d.d_meta then EnumAbstract else Abstract in
99106
let parent = add_type d kind in
100107
List.iter (field parent kind) d.d_data
108+
| EStatic d ->
109+
let path, name = get_decl_path d in
110+
let dotpath = string_of_path (path @ [name]) in
111+
field' dotpath Class d.d_name d.d_data d.d_flags p d.d_meta
101112
) decls;
102113
l
103114

src/context/display/syntaxExplorer.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ let find_in_syntax symbols (pack,decls) =
9797
expr_opt f.f_expr
9898
and field cff =
9999
check KClassField (fst cff.cff_name);
100-
match cff.cff_kind with
100+
field_kind cff.cff_kind
101+
and field_kind cff_kind =
102+
match cff_kind with
101103
| FVar(tho,eo) ->
102104
Option.may type_hint tho;
103105
expr_opt eo
@@ -152,6 +154,9 @@ let find_in_syntax symbols (pack,decls) =
152154
| AbFrom th | AbTo th | AbOver th -> type_hint th
153155
| _ -> ()
154156
) d.d_flags;
157+
| EStatic d ->
158+
check KModuleType (fst d.d_name);
159+
field_kind d.d_data
155160
) decls
156161

157162
let explore_uncached_modules tctx cs symbols =

src/context/typecore.ml

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ let create_fake_module ctx file =
354354
m_id = alloc_mid();
355355
m_path = (["$DEP"],file);
356356
m_types = [];
357+
m_statics = None;
357358
m_extra = module_extra file (Define.get_signature ctx.com.defines) (file_time file) MFake [];
358359
} in
359360
Hashtbl.add fake_modules file mdep;

src/core/ast.ml

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ type type_def =
321321
| EEnum of (enum_flag, enum_constructor list) definition
322322
| ETypedef of (enum_flag, type_hint) definition
323323
| EAbstract of (abstract_flag, class_field list) definition
324+
| EStatic of (placed_access, class_field_kind) definition
324325
| EImport of import
325326
| EUsing of placed_name list
326327

src/core/display/completionItem.ml

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module CompletionModuleKind = struct
2020
| TypeAlias
2121
| Struct
2222
| TypeParameter
23+
| Static
2324

2425
let to_int = function
2526
| Class -> 0
@@ -30,6 +31,7 @@ module CompletionModuleKind = struct
3031
| TypeAlias -> 5
3132
| Struct -> 6
3233
| TypeParameter -> 7
34+
| Static -> 8
3335
end
3436

3537
module ImportStatus = struct
@@ -154,6 +156,22 @@ module CompletionModuleType = struct
154156
has_constructor = ctor;
155157
source = Syntax td;
156158
}
159+
| EStatic d ->
160+
{
161+
pack = pack;
162+
name = fst d.d_name;
163+
module_name = module_name;
164+
pos = p;
165+
is_private = List.exists (fun (f,_) -> f = APrivate) d.d_flags;
166+
params = d.d_params;
167+
meta = d.d_meta;
168+
doc = d.d_doc;
169+
is_extern = List.exists (fun (f,_) -> f = AExtern) d.d_flags;
170+
is_final = true;
171+
kind = Static;
172+
has_constructor = No;
173+
source = Syntax td;
174+
}
157175
| EImport _ | EUsing _ ->
158176
raise Exit
159177

src/core/json/genjson.ml

+1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ let generate_class ctx c =
584584
| KMacroType -> "KMacroType",None
585585
| KGenericBuild _ -> "KGenericBuild",None
586586
| KAbstractImpl a -> "KAbstractImpl",Some (abstract_ref ctx a)
587+
| KModuleStatics m -> "KModuleStatics",Some (generate_module_path m.m_path)
587588
in
588589
generate_adt ctx (Some (["haxe";"macro"],"ClassKind")) ctor args
589590
in

src/core/tFunctions.ml

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ let null_module = {
156156
m_id = alloc_mid();
157157
m_path = [] , "";
158158
m_types = [];
159+
m_statics = None;
159160
m_extra = module_extra "" "" 0. MFake [];
160161
}
161162

src/core/tPrinting.ml

+2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ let s_class_kind = function
423423
"KGenericBuild"
424424
| KAbstractImpl a ->
425425
Printf.sprintf "KAbstractImpl %s" (s_type_path a.a_path)
426+
| KModuleStatics m ->
427+
Printf.sprintf "KModuleStatics %s" (s_type_path m.m_path)
426428

427429
module Printer = struct
428430

src/core/tType.ml

+2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ and tclass_kind =
185185
| KMacroType
186186
| KGenericBuild of class_field list
187187
| KAbstractImpl of tabstract
188+
| KModuleStatics of module_def
188189

189190
and metadata = Ast.metadata
190191

@@ -312,6 +313,7 @@ and module_def = {
312313
m_id : int;
313314
m_path : path;
314315
mutable m_types : module_type list;
316+
mutable m_statics : tclass option;
315317
m_extra : module_def_extra;
316318
}
317319

src/filters/filters.ml

+13-9
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,19 @@ let collect_reserved_local_names com =
203203
List.iter (fun mt ->
204204
let tinfos = t_infos mt in
205205
let native_name = try fst (get_native_name tinfos.mt_meta) with Not_found -> Path.flat_path tinfos.mt_path in
206-
if native_name = "" then
207-
match mt with
208-
| TClassDecl c ->
209-
List.iter (fun cf ->
210-
let native_name = try fst (get_native_name cf.cf_meta) with Not_found -> cf.cf_name in
211-
add native_name
212-
) c.cl_ordered_statics;
213-
| _ -> ()
214-
else
206+
match mt with
207+
| TClassDecl c when native_name = "" ->
208+
List.iter (fun cf ->
209+
let native_name = try fst (get_native_name cf.cf_meta) with Not_found -> cf.cf_name in
210+
add native_name
211+
) c.cl_ordered_statics
212+
| TClassDecl { cl_kind = KModuleStatics m; cl_ordered_statics = fl } ->
213+
let prefix = Path.flat_path m.m_path ^ "_" in
214+
List.iter (fun cf ->
215+
let name = try fst (get_native_name cf.cf_meta) with Not_found -> prefix ^ cf.cf_name in
216+
add name
217+
) fl
218+
| _ ->
215219
add native_name
216220
) com.types;
217221
!h

src/generators/gencs.ml

+8
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,14 @@ let generate con =
34843484
let old_dir = Sys.getcwd() in
34853485
Sys.chdir gen.gcon.file;
34863486
let cmd = "haxelib run hxcs hxcs_build.txt --haxe-version " ^ (string_of_int gen.gcon.version) ^ " --feature-level 1" in
3487+
let cmd =
3488+
match gen.gentry_point with
3489+
| Some (name,_,_) ->
3490+
let name = if gen.gcon.debug then name ^ "-Debug" else name in
3491+
cmd ^ " --out " ^ gen.gcon.file ^ "/bin/" ^ name
3492+
| _ ->
3493+
cmd
3494+
in
34873495
print_endline cmd;
34883496
if gen.gcon.run_command cmd <> 0 then failwith "Build failed";
34893497
Sys.chdir old_dir;

src/generators/genjava.ml

+8
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,14 @@ let generate con =
26672667
let old_dir = Sys.getcwd() in
26682668
Sys.chdir gen.gcon.file;
26692669
let cmd = "haxelib run hxjava hxjava_build.txt --haxe-version " ^ (string_of_int gen.gcon.version) ^ " --feature-level 1" in
2670+
let cmd =
2671+
match gen.gentry_point with
2672+
| Some (name,_,_) ->
2673+
let name = if gen.gcon.debug then name ^ "-Debug" else name in
2674+
cmd ^ " --out " ^ gen.gcon.file ^ "/" ^ name
2675+
| _ ->
2676+
cmd
2677+
in
26702678
print_endline cmd;
26712679
if gen.gcon.run_command cmd <> 0 then failwith "Build failed";
26722680
Sys.chdir old_dir;

0 commit comments

Comments
 (0)