Skip to content

Commit

Permalink
module-level static declarations (squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadako committed May 15, 2020
1 parent e9ba29d commit 991550d
Show file tree
Hide file tree
Showing 76 changed files with 1,156 additions and 256 deletions.
6 changes: 3 additions & 3 deletions src/codegen/gencommon/gencommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,11 @@ let new_ctx con =
gadd_type = (fun md should_filter ->
if should_filter then begin
gen.gtypes_list <- md :: gen.gtypes_list;
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
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;
Hashtbl.add gen.gtypes (t_path md) md;
end else gen.gafter_filters_ended <- (fun () ->
gen.gtypes_list <- md :: gen.gtypes_list;
gen.gmodules <- { m_id = alloc_mid(); m_path = (t_path md); m_types = [md]; m_extra = module_extra "" "" 0. MFake [] } :: gen.gmodules;
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;
Hashtbl.add gen.gtypes (t_path md) md;
) :: gen.gafter_filters_ended;
);
Expand Down Expand Up @@ -685,7 +685,7 @@ let reorder_modules gen =
Hashtbl.iter (fun md_path md ->
if not (Hashtbl.mem processed md_path) then begin
Hashtbl.add processed md_path true;
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
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
end
) modules

Expand Down
2 changes: 1 addition & 1 deletion src/codegen/gencommon/overloadingConstructor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ let ensure_super_is_first com cf =

let init com (empty_ctor_type : t) (empty_ctor_expr : texpr) (follow_type : t -> t) =
let basic = com.basic in
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
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
let msize = List.length com.types in
let processed, empty_ctors = Hashtbl.create msize, Hashtbl.create msize in

Expand Down
6 changes: 3 additions & 3 deletions src/codegen/gencommon/reflectionCFs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1482,8 +1482,8 @@ struct
match md with
| 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 ->
cl.cl_implements <- (baseinterface, []) :: cl.cl_implements
| TClassDecl ({ cl_kind = KAbstractImpl _ }) ->
(* don't add any base classes to abstract implementations *)
| TClassDecl ({ cl_kind = KAbstractImpl _ | KModuleStatics _ }) ->
(* don't add any base classes to abstract implementations and module statics *)
()
| 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 ->
cl.cl_super <- Some (baseclass,[])
Expand Down Expand Up @@ -1518,7 +1518,7 @@ let has_field_override cl name =
let configure ctx baseinterface ~slow_invoke =
let run md =
(match md with
| 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) ->
| 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) ->
if is_some cl.cl_super then begin
ignore (has_field_override cl (mk_internal_name "hx" "setField"));
ignore (has_field_override cl (mk_internal_name "hx" "setField_f"));
Expand Down
6 changes: 5 additions & 1 deletion src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,11 @@ let is_legacy_completion com = match com.json_out with
let get_entry_point com =
Option.map (fun path ->
let m = List.find (fun m -> m.m_path = path) com.modules in
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
let c =
match m.m_statics with
| Some c when (PMap.mem "main" c.cl_statics) -> c
| _ -> ExtList.List.find_map (fun t -> match t with TClassDecl c when c.cl_path = path -> Some c | _ -> None) m.m_types
in
let e = Option.get com.main in (* must be present at this point *)
(snd path, c, e)
) com.main_class
2 changes: 1 addition & 1 deletion src/context/display/displayToplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ let collect ctx tk with_type sort =

let add_type mt =
match mt with
| TClassDecl {cl_kind = KAbstractImpl _} -> ()
| TClassDecl {cl_kind = KAbstractImpl _ | KModuleStatics _} -> ()
| _ ->
let path = (t_infos mt).mt_path in
let mname = snd (t_infos mt).mt_module.m_path in
Expand Down
31 changes: 21 additions & 10 deletions src/context/display/documentSymbols.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,42 @@ let collect_module_symbols with_locals (pack,decls) =
expr_opt parent f.f_expr
in
let is_deprecated meta = Meta.has Meta.Deprecated meta in
let field parent parent_kind cff =
let field_parent = parent ^ "." ^ (fst cff.cff_name) in
let add_field kind = add (fst cff.cff_name) kind cff.cff_pos parent (is_deprecated cff.cff_meta) in
match cff.cff_kind with
let field' parent parent_kind cff_name cff_kind cff_access cff_pos cff_meta =
let field_parent = parent ^ "." ^ (fst cff_name) in
let add_field kind = add (fst cff_name) kind cff_pos parent (is_deprecated cff_meta) in
match cff_kind with
| FVar(_,eo) ->
add_field (
if parent_kind = EnumAbstract && not (List.mem_assoc AStatic cff.cff_access) then EnumMember
else if (List.mem_assoc AInline cff.cff_access) then Constant
if parent_kind = EnumAbstract && not (List.mem_assoc AStatic cff_access) then EnumMember
else if (List.mem_assoc AInline cff_access) then Constant
else Field
);
if with_locals then expr_opt field_parent eo
| FFun f ->
add_field (
if fst cff.cff_name = "new" then Constructor
else if ((parent_kind = EnumAbstract or parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff.cff_meta) then Operator
if fst cff_name = "new" then Constructor
else if ((parent_kind = EnumAbstract or parent_kind = Abstract) && Meta.has_one_of [Meta.Op; Meta.ArrayAccess; Meta.Resolve] cff_meta) then Operator
else Method
);
if with_locals then func field_parent f
| FProp(_,_,_,eo) ->
add_field Property;
if with_locals then expr_opt field_parent eo
in
let field parent parent_kind cff =
field' parent parent_kind cff.cff_name cff.cff_kind cff.cff_access cff.cff_pos cff.cff_meta
in
List.iter (fun (td,p) ->
let add_type d kind =
let string_of_path l = String.concat "." l in
let get_decl_path d =
let module_name = Path.module_name_of_file p.pfile in
let type_name = fst d.d_name in
let is_primary_type = type_name = module_name in
let type_path = if is_primary_type then pack else pack @ [module_name] in
type_path, type_name
in
let string_of_path l = String.concat "." l in
let add_type d kind =
let type_path, type_name = get_decl_path d in
add type_name kind p (string_of_path type_path) (is_deprecated d.d_meta);
string_of_path (type_path @ [type_name])
in
Expand Down Expand Up @@ -98,6 +105,10 @@ let collect_module_symbols with_locals (pack,decls) =
let kind = if Meta.has Meta.Enum d.d_meta then EnumAbstract else Abstract in
let parent = add_type d kind in
List.iter (field parent kind) d.d_data
| EStatic d ->
let path, name = get_decl_path d in
let dotpath = string_of_path (path @ [name]) in
field' dotpath Class d.d_name d.d_data d.d_flags p d.d_meta
) decls;
l

Expand Down
7 changes: 6 additions & 1 deletion src/context/display/syntaxExplorer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ let find_in_syntax symbols (pack,decls) =
expr_opt f.f_expr
and field cff =
check KClassField (fst cff.cff_name);
match cff.cff_kind with
field_kind cff.cff_kind
and field_kind cff_kind =
match cff_kind with
| FVar(tho,eo) ->
Option.may type_hint tho;
expr_opt eo
Expand Down Expand Up @@ -152,6 +154,9 @@ let find_in_syntax symbols (pack,decls) =
| AbFrom th | AbTo th | AbOver th -> type_hint th
| _ -> ()
) d.d_flags;
| EStatic d ->
check KModuleType (fst d.d_name);
field_kind d.d_data
) decls

let explore_uncached_modules tctx cs symbols =
Expand Down
1 change: 1 addition & 0 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ let create_fake_module ctx file =
m_id = alloc_mid();
m_path = (["$DEP"],file);
m_types = [];
m_statics = None;
m_extra = module_extra file (Define.get_signature ctx.com.defines) (file_time file) MFake [];
} in
Hashtbl.add fake_modules key mdep;
Expand Down
1 change: 1 addition & 0 deletions src/core/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ type type_def =
| EEnum of (enum_flag, enum_constructor list) definition
| ETypedef of (enum_flag, type_hint) definition
| EAbstract of (abstract_flag, class_field list) definition
| EStatic of (placed_access, class_field_kind) definition
| EImport of import
| EUsing of placed_name list

Expand Down
18 changes: 18 additions & 0 deletions src/core/display/completionItem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module CompletionModuleKind = struct
| TypeAlias
| Struct
| TypeParameter
| Static

let to_int = function
| Class -> 0
Expand All @@ -30,6 +31,7 @@ module CompletionModuleKind = struct
| TypeAlias -> 5
| Struct -> 6
| TypeParameter -> 7
| Static -> 8
end

module ImportStatus = struct
Expand Down Expand Up @@ -154,6 +156,22 @@ module CompletionModuleType = struct
has_constructor = ctor;
source = Syntax td;
}
| EStatic d ->
{
pack = pack;
name = fst d.d_name;
module_name = module_name;
pos = p;
is_private = List.exists (fun (f,_) -> f = APrivate) d.d_flags;
params = d.d_params;
meta = d.d_meta;
doc = d.d_doc;
is_extern = List.exists (fun (f,_) -> f = AExtern) d.d_flags;
is_final = true;
kind = Static;
has_constructor = No;
source = Syntax td;
}
| EImport _ | EUsing _ ->
raise Exit

Expand Down
1 change: 1 addition & 0 deletions src/core/json/genjson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ let generate_class ctx c =
| KMacroType -> "KMacroType",None
| KGenericBuild _ -> "KGenericBuild",None
| KAbstractImpl a -> "KAbstractImpl",Some (abstract_ref ctx a)
| KModuleStatics m -> "KModuleStatics",Some (generate_module_path m.m_path)
in
generate_adt ctx (Some (["haxe";"macro"],"ClassKind")) ctor args
in
Expand Down
1 change: 1 addition & 0 deletions src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ let null_module = {
m_id = alloc_mid();
m_path = [] , "";
m_types = [];
m_statics = None;
m_extra = module_extra "" "" 0. MFake [];
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ let s_class_kind = function
"KGenericBuild"
| KAbstractImpl a ->
Printf.sprintf "KAbstractImpl %s" (s_type_path a.a_path)
| KModuleStatics m ->
Printf.sprintf "KModuleStatics %s" (s_type_path m.m_path)

module Printer = struct

Expand Down
2 changes: 2 additions & 0 deletions src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ and tclass_kind =
| KMacroType
| KGenericBuild of class_field list
| KAbstractImpl of tabstract
| KModuleStatics of module_def

and metadata = Ast.metadata

Expand Down Expand Up @@ -312,6 +313,7 @@ and module_def = {
m_id : int;
m_path : path;
mutable m_types : module_type list;
mutable m_statics : tclass option;
m_extra : module_def_extra;
}

Expand Down
22 changes: 13 additions & 9 deletions src/filters/renameVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ let reserve_all_types ri com path_to_name =
List.iter (fun mt ->
let tinfos = t_infos mt in
let native_name = try fst (TypeloadCheck.get_native_name tinfos.mt_meta) with Not_found -> path_to_name tinfos.mt_path in
if native_name = "" then
match mt with
| TClassDecl c ->
List.iter (fun cf ->
let native_name = try fst (TypeloadCheck.get_native_name cf.cf_meta) with Not_found -> cf.cf_name in
reserve_init ri native_name
) c.cl_ordered_statics;
| _ -> ()
else
match mt with
| TClassDecl c when native_name = "" ->
List.iter (fun cf ->
let native_name = try fst (TypeloadCheck.get_native_name cf.cf_meta) with Not_found -> cf.cf_name in
reserve_init ri native_name
) c.cl_ordered_statics
| TClassDecl { cl_kind = KModuleStatics m; cl_ordered_statics = fl } ->
let prefix = Path.flat_path m.m_path ^ "_" in
List.iter (fun cf ->
let name = try fst (TypeloadCheck.get_native_name cf.cf_meta) with Not_found -> prefix ^ cf.cf_name in
reserve_init ri name
) fl
| _ ->
reserve_init ri native_name
) com.types

Expand Down
8 changes: 8 additions & 0 deletions src/generators/gencs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,14 @@ let generate con =
let old_dir = Sys.getcwd() in
Sys.chdir gen.gcon.file;
let cmd = "haxelib run hxcs hxcs_build.txt --haxe-version " ^ (string_of_int gen.gcon.version) ^ " --feature-level 1" in
let cmd =
match gen.gentry_point with
| Some (name,_,_) ->
let name = if gen.gcon.debug then name ^ "-Debug" else name in
cmd ^ " --out " ^ gen.gcon.file ^ "/bin/" ^ name
| _ ->
cmd
in
print_endline cmd;
if gen.gcon.run_command cmd <> 0 then failwith "Build failed";
Sys.chdir old_dir;
Expand Down
8 changes: 8 additions & 0 deletions src/generators/genjava.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,14 @@ let generate con =
let old_dir = Sys.getcwd() in
Sys.chdir gen.gcon.file;
let cmd = "haxelib run hxjava hxjava_build.txt --haxe-version " ^ (string_of_int gen.gcon.version) ^ " --feature-level 1" in
let cmd =
match gen.gentry_point with
| Some (name,_,_) ->
let name = if gen.gcon.debug then name ^ "-Debug" else name in
cmd ^ " --out " ^ gen.gcon.file ^ "/" ^ name
| _ ->
cmd
in
print_endline cmd;
if gen.gcon.run_command cmd <> 0 then failwith "Build failed";
Sys.chdir old_dir;
Expand Down
Loading

0 comments on commit 991550d

Please sign in to comment.