Skip to content

Commit

Permalink
Merge branch 'development' into gencpp_rework_mkii
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Nov 20, 2024
2 parents 078a5a8 + 5b757af commit a2f763a
Show file tree
Hide file tree
Showing 92 changed files with 512 additions and 162 deletions.
5 changes: 4 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"label": "make: haxe",
"type": "shell",
"command": "make ADD_REVISION=1 -s -j haxe",
"osx": {
"command": "eval $(opam env) && make ADD_REVISION=1 -s -j haxe",
},
"windows": {
"command": "make ADD_REVISION=1 -f Makefile.win -s -j haxe"
},
Expand Down Expand Up @@ -48,4 +51,4 @@
"problemMatcher": []
}
]
}
}
2 changes: 1 addition & 1 deletion src-json/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@
"name": "InheritDoc",
"metadata": ":inheritDoc",
"doc": "Append documentation from a parent field or class (if used without an argument) or from a specified class or field (if used like @:inheritDoc(pack.Some.field)).",
"targets": ["TClass", "TClass", "TEnum", "TAbstract", "TAnyField"]
"targets": ["TClass", "TEnum", "TAbstract", "TAnyField"]
},
{
"name": "InitPackage",
Expand Down
6 changes: 6 additions & 0 deletions src-json/warning.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
"doc": "Constructor call could not be inlined because a field is uninitialized",
"parent": "WTyper"
},
{
"name": "WUnsafeEnumEquality",
"doc": "Equality operations on enums with parameters might not work as expected",
"parent": "WTyper",
"enabled": false
},
{
"name": "WHxb",
"doc": "Hxb (either --hxb output or haxe compiler cache) related warnings"
Expand Down
15 changes: 15 additions & 0 deletions src-prebuild/prebuild.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type parsed_warning = {
w_doc : string;
w_parent : string option;
w_generic : bool;
w_enabled : bool;
}

type parsed_meta = {
Expand Down Expand Up @@ -143,6 +144,7 @@ let parse_warning json =
w_doc = get_field "doc" as_string fields;
w_parent = get_optional_field2 "parent" as_string fields;
w_generic = get_optional_field "generic" as_bool false fields;
w_enabled = get_optional_field "enabled" as_bool true fields;
}

let parse_file_array path map =
Expand Down Expand Up @@ -255,6 +257,15 @@ let gen_warning_obj warnings =
) warnings in
String.concat "\n" warning_str

let gen_disabled_warnings warnings =
let warning_str = ExtList.List.filter_map (fun w ->
if w.w_enabled then
None
else
Some w.w_name
) warnings in
String.concat ";" warning_str

let autogen_header = "(* This file is auto-generated using prebuild from files in src-json *)
(* Do not edit manually! *)
"
Expand Down Expand Up @@ -355,6 +366,10 @@ match Array.to_list (Sys.argv) with
print_endline "";
print_endline "let warning_obj = function";
print_endline (gen_warning_obj warnings);
print_endline ";;";
print_endline "let disabled_warnings = [";
print_endline (gen_disabled_warnings warnings);
print_endline "];;";
print_endline "";
print_endline "let from_string = function";
print_endline (gen_warning_parse warnings);
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module Setup = struct
message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Information)
);
com.warning <- (fun ?(depth=0) ?(from_macro=false) w options msg p ->
match Warning.get_mode w (com.warning_options @ options) with
match Warning.get_mode w (options @ com.warning_options) with
| WMEnable ->
let wobj = Warning.warning_obj w in
let msg = if wobj.w_generic then
Expand Down Expand Up @@ -578,6 +578,7 @@ module HighLevel = struct
let args = !each_args @ args in
let added_libs = Hashtbl.create 0 in
let server_mode = ref SMNone in
let hxml_stack = ref [] in
let create_context args =
let ctx = create (server_api.on_context_create()) args in
ctx
Expand Down Expand Up @@ -637,6 +638,11 @@ module HighLevel = struct
| arg :: l ->
match List.rev (ExtString.String.nsplit arg ".") with
| "hxml" :: _ :: _ when (match acc with "-cmd" :: _ | "--cmd" :: _ -> false | _ -> true) ->
let full_path = Extc.get_full_path arg in
if List.mem full_path !hxml_stack then
raise (Arg.Bad (Printf.sprintf "Duplicate hxml inclusion: %s" full_path))
else
hxml_stack := full_path :: !hxml_stack;
let acc, l = (try acc, Helper.parse_hxml arg @ l with Not_found -> (arg ^ " (file not found)") :: acc, l) in
loop acc l
| _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/displayProcessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let process_display_configuration ctx =
add_diagnostics_message ?depth com s p DKCompilerMessage Information
);
com.warning <- (fun ?(depth = 0) ?from_macro w options s p ->
match Warning.get_mode w (com.warning_options @ options) with
match Warning.get_mode w (options @ com.warning_options) with
| WMEnable ->
let wobj = Warning.warning_obj w in
add_diagnostics_message ~depth ~code:(Some wobj.w_name) com s p DKCompilerMessage Warning
Expand Down
2 changes: 1 addition & 1 deletion src/context/abstractCast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ let handle_abstract_casts ctx e =
| TCast(e2,None) ->
{e1 with eexpr = TCast(find_field e2,None)}
| TField(e2,fa) ->
let e2 = loop e2 in
let a,pl,e2 = find_abstract e2 e2.etype in
let e2 = loop e2 in
let m = Abstract.get_underlying_type a pl in
let fname = field_name fa in
let el = List.map loop el in
Expand Down
2 changes: 1 addition & 1 deletion src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ let create compilation_step cs version args display_mode =
get_macros = (fun() -> None);
info = (fun ?depth ?from_macro _ _ -> die "" __LOC__);
warning = (fun ?depth ?from_macro _ _ _ -> die "" __LOC__);
warning_options = [];
warning_options = [List.map (fun w -> {wo_warning = w;wo_mode = WMDisable}) WarningList.disabled_warnings];
error = (fun ?depth _ _ -> die "" __LOC__);
error_ext = (fun _ -> die "" __LOC__);
get_messages = (fun() -> []);
Expand Down
11 changes: 1 addition & 10 deletions src/context/display/display.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,12 @@ let preprocess_expr com e = match com.display.dms_kind with
| DMSignature -> ExprPreprocessing.find_display_call e
| _ -> e

let get_expected_name with_type = match with_type with
| WithType.Value (Some src) | WithType.WithType(_,Some src) ->
(match src with
| WithType.FunctionArgument si -> Some si.si_name
| WithType.StructureField si -> Some si .si_name
| WithType.ImplicitReturn -> None
)
| _ -> None

let sort_fields l with_type tk =
let p = match tk with
| TKExpr p | TKField p -> Some p
| _ -> None
in
let expected_name = get_expected_name with_type in
let expected_name = WithType.get_expected_name with_type in
let l = List.map (fun ci ->
let i = get_sort_index tk ci (Option.default Globals.null_pos p) expected_name in
ci,i
Expand Down
3 changes: 2 additions & 1 deletion src/context/display/displayException.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ let to_json ctx de =
let named_source_kind = function
| WithType.FunctionArgument name -> (0, name)
| WithType.StructureField name -> (1, name)
| _ -> die "" __LOC__
| LocalVariable name -> (2, name)
| ImplicitReturn -> die "" __LOC__
in
let ctx = Genjson.create_context GMFull in
let generate_name kind =
Expand Down
2 changes: 1 addition & 1 deletion src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ let type_generic_function_ref : (typer -> field_access -> (unit -> texpr) field_
let create_context_ref : (Common.context -> ((unit -> unit) * typer) option -> typer) ref = ref (fun _ -> assert false)

let warning ?(depth=0) ctx w msg p =
let options = (Warning.from_meta ctx.c.curclass.cl_meta) @ (Warning.from_meta ctx.f.curfield.cf_meta) in
let options = (Warning.from_meta ctx.f.curfield.cf_meta) @ (Warning.from_meta ctx.c.curclass.cl_meta) in
match Warning.get_mode w options with
| WMEnable ->
module_warning ctx.com ctx.m.curmod w options msg p
Expand Down
3 changes: 2 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,11 @@ type flag_tclass_field =
| CfPostProcessed (* Marker to indicate the field has been post-processed *)
| CfUsed (* Marker for DCE *)
| CfMaybeUsed (* Marker for DCE *)
| CfNoLookup (* Field cannot be accessed by-name. *)

(* Order has to match declaration for printing*)
let flag_tclass_field_names = [
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault";"CfPostProcessed";"CfUsed";"CfMaybeUsed"
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault";"CfPostProcessed";"CfUsed";"CfMaybeUsed";"CfNoLookup"
]

type flag_tenum =
Expand Down
1 change: 1 addition & 0 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ let duplicate_tvars f_this e =
let v2 = alloc_var v.v_kind v.v_name v.v_type v.v_pos in
v2.v_meta <- v.v_meta;
v2.v_extra <- v.v_extra;
v2.v_flags <- v.v_flags;
Hashtbl.add vars v.v_id v2;
v2;
in
Expand Down
19 changes: 11 additions & 8 deletions src/core/warning.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@ let get_mode w (l : warning_option list list) =
| None -> false
| Some w' -> matches w' id
in
let rec loop mode l = match l with
let rec loop l = match l with
| [] ->
mode
WMEnable
| l2 :: l ->
let rec loop2 mode l = match l with
let rec loop2 l = match l with
| [] ->
mode
None
| opt :: l ->
let mode = if matches w opt.wo_warning then opt.wo_mode else mode in
loop2 mode l
if matches w opt.wo_warning then Some opt.wo_mode else loop2 l
in
loop (loop2 mode l2) l
match loop2 l2 with
| None ->
loop l
| Some mode ->
mode
in
loop WMEnable (* ? *) l
loop l
45 changes: 37 additions & 8 deletions src/core/withType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type with_type_source_information = {
type with_type_source =
| FunctionArgument of with_type_source_information
| StructureField of with_type_source_information
| LocalVariable of with_type_source_information
| ImplicitReturn

type t =
Expand All @@ -25,18 +26,46 @@ let of_implicit_return t = WithType(t,Some ImplicitReturn)
let with_argument t name = WithType(t,Some(FunctionArgument (make_with_type_source_information name None)))
let with_argument_and_doc t name doc = WithType(t,Some(FunctionArgument (make_with_type_source_information name (Some doc))))
let with_structure_field t name = WithType(t,Some(StructureField (make_with_type_source_information name None)))
let with_local_variable t name = WithType(t,Some(LocalVariable (make_with_type_source_information name None)))
let value = Value None
let named_argument name = Value (Some(FunctionArgument (make_with_type_source_information name None)))
let named_structure_field name = Value (Some(StructureField (make_with_type_source_information name None)))
let no_value = NoValue

let get_source_info_name = function
| FunctionArgument si -> Some si.si_name
| StructureField si -> Some si.si_name
| LocalVariable si -> Some si.si_name
| ImplicitReturn -> None

let string_of_with_type_source = function
| FunctionArgument si ->
Printf.sprintf "FunctionArgument(%s)" si.si_name
| StructureField si ->
Printf.sprintf "StructureField(%s)" si.si_name
| LocalVariable si ->
Printf.sprintf "LocalVariable(%s)" si.si_name
| ImplicitReturn ->
"ImplicitReturn"

let get_expected_name with_type = match with_type with
| Value (Some si) | WithType(_,Some si) ->
get_source_info_name si
| _ ->
None

let to_string = function
| NoValue -> "NoValue"
| Value (None | Some ImplicitReturn) -> "Value"
| Value (Some(FunctionArgument si | StructureField si)) -> "Value " ^ si.si_name
| WithType(t,s) ->
let name = match s with
| Some(FunctionArgument si | StructureField si) -> si.si_name
| _ -> "None"
| NoValue ->
"NoValue"
| Value None ->
"Value(None)"
| Value (Some wts) ->
Printf.sprintf "Value(Some(%s))" (string_of_with_type_source wts)
| WithType(t,wts) ->
let s = match wts with
| None ->
"None"
| Some wts ->
Printf.sprintf "Some(%s)" (string_of_with_type_source wts)
in
Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) name
Printf.sprintf "WithType(%s, %s)" (s_type (print_context()) t) s
2 changes: 1 addition & 1 deletion src/filters/filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ module ForRemap = struct
| TFor(v,e1,e2) ->
let e1 = loop e1 in
let e2 = loop e2 in
let iterator = ForLoop.IterationKind.of_texpr ctx e1 (ForLoop.is_cheap_enough_t ctx e2) e.epos in
let iterator = ForLoop.IterationKind.of_texpr ctx e1 (ForLoop.get_unroll_params_t ctx e2) e.epos in
let restore = save_locals ctx in
let e = ForLoop.IterationKind.to_texpr ctx v iterator e2 e.epos in
restore();
Expand Down
3 changes: 2 additions & 1 deletion src/filters/localStatic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let promote_local_static lsctx run v eo =
] v.v_pos);
with Not_found ->
let cf = mk_field name ~static:true v.v_type v.v_pos v.v_pos in
cf.cf_meta <- v.v_meta;
cf.cf_meta <- (Meta.NoCompletion,[],Globals.null_pos) :: v.v_meta;
add_class_field_flag cf CfNoLookup;
begin match eo with
| None ->
()
Expand Down
2 changes: 1 addition & 1 deletion src/generators/hlopt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ let remap_fun ctx f dump get_str old_code =
if p < 0 || (match op p with ONop _ -> false | _ -> true) then [(i,p)] else
let reg, last_w = try Hashtbl.find ctx.r_reg_moved p with Not_found -> (-1,-1) in
if reg < 0 then [] (* ? *) else
if reg < nargs then [(i,-reg-1)] else
if reg < nargs then [(i,-reg-2)] else
let b = resolve_block p in
if last_w >= b.bstart && last_w < b.bend && last_w < p then loop last_w else
let wp = try PMap.find reg b.bwrite with Not_found -> -1 in
Expand Down
21 changes: 17 additions & 4 deletions src/typing/calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ let call_to_string ctx ?(resume=false) e =
mk (TIf (check_null, string_null, Some (gen_to_string e))) ctx.t.tstring e.epos
end

let type_bind ctx (e : texpr) (args,ret) params p =
let type_bind ctx (e : texpr) (args,ret) params safe p =
let vexpr v = mk (TLocal v) v.v_type p in
let acount = ref 0 in
let alloc_name n =
Expand Down Expand Up @@ -409,10 +409,23 @@ let type_bind ctx (e : texpr) (args,ret) params p =
let e_var = alloc_var VGenerated gen_local_prefix e.etype e.epos in
(mk (TLocal e_var) e.etype e.epos), (mk (TVar(e_var,Some e)) ctx.t.tvoid e.epos) :: var_decls
in
let call = make_call ctx e ordered_args ret p in
let e_body = if safe then begin
let eobj, tempvar = get_safe_nav_base ctx e in
let sn = {
sn_pos = p;
sn_base = eobj;
sn_temp_var = tempvar;
sn_access = AKExpr e; (* This is weird, but it's not used by safe_nav_branch. *)
} in
safe_nav_branch ctx sn (fun () ->
make_call ctx eobj ordered_args ret p
)
end else
make_call ctx e ordered_args ret p
in
let body =
if ExtType.is_void (follow ret) then call
else mk (TReturn(Some call)) ret p
if ExtType.is_void (follow ret) then e_body
else mk (TReturn(Some e_body)) ret p
in
let arg_default optional t =
if optional then Some (Texpr.Builder.make_null t null_pos)
Expand Down
5 changes: 5 additions & 0 deletions src/typing/fields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
acc
) c.cl_implements
in
let no_no_lookup cf =
if has_class_field_flag cf CfNoLookup then display_error ctx.com "This field cannot be accessed explicitly" pfield
in
let rec type_field_by_type e t =
let field_access = field_access e in
match t with
Expand All @@ -334,6 +337,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
begin try
let cf = PMap.find i c.cl_statics in
if has_class_field_flag cf CfImpl && not (has_class_field_flag cf CfEnum) then display_error ctx.com "Cannot access non-static abstract field statically" pfield;
no_no_lookup cf;
field_access cf (FHStatic c)
with Not_found ->
begin match c.cl_kind with
Expand Down Expand Up @@ -401,6 +405,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
let c = find_some a.a_impl in
let f = PMap.find i c.cl_statics in
if not (has_class_field_flag f CfImpl) then raise Not_found;
no_no_lookup f;
field_access f (FHAbstract (a,tl,c))
with Not_found ->
type_field_by_forward_member type_field_by_type e a tl
Expand Down
Loading

0 comments on commit a2f763a

Please sign in to comment.