소스 검색

rename TDStatic/KModuleStatics to TDField/KModuleFields (#9485)

* rename TDStatic/KModuleStatics to TDField/KModuleFields

* fix wild space [skip ci]
Dan Korostelev 5 년 전
부모
커밋
1940b1ca36

+ 1 - 1
src/codegen/gencommon/overloadingConstructor.ml

@@ -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 _ | KModuleStatics _ -> 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 _ | KModuleFields _ -> false | _ -> true) in
 	let msize = List.length com.types in
 	let processed, empty_ctors = Hashtbl.create msize, Hashtbl.create msize in
 

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

@@ -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 _ | KModuleStatics _ }) ->
-					(* don't add any base classes to abstract implementations and module statics *)
+				| TClassDecl ({ cl_kind = KAbstractImpl _ | KModuleFields _ }) ->
+					(* don't add any base classes to abstract implementations and module field containers *)
 					()
 				| 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,[])
@@ -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 _ | KModuleStatics _ -> 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 _ | KModuleFields _ -> 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"));

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

@@ -110,7 +110,7 @@ let check_display_abstract ctx cc cfile a =
 			()
 	) sa.d_flags
 
-let check_display_module_statics ctx cfile m =
+let check_display_module_fields ctx cfile m =
 	Option.may (fun c ->
 		let sc = find_class_by_position cfile c.cl_name_pos in
 		List.iter (fun cf ->
@@ -143,7 +143,7 @@ let check_display_module ctx cc cfile m =
 		end;
 		DisplayEmitter.check_display_metadata ctx infos.mt_meta
 	) m.m_types;
-	check_display_module_statics ctx cfile m
+	check_display_module_fields ctx cfile m
 
 let check_display_file ctx cs =
 	match ctx.com.cache with

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

@@ -223,7 +223,7 @@ let collect ctx tk with_type sort =
 
 	let add_type mt =
 		match mt with
-		| TClassDecl {cl_kind = KAbstractImpl _ | KModuleStatics _} -> ()
+		| TClassDecl {cl_kind = KAbstractImpl _ | KModuleFields _} -> ()
 		| _ ->
 			let path = (t_infos mt).mt_path in
 			let mname = snd (t_infos mt).mt_module.m_path in

+ 1 - 1
src/core/json/genjson.ml

@@ -584,7 +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)
+		| KModuleFields m -> "KModuleFields",Some (generate_module_path m.m_path)
 		in
 		generate_adt ctx (Some (["haxe";"macro"],"ClassKind")) ctor args
 	in

+ 2 - 2
src/core/tFunctions.ml

@@ -734,8 +734,8 @@ let has_constructor c =
 		true
 	with Not_found -> false
 
-let is_module_statics_class c =
-	match c.cl_kind with KModuleStatics _ -> true | _ -> false
+let is_module_fields_class c =
+	match c.cl_kind with KModuleFields _ -> true | _ -> false
 
 let is_pos_outside_class c p =
 	p.pfile <> c.cl_pos.pfile || p.pmax < c.cl_pos.pmin || p.pmin > c.cl_pos.pmax

+ 2 - 2
src/core/tPrinting.ml

@@ -429,8 +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)
+	| KModuleFields m ->
+		Printf.sprintf "KModuleFields %s" (s_type_path m.m_path)
 
 module Printer = struct
 

+ 1 - 1
src/core/tType.ml

@@ -185,7 +185,7 @@ and tclass_kind =
 	| KMacroType
 	| KGenericBuild of class_field list
 	| KAbstractImpl of tabstract
-	| KModuleStatics of module_def
+	| KModuleFields of module_def
 
 and metadata = Ast.metadata
 

+ 3 - 3
src/filters/renameVars.ml

@@ -22,8 +22,8 @@ let reserve_init ri name =
 	ri.ri_reserved <- StringMap.add name true ri.ri_reserved
 
 (**
-	Make all class names reserved names.
-	No local variable will have a name matching a class.
+	Make all module-level names reserved.
+	No local variable will have a name matching a module-level declaration.
 *)
 let reserve_all_types ri com path_to_name =
 	List.iter (fun mt ->
@@ -35,7 +35,7 @@ let reserve_all_types ri com path_to_name =
 				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 } ->
+		| TClassDecl { cl_kind = KModuleFields 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

+ 14 - 14
src/generators/genjs.ml

@@ -151,13 +151,13 @@ let static_field ctx c f =
 	| s ->
 		field s
 
-let module_static m f =
+let module_field m f =
 	try
 		fst (TypeloadCheck.get_native_name f.cf_meta)
 	with Not_found ->
 		Path.flat_path m.m_path ^ "_" ^ f.cf_name
 
-let module_static_expose_path mpath f =
+let module_field_expose_path mpath f =
 	try
 		fst (TypeloadCheck.get_native_name f.cf_meta)
 	with Not_found ->
@@ -613,8 +613,8 @@ and gen_expr ctx e =
 		spr ctx f.cf_name;
 	| TField (x, (FInstance(_,_,f) | FStatic(_,f) | FAnon(f))) when Meta.has Meta.SelfCall f.cf_meta ->
 		gen_value ctx x;
-	| TField (_,FStatic ({ cl_kind = KModuleStatics m },f)) ->
-		spr ctx (module_static m f)
+	| TField (_,FStatic ({ cl_kind = KModuleFields m },f)) ->
+		spr ctx (module_field m f)
 	| TField (x,f) ->
 		let rec skip e = match e.eexpr with
 			| TCast(e1,None) | TMeta(_,e1) -> skip e1
@@ -1099,9 +1099,9 @@ let path_to_brackets path =
 	let parts = ExtString.String.nsplit path "." in
 	"[\"" ^ (String.concat "\"][\"" parts) ^ "\"]"
 
-let gen_module_statics ctx m c fl =
+let gen_module_fields ctx m c fl =
 	List.iter (fun f ->
-		let name = module_static m f in
+		let name = module_field m f in
 		match f.cf_expr with
 		| None when not (is_physical_field f) ->
 			()
@@ -1116,7 +1116,7 @@ let gen_module_statics ctx m c fl =
 				gen_function ~keyword:"" ctx fn e.epos;
 				ctx.separator <- false;
 				newline ctx;
-				process_expose f.cf_meta (fun () -> module_static_expose_path m.m_path f) (fun s ->
+				process_expose f.cf_meta (fun () -> module_field_expose_path m.m_path f) (fun s ->
 					print ctx "$hx_exports%s = %s" (path_to_brackets s) name;
 					newline ctx
 				)
@@ -1480,8 +1480,8 @@ let generate_class ctx c =
 	| [],"Function" -> abort "This class redefine a native one" c.cl_pos
 	| _ -> ());
 	match c.cl_kind with
-	| KModuleStatics m ->
-		gen_module_statics ctx m c c.cl_ordered_statics
+	| KModuleFields m ->
+		gen_module_fields ctx m c c.cl_ordered_statics
 	| _ ->
 		if ctx.es_version >= 6 then
 			generate_class_es6 ctx c
@@ -1582,9 +1582,9 @@ let generate_enum ctx e =
 let generate_static ctx (c,f,e) =
 	begin
 	match c.cl_kind with 
-	| KModuleStatics m ->
-		print ctx "var %s = " (module_static m f);
-		process_expose f.cf_meta (fun () -> module_static_expose_path m.m_path f) (fun s -> print ctx "$hx_exports%s = " (path_to_brackets s));
+	| KModuleFields m ->
+		print ctx "var %s = " (module_field m f);
+		process_expose f.cf_meta (fun () -> module_field_expose_path m.m_path f) (fun s -> print ctx "$hx_exports%s = " (path_to_brackets s));
 	| _ ->
 		let cl_path = get_generated_class_path c in
 		process_expose f.cf_meta (fun () -> (dot_path cl_path) ^ "." ^ f.cf_name) (fun s -> print ctx "$hx_exports%s = " (path_to_brackets s));
@@ -1736,8 +1736,8 @@ let generate com =
 				let add s = r := s :: !r in
 				let get_expose_path = 
 					match c.cl_kind with
-					| KModuleStatics m ->
-						module_static_expose_path m.m_path
+					| KModuleFields m ->
+						module_field_expose_path m.m_path
 					| _ ->
 						let path = dot_path c.cl_path in
 						process_expose c.cl_meta (fun () -> path) add;

+ 1 - 1
src/macro/macroApi.ml

@@ -976,7 +976,7 @@ and encode_class_kind k =
 	let tag, pl = (match k with
 		| KNormal -> 0, []
 		| KTypeParameter pl -> 1, [encode_tparams pl]
-		| KModuleStatics m -> 2, [encode_string (s_type_path m.m_path)]
+		| KModuleFields m -> 2, [encode_string (s_type_path m.m_path)]
 		| KExpr e -> 3, [encode_expr e]
 		| KGeneric -> 4, []
 		| KGenericInstance (cl, params) -> 5, [encode_clref cl; encode_tparams params]

+ 3 - 3
src/syntax/grammar.mly

@@ -199,7 +199,7 @@ and parse_type_decl mode s =
 				d_doc = doc_from_string_opt doc;
 				d_meta = meta;
 				d_params = pl;
-				d_flags = ExtList.List.filter_map decl_flag_to_module_static_flag c;
+				d_flags = ExtList.List.filter_map decl_flag_to_module_field_flag c;
 				d_data = FFun f;
 			}, punion p1 p2)
 		| [< '(Kwd Var,p1); name = dollar_ident; s >] ->
@@ -218,7 +218,7 @@ and parse_type_decl mode s =
 				d_doc = doc_from_string_opt doc;
 				d_meta = meta;
 				d_params = [];
-				d_flags = ExtList.List.filter_map decl_flag_to_module_static_flag c;
+				d_flags = ExtList.List.filter_map decl_flag_to_module_field_flag c;
 				d_data = t;
 			}, punion p1 p2)
 		| [< '(Kwd Enum,p1) >] ->
@@ -300,7 +300,7 @@ and parse_type_decl mode s =
 						d_doc = doc_from_string_opt doc;
 						d_meta = meta;
 						d_params = [];
-						d_flags = (ExtList.List.filter_map decl_flag_to_module_static_flag (List.rev crest)) @ [AFinal,p1];
+						d_flags = (ExtList.List.filter_map decl_flag_to_module_field_flag (List.rev crest)) @ [AFinal,p1];
 						d_data = FVar(t,e);
 					}, punion p1 p2)
 				| [< >] -> check_type_decl_flag_completion mode c s)

+ 3 - 3
src/syntax/parser.ml

@@ -198,7 +198,7 @@ let unsupported_decl_flag decl flag pos =
 let unsupported_decl_flag_class = unsupported_decl_flag "classes"
 let unsupported_decl_flag_enum = unsupported_decl_flag "enums"
 let unsupported_decl_flag_abstract = unsupported_decl_flag "abstracts"
-let unsupported_decl_flag_module_static = unsupported_decl_flag "module-level fields"
+let unsupported_decl_flag_module_field = unsupported_decl_flag "module-level fields"
 
 let decl_flag_to_class_flag (flag,p) = match flag with
 	| DPrivate -> Some HPrivate
@@ -216,12 +216,12 @@ let decl_flag_to_abstract_flag (flag,p) = match flag with
 	| DExtern -> Some AbExtern
 	| DFinal | DMacro | DDynamic | DInline | DPublic | DStatic -> unsupported_decl_flag_abstract flag p
 
-let decl_flag_to_module_static_flag (flag,p) = match flag with
+let decl_flag_to_module_field_flag (flag,p) = match flag with
 	| DPrivate -> Some (APrivate,p)
 	| DMacro -> Some (AMacro,p)
 	| DDynamic -> Some (ADynamic,p)
 	| DInline -> Some (AInline,p)
-	| DExtern | DFinal | DPublic | DStatic -> unsupported_decl_flag_module_static flag p
+	| DExtern | DFinal | DPublic | DStatic -> unsupported_decl_flag_module_field flag p
 
 let serror() = raise (Stream.Error "")
 

+ 2 - 2
src/typing/typeloadFields.ml

@@ -514,7 +514,7 @@ let create_class_context ctx c context_init p =
 			ctx.com.error msg ep;
 			(* macros expressions might reference other code, let's recall which class we are actually compiling *)
 			let open TFunctions in
-			if !locate_macro_error && (is_pos_outside_class c ep) && not (is_module_statics_class c) then ctx.com.error "Defined in this class" c.cl_pos
+			if !locate_macro_error && (is_pos_outside_class c ep) && not (is_module_fields_class c) then ctx.com.error "Defined in this class" c.cl_pos
 		);
 	} in
 	(* a lib type will skip most checks *)
@@ -606,7 +606,7 @@ let is_public (ctx,cctx) access parent =
 		true
 	else match parent with
 		| Some cf -> (has_class_field_flag cf CfPublic)
-		| _ -> c.cl_extern || c.cl_interface || cctx.extends_public || (match c.cl_kind with KModuleStatics _ -> true | _ -> false)
+		| _ -> c.cl_extern || c.cl_interface || cctx.extends_public || (match c.cl_kind with KModuleFields _ -> true | _ -> false)
 
 let rec get_parent c name =
 	match c.cl_super with

+ 2 - 2
src/typing/typeloadModule.ml

@@ -393,7 +393,7 @@ let module_pass_1 ctx m tdecls loadp =
 			| (TClassDecl c,_) :: _ ->
 				assert (m.m_statics = None);
 				m.m_statics <- Some c;
-				c.cl_kind <- KModuleStatics m;
+				c.cl_kind <- KModuleFields m;
 				c.cl_final <- true;
 			| _ -> assert false);
 			tdecls
@@ -896,7 +896,7 @@ let init_module_type ctx context_init (decl,p) =
 				error "Abstract is missing underlying type declaration" a.a_pos
 		end
 	| EStatic _ ->
-		(* nothing to do here as module statics are collected into a special EClass *)
+		(* nothing to do here as module fields are collected into a special EClass *)
 		()
 
 let module_pass_2 ctx m decls tdecls p =

+ 4 - 4
src/typing/typerDotPath.ml

@@ -39,8 +39,8 @@ let mk_dot_path_part s p : dot_path_part =
 let s_dot_path parts =
 	String.concat "." (List.map (fun (s,_,_) -> s) parts)
 
-(** resolve given path against module statics or raise Not_found *)
-let resolve_module_static ctx m path p =
+(** resolve given path against module fields or raise Not_found *)
+let resolve_module_field ctx m path p =
 	match path, m.m_statics with
 	| [], _ | _, None ->
 		raise Not_found
@@ -58,9 +58,9 @@ let resolve_module_type ctx m name p =
 let resolve_in_module ctx m path p =
 	try
 		(* first, try to find module-level static access *)
-		resolve_module_static ctx m path p
+		resolve_module_field ctx m path p
 	with Not_found ->
-		(* if there was no module-statics, resolve  *)
+		(* if there was no module fields, resolve  *)
 		let mname = snd m.m_path in
 		match path with
 		| (sname,PUppercase,sp) :: path_rest ->

+ 2 - 2
std/haxe/macro/Expr.hx

@@ -955,9 +955,9 @@ enum TypeDefKind {
 	TDAbstract(tthis:Null<ComplexType>, ?from:Array<ComplexType>, ?to:Array<ComplexType>);
 
 	/**
-		Represents a module-level static field.
+		Represents a module-level field.
 	**/
-	TDStatic(kind:FieldType, ?access:Array<Access>); // ignore TypeDefinition.fields
+	TDField(kind:FieldType, ?access:Array<Access>); // ignore TypeDefinition.fields
 }
 
 /**

+ 1 - 1
std/haxe/macro/Printer.hx

@@ -377,7 +377,7 @@ class Printer {
 						}
 					].join("\n")
 					+ "\n}";
-				case TDStatic(kind, access):
+				case TDField(kind, access):
 					tabs = old;
 					(access != null && access.length > 0 ? access.map(printAccess).join(" ") + " " : "")
 					+ switch (kind) {

+ 2 - 2
std/haxe/macro/Type.hx

@@ -303,9 +303,9 @@ enum ClassKind {
 	KTypeParameter(constraints:Array<Type>);
 
 	/**
-		A class containing module statics.
+		A class containing module fields.
 	**/
-	KModuleStatics(module:String);
+	KModuleFields(module:String);
 
 	/**
 		A special kind of class to encode expressions into type parameters.

+ 3 - 3
tests/unit/src/unit/TestModuleStaticsMacro.hx

@@ -14,14 +14,14 @@ class TestModuleStaticsMacro {
 			{
 				pos: pos,
 				name: "funcA",
-				kind: TDStatic(FFun({ret: macro : Int, args: [], expr: macro return 42})),
+				kind: TDField(FFun({ret: macro : Int, args: [], expr: macro return 42})),
 				pack: ["mstatics"],
 				fields: []
 			},
 			{
 				pos: pos,
 				name: "funcB",
-				kind: TDStatic(FFun({ret: macro : Int, args: [], expr: macro return 43})),
+				kind: TDField(FFun({ret: macro : Int, args: [], expr: macro return 43})),
 				pack: ["mstatics"],
 				fields: []
 			}
@@ -31,7 +31,7 @@ class TestModuleStaticsMacro {
 			pos: pos,
 			pack: ["mstatics"],
 			name: "FuncC",
-			kind: TDStatic(FFun({ret: macro : Int, args: [], expr: macro return 44})),
+			kind: TDField(FFun({ret: macro : Int, args: [], expr: macro return 44})),
 			fields: []
 		});