Browse Source

Rewrite deprecated defines (#12101)

* turn into record

* support deprecatedDefine

* deprecate all the whatever-times to times.whatever
Simon Krajewski 4 months ago
parent
commit
70a1f3d1d6
3 changed files with 60 additions and 24 deletions
  1. 10 5
      src-json/define.json
  2. 8 2
      src/compiler/compiler.ml
  3. 42 17
      src/prebuild.ml

+ 10 - 5
src-json/define.json

@@ -18,7 +18,8 @@
 	},
 	},
 	{
 	{
 		"name": "AnalyzerTimes",
 		"name": "AnalyzerTimes",
-		"define": "analyzer-times",
+		"define": "times.analyzer",
+		"deprecatedDefine": "analyzer-times",
 		"doc": "Record detailed timers for the analyzer",
 		"doc": "Record detailed timers for the analyzer",
 		"params": ["level: 0 | 1 | 2"]
 		"params": ["level: 0 | 1 | 2"]
 	},
 	},
@@ -166,7 +167,8 @@
 	},
 	},
 	{
 	{
 		"name": "EvalTimes",
 		"name": "EvalTimes",
-		"define": "eval-times",
+		"define": "times.eval",
+		"deprecatedDefine": "eval-times",
 		"doc": "Record per-method execution times in macro/interp mode. Implies eval-stack.",
 		"doc": "Record per-method execution times in macro/interp mode. Implies eval-stack.",
 		"platforms": ["eval"]
 		"platforms": ["eval"]
 	},
 	},
@@ -177,7 +179,8 @@
 	},
 	},
 	{
 	{
 		"name": "FilterTimes",
 		"name": "FilterTimes",
-		"define": "filter-times",
+		"define": "times.filter",
+		"deprecatedDefine": "filter-times",
 		"doc": "Record per-filter execution times upon --times."
 		"doc": "Record per-filter execution times upon --times."
 	},
 	},
 	{
 	{
@@ -273,7 +276,8 @@
 	},
 	},
 	{
 	{
 		"name": "HxbTimes",
 		"name": "HxbTimes",
-		"define": "hxb-times",
+		"define": "times.hxb",
+		"deprecatedDefine": "hxb-times",
 		"doc": "Display hxb timing when used with `--times`."
 		"doc": "Display hxb timing when used with `--times`."
 	},
 	},
 	{
 	{
@@ -510,7 +514,8 @@
 	},
 	},
 	{
 	{
 		"name": "MacroTimes",
 		"name": "MacroTimes",
-		"define": "macro-times",
+		"define": "times.macro",
+		"deprecatedDefine": "macro-times",
 		"doc": "Display per-macro timing when used with `--times`."
 		"doc": "Display per-macro timing when used with `--times`."
 	},
 	},
 	{
 	{

+ 8 - 2
src/compiler/compiler.ml

@@ -274,11 +274,17 @@ end
 
 
 let check_defines com =
 let check_defines com =
 	if is_next com then begin
 	if is_next com then begin
-		PMap.iter (fun k _ ->
+		PMap.iter (fun k v ->
 			try
 			try
 				let reason = Hashtbl.find Define.deprecation_lut k in
 				let reason = Hashtbl.find Define.deprecation_lut k in
 				let p = fake_pos ("-D " ^ k) in
 				let p = fake_pos ("-D " ^ k) in
-				com.warning WDeprecatedDefine [] reason p
+				begin match reason with
+				| DueTo reason ->
+					com.warning WDeprecatedDefine [] reason p
+				| InFavorOf d ->
+					Define.raw_define_value com.defines d v;
+					com.warning WDeprecatedDefine [] (Printf.sprintf "-D %s has been deprecated in favor of -D %s" k d) p
+				end;
 			with Not_found ->
 			with Not_found ->
 				()
 				()
 		) com.defines.values
 		) com.defines.values

+ 42 - 17
src/prebuild.ml

@@ -105,18 +105,31 @@ let get_field name map fields =
 	| None -> raise (Prebuild_error ("field `" ^ name ^ "` has invalid data"))
 	| None -> raise (Prebuild_error ("field `" ^ name ^ "` has invalid data"))
 	| Some v -> v
 	| Some v -> v
 
 
+type parsed_define = {
+	d_name : string;
+	d_define : string;
+	d_doc : string;
+	d_params : string list;
+	d_platforms : string list;
+	d_links: string list;
+	d_deprecated : string option;
+	d_deprecated_define : string option;
+}
 let parse_define json =
 let parse_define json =
 	let fields = match json with
 	let fields = match json with
 		| JObject fl -> fl
 		| JObject fl -> fl
 		| _ -> raise (Prebuild_error "not an object")
 		| _ -> raise (Prebuild_error "not an object")
 	in
 	in
-	(* name *) get_field "name" as_string fields,
-	(* define *) get_field "define" as_string fields,
-	(* doc *) get_field "doc" as_string fields,
-	(* params *) get_optional_field "params" as_params [] fields,
-	(* platforms *) get_optional_field "platforms" as_platforms [] fields,
-	(* links *) get_optional_field "links" as_links [] fields,
-	(* deprecated *) get_optional_field2 "deprecated" as_string fields
+	{
+		d_name = get_field "name" as_string fields;
+		d_define = get_field "define" as_string fields;
+		d_doc = get_field "doc" as_string fields;
+		d_params = get_optional_field "params" as_params [] fields;
+		d_platforms = get_optional_field "platforms" as_platforms [] fields;
+		d_links = get_optional_field "links" as_links [] fields;
+		d_deprecated = get_optional_field2 "deprecated" as_string fields;
+		d_deprecated_define = get_optional_field2 "deprecatedDefine" as_string fields;
+	}
 
 
 let parse_meta json =
 let parse_meta json =
 	let fields = match json with
 	let fields = match json with
@@ -180,7 +193,7 @@ let gen_params = List.map (function param -> "HasParam \"" ^ param ^ "\"" )
 let gen_links = List.map (function link -> "Link \"" ^ link ^ "\"" )
 let gen_links = List.map (function link -> "Link \"" ^ link ^ "\"" )
 
 
 let gen_define_type defines =
 let gen_define_type defines =
-	String.concat "\n" (List.map (function (name, _, _, _, _, _, _) -> "\t| " ^ name) defines)
+	String.concat "\n" (List.map (function def -> "\t| " ^ def.d_name) defines)
 
 
 let gen_option f = function
 let gen_option f = function
 	| None -> "None"
 	| None -> "None"
@@ -189,22 +202,29 @@ 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 define_str = List.map (function
 	let define_str = List.map (function
-		(name, define, doc, params, platforms, links, deprecated) ->
-			let platforms_str = gen_platforms platforms in
-			let params_str = gen_params params in
-			let links_str = gen_links links in
-			let define = String.concat "_" (ExtString.String.nsplit define "-") in
-			let deprecated = match deprecated with
+		def ->
+			let platforms_str = gen_platforms def.d_platforms in
+			let params_str = gen_params def.d_params in
+			let links_str = gen_links def.d_links in
+			let convert_define s = String.concat "_" (ExtString.String.nsplit s "-") in
+			let define = convert_define def.d_define in
+			let deprecated = match def.d_deprecated with
 				| None ->
 				| None ->
+					begin match def.d_deprecated_define with
+					| None ->
+						()
+					| Some s ->
+						DynArray.add deprecations (Printf.sprintf "\t(%S,InFavorOf(%S));" (convert_define s) define)
+					end;
 					[]
 					[]
 				| Some x ->
 				| Some x ->
 					let quoted = Printf.sprintf "%S" x in
 					let quoted = Printf.sprintf "%S" x in
-					DynArray.add deprecations (Printf.sprintf "\t(%S,%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| " ^ name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated)) ^ "])"
+			"\t| " ^ def.d_name ^ " -> \"" ^ define ^ "\",(" ^ (Printf.sprintf "%S" def.d_doc) ^ ",[" ^ (String.concat "; " (platforms_str @ params_str @ links_str @ deprecated)) ^ "])"
 	) 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)
 
 
 let gen_meta_type metas =
 let gen_meta_type metas =
 	String.concat "\n" (List.map (function
 	String.concat "\n" (List.map (function
@@ -278,6 +298,11 @@ type define_parameter =
 	| Platforms of platform list
 	| Platforms of platform list
 	| Link of string
 	| Link of string
 	| Deprecated of string
 	| Deprecated of string
+
+type define_deprecation =
+	| DueTo of string
+	| InFavorOf of string
+
 "
 "
 
 
 let meta_header = autogen_header ^ "
 let meta_header = autogen_header ^ "