Kaynağa Gözat

[typer] also add CfEnum

Simon Krajewski 5 yıl önce
ebeveyn
işleme
4581cae5cc

+ 3 - 3
src/context/display/displayFields.ml

@@ -171,7 +171,7 @@ let collect ctx e_ast e dk with_type p =
 			Display.merge_core_doc ctx (TAbstractDecl a);
 			(* Abstracts should show all their @:impl fields minus the constructor. *)
 			let items = List.fold_left (fun acc cf ->
-				if has_class_field_flag cf CfImpl && not (Meta.has Meta.Enum cf.cf_meta) && should_access c cf false && is_new_item acc cf.cf_name then begin
+				if has_class_field_flag cf CfImpl && not (has_class_field_flag cf CfEnum) && should_access c cf false && is_new_item acc cf.cf_name then begin
 					let origin = Self(TAbstractDecl a) in
 					let cf = prepare_using_field cf in
 					let cf = if tl = [] then cf else {cf with cf_type = apply_params a.a_params tl cf.cf_type} in
@@ -225,7 +225,7 @@ let collect ctx e_ast e dk with_type p =
 				if is_new_item acc name then begin
 					let allow_static_abstract_access c cf =
 						should_access c cf false &&
-						(not (has_class_field_flag cf CfImpl) || Meta.has Meta.Enum cf.cf_meta)
+						(not (has_class_field_flag cf CfImpl) || has_class_field_flag cf CfEnum)
 					in
 					let ct = CompletionType.from_type (get_import_status ctx) ~values:(get_value_meta cf.cf_meta) cf.cf_type in
 					let add origin make_field =
@@ -234,7 +234,7 @@ let collect ctx e_ast e dk with_type p =
 					match !(an.a_status) with
 						| Statics ({cl_kind = KAbstractImpl a} as c) ->
 							if allow_static_abstract_access c cf then
-								let make = if Meta.has Meta.Enum cf.cf_meta then
+								let make = if has_class_field_flag cf CfEnum then
 										(make_ci_enum_abstract_field a)
 									else
 										make_ci_class_field

+ 2 - 2
src/context/display/displayToplevel.ml

@@ -344,7 +344,7 @@ let collect ctx tk with_type sort =
 				add_path cctx a.a_path;
 				List.iter (fun cf ->
 					let ccf = CompletionClassField.make cf CFSMember (Self (decl_of_class c)) true in
-					if (Meta.has Meta.Enum cf.cf_meta) && not (Meta.has Meta.NoCompletion cf.cf_meta) then
+					if (has_class_field_flag cf CfEnum) && not (Meta.has Meta.NoCompletion cf.cf_meta) then
 						add (make_ci_enum_abstract_field a ccf (tpair cf.cf_type)) (Some cf.cf_name);
 				) c.cl_ordered_statics
 			| TTypeDecl t ->
@@ -381,7 +381,7 @@ let collect ctx tk with_type sort =
 					let cf = if name = cf.cf_name then cf else {cf with cf_name = name} in
 					let decl,make = match c.cl_kind with
 						| KAbstractImpl a -> TAbstractDecl a,
-							if Meta.has Meta.Enum cf.cf_meta then make_ci_enum_abstract_field a else make_ci_class_field
+							if has_class_field_flag cf CfEnum then make_ci_enum_abstract_field a else make_ci_class_field
 						| _ -> TClassDecl c,make_ci_class_field
 					in
 					let origin = StaticImport decl in

+ 1 - 0
src/core/tType.ml

@@ -394,6 +394,7 @@ type flag_tclass_field =
 	| CfAbstract
 	| CfOverload
 	| CfImpl
+	| CfEnum
 	| CfGeneric
 
 type flag_tvar =

+ 1 - 1
src/generators/genhxold.ml

@@ -289,7 +289,7 @@ let generate_type com t =
 
 			List.iter (fun f ->
 				let static = not (has_class_field_flag f CfImpl) in
-				if not static && is_enum && Meta.has Meta.Enum f.cf_meta then begin
+				if not static && is_enum && has_class_field_flag f CfEnum then begin
 					p "\tvar %s;\n" f.cf_name;
 				end else
 					print_field static f

+ 1 - 1
src/optimization/dce.ml

@@ -671,7 +671,7 @@ let fix_accessors com =
 			add_class_flag c CExtern;
 		| TClassDecl({cl_kind = KAbstractImpl a} as c) when a.a_enum ->
 			let is_runtime_field cf =
-				not (Meta.has Meta.Enum cf.cf_meta)
+				not (has_class_field_flag cf CfEnum)
 			in
 			(* also filter abstract implementation classes that have only @:enum fields (issue #2858) *)
 			if not (List.exists is_runtime_field c.cl_ordered_statics) then

+ 1 - 1
src/typing/fields.ml

@@ -411,7 +411,7 @@ let rec type_field cfg ctx e i p mode (with_type : WithType.t) =
 	| TAnon a ->
 		(try
 			let f = PMap.find i a.a_fields in
-			if has_class_field_flag f CfImpl && not (Meta.has Meta.Enum f.cf_meta) then display_error ctx "Cannot access non-static abstract field statically" pfield;
+			if has_class_field_flag f CfImpl && not (has_class_field_flag f CfEnum) then display_error ctx "Cannot access non-static abstract field statically" pfield;
 			begin match mode with
 			| MCall _ when has_class_field_flag f CfOverload ->
 				()

+ 2 - 2
src/typing/matcher.ml

@@ -296,7 +296,7 @@ module Pattern = struct
 							en.e_names
 						| TAbstract({a_impl = Some c} as a,pl) when a.a_enum ->
 							ExtList.List.filter_map (fun cf ->
-								if has_class_field_flag cf CfImpl && Meta.has Meta.Enum cf.cf_meta then Some cf.cf_name else None
+								if has_class_field_flag cf CfImpl && has_class_field_flag cf CfEnum then Some cf.cf_name else None
 							) c.cl_ordered_statics
 						| _ ->
 							[]
@@ -1384,7 +1384,7 @@ module TexprConverter = struct
 			| TAbstract({a_impl = Some c} as a,pl) when a.a_enum ->
 				List.iter (fun cf ->
 					ignore(follow cf.cf_type);
-					if has_class_field_flag cf CfImpl && Meta.has Meta.Enum cf.cf_meta then match cf.cf_expr with
+					if has_class_field_flag cf CfImpl && has_class_field_flag cf CfEnum then match cf.cf_expr with
 						| Some e ->
 							begin match extract_const e with
 							| Some ct -> if ct <> TNull then add (ConConst ct,null_pos)

+ 3 - 1
src/typing/typeloadFields.ml

@@ -856,7 +856,7 @@ let bind_var (ctx,cctx,fctx) cf e =
 				| Var v when v.v_read = AccInline ->
 					let e = require_constant_expression e "Inline variable initialization must be a constant value" in
 					begin match c.cl_kind with
-						| KAbstractImpl a when Meta.has Meta.Enum cf.cf_meta && a.a_enum ->
+						| KAbstractImpl a when has_class_field_flag cf CfEnum && a.a_enum ->
 							unify ctx t (TAbstract(a,(Monomorph.spawn_constrained_monos (fun t -> t) a.a_params))) p;
 							let e1 = match e.eexpr with TCast(e1,None) -> e1 | _ -> e in
 							unify ctx e1.etype a.a_this e1.epos
@@ -909,6 +909,7 @@ let create_variable (ctx,cctx,fctx) c f t eo p =
 	if fctx.is_final then add_class_field_flag cf CfFinal;
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
+	if Meta.has Meta.Enum cf.cf_meta then add_class_field_flag cf CfEnum;
 	ctx.curfield <- cf;
 	bind_var (ctx,cctx,fctx) cf eo;
 	cf
@@ -1405,6 +1406,7 @@ let create_property (ctx,cctx,fctx) c f (get,set,t,eo) p =
 	if (set = AccNever && get = AccNever)  then error (name ^ ": Unsupported property combination") p;
 	cf.cf_kind <- Var { v_read = get; v_write = set };
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
+	if Meta.has Meta.Enum cf.cf_meta then add_class_field_flag cf CfEnum;
 	ctx.curfield <- cf;
 	bind_var (ctx,cctx,fctx) cf eo;
 	cf

+ 1 - 1
src/typing/typeloadFunction.ml

@@ -86,7 +86,7 @@ let type_function_arg_value ctx t c do_display =
 			let rec loop e = match e.eexpr with
 				| TConst _ -> Some e
 				| TField({eexpr = TTypeExpr _},FEnum _) -> Some e
-				| TField({eexpr = TTypeExpr _},FStatic({cl_kind = KAbstractImpl a},cf)) when a.a_enum && Meta.has Meta.Enum cf.cf_meta -> Some e
+				| TField({eexpr = TTypeExpr _},FStatic({cl_kind = KAbstractImpl a},cf)) when a.a_enum && has_class_field_flag cf CfEnum -> Some e
 				| TCast(e,None) -> loop e
 				| _ ->
 					if ctx.com.display.dms_kind = DMNone || ctx.com.display.dms_inline && ctx.com.display.dms_error_policy = EPCollect then

+ 3 - 3
src/typing/typer.ml

@@ -105,7 +105,7 @@ let maybe_type_against_enum ctx f with_type iscall p =
 					true,en.e_path,en.e_names,TEnumDecl en
 				| TAbstract ({a_impl = Some c} as a,_) when a.a_enum ->
 					let fields = ExtList.List.filter_map (fun cf ->
-						if Meta.has Meta.Enum cf.cf_meta then Some cf.cf_name else None
+						if has_class_field_flag cf CfEnum then Some cf.cf_name else None
 					) c.cl_ordered_statics in
 					false,a.a_path,fields,TAbstractDecl a
 				| TAbstract (a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
@@ -369,7 +369,7 @@ let rec type_ident_raise ctx i p mode with_type =
 		(* static variable lookup *)
 		let f = PMap.find i ctx.curclass.cl_statics in
 		let is_impl = has_class_field_flag f CfImpl in
-		let is_enum = Meta.has Meta.Enum f.cf_meta in
+		let is_enum = has_class_field_flag f CfEnum in
 		if is_impl && not (has_class_field_flag ctx.curfield CfImpl) && not is_enum then
 			error (Printf.sprintf "Cannot access non-static field %s from static method" f.cf_name) p;
 		let e,fa = match ctx.curclass.cl_kind with
@@ -407,7 +407,7 @@ let rec type_ident_raise ctx i p mode with_type =
 				| TAbstractDecl ({a_impl = Some c} as a) when a.a_enum ->
 					begin try
 						let cf = PMap.find i c.cl_statics in
-						if not (Meta.has Meta.Enum cf.cf_meta) then
+						if not (has_class_field_flag cf CfEnum) then
 							loop l
 						else begin
 							let et = type_module_type ctx (TClassDecl c) None p in

+ 1 - 1
src/typing/typerDisplay.ml

@@ -58,7 +58,7 @@ let completion_item_of_expr ctx e =
 				| _ -> Self decl
 			in
 			let make_ci = match c.cl_kind with
-				| KAbstractImpl a when Meta.has Meta.Enum cf.cf_meta -> make_ci_enum_abstract_field a
+				| KAbstractImpl a when has_class_field_flag cf CfEnum -> make_ci_enum_abstract_field a
 				| _ -> make_ci_class_field
 			in
 			of_field {e with etype = te} origin cf CFSStatic make_ci