Skip to content

Revert private getters/setters #12271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/codegen/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ open Extlib_leftovers
let rec has_properties c =
List.exists (fun f ->
match f.cf_kind with
| Var { v_read = AccCall | AccPrivateCall } -> true
| Var { v_write = AccCall | AccPrivateCall } -> true
| Var { v_read = AccCall } -> true
| Var { v_write = AccCall } -> true
| _ when Meta.has Meta.Accessor f.cf_meta -> true
| _ -> false
) c.cl_ordered_fields || (match c.cl_super with Some (c,_) -> has_properties c | _ -> false)
Expand All @@ -40,10 +40,10 @@ let get_properties fields =
(f.cf_name, f.cf_name) :: acc
else
let acc = (match f.cf_kind with
| Var { v_read = AccCall | AccPrivateCall } -> ("get_" ^ f.cf_name , "get_" ^ f.cf_name) :: acc
| Var { v_read = AccCall } -> ("get_" ^ f.cf_name , "get_" ^ f.cf_name) :: acc
| _ -> acc) in
match f.cf_kind with
| Var { v_write = AccCall | AccPrivateCall } -> ("set_" ^ f.cf_name , "set_" ^ f.cf_name) :: acc
| Var { v_write = AccCall } -> ("set_" ^ f.cf_name , "set_" ^ f.cf_name) :: acc
| _ -> acc
) [] fields

Expand Down
2 changes: 1 addition & 1 deletion src/codegen/genxml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ and gen_field att f =
match acc with
| AccNormal | AccRequire _ | AccCtor -> att
| AccNo | AccNever -> (name, "null") :: att
| AccCall | AccPrivateCall -> (name,"accessor") :: att
| AccCall -> (name,"accessor") :: att
| AccInline -> (name,"inline") :: att
in
let att = (match f.cf_expr with None -> att | Some e -> ("line",string_of_int (Lexer.get_error_line e.epos)) :: att) in
Expand Down
1 change: 0 additions & 1 deletion src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,6 @@ class hxb_reader
let s = self#read_string in
let so = self#read_option (fun () -> self#read_string) in
AccRequire(s,so)
| 7 -> AccPrivateCall
| i ->
error (Printf.sprintf "Bad accessor kind: %i" i)
in
Expand Down
1 change: 0 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,6 @@ module HxbWriter = struct
Chunk.write_u8 writer.chunk 6;
Chunk.write_string writer.chunk s;
Chunk.write_option writer.chunk so (Chunk.write_string writer.chunk)
| AccPrivateCall -> Chunk.write_u8 writer.chunk 7
in
f r;
f w
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/findReferences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let rec collect_reference_positions com (name,pos,kind) =
| Var vk ->
let host = FieldAccess.get_host c cf in
let check r mode = match r with
| AccCall | AccPrivateCall ->
| AccCall ->
begin match FieldAccess.find_accessor_for_field host cf cf.cf_type mode with
| AccessorFound (cf_acc,new_host) ->
let c_host = FieldAccess.get_host_class_raise new_host in
Expand Down
8 changes: 2 additions & 6 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,8 @@ let needs_inline ctx c cf =
cf.cf_kind = Method MethInline && ctx.allow_inline && (ctx.com.doinline || is_forced_inline c cf)

(** checks if we can access to a given class field using current context *)
let can_access ctx c cf ?(check_prop=false) ?(is_setter=false) stat =
let is_not_private_prop = not check_prop || match cf.cf_kind with
| Var { v_read = AccPrivateCall } when not is_setter -> false
| Var { v_write = AccPrivateCall } when is_setter -> false
| _ -> true in
if (is_not_private_prop && has_class_field_flag cf CfPublic) then
let can_access ctx c cf stat =
if (has_class_field_flag cf CfPublic) then
true
else if c == ctx.c.curclass then
true
Expand Down
3 changes: 1 addition & 2 deletions src/core/json/genjson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ and generate_class_field' ctx cfs cf =
| AccNever -> "AccNever",None
| AccCtor -> "AccCtor",None
| AccCall -> "AccCall",None
| AccPrivateCall -> "AccPrivateCall",None
| AccInline -> "AccInline",None
| AccRequire(s,so) -> "AccRequire",Some (jobject ["require",jstring s;"message",jopt jstring so])
in
Expand Down Expand Up @@ -737,4 +736,4 @@ let generate timer_ctx types file =
let ch = open_out_bin file in
Json.write_json (output_string ch) json;
close_out ch;
) ()
) ()
2 changes: 1 addition & 1 deletion src/core/tOther.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module TExprToExpr = struct
| AccNormal | AccCtor | AccInline | AccRequire _ -> "default"
| AccNo -> "null"
| AccNever -> "never"
| AccCall | AccPrivateCall -> get_or_set
| AccCall -> get_or_set
in
let read = (var_access_to_string v.v_read "get",null_pos) in
let write = (var_access_to_string v.v_write "set",null_pos) in
Expand Down
1 change: 0 additions & 1 deletion src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ let s_access is_read = function
| AccNo -> "null"
| AccNever -> "never"
| AccCall -> if is_read then "get" else "set"
| AccPrivateCall -> if is_read then "private get" else "private set"
| AccInline -> "inline"
| AccRequire (n,_) -> "require " ^ n
| AccCtor -> "ctor"
Expand Down
1 change: 0 additions & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ and var_access =
| AccNever (* can't be accessed, even in subclasses *)
| AccCtor (* can only be accessed from the constructor *)
| AccCall (* perform a method call when accessed *)
| AccPrivateCall (* perform a method call when accessed, but private like AccNo *)
| AccInline (* similar to Normal but inline when accessed *)
| AccRequire of string * string option (* set when @:require(cond) fails *)

Expand Down
7 changes: 3 additions & 4 deletions src/core/tUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,11 @@ let unify_access a1 a2 =
a1 = a2 || match a1, a2 with
| _, AccNo | _, AccNever -> true
| AccInline, AccNormal -> true
| AccCall, AccPrivateCall -> true
| _ -> false

let direct_access = function
| AccNo | AccNever | AccNormal | AccInline | AccRequire _ | AccCtor -> true
| AccCall | AccPrivateCall -> false
| AccCall -> false

let unify_kind ~(strict:bool) k1 k2 =
k1 = k2 || match k1, k2 with
Expand Down Expand Up @@ -909,8 +908,8 @@ let rec unify (uctx : unification_context) a b =
with Not_found ->
()
in
(match vk.v_read with AccCall | AccPrivateCall -> check ("get_" ^ f1.cf_name) | _ -> ());
(match vk.v_write with AccCall | AccPrivateCall -> check ("set_" ^ f1.cf_name) | _ -> ());
(match vk.v_read with AccCall -> check ("get_" ^ f1.cf_name) | _ -> ());
(match vk.v_write with AccCall -> check ("set_" ^ f1.cf_name) | _ -> ());
| _ -> ()
end;
(match f1.cf_kind with
Expand Down
16 changes: 8 additions & 8 deletions src/generators/cpp/cppRetyper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ let get_id path ids =
| None ->
let new_id = make_id 0 in
(new_id, ObjectIds.add path new_id ids)

let native_field_name_remap field =
match get_meta_string field.cf_meta Meta.Native with
| Some nativeImpl ->
Expand Down Expand Up @@ -1533,7 +1533,7 @@ let rec tcpp_class_from_tclass ctx ids slots class_def class_params =
tcv_type = field.cf_type;
tcv_default = None;

tcv_has_getter = (match field.cf_kind with | Var { v_read = AccCall | AccPrivateCall } -> true | _ -> false);
tcv_has_getter = (match field.cf_kind with | Var { v_read = AccCall } -> true | _ -> false);
tcv_is_stackonly = has_meta Meta.StackOnly field.cf_meta;
tcv_is_reflective = reflective class_def field;
tcv_is_gc_element = cpp_type_of field.cf_type |> is_gc_element ctx;
Expand Down Expand Up @@ -1567,14 +1567,14 @@ let rec tcpp_class_from_tclass ctx ids slots class_def class_params =
(* We can't implement abstract functions as pure virtual due to cppia needing to construct the class *)
let map_arg (name, _, t) =
( (alloc_var VGenerated name t null_pos), (get_default_value name) ) in
let expr =
let expr =
match follow ret with
| TAbstract ({ a_path = ([], "Void") }, _) ->
{ eexpr = TReturn None; etype = ret; epos = null_pos }
| _ ->
let zero_val = Some { eexpr = TConst (TInt Int32.zero); etype = ret; epos = null_pos } in
{ eexpr = TReturn zero_val; etype = ret; epos = null_pos } in

{
tf_args = args |> List.map map_arg;
tf_type = ret;
Expand Down Expand Up @@ -1611,7 +1611,7 @@ let rec tcpp_class_from_tclass ctx ids slots class_def class_params =
| Var _, _ ->
Some (create_variable field)
(* Dynamic methods are implemented as a physical field holding a closure *)
| Method MethDynamic, Some { eexpr = TFunction func } ->
| Method MethDynamic, Some { eexpr = TFunction func } ->
Some (create_variable { field with cf_expr = None; cf_kind = Var ({ v_read = AccNormal; v_write = AccNormal }) })
(* Below should cause abstracts which have functions with no implementation to be generated as a field *)
(* See Int32.hx as an example *)
Expand All @@ -1631,7 +1631,7 @@ let rec tcpp_class_from_tclass ctx ids slots class_def class_params =
None in

let id, ids = get_id class_def.cl_path ids in

let static_functions =
class_def.cl_ordered_statics
|> List.filter_map (filter_functions true) in
Expand All @@ -1650,7 +1650,7 @@ let rec tcpp_class_from_tclass ctx ids slots class_def class_params =
|> List.filter (fun field -> field.cf_name <> "__meta__" && field.cf_name <> "__rtti")
|> List.filter_map filter_properties in

let functions =
let functions =
class_def.cl_ordered_fields
|> List.filter_map (filter_functions true) in

Expand Down Expand Up @@ -1822,4 +1822,4 @@ and tcpp_enum_from_tenum ctx ids enum_def =
in
let enum = { te_enum = enum_def; te_id = self_id; te_constructors = constructors } in

(ids, enum)
(ids, enum)
2 changes: 1 addition & 1 deletion src/generators/cpp/gen/cppCppia.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ let generate_script_class common_ctx script class_def =
| AccNormal | AccCtor -> IaAccessNormal
| AccNo -> IaAccessNot
| AccNever -> IaAccessNot
| AccCall | AccPrivateCall ->
| AccCall ->
if
Meta.has Meta.NativeProperty class_def.cl_meta
|| Meta.has Meta.NativeProperty field.cf_meta
Expand Down
26 changes: 13 additions & 13 deletions src/generators/cpp/gen/cppGenClassImplementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let gen_function ctx class_def class_name is_static func =
(gen_cpp_function_body ctx class_def is_static func.tcf_field.cf_name func.tcf_func code tail_code);

output "\n\n";

(* generate dynamic version too ... *)
if (not func.tcf_is_virtual || not func.tcf_is_overriding) && func.tcf_is_reflective then
let tcpp_args = List.map (fun (v, _) -> cpp_type_of v.v_type) func.tcf_func.tf_args in
Expand Down Expand Up @@ -85,7 +85,7 @@ let gen_function ctx class_def class_name is_static func =
Printf.sprintf "(::cpp::Struct< %s >) a%i" (tcpp_to_string arg) idx
| _ ->
Printf.sprintf "a%i" idx in

tcpp_args
|> ExtList.List.mapi cast_prefix
|> String.concat ", "
Expand Down Expand Up @@ -120,7 +120,7 @@ let gen_dynamic_function ctx class_def class_name is_static is_for_static_var (f
let ret = if is_void then "(void)" else "return " in

ctx.ctx_real_this_ptr <- false;
Printf.sprintf "HX_BEGIN_DEFAULT_FUNC(%s, %s)\n" func_name class_name |> output;
Printf.sprintf "HX_BEGIN_DEFAULT_FUNC(%s, %s)\n" func_name class_name |> output;
Printf.sprintf "%s _hx_run(%s)" return_type_str (print_arg_list func.tcf_func.tf_args "__o_") |> output;

gen_cpp_function_body ctx class_def is_static func_name func.tcf_func "" "" no_debug;
Expand Down Expand Up @@ -273,7 +273,7 @@ let generate_native_class base_ctx tcpp_class =
output_cpp "\n";

gen_dynamic_function_allocator ctx output_cpp tcpp_class;

generate_native_constructor ctx output_cpp class_def false;
gen_boot_field ctx output_cpp tcpp_class;

Expand Down Expand Up @@ -394,13 +394,13 @@ let generate_managed_class base_ctx tcpp_class =
let impl_name = cpp_class_name class_def in

let fold_interface (glued, acc) interface =

let rec gen_interface_funcs interface =

let fold_field (glued, acc) func =
let cast = cpp_tfun_signature false func.iff_args func.iff_return in
let real_name = cpp_member_name_of func.iff_field in

(* C++ can't work out which function it needs to take the addrss of
when the implementation is overloaded - currently the map-set functions.
Change the castKey to force a glue function in this case (could double-cast the pointer, but it is ugly)
Expand Down Expand Up @@ -452,7 +452,7 @@ let generate_managed_class base_ctx tcpp_class =
let call = Printf.sprintf "static %s %s_%s = {\n%s\n};\n" (cpp_class_name interface.if_class) cname interface_name combined in
(glued, call :: acc)
in

let glued, calls =
List.fold_left
fold_interface
Expand Down Expand Up @@ -615,7 +615,7 @@ let generate_managed_class base_ctx tcpp_class =
else
acc
in

let castable f =
match cpp_type_of f.cf_type with
| TCppInst (t, _) as inst when Meta.has Meta.StructAccess t.cl_meta ->
Expand Down Expand Up @@ -671,7 +671,7 @@ let generate_managed_class base_ctx tcpp_class =
Printf.sprintf "%s = inValue.Cast< %s >(); return inValue;" var.tcv_name casted in

match var.tcv_field.cf_kind with
| Var { v_write = AccCall | AccPrivateCall } ->
| Var { v_write = AccCall } ->
let prop_call = checkPropCall var.tcv_field in
let setter = Printf.sprintf "set_%s" var.tcv_field.cf_name |> get_wrapper var.tcv_field in
let call = Printf.sprintf "if (%s) { return ::hx::Val( %s(inValue.Cast< %s >()) ); } else { %s }" prop_call setter casted default in
Expand All @@ -690,7 +690,7 @@ let generate_managed_class base_ctx tcpp_class =
let casted = castable var.tcv_field in

match var.tcv_field.cf_kind with
| Var { v_write = AccCall | AccPrivateCall } ->
| Var { v_write = AccCall } ->
let prop_call = checkPropCall var.tcv_field in
let setter = Printf.sprintf "set_%s" var.tcv_field.cf_name |> get_wrapper var.tcv_field in
let call = Printf.sprintf "if (%s) { return ::hx::Val( %s(inValue.Cast< %s >()) ); }" prop_call setter casted in
Expand All @@ -717,7 +717,7 @@ let generate_managed_class base_ctx tcpp_class =
let casted = castable var.tcv_field in

match var.tcv_field.cf_kind with
| Var { v_write = AccCall | AccPrivateCall } ->
| Var { v_write = AccCall } ->
let prop_call = checkPropCall var.tcv_field in
let setter = Printf.sprintf "set_%s" var.tcv_field.cf_name |> get_wrapper var.tcv_field in
let call = Printf.sprintf "if (%s) { ioValue = %s(ioValue.Cast< %s >()); } else { %s = ioValue.Cast< %s >(); } return true;" prop_call setter casted var.tcv_name casted in
Expand All @@ -734,7 +734,7 @@ let generate_managed_class base_ctx tcpp_class =
let fold_property (var:tcpp_class_variable) acc =
if var.tcv_is_reflective && not (is_abstract_impl class_def) then
match var.tcv_field.cf_kind with
| Var { v_write = AccCall | AccPrivateCall } ->
| Var { v_write = AccCall } ->
let prop_call = checkPropCall var.tcv_field in
let setter = Printf.sprintf "set_%s" var.tcv_field.cf_name |> get_wrapper var.tcv_field in
let casted = castable var.tcv_field in
Expand Down Expand Up @@ -965,7 +965,7 @@ let generate_managed_class base_ctx tcpp_class =
| _ -> [] in
current_virtual_functions_rev cls initial
in

flatten_tcpp_class_functions_rec tcpp_class |> List.rev
in

Expand Down
8 changes: 4 additions & 4 deletions src/generators/flashProps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ let find_property_for_accessor ~isget cl tl accessor_name =
match Type.class_field cl tl prop_name with
| Some (prop_cl, prop_tl), _, prop_cf ->
(match prop_cf.cf_kind with
| Var { v_read = AccCall | AccPrivateCall; v_write = AccCall | AccPrivateCall | AccNever } when isget && is_flash_property prop_cf -> Some (prop_cl, prop_tl, prop_cf)
| Var { v_read = AccCall | AccPrivateCall | AccNever; v_write = AccCall | AccPrivateCall } when not isget && is_flash_property prop_cf -> Some (prop_cl, prop_tl, prop_cf)
| Var { v_read = AccCall; v_write = AccCall | AccNever } when isget && is_flash_property prop_cf -> Some (prop_cl, prop_tl, prop_cf)
| Var { v_read = AccCall | AccNever; v_write = AccCall } when not isget && is_flash_property prop_cf -> Some (prop_cl, prop_tl, prop_cf)
| _ -> None)
| _ -> None
with Not_found ->
Expand All @@ -47,8 +47,8 @@ let find_static_property_for_accessor ~isget cl accessor_name =
try
let prop_cf = PMap.find prop_name cl.cl_statics in
(match prop_cf.cf_kind with
| Var { v_read = AccCall | AccPrivateCall; v_write = AccCall | AccPrivateCall | AccNever } when isget && is_flash_property prop_cf -> Some prop_cf
| Var { v_read = AccCall | AccPrivateCall | AccNever; v_write = AccCall | AccPrivateCall } when not isget && is_flash_property prop_cf -> Some prop_cf
| Var { v_read = AccCall; v_write = AccCall | AccNever } when isget && is_flash_property prop_cf -> Some prop_cf
| Var { v_read = AccCall | AccNever; v_write = AccCall } when not isget && is_flash_property prop_cf -> Some prop_cf
| _ -> None)
with Not_found ->
None
Expand Down
2 changes: 0 additions & 2 deletions src/generators/genphp7.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3891,8 +3891,6 @@ class class_builder ctx (cls:tclass) =
| Var { v_read = read; v_write = write } ->
if read = AccCall then getters := field.cf_name :: !getters;
if write = AccCall then setters := field.cf_name :: !setters;
if read = AccPrivateCall then getters := field.cf_name :: !getters;
if write = AccPrivateCall then setters := field.cf_name :: !setters;
| _ -> ()
in
List.iter collect cls.cl_ordered_fields;
Expand Down
4 changes: 2 additions & 2 deletions src/generators/genpy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ module Generator = struct
match cf.cf_kind with
| Var _ when not (is_physical_field cf) ->
()
| Var({v_read = AccCall | AccPrivateCall}) ->
| Var({v_read = AccCall}) ->
if Meta.has Meta.IsVar cf.cf_meta then
DynArray.add fields cf.cf_name
else
Expand Down Expand Up @@ -1922,7 +1922,7 @@ module Generator = struct
print ctx " @staticmethod\n def _hx_empty_init(_hx_o):";
let found_fields = ref false in
List.iter (fun cf -> match cf.cf_kind with
| Var ({v_read = AccCall | AccPrivateCall}) ->
| Var ({v_read = AccCall}) ->
()
| Var _ ->
found_fields := true;
Expand Down
Loading
Loading