2
0
Эх сурвалжийг харах

support specifying platforms for defines (so they are mentioned in --help-defines)

Dan Korostelev 8 жил өмнө
parent
commit
39c25f4d37

+ 5 - 0
src/compiler/globals.ml

@@ -58,6 +58,11 @@ let platform_name = function
 	| Hl -> "hl"
 	| Eval -> "eval"
 
+let platform_list_help = function
+	| [] -> ""
+	| [p] -> " (" ^ platform_name p ^ " only)"
+	| pl -> " (for " ^ String.concat "," (List.map platform_name pl) ^ ")"
+
 let null_pos = { pfile = "?"; pmin = -1; pmax = -1 }
 
 let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s

+ 2 - 12
src/compiler/main.ml

@@ -702,18 +702,8 @@ try
 			did_something := true;
 		),": print version and exit");
 		("--help-defines", Arg.Unit (fun() ->
-			let m = ref 0 in
-			let rec loop i =
-				let d = Obj.magic i in
-				if d <> Define.Last then begin
-					let t, doc = Define.infos d in
-					if String.length t > !m then m := String.length t;
-					((String.concat "-" (ExtString.String.nsplit t "_")),doc) :: (loop (i + 1))
-				end else
-					[]
-			in
-			let all = List.sort (fun (s1,_) (s2,_) -> String.compare s1 s2) (loop 0) in
-			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" !m n (limit_string doc (!m + 3))) all in
+			let all,max_length = Define.get_documentation_list() in
+			let all = List.map (fun (n,doc) -> Printf.sprintf " %-*s: %s" max_length n (limit_string doc (max_length + 3))) all in
 			List.iter (fun msg -> ctx.com.print (msg ^ "\n")) all;
 			did_something := true
 		),": print help for all compiler specific defines");

+ 123 - 97
src/context/common.ml

@@ -550,106 +550,132 @@ module Define = struct
 		| NoMacroCache
 		| Last (* must be last *)
 
+	type define_parameter =
+		| HasParam of string
+		| Platform of platform
+		| Platforms of platform list
+
 	let infos = function
-		| AbsolutePath -> ("absolute_path","Print absolute file path in trace output")
-		| AdvancedTelemetry -> ("advanced-telemetry","Allow the SWF to be measured with Monocle tool")
-		| AnnotateSource -> ("annotate_source","Add additional comments to generated source code")
-		(* | Analyzer -> ("analyzer","Use static analyzer for optimization (experimental)") *)
-		| As3 -> ("as3","Defined when outputing flash9 as3 source code")
-		| CheckXmlProxy -> ("check_xml_proxy","Check the used fields of the xml proxy")
-		| CoreApi -> ("core_api","Defined in the core api context")
-		| CoreApiSerialize -> ("core_api_serialize","Mark some generated core api classes with the Serializable attribute on C#")
-		| Cppia -> ("cppia", "Generate cpp instruction assembly")
-		| CppiaAst -> ("cppiaast", "Experimental cppia generation based on cpp ast")
-		| Dce -> ("dce","<mode:std|full|no> Set the dead code elimination mode (default std)")
-		| DceDebug -> ("dce_debug","Show DCE log")
-		| Debug -> ("debug","Activated when compiling with -debug")
-		| Display -> ("display","Activated during completion")
-		| DisplayStdin -> ("display_stdin","Read the contents of a file specified in --display from standard input")
-		| DllExport -> ("dll_export", "GenCPP experimental linking")
-		| DllImport -> ("dll_import", "GenCPP experimental linking")
-		| DocGen -> ("doc_gen","Do not perform any removal/change in order to correctly generate documentation")
-		| Dump -> ("dump","<mode:pretty|record|legacy> Dump typed AST in dump subdirectory using specified mode or non-prettified default")
-		| DumpDependencies -> ("dump_dependencies","Dump the classes dependencies in a dump subdirectory")
-		| DumpIgnoreVarIds -> ("dump_ignore_var_ids","Remove variable IDs from non-pretty dumps (helps with diff)")
-		| DynamicInterfaceClosures -> ("dynamic_interface_closures","Use slow path for interface closures to save space")
-		| EraseGenerics -> ("erase_generics","Erase generic classes on C#")
-		| EvalDebugger -> ("eval_debugger","Support debugger in macro/interp mode. Allows host:port value to open a socket. Implies eval_stack.")
-		| EvalStack -> ("eval_stack","Record stack information in macro/interp mode")
-		| EvalTimes -> ("eval_times","Record per-method execution times in macro/interp mode. Implies eval_stack.")
-		| FastCast -> ("fast_cast","Enables an experimental casts cleanup on C# and Java")
-		| Fdb -> ("fdb","Enable full flash debug infos for FDB interactive debugging")
-		| FileExtension -> ("file_extension","Output filename extension for cpp source code")
-		| FlashStrict -> ("flash_strict","More strict typing for flash target")
-		| FlashUseStage -> ("flash_use_stage","Keep the SWF library initial stage")
+		| AbsolutePath -> "absolute_path",("Print absolute file path in trace output",[])
+		| AdvancedTelemetry -> "advanced-telemetry",("Allow the SWF to be measured with Monocle tool",[])
+		| AnnotateSource -> "annotate_source",("Add additional comments to generated source code",[])
+		(* | Analyzer -> "analyzer",("Use static analyzer for optimization (experimental)") *)
+		| As3 -> "as3",("Defined when outputing flash9 as3 source code",[])
+		| CheckXmlProxy -> "check_xml_proxy",("Check the used fields of the xml proxy",[])
+		| CoreApi -> "core_api",("Defined in the core api context",[])
+		| CoreApiSerialize -> "core_api_serialize",("Mark some generated core api classes with the Serializable attribute on C#",[])
+		| Cppia -> "cppia",("Generate cpp instruction assembly",[])
+		| CppiaAst -> "cppiaast",("Experimental cppia generation based on cpp ast",[])
+		| Dce -> "dce",("<mode:std|full|no> Set the dead code elimination mode (default std)",[])
+		| DceDebug -> "dce_debug",("Show DCE log",[])
+		| Debug -> "debug",("Activated when compiling with -debug",[])
+		| Display -> "display",("Activated during completion",[])
+		| DisplayStdin -> "display_stdin",("Read the contents of a file specified in --display from standard input",[])
+		| DllExport -> "dll_export",("GenCPP experimental linking",[])
+		| DllImport -> "dll_import",("GenCPP experimental linking",[])
+		| DocGen -> "doc_gen",("Do not perform any removal/change in order to correctly generate documentation",[])
+		| Dump -> "dump",("<mode:pretty|record|legacy> Dump typed AST in dump subdirectory using specified mode or non-prettified default",[])
+		| DumpDependencies -> "dump_dependencies",("Dump the classes dependencies in a dump subdirectory",[])
+		| DumpIgnoreVarIds -> "dump_ignore_var_ids",("Remove variable IDs from non-pretty dumps (helps with diff)",[])
+		| DynamicInterfaceClosures -> "dynamic_interface_closures",("Use slow path for interface closures to save space",[])
+		| EraseGenerics -> "erase_generics",("Erase generic classes on C#",[])
+		| EvalDebugger -> "eval_debugger",("Support debugger in macro/interp mode. Allows host:port value to open a socket. Implies eval_stack.",[])
+		| EvalStack -> "eval_stack",("Record stack information in macro/interp mode",[])
+		| EvalTimes -> "eval_times",("Record per-method execution times in macro/interp mode. Implies eval_stack.",[])
+		| FastCast -> "fast_cast",("Enables an experimental casts cleanup on C# and Java",[])
+		| Fdb -> "fdb",("Enable full flash debug infos for FDB interactive debugging",[])
+		| FileExtension -> "file_extension",("Output filename extension for cpp source code",[])
+		| FlashStrict -> "flash_strict",("More strict typing for flash target",[])
+		| FlashUseStage -> "flash_use_stage",("Keep the SWF library initial stage",[])
 		(* force_lib_check is only here as a debug facility - compiler checking allows errors to be found more easily *)
-		| ForceLibCheck -> ("force_lib_check","Force the compiler to check -net-lib and -java-lib added classes (internal)")
-		| ForceNativeProperty -> ("force_native_property","Tag all properties with :nativeProperty metadata for 3.1 compatibility")
-		| FormatWarning -> ("format_warning","Print a warning for each formated string, for 2.x compatibility")
-		| GencommonDebug -> ("gencommon_debug","GenCommon internal")
-		| HaxeBoot -> ("haxe_boot","Given the name 'haxe' to the flash boot class instead of a generated name")
-		| HaxeVer -> ("haxe_ver","The current Haxe version value")
-		| HxcppApiLevel -> ("hxcpp_api_level","Provided to allow compatibility between hxcpp versions")
-		| HxcppGcGenerational -> ("HXCPP_GC_GENERATIONAL","Experimental Garbage Collector")
-		| HxcppDebugger -> ("HXCPP_DEBUGGER","Include additional information for HXCPP_DEBUGGER")
-		| IncludePrefix -> ("include_prefix","prepend path to generated include files")
-		| Interp -> ("interp","The code is compiled to be run with --interp")
-		| JavaVer -> ("java_ver", "<version:5-7> Sets the Java version to be targeted")
-		| JqueryVer -> ("jquery_ver", "The jQuery version supported by js.jquery.*. The version is encoded as an interger. e.g. 1.11.3 is encoded as 11103")
-		| JsClassic -> ("js_classic","Don't use a function wrapper and strict mode in JS output")
-		| JsEs -> ("js_es","Generate JS compilant with given ES standard version (default 5)")
-		| JsUnflatten -> ("js_unflatten","Generate nested objects for packages and types")
-		| JsSourceMap -> ("js_source_map","Generate JavaScript source map even in non-debug mode")
-		| SourceMap -> ("source_map","Generate source map for compiled files (Currently supported for php7 only)")
-		| KeepOldOutput -> ("keep_old_output","Keep old source files in the output directory (for C#/Java)")
-		| LoopUnrollMaxCost -> ("loop_unroll_max_cost","Maximum cost (number of expressions * iterations) before loop unrolling is canceled (default 250)")
-		| LuaJit -> ("lua_jit","Enable the jit compiler for lua (version 5.2 only")
-		| LuaVer -> ("lua_ver","The lua version to target")
-		| Macro -> ("macro","Defined when code is compiled in the macro context")
-		| MacroDebug -> ("macro_debug","Show warnings for potential macro problems (e.g. macro-in-macro calls)")
-		| MacroTimes -> ("macro_times","Display per-macro timing when used with --times")
-		| NetVer -> ("net_ver", "<version:20-45> Sets the .NET version to be targeted")
-		| NetTarget -> ("net_target", "<name> Sets the .NET target. Defaults to \"net\". xbox, micro (Micro Framework), compact (Compact Framework) are some valid values")
-		| NekoSource -> ("neko_source","Output neko source instead of bytecode")
-		| NekoV1 -> ("neko_v1","Keep Neko 1.x compatibility")
-		| NetworkSandbox -> ("network-sandbox","Use local network sandbox instead of local file access one")
-		| NoCompilation -> ("no-compilation","Disable final compilation for Cs, Cpp and Java")
-		| NoCOpt -> ("no_copt","Disable completion optimization (for debug purposes)")
-		| NoDebug -> ("no_debug","Remove all debug macros from cpp output")
-		| NoDeprecationWarnings -> ("no-deprecation-warnings","Do not warn if fields annotated with @:deprecated are used")
-		| NoFlashOverride -> ("no-flash-override", "Change overrides on some basic classes into HX suffixed methods, flash only")
-		| NoOpt -> ("no_opt","Disable optimizations")
-		| NoInline -> ("no_inline","Disable inlining")
-		| NoRoot -> ("no_root","Generate top-level types into haxe.root namespace")
-		| NoMacroCache -> ("no_macro_cache","Disable macro context caching")
-		| NoSwfCompress -> ("no_swf_compress","Disable SWF output compression")
-		| NoTraces -> ("no_traces","Disable all trace calls")
-		| Objc -> ("objc","Sets the hxcpp output to objective-c++ classes. Must be defined for interop")
-		| OldConstructorInline -> ("old-constructor-inline","Use old constructor inlining logic (from haxe 3.4.2) instead of the reworked version.")
-		| OldErrorFormat -> ("old-error-format", "Use Haxe 3.x zero-based column error messages instead of new one-based format.")
-		| PhpPrefix -> ("php_prefix","Compiled with --php-prefix")
-		| RealPosition -> ("real_position","Disables Haxe source mapping when targetting C#, removes position comments in Java and Php7 output")
-		| ReplaceFiles -> ("replace_files","GenCommon internal")
-		| Scriptable -> ("scriptable","GenCPP internal")
-		| ShallowExpose -> ("shallow-expose","Expose types to surrounding scope of Haxe generated closure without writing to window object")
-		| SourceHeader -> ("source-header","Print value as comment on top of generated files, use '' value to disable")
-		| SourceMapContent -> ("source-map-content","Include the hx sources as part of the JS source map")
-		| Swc -> ("swc","Output a SWC instead of a SWF")
-		| SwfCompressLevel -> ("swf_compress_level","<level:1-9> Set the amount of compression for the SWF output")
-		| SwfDebugPassword -> ("swf_debug_password", "Set a password for debugging")
-		| SwfDirectBlit -> ("swf_direct_blit", "Use hardware acceleration to blit graphics")
-		| SwfGpu -> ("swf_gpu", "Use GPU compositing features when drawing graphics")
-		| SwfMetadata -> ("swf_metadata", "<file> Include contents of <file> as metadata in the swf")
-		| SwfPreloaderFrame -> ("swf_preloader_frame", "Insert empty first frame in swf")
-		| SwfProtected -> ("swf_protected","Compile Haxe private as protected in the SWF instead of public")
-		| SwfScriptTimeout -> ("swf_script_timeout", "Maximum ActionScript processing time before script stuck dialog box displays (in seconds)")
-		| SwfUseDoAbc -> ("swf_use_doabc", "Use DoAbc swf-tag instead of DoAbcDefine")
-		| Sys -> ("sys","Defined for all system platforms")
-		| Unsafe -> ("unsafe","Allow unsafe code when targeting C#")
-		| UseNekoc -> ("use_nekoc","Use nekoc compiler instead of internal one")
-		| UseRttiDoc -> ("use_rtti_doc","Allows access to documentation during compilation")
-		| Vcproj -> ("vcproj","GenCPP internal")
+		| ForceLibCheck -> "force_lib_check",("Force the compiler to check -net-lib and -java-lib added classes (internal)",[])
+		| ForceNativeProperty -> "force_native_property",("Tag all properties with :nativeProperty metadata for 3.1 compatibility",[])
+		| FormatWarning -> "format_warning",("Print a warning for each formated string, for 2.x compatibility",[])
+		| GencommonDebug -> "gencommon_debug",("GenCommon internal",[])
+		| HaxeBoot -> "haxe_boot",("Given the name 'haxe' to the flash boot class instead of a generated name",[])
+		| HaxeVer -> "haxe_ver",("The current Haxe version value",[])
+		| HxcppApiLevel -> "hxcpp_api_level",("Provided to allow compatibility between hxcpp versions",[])
+		| HxcppGcGenerational -> "HXCPP_GC_GENERATIONAL",("Experimental Garbage Collector",[])
+		| HxcppDebugger -> "HXCPP_DEBUGGER",("Include additional information for HXCPP_DEBUGGER",[])
+		| IncludePrefix -> "include_prefix",("prepend path to generated include files",[])
+		| Interp -> "interp",("The code is compiled to be run with --interp",[])
+		| JavaVer -> "java_ver",("<version:5-7> Sets the Java version to be targeted",[])
+		| JqueryVer -> "jquery_ver",("The jQuery version supported by js.jquery.*. The version is encoded as an interger. e.g. 1.11.3 is encoded as 11103",[])
+		| JsClassic -> "js_classic",("Don't use a function wrapper and strict mode in JS output",[])
+		| JsEs -> "js_es",("Generate JS compilant with given ES standard version (default 5)",[])
+		| JsUnflatten -> "js_unflatten",("Generate nested objects for packages and types",[])
+		| JsSourceMap -> "js_source_map",("Generate JavaScript source map even in non-debug mode",[])
+		| SourceMap -> "source_map",("Generate source map for compiled files (Currently supported for php7 only)",[])
+		| KeepOldOutput -> "keep_old_output",("Keep old source files in the output directory (for C#/Java)",[])
+		| LoopUnrollMaxCost -> "loop_unroll_max_cost",("Maximum cost (number of expressions * iterations) before loop unrolling is canceled (default 250)",[])
+		| LuaJit -> "lua_jit",("Enable the jit compiler for lua (version 5.2 only",[])
+		| LuaVer -> "lua_ver",("The lua version to target",[])
+		| Macro -> "macro",("Defined when code is compiled in the macro context",[])
+		| MacroDebug -> "macro_debug",("Show warnings for potential macro problems (e.g. macro-in-macro calls)",[])
+		| MacroTimes -> "macro_times",("Display per-macro timing when used with --times",[])
+		| NetVer -> "net_ver",("<version:20-45> Sets the .NET version to be targeted",[])
+		| NetTarget -> "net_target",("<name> Sets the .NET target. Defaults to \"net\". xbox, micro (Micro Framework), compact (Compact Framework) are some valid values",[])
+		| NekoSource -> "neko_source",("Output neko source instead of bytecode",[])
+		| NekoV1 -> "neko_v1",("Keep Neko 1.x compatibility",[])
+		| NetworkSandbox -> "network-sandbox",("Use local network sandbox instead of local file access one",[])
+		| NoCompilation -> "no-compilation",("Disable final compilation for Cs, Cpp and Java",[])
+		| NoCOpt -> "no_copt",("Disable completion optimization (for debug purposes)",[])
+		| NoDebug -> "no_debug",("Remove all debug macros from cpp output",[])
+		| NoDeprecationWarnings -> "no-deprecation-warnings",("Do not warn if fields annotated with @:deprecated are used",[])
+		| NoFlashOverride -> "no-flash-override",("Change overrides on some basic classes into HX suffixed methods, flash only",[])
+		| NoOpt -> "no_opt",("Disable optimizations",[])
+		| NoInline -> "no_inline",("Disable inlining",[])
+		| NoRoot -> "no_root",("Generate top-level types into haxe.root namespace",[])
+		| NoMacroCache -> "no_macro_cache",("Disable macro context caching",[])
+		| NoSwfCompress -> "no_swf_compress",("Disable SWF output compression",[])
+		| NoTraces -> "no_traces",("Disable all trace calls",[])
+		| Objc -> "objc",("Sets the hxcpp output to objective-c++ classes. Must be defined for interop",[])
+		| OldConstructorInline -> "old-constructor-inline",("Use old constructor inlining logic (from haxe 3.4.2) instead of the reworked version.",[])
+		| OldErrorFormat -> "old-error-format",("Use Haxe 3.x zero-based column error messages instead of new one-based format.",[])
+		| PhpPrefix -> "php_prefix",("Compiled with --php-prefix",[])
+		| RealPosition -> "real_position",("Disables Haxe source mapping when targetting C#, removes position comments in Java and Php7 output",[])
+		| ReplaceFiles -> "replace_files",("GenCommon internal",[Platforms [Java;Cs]])
+		| Scriptable -> "scriptable",("GenCPP internal",[Platform Cpp])
+		| ShallowExpose -> "shallow-expose",("Expose types to surrounding scope of Haxe generated closure without writing to window object",[Platform Js])
+		| SourceHeader -> "source-header",("Print value as comment on top of generated files, use '' value to disable",[])
+		| SourceMapContent -> "source-map-content",("Include the hx sources as part of the JS source map",[])
+		| Swc -> "swc",("Output a SWC instead of a SWF",[])
+		| SwfCompressLevel -> "swf_compress_level",("<level:1-9> Set the amount of compression for the SWF output",[])
+		| SwfDebugPassword -> "swf_debug_password",("Set a password for debugging",[])
+		| SwfDirectBlit -> "swf_direct_blit",("Use hardware acceleration to blit graphics",[])
+		| SwfGpu -> "swf_gpu",("Use GPU compositing features when drawing graphics",[])
+		| SwfMetadata -> "swf_metadata",("<file> Include contents of <file> as metadata in the swf",[])
+		| SwfPreloaderFrame -> "swf_preloader_frame",("Insert empty first frame in swf",[])
+		| SwfProtected -> "swf_protected",("Compile Haxe private as protected in the SWF instead of public",[])
+		| SwfScriptTimeout -> "swf_script_timeout",("Maximum ActionScript processing time before script stuck dialog box displays (in seconds)",[])
+		| SwfUseDoAbc -> "swf_use_doabc",("Use DoAbc swf-tag instead of DoAbcDefine",[])
+		| Sys -> "sys",("Defined for all system platforms",[])
+		| Unsafe -> "unsafe",("Allow unsafe code when targeting C#",[])
+		| UseNekoc -> "use_nekoc",("Use nekoc compiler instead of internal one",[])
+		| UseRttiDoc -> "use_rtti_doc",("Allows access to documentation during compilation",[])
+		| Vcproj -> "vcproj",("GenCPP internal",[Platform Cpp])
 		| Last -> assert false
+
+	let get_documentation_list() =
+		let m = ref 0 in
+		let rec loop i =
+			let d = Obj.magic i in
+			if d <> Last then begin
+				let t, (doc,flags) = infos d in
+				let pfs = ref [] in
+				List.iter (function
+				| HasParam s -> () (* TODO *)
+				| Platform p -> pfs := p :: !pfs;
+				| Platforms pl -> pfs := pl @ !pfs;
+				) flags;
+				let pfs = platform_list_help (List.rev !pfs) in
+				if String.length t > !m then m := String.length t;
+				((String.concat "-" (ExtString.String.nsplit t "_")),doc ^ pfs) :: (loop (i + 1))
+			end else
+				[]
+		in
+		let all = List.sort (fun (s1,_) (s2,_) -> String.compare s1 s2) (loop 0) in
+		all,!m
 end
 
 let short_platform_name = function

+ 1 - 5
src/context/meta.ml

@@ -410,11 +410,7 @@ let get_documentation d =
 			| [] -> ""
 			| l -> "(" ^ String.concat "," l ^ ")"
 		) in
-		let pfs = (match List.rev !pfs with
-			| [] -> ""
-			| [p] -> " (" ^ platform_name p ^ " only)"
-			| pl -> " (for " ^ String.concat "," (List.map platform_name pl) ^ ")"
-		) in
+		let pfs = platform_list_help (List.rev !pfs) in
 		let str = "@" ^ t in
 		Some (str,params ^ doc ^ pfs)
 	end else