Browse Source

Changed is_extern_field to is_physical_field (#6404)

* changed is_extern_field to is_physical_field

* fix is_extern_field->is_physical_field change in genlua
Alexander Kuzmenko 8 years ago
parent
commit
056cf89ca2

+ 1 - 1
src/generators/gencommon/initFunction.ml

@@ -83,7 +83,7 @@ let handle_class com cl =
 					| Some e -> ensure_simple_expr com e);
 					acc
 			| Var _
-			| Method MethDynamic when not (Type.is_extern_field cf) ->
+			| Method MethDynamic when Type.is_physical_field cf ->
 				(match cf.cf_expr with
 				| Some e ->
 					(match cf.cf_params with

+ 1 - 1
src/generators/gencommon/interfaceVarsDeleteModf.ml

@@ -45,7 +45,7 @@ let configure gen =
 				match cf.cf_kind with
 				| Var _ when gen.gcon.platform = Cs && Meta.has Meta.Event cf.cf_meta ->
 					true
-				| Var vkind when not (Type.is_extern_field cf && Meta.has Meta.Property cf.cf_meta) ->
+				| Var vkind when Type.is_physical_field cf || not (Meta.has Meta.Property cf.cf_meta) ->
 					(match vkind.v_read with
 						| AccCall ->
 							let newcf = mk_class_field ("get_" ^ cf.cf_name) (TFun([],cf.cf_type)) true cf.cf_pos (Method MethNormal) [] in

+ 3 - 3
src/generators/gencommon/reflectionCFs.ml

@@ -1037,7 +1037,7 @@ let implement_get_set ctx cl =
 							mk_this_call_raw ("set_" ^ cf.cf_name) (TFun(["value",false,cf.cf_type], cf.cf_type)) [ value_local ];
 							mk_return value_local
 						] in
-						if Type.is_extern_field cf then
+						if not (Type.is_physical_field cf) then
 							{ eexpr = TBlock bl; etype = value_local.etype; epos = pos }
 						else
 							{
@@ -1084,7 +1084,7 @@ let implement_get_set ctx cl =
 
 			let get_field cf cf_type ethis cl name =
 				match cf.cf_kind with
-					| Var { v_read = AccCall } when Type.is_extern_field cf ->
+					| Var { v_read = AccCall } when not (Type.is_physical_field cf) ->
 						mk_this_call_raw ("get_" ^ cf.cf_name) (TFun(["value",false,cf.cf_type], cf.cf_type)) []
 					| Var { v_read = AccCall } ->
 						{
@@ -1147,7 +1147,7 @@ let implement_get_set ctx cl =
 			let fields = List.filter (fun (_, cf) -> match is_set, cf.cf_kind with
 				| true, Var { v_write = AccCall } -> true
 				| false, Var { v_read = AccCall } -> true
-				| _ -> not (Type.is_extern_field cf)) fields
+				| _ -> Type.is_physical_field cf) fields
 			in
 			(if fields <> [] then has_fields := true);
 			let cases = List.map (fun (names, cf) ->

+ 9 - 9
src/generators/gencpp.ml

@@ -949,7 +949,7 @@ let member_type ctx field_object member =
 *)
 let is_interface obj = is_interface_type obj.etype;;
 
-let should_implement_field x = not (is_extern_field x);;
+let should_implement_field x = is_physical_field x;;
 
 let is_extern_class class_def =
    class_def.cl_extern || (has_meta_key class_def.cl_meta Meta.Extern) ||
@@ -4394,7 +4394,7 @@ let gen_field ctx class_def class_name ptr_name dot_name is_static is_interface
          output ( " " ^ class_name ^ "::" ^ remap_name ^ ";\n\n");
       end
    | _ ->
-      if is_static && (not (is_extern_field field)) then begin
+      if is_static && is_physical_field field then begin
          gen_type ctx field.cf_type;
          output ( " " ^ class_name ^ "::" ^ remap_name ^ ";\n\n");
       end
@@ -5216,7 +5216,7 @@ let variable_field field =
 
 let is_readable class_def field =
    (match field.cf_kind with
-   | Var { v_read = AccNever } when (is_extern_field field) -> false
+   | Var { v_read = AccNever } when not (is_physical_field field) -> false
    | Var { v_read = AccInline } -> false
    | Var _ when is_abstract_impl class_def -> false
    | _ -> true)
@@ -5224,7 +5224,7 @@ let is_readable class_def field =
 
 let is_writable class_def field =
    (match field.cf_kind with
-   | Var { v_write = AccNever } when (is_extern_field field) -> false
+   | Var { v_write = AccNever } when not (is_physical_field field) -> false
    | Var { v_read = AccInline } -> false
    | Var _ when is_abstract_impl class_def -> false
    | _ -> true)
@@ -5929,7 +5929,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
          let get_field_dat = List.map (fun f ->
             (f.cf_name, String.length f.cf_name,
                (match f.cf_kind with
-               | Var { v_read = AccCall } when is_extern_field f ->
+               | Var { v_read = AccCall } when not (is_physical_field f) ->
                      "if (" ^ (checkPropCall f) ^ ") return " ^ (toVal f ((keyword_remap ("get_" ^ f.cf_name)) ^ "()" ) ) ^ ";"
                | Var { v_read = AccCall } -> "return " ^ (toVal f ((checkPropCall f) ^ " ? " ^ (keyword_remap ("get_" ^ f.cf_name)) ^ "() : " ^
                      ((keyword_remap f.cf_name) ^ (if (variable_field f) then "" else "_dyn()")) ) ) ^ ";"
@@ -5948,7 +5948,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
          let get_field_dat = List.map (fun f ->
             (f.cf_name, String.length f.cf_name,
                (match f.cf_kind with
-               | Var { v_read = AccCall } when is_extern_field f ->
+               | Var { v_read = AccCall } when not (is_physical_field f) ->
                      "if (" ^ (checkPropCall f) ^ ") { outValue = " ^ (toDynamic f (keyword_remap ("get_" ^ f.cf_name) ^ "()")) ^ "; return true; }"
                | Var { v_read = AccCall } -> "outValue = " ^ (toDynamic f ((checkPropCall f) ^ " ? " ^ (keyword_remap ("get_" ^ f.cf_name)) ^ "() : " ^
                      ((keyword_remap f.cf_name) ^ if (variable_field f) then "" else "_dyn()"))) ^ "; return true;";
@@ -5986,7 +5986,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
                   let inVal =  "(inValue.Cast< " ^ (castable f) ^ " >())" in
                   let setter = keyword_remap ("set_" ^ f.cf_name) in
                   "if (" ^ (checkPropCall f) ^ ") return " ^ (toVal f (setter ^inVal) ) ^ ";" ^
-                      ( if is_extern_field f then "" else default_action )
+                      ( if not (is_physical_field f) then "" else default_action )
                | _ -> default_action
                )
             )
@@ -6014,7 +6014,7 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
                   let inVal = "(ioValue.Cast< " ^ (castable f) ^ " >())" in
                   let setter = keyword_remap ("set_" ^ f.cf_name) in
                   "if (" ^ (checkPropCall f) ^ ")  ioValue = " ^ (toDynamic f (setter ^ inVal) ) ^ ";"
-                      ^ ( if is_extern_field f then "" else " else " ^ default_action )
+                      ^ ( if not (is_physical_field f) then "" else " else " ^ default_action )
                | _ -> default_action
                )
             )
@@ -8006,7 +8006,7 @@ let generate_script_class common_ctx script class_def =
          | AccInline -> IaAccessNormal
          | AccRequire (_,_) -> IaAccessNormal
          in
-         let isExtern = is_extern_field field in
+         let isExtern = not (is_physical_field field) in
          script#var (mode_code v.v_read) (mode_code v.v_write) isExtern isStatic field.cf_name field.cf_type field.cf_expr
       | Method MethDynamic, TFun(args,ret) ->
          script#func isStatic true field.cf_name ret args class_def.cl_interface field.cf_expr

+ 5 - 5
src/generators/gencs.ml

@@ -1123,7 +1123,7 @@ let generate con =
 			| TInst({ cl_interface = true; cl_extern = true } as cl, _), FNotFound ->
 				not (is_hxgen (TClassDecl cl))
 			| _, FClassField(_,_,decl,v,_,t,_) ->
-				Type.is_extern_field v && (Meta.has Meta.Property v.cf_meta || (decl.cl_extern && not (is_hxgen (TClassDecl decl))))
+				not (Type.is_physical_field v) && (Meta.has Meta.Property v.cf_meta || (decl.cl_extern && not (is_hxgen (TClassDecl decl))))
 			| _ -> false
 		in
 
@@ -2024,7 +2024,7 @@ let generate con =
 
 			(match cf.cf_kind with
 				| Var _
-				| Method (MethDynamic) when not (Type.is_extern_field cf) ->
+				| Method (MethDynamic) when Type.is_physical_field cf ->
 					(if is_overload || List.exists (fun cf -> cf.cf_expr <> None) cf.cf_overloads then
 						gen.gcon.error "Only normal (non-dynamic) methods can be overloaded" cf.cf_pos);
 					if not is_interface then begin
@@ -2040,7 +2040,7 @@ let generate con =
 						);
 						write w ";"
 					end (* TODO see how (get,set) variable handle when they are interfaces *)
-				| Method _ when Type.is_extern_field cf || (match cl.cl_kind, cf.cf_expr with | KAbstractImpl _, None -> true | _ -> false) ->
+				| Method _ when not (Type.is_physical_field cf) || (match cl.cl_kind, cf.cf_expr with | KAbstractImpl _, None -> true | _ -> false) ->
 					List.iter (fun cf -> if cl.cl_interface || cf.cf_expr <> None then
 						gen_class_field w ~is_overload:true is_static cl (Meta.has Meta.Final cf.cf_meta) cf
 					) cf.cf_overloads
@@ -2312,7 +2312,7 @@ let generate con =
 			let handle_prop static f =
 				match f.cf_kind with
 				| Method _ -> ()
-				| Var v when not (Type.is_extern_field f) -> ()
+				| Var v when Type.is_physical_field f -> ()
 				| Var v ->
 					let prop acc = match acc with
 						| AccNo | AccNever | AccCall -> true
@@ -2466,7 +2466,7 @@ let generate con =
 				let events, props, nonprops = ref [], ref [], ref [] in
 
 				List.iter (fun v -> match v.cf_kind with
-					| Var { v_read = AccCall } | Var { v_write = AccCall } when Type.is_extern_field v && Meta.has Meta.Property v.cf_meta ->
+					| Var { v_read = AccCall } | Var { v_write = AccCall } when not (Type.is_physical_field v) && Meta.has Meta.Property v.cf_meta ->
 						props := (v.cf_name, ref (v, v.cf_type, None, None)) :: !props;
 					| Var { v_read = AccNormal; v_write = AccNormal } when Meta.has Meta.Event v.cf_meta ->
 						events := (v.cf_name, ref (v, v.cf_type, false, None, None)) :: !events;

+ 1 - 1
src/generators/genhl.ml

@@ -135,7 +135,7 @@ let is_to_string t =
 	| _ -> false
 
 let is_extern_field f =
-	Type.is_extern_field f || (match f.cf_kind with Method MethNormal -> List.exists (fun (m,_,_) -> m = Meta.Custom ":hlNative") f.cf_meta | _ -> false) || Meta.has Meta.Extern f.cf_meta
+	not (Type.is_physical_field f) || (match f.cf_kind with Method MethNormal -> List.exists (fun (m,_,_) -> m = Meta.Custom ":hlNative") f.cf_meta | _ -> false) || Meta.has Meta.Extern f.cf_meta
 
 let is_array_class name =
 	match name with

+ 2 - 2
src/generators/genjava.ml

@@ -1915,7 +1915,7 @@ let generate con =
 		in
 		(match cf.cf_kind with
 			| Var _
-			| Method (MethDynamic) when not (Type.is_extern_field cf) ->
+			| Method (MethDynamic) when Type.is_physical_field cf ->
 				(if is_overload || List.exists (fun cf -> cf.cf_expr <> None) cf.cf_overloads then
 					gen.gcon.error "Only normal (non-dynamic) methods can be overloaded" cf.cf_pos);
 				if not is_interface then begin
@@ -1929,7 +1929,7 @@ let generate con =
 						| None -> write w ";"
 					)
 				end (* TODO see how (get,set) variable handle when they are interfaces *)
-			| Method _ when Type.is_extern_field cf || (match cl.cl_kind, cf.cf_expr with | KAbstractImpl _, None -> true | _ -> false) ->
+			| Method _ when not (Type.is_physical_field cf) || (match cl.cl_kind, cf.cf_expr with | KAbstractImpl _, None -> true | _ -> false) ->
 				List.iter (fun cf -> if cl.cl_interface || cf.cf_expr <> None then
 					gen_class_field w ~is_overload:true is_static cl (Meta.has Meta.Final cf.cf_meta) cf
 				) cf.cf_overloads

+ 2 - 2
src/generators/genjs.ml

@@ -990,7 +990,7 @@ let gen_class_static_field ctx c f =
 	match f.cf_expr with
 	| None | Some { eexpr = TConst TNull } when not (has_feature ctx "Type.getClassFields") ->
 		()
-	| None when is_extern_field f ->
+	| None when not (is_physical_field f) ->
 		()
 	| None ->
 		print ctx "%s%s = null" (s_path ctx c.cl_path) (static_field c f.cf_name);
@@ -1012,7 +1012,7 @@ let can_gen_class_field ctx = function
 	| { cf_expr = (None | Some { eexpr = TConst TNull }) } when not (has_feature ctx "Type.getInstanceFields") ->
 		false
 	| f ->
-		not (is_extern_field f)
+		is_physical_field f
 
 let gen_class_field ctx c f =
 	check_field_name c f;

+ 2 - 2
src/generators/genlua.ml

@@ -1346,7 +1346,7 @@ and can_gen_class_field ctx = function
 	| { cf_expr = (None | Some { eexpr = TConst TNull }) } when not (has_feature ctx "Type.getInstanceFields") ->
 		false
 	| f ->
-		not (is_extern_field f)
+		is_physical_field f
 
 
 let check_multireturn ctx c =
@@ -1398,7 +1398,7 @@ let gen_class_static_field ctx c f =
 	match f.cf_expr with
 	| None | Some { eexpr = TConst TNull } when not (has_feature ctx "Type.getClassFields") ->
 		()
-	| None when is_extern_field f ->
+	| None when not (is_physical_field f) ->
 		()
 	| None ->
 		println ctx "%s%s = nil" (s_path ctx c.cl_path) (field f.cf_name);

+ 1 - 1
src/generators/genneko.ml

@@ -401,7 +401,7 @@ and gen_expr ctx e =
 
 let gen_method ctx p c acc =
 	ctx.curmethod <- c.cf_name;
-	if is_extern_field c then acc else
+	if not (is_physical_field c) then acc else
 	match c.cf_expr with
 	| None ->
 		((c.cf_name, null p) :: acc)

+ 3 - 3
src/generators/genphp.ml

@@ -1904,7 +1904,7 @@ let gen_assigned_value ctx eo =	match eo with
 		()
 
 let generate_field ctx static f =
-	if not (is_extern_field f) then
+	if is_physical_field f then
 		newline ctx;
 	ctx.locals <- PMap.empty;
 	ctx.inv_locals <- PMap.empty;
@@ -1923,7 +1923,7 @@ let generate_field ctx static f =
 		else
 			gen_function ctx (s_ident f.cf_name) fd f.cf_params p
 	| _ ->
-		if (is_extern_field f) then
+		if not (is_physical_field f) then
 			()
 		else if ctx.curclass.cl_interface then
 			match follow f.cf_type, f.cf_kind with
@@ -2012,7 +2012,7 @@ let generate_static_field_assign ctx path f =
 					print ctx "%s::$%s = " (s_path ctx path false p) (s_ident f.cf_name);
 					gen_value ctx e
 				| _ -> ())
-			| _ when is_extern_field f ->
+			| _ when not (is_physical_field f) ->
 				()
 			| _ ->
 				newline ctx;

+ 1 - 1
src/generators/genphp7.ml

@@ -3474,7 +3474,7 @@ class class_builder ctx (cls:tclass) =
 		method private write_field is_static field =
 			match field.cf_kind with
 				| Var { v_read = AccInline; v_write = AccNever } -> self#write_const field
-				| Var _ when not (is_extern_field field) ->
+				| Var _ when is_physical_field field ->
 					(* Do not generate fields for RTTI meta, because this generator uses another way to store it *)
 					let is_auto_meta_var = is_static && field.cf_name = "__meta__" && (has_rtti_meta ctx wrapper#get_module_type) in
 					if not is_auto_meta_var then self#write_var field is_static;

+ 4 - 4
src/generators/genpy.ml

@@ -1764,7 +1764,7 @@ module Generator = struct
 			match cf.cf_kind with
 				| Var({v_read = AccResolve}) ->
 					()
-				| Var _ when is_extern_field cf ->
+				| Var _ when not (is_physical_field cf) ->
 					()
 				| Var({v_read = AccCall}) ->
 					if Meta.has Meta.IsVar cf.cf_meta then
@@ -1785,7 +1785,7 @@ module Generator = struct
 	let collect_class_statics_data cfl =
 		let fields = DynArray.create () in
 		List.iter (fun cf ->
-			if not (is_extern_field cf) then
+			if is_physical_field cf then
 				DynArray.add fields cf.cf_name
 		) cfl;
 		DynArray.to_list fields
@@ -1795,7 +1795,7 @@ module Generator = struct
 
 	let get_members_with_init_expr c =
 		List.filter (fun cf -> match cf.cf_kind with
-			| Var _ when is_extern_field cf -> false
+			| Var _ when not (is_physical_field cf) -> false
 			| Var _ when cf.cf_expr = None -> true
 			| _ -> false
 		) c.cl_ordered_fields
@@ -2090,7 +2090,7 @@ module Generator = struct
 					let real_fields =
 						List.filter (fun f -> match f.cf_kind with
 							| Method MethDynamic -> raise Exit (* if a class has dynamic method, we can't use __slots__ because python will complain *)
-							| Var _ -> not (is_extern_field f)
+							| Var _ -> is_physical_field f
 							| _ -> false
 						) c.cl_ordered_fields
 					in

+ 1 - 1
src/generators/genswf9.ml

@@ -1957,7 +1957,7 @@ let generate_field_kind ctx f c stat =
 		in
 		loop f.cf_meta
 	in
-	if is_extern_field f then None else
+	if not (is_physical_field f) then None else
 	match f.cf_expr with
 	| Some { eexpr = TFunction fdata } ->
 		let rec loop c name =

+ 2 - 2
src/macro/eval/evalPrototype.ml

@@ -191,7 +191,7 @@ let create_static_prototype ctx mt =
 				PrototypeBuilder.add_proto_field pctx name (lazy vnull);
 				let i = DynArray.length pctx.PrototypeBuilder.fields - 1 in
 				DynArray.add delays (fun proto -> proto.pfields.(i) <- (match eval_expr ctx key name e with Some e -> e | None -> vnull))
-			| _,None when not (is_extern_field cf) ->
+			| _,None when is_physical_field cf ->
 				PrototypeBuilder.add_proto_field pctx (hash_s cf.cf_name) (lazy vnull);
 			|  _ ->
 				()
@@ -243,7 +243,7 @@ let create_instance_prototype ctx c =
 			let v = lazy (vfunction (jit_tfunction ctx key name tf false pos)) in
 			if meth = MethDynamic then PrototypeBuilder.add_instance_field pctx name v;
 			PrototypeBuilder.add_proto_field pctx name v
-		| Var _,_ when not (is_extern_field cf) ->
+		| Var _,_ when is_physical_field cf ->
 			let name = hash_s cf.cf_name in
 			PrototypeBuilder.add_instance_field pctx name (lazy vnull);
 		|  _ ->

+ 3 - 3
src/optimization/dce.ml

@@ -80,7 +80,7 @@ let keep_field dce cf c is_static =
 	Meta.has Meta.Keep cf.cf_meta
 	|| Meta.has Meta.Used cf.cf_meta
 	|| cf.cf_name = "__init__"
-	|| is_extern_field cf
+	|| not (is_physical_field cf)
 	|| (not is_static && is_or_overrides_extern_field cf c)
 
 (* marking *)
@@ -702,7 +702,7 @@ let run com main full =
 			List.iter (fun (c,cf,stat) -> mark_dependent_fields dce c cf.cf_name stat) cfl;
 			(* mark fields as used *)
 			List.iter (fun (c,cf,stat) ->
-				if not (is_extern_field cf) then mark_class dce c;
+				if is_physical_field cf then mark_class dce c;
 				mark_field dce c cf stat;
 				mark_t dce cf.cf_pos cf.cf_type
 			) cfl;
@@ -767,7 +767,7 @@ let run com main full =
 				b
 			) c.cl_ordered_fields;
 			(match c.cl_constructor with Some cf when not (keep_field dce cf c false) -> c.cl_constructor <- None | _ -> ());
-			let inef cf = not (is_extern_field cf) in
+			let inef cf = is_physical_field cf in
 			let has_non_extern_fields = List.exists inef c.cl_ordered_fields || List.exists inef c.cl_ordered_statics in
 			(* we keep a class if it was used or has a used field *)
 			if Meta.has Meta.Used c.cl_meta || has_non_extern_fields then loop (mt :: acc) l else begin

+ 4 - 5
src/typing/type.ml

@@ -772,12 +772,11 @@ let extract_field = function
 	| FAnon f | FInstance (_,_,f) | FStatic (_,f) | FClosure (_,f) -> Some f
 	| _ -> None
 
-(* TODO: Function with bad name. It should be `is_non_physical_field` *)
-let is_extern_field f =
+let is_physical_field f =
 	match f.cf_kind with
-	| Method _ -> false
-	| Var { v_read = AccNormal | AccInline | AccNo } | Var { v_write = AccNormal | AccNo } -> false
-	| _ -> not (Meta.has Meta.IsVar f.cf_meta)
+	| Method _ -> true
+	| Var { v_read = AccNormal | AccInline | AccNo } | Var { v_write = AccNormal | AccNo } -> true
+	| _ -> Meta.has Meta.IsVar f.cf_meta
 
 let field_type f =
 	match f.cf_params with

+ 1 - 1
src/typing/typeload.ml

@@ -2228,7 +2228,7 @@ module ClassInitializer = struct
 							display_error ctx "Extern non-inline variables may not be initialized" p;
 							e
 						end else require_constant_expression e "Extern variable initialization must be a constant value"
-					| Var v when is_extern_field cf ->
+					| Var v when not (is_physical_field cf) ->
 						(* disallow initialization of non-physical fields (issue #1958) *)
 						display_error ctx "This field cannot be initialized because it is not a real variable" p; e
 					| Var v when not fctx.is_static ->

+ 1 - 1
src/typing/typer.ml

@@ -1057,7 +1057,7 @@ let field_access ctx mode f fmode t e p =
 			in
 			if m = ctx.curfield.cf_name && (match e.eexpr with TConst TThis -> true | TLocal v -> Option.map_default (fun vthis -> v == vthis) false ctx.vthis | TTypeExpr (TClassDecl c) when c == ctx.curclass -> true | _ -> false) then
 				let prefix = (match ctx.com.platform with Flash when Common.defined ctx.com Define.As3 -> "$" | _ -> "") in
-				if is_extern_field f then begin
+				if not (is_physical_field f) then begin
 					display_error ctx "This field cannot be accessed because it is not a real variable" p;
 					display_error ctx "Add @:isVar here to enable it" f.cf_pos;
 				end;