소스 검색

Set default define values from define.json (#12130)

Rudy Ges 3 달 전
부모
커밋
cd11d95e93
4개의 변경된 파일55개의 추가작업 그리고 9개의 파일을 삭제
  1. 30 1
      src-json/define.json
  2. 1 4
      src/compiler/compiler.ml
  3. 4 1
      src/core/define.ml
  4. 20 3
      src/prebuild.ml

+ 30 - 1
src-json/define.json

@@ -54,6 +54,7 @@
 		"define": "dce",
 		"define": "dce",
 		"doc": "Set the dead code elimination mode. (default: std)",
 		"doc": "Set the dead code elimination mode. (default: std)",
 		"params": ["mode: std | full | no"],
 		"params": ["mode: std | full | no"],
+		"default": "std",
 		"links": ["https://haxe.org/manual/cr-dce.html"]
 		"links": ["https://haxe.org/manual/cr-dce.html"]
 	},
 	},
 	{
 	{
@@ -115,6 +116,7 @@
 		"name": "DumpPath",
 		"name": "DumpPath",
 		"define": "dump-path",
 		"define": "dump-path",
 		"doc": "Path to generate dumps to (default: \"dump\").",
 		"doc": "Path to generate dumps to (default: \"dump\").",
+		"default": "dump",
 		"params": ["path"]
 		"params": ["path"]
 	},
 	},
 	{
 	{
@@ -125,7 +127,8 @@
 	{
 	{
 		"name": "DumpIgnoreVarIds",
 		"name": "DumpIgnoreVarIds",
 		"define": "dump-ignore-var-ids",
 		"define": "dump-ignore-var-ids",
-		"doc": "Remove variable IDs from non-pretty dumps (helps with diff)."
+		"doc": "Remove variable IDs from non-pretty dumps (helps with diff).",
+		"default": "1"
 	},
 	},
 	{
 	{
 		"name": "DynamicInterfaceClosures",
 		"name": "DynamicInterfaceClosures",
@@ -138,6 +141,7 @@
 		"define": "eval-call-stack-depth",
 		"define": "eval-call-stack-depth",
 		"doc": "Set maximum call stack depth for eval. (default: 1000)",
 		"doc": "Set maximum call stack depth for eval. (default: 1000)",
 		"platforms": ["eval"],
 		"platforms": ["eval"],
+		"default": "1000",
 		"params": ["depth"]
 		"params": ["depth"]
 	},
 	},
 	{
 	{
@@ -151,6 +155,7 @@
 		"define": "eval-print-depth",
 		"define": "eval-print-depth",
 		"doc": "Set maximum print depth (before replacing with '<...>') for eval. (default: 5)",
 		"doc": "Set maximum print depth (before replacing with '<...>') for eval. (default: 5)",
 		"platforms": ["eval"],
 		"platforms": ["eval"],
+		"default": "5",
 		"params": ["depth"]
 		"params": ["depth"]
 	},
 	},
 	{
 	{
@@ -241,6 +246,27 @@
 		"doc": "The current Haxe version value in SemVer format.",
 		"doc": "The current Haxe version value in SemVer format.",
 		"reserved": true
 		"reserved": true
 	},
 	},
+	{
+		"name": "Haxe3",
+		"define": "haxe3",
+		"doc": "The current Haxe major version is >= 3.",
+		"default": "1",
+		"reserved": true
+	},
+	{
+		"name": "Haxe4",
+		"define": "haxe4",
+		"doc": "The current Haxe major version is >= 4.",
+		"default": "1",
+		"reserved": true
+	},
+	{
+		"name": "Haxe5",
+		"define": "haxe5",
+		"doc": "The current Haxe major version is >= 5.",
+		"default": "1",
+		"reserved": true
+	},
 	{
 	{
 		"name": "HaxeNext",
 		"name": "HaxeNext",
 		"define": "haxe-next",
 		"define": "haxe-next",
@@ -484,6 +510,7 @@
 		"name": "LoopUnrollMaxCost",
 		"name": "LoopUnrollMaxCost",
 		"define": "loop-unroll-max-cost",
 		"define": "loop-unroll-max-cost",
 		"doc": "Maximum cost (number of expressions * iterations) before loop unrolling is canceled. (default: 250)",
 		"doc": "Maximum cost (number of expressions * iterations) before loop unrolling is canceled. (default: 250)",
+		"default": "250",
 		"params": ["cost"]
 		"params": ["cost"]
 	},
 	},
 	{
 	{
@@ -810,6 +837,7 @@
 		"name": "MessageReporting",
 		"name": "MessageReporting",
 		"define": "message.reporting",
 		"define": "message.reporting",
 		"doc": "Select message reporting mode for compiler output. (default: pretty)",
 		"doc": "Select message reporting mode for compiler output. (default: pretty)",
+		"default": "pretty",
 		"params": ["mode: classic | pretty | indent"]
 		"params": ["mode: classic | pretty | indent"]
 	},
 	},
 	{
 	{
@@ -831,6 +859,7 @@
 		"name": "MessageLogFormat",
 		"name": "MessageLogFormat",
 		"define": "message.log-format",
 		"define": "message.log-format",
 		"doc": "Select message reporting mode for message log file. (default: indent)",
 		"doc": "Select message reporting mode for message log file. (default: indent)",
+		"default": "indent",
 		"params": ["format: classic | pretty | indent"]
 		"params": ["format: classic | pretty | indent"]
 	}
 	}
 ]
 ]

+ 1 - 4
src/compiler/compiler.ml

@@ -232,12 +232,9 @@ module Setup = struct
 		let com = ctx.com in
 		let com = ctx.com in
 		ctx.com.print <- ctx.comm.write_out;
 		ctx.com.print <- ctx.comm.write_out;
 		Common.define_value com Define.HaxeVer (Printf.sprintf "%.3f" (float_of_int version /. 1000.));
 		Common.define_value com Define.HaxeVer (Printf.sprintf "%.3f" (float_of_int version /. 1000.));
-		Common.raw_define com "haxe3";
-		Common.raw_define com "haxe4";
-		Common.raw_define com "haxe5";
 		Common.define_value com Define.Haxe s_version;
 		Common.define_value com Define.Haxe s_version;
 		Common.raw_define com "true";
 		Common.raw_define com "true";
-		Common.define_value com Define.Dce "std";
+		List.iter (fun (k,v) -> Define.raw_define_value com.defines k v) DefineList.default_values;
 		com.info <- (fun ?(depth=0) ?(from_macro=false) msg p ->
 		com.info <- (fun ?(depth=0) ?(from_macro=false) msg p ->
 			message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Information)
 			message ctx (make_compiler_message ~from_macro msg p depth DKCompilerMessage Information)
 		);
 		);

+ 4 - 1
src/core/define.ml

@@ -31,16 +31,18 @@ type define_infos = {
 	d_origin : define_origin;
 	d_origin : define_origin;
 	d_links : string list;
 	d_links : string list;
 	d_deprecated : string option;
 	d_deprecated : string option;
+	d_default : string option;
 }
 }
 
 
 let infos ?user_defines d =
 let infos ?user_defines d =
 	let extract_infos (t, (doc, flags), origin) =
 	let extract_infos (t, (doc, flags), origin) =
-		let params = ref [] and pfs = ref [] and links = ref [] and deprecated = ref None in
+		let params = ref [] and pfs = ref [] and links = ref [] and deprecated = ref None and default = ref None in
 		List.iter (function
 		List.iter (function
 			| HasParam s -> params := s :: !params
 			| HasParam s -> params := s :: !params
 			| Platforms fl -> pfs := fl @ !pfs
 			| Platforms fl -> pfs := fl @ !pfs
 			| Link url -> links := url :: !links
 			| Link url -> links := url :: !links
 			| Deprecated s -> deprecated := Some s
 			| Deprecated s -> deprecated := Some s
+			| DefaultValue s -> default := Some s
 		) flags;
 		) flags;
 		(t, {
 		(t, {
 			d_doc = doc;
 			d_doc = doc;
@@ -49,6 +51,7 @@ let infos ?user_defines d =
 			d_origin = origin;
 			d_origin = origin;
 			d_links = !links;
 			d_links = !links;
 			d_deprecated = !deprecated;
 			d_deprecated = !deprecated;
+			d_default = !default;
 		})
 		})
 	in
 	in
 
 

+ 20 - 3
src/prebuild.ml

@@ -114,6 +114,7 @@ type parsed_define = {
 	d_links: string list;
 	d_links: string list;
 	d_deprecated : string option;
 	d_deprecated : string option;
 	d_deprecated_define : string option;
 	d_deprecated_define : string option;
+	d_default : string option;
 }
 }
 let parse_define json =
 let parse_define json =
 	let fields = match json with
 	let fields = match json with
@@ -129,6 +130,7 @@ let parse_define json =
 		d_links = get_optional_field "links" as_links [] fields;
 		d_links = get_optional_field "links" as_links [] fields;
 		d_deprecated = get_optional_field2 "deprecated" as_string fields;
 		d_deprecated = get_optional_field2 "deprecated" as_string fields;
 		d_deprecated_define = get_optional_field2 "deprecatedDefine" as_string fields;
 		d_deprecated_define = get_optional_field2 "deprecatedDefine" as_string fields;
+		d_default = get_optional_field2 "default" as_string fields;
 	}
 	}
 
 
 let parse_meta json =
 let parse_meta json =
@@ -201,6 +203,7 @@ let gen_option f = function
 
 
 let gen_define_info defines =
 let gen_define_info defines =
 	let deprecations = DynArray.create() in
 	let deprecations = DynArray.create() in
+	let default_values = DynArray.create() in
 	let define_str = List.map (function
 	let define_str = List.map (function
 		def ->
 		def ->
 			let platforms_str = gen_platforms def.d_platforms in
 			let platforms_str = gen_platforms def.d_platforms in
@@ -222,9 +225,21 @@ let gen_define_info defines =
 					DynArray.add deprecations (Printf.sprintf "\t(%S,DueTo(%S));" define x);
 					DynArray.add deprecations (Printf.sprintf "\t(%S,DueTo(%S));" define x);
 					[Printf.sprintf "Deprecated(%s)" quoted]
 					[Printf.sprintf "Deprecated(%s)" quoted]
 			in
 			in
-			"\t| " ^ def.d_name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" def.d_doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated)) ^ "])"
+			let default = match def.d_default with
+				| None ->
+					[]
+				| Some x ->
+					let quoted = Printf.sprintf "%S" x in
+					DynArray.add default_values (Printf.sprintf "\t(%S,%S)" define x);
+					[Printf.sprintf "DefaultValue(%s)" quoted]
+			in
+			"\t| " ^ def.d_name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" def.d_doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated @ default)) ^ "])"
 	) defines in
 	) defines in
-	String.concat "\n" define_str,String.concat "\n" (DynArray.to_list deprecations)
+	(
+		String.concat "\n" define_str,
+		String.concat "\n" (DynArray.to_list deprecations),
+		String.concat ";\n" (DynArray.to_list default_values)
+	)
 
 
 let gen_meta_type metas =
 let gen_meta_type metas =
 	String.concat "\n" (List.map (function
 	String.concat "\n" (List.map (function
@@ -298,6 +313,7 @@ type define_parameter =
 	| Platforms of platform list
 	| Platforms of platform list
 	| Link of string
 	| Link of string
 	| Deprecated of string
 	| Deprecated of string
+	| DefaultValue of string
 
 
 type define_deprecation =
 type define_deprecation =
 	| DueTo of string
 	| DueTo of string
@@ -363,11 +379,12 @@ match Array.to_list (Sys.argv) with
 		Printf.printf "type strict_defined =\n";
 		Printf.printf "type strict_defined =\n";
 		Printf.printf "%s" (gen_define_type defines);
 		Printf.printf "%s" (gen_define_type defines);
 		Printf.printf "\n\t| Last\n\t| Custom of string\n\n";
 		Printf.printf "\n\t| Last\n\t| Custom of string\n\n";
-		let infos,deprecations = gen_define_info defines in
+		let infos,deprecations,default_values = gen_define_info defines in
 		Printf.printf "let infos = function\n";
 		Printf.printf "let infos = function\n";
 		Printf.printf "%s" infos;
 		Printf.printf "%s" infos;
 		Printf.printf "\n\t| Last -> die \"\" __LOC__\n\t| Custom s -> s,(\"\",[])\n";
 		Printf.printf "\n\t| Last -> die \"\" __LOC__\n\t| Custom s -> s,(\"\",[])\n";
 		Printf.printf "\nlet deprecated_defines = [\n%s\n]\n" deprecations;
 		Printf.printf "\nlet deprecated_defines = [\n%s\n]\n" deprecations;
+		Printf.printf "\nlet default_values = [\n%s\n]\n" default_values;
 	| [_; "meta"; meta_path]->
 	| [_; "meta"; meta_path]->
 		let metas = parse_file_array meta_path parse_meta in
 		let metas = parse_file_array meta_path parse_meta in
 		Printf.printf "%s" meta_header;
 		Printf.printf "%s" meta_header;