فهرست منبع

add -D source-target (see #4328)

Simon Krajewski 10 سال پیش
والد
کامیت
38b61aa6ed
7فایلهای تغییر یافته به همراه22 افزوده شده و 4 حذف شده
  1. 5 0
      codegen.ml
  2. 8 1
      common.ml
  3. 1 0
      gencs.ml
  4. 1 0
      genjava.ml
  5. 1 1
      genjs.ml
  6. 5 2
      genphp.ml
  7. 1 0
      genpy.ml

+ 5 - 0
codegen.ml

@@ -1981,6 +1981,11 @@ let interpolate_code com code tl f_string f_expr p =
 	in
 	loop (Str.full_split regex code)
 
+let map_source_header com f =
+	match Common.defined_value_safe com Define.SourceHeader with
+	| "" -> ()
+	| s -> f s
+
 (* Collection of functions that return expressions *)
 module ExprBuilder = struct
 	let make_static_this c p =

+ 8 - 1
common.ml

@@ -228,6 +228,7 @@ module Define = struct
 		| ReplaceFiles
 		| Scriptable
 		| ShallowExpose
+		| SourceHeader
 		| SourceMapContent
 		| Swc
 		| SwfCompressLevel
@@ -312,6 +313,7 @@ module Define = struct
 		| 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")
@@ -693,6 +695,11 @@ let memory_marker = [|Unix.time()|]
 
 let create v args =
 	let m = Type.mk_mono() in
+	let defines =
+		PMap.add "true" "1" (
+		PMap.add "source-header" "Generated by Haxe" (
+		if !display_default <> DMNone then PMap.add "display" "1" PMap.empty else PMap.empty))
+	in
 	{
 		version = v;
 		args = args;
@@ -709,7 +716,7 @@ let create v args =
 		std_path = [];
 		class_path = [];
 		main_class = None;
-		defines = PMap.add "true" "1" (if !display_default <> DMNone then PMap.add "display" "1" PMap.empty else PMap.empty);
+		defines = defines;
 		package_rules = PMap.empty;
 		file = "";
 		types = [];

+ 1 - 0
gencs.ml

@@ -2595,6 +2595,7 @@ let configure gen =
 	in
 
 	let module_type_gen w md_tp =
+		Codegen.map_source_header gen.gcon (fun s -> print w "// %s\n" s);
 		reset_temps();
 		match md_tp with
 			| TClassDecl cl ->

+ 1 - 0
genjava.ml

@@ -1993,6 +1993,7 @@ let configure gen =
 	in
 
 	let module_type_gen w md_tp =
+		Codegen.map_source_header gen.gcon (fun s -> print w "// %s\n" s);
 		match md_tp with
 			| TClassDecl cl ->
 				if not cl.cl_extern then begin

+ 1 - 1
genjs.ml

@@ -1245,7 +1245,7 @@ let generate com =
 	| Some g -> g()
 	| None ->
 	let ctx = alloc_ctx com in
-
+	Codegen.map_source_header com (fun s -> print ctx "// %s\n" s);
 	if has_feature ctx "Class" || has_feature ctx "Type.getClassName" then add_feature ctx "js.Boot.isClass";
 	if has_feature ctx "Enum" || has_feature ctx "Type.getEnumName" then add_feature ctx "js.Boot.isEnum";
 

+ 5 - 2
genphp.ml

@@ -361,7 +361,7 @@ let init com cwd path def_type =
 	let ch = open_out (String.concat "/" dir ^ "/" ^ (filename path) ^ (if def_type = 0 then ".class" else if def_type = 1 then ".enum"  else if def_type = 2 then ".interface" else ".extern") ^ ".php") in
 	let imports = Hashtbl.create 0 in
 	Hashtbl.add imports (snd path) [fst path];
-	{
+	let ctx = {
 		com = com;
 		stack = stack_init com false;
 		tabs = "";
@@ -390,7 +390,10 @@ let init com cwd path def_type =
 		inline_index = 0;
 		in_block = false;
 		lib_path = match com.php_lib with None -> "lib" | Some s -> s;
-	}
+	} in
+	Codegen.map_source_header com (fun s -> print ctx "// %s\n" s);
+	ctx
+
 let unsupported msg p = error ("This expression cannot be generated to PHP: " ^ msg) p
 
 let newline ctx =

+ 1 - 0
genpy.ml

@@ -2394,6 +2394,7 @@ module Generator = struct
 	let run com =
 		Transformer.init com;
 		let ctx = mk_context com in
+		Codegen.map_source_header com (fun s -> print ctx "// %s\n" s);
 		gen_imports ctx;
 		gen_resources ctx;
 		gen_types ctx;