소스 검색

[php7] do not print Haxe positions if -D real-position is defined

Alexander Kuzmenko 8 년 전
부모
커밋
c47d199ed3
2개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      src/context/common.ml
  2. 9 2
      src/generators/genphp7.ml

+ 1 - 1
src/context/common.ml

@@ -608,7 +608,7 @@ module Define = struct
 		| NoTraces -> ("no_traces","Disable all trace calls")
 		| Objc -> ("objc","Sets the hxcpp output to objective-c++ classes. Must be defined for interop")
 		| PhpPrefix -> ("php_prefix","Compiled with --php-prefix")
-		| RealPosition -> ("real_position","Disables Haxe source mapping when targetting C#, removes position comments in Java output")
+		| 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")

+ 9 - 2
src/generators/genphp7.ml

@@ -9,6 +9,10 @@ open Meta
 open Globals
 
 let debug = ref false
+(**
+	Do not add comments with Haxe positions before each line of generated php code
+*)
+let skip_line_directives = ref false
 
 (**
 	Escape string for constant strings generation.
@@ -1926,8 +1930,10 @@ class virtual type_builder ctx wrapper =
 			and exprs = match expr.eexpr with TBlock exprs -> exprs | _ -> [expr] in
 			let write_body () =
 				let write_expr expr =
-					self#write_pos expr;
-					self#write_indentation;
+					if not !skip_line_directives then begin
+						self#write_pos expr;
+						self#write_indentation
+					end;
 					self#write_expr expr;
 					match expr.eexpr with
 						| TBlock _ | TIf _ | TTry _ | TSwitch _ | TWhile (_, _, NormalWhile) -> self#write "\n"
@@ -3498,6 +3504,7 @@ class generator (com:context) =
 	Entry point to Genphp7
 *)
 let generate (com:context) =
+	skip_line_directives := Common.defined com Define.RealPosition;
 	let gen = new generator com in
 	gen#initialize;
 	let rec generate com_type =