Browse Source

[php7] print haxe positions above each line of generated php code

Alexander Kuzmenko 8 years ago
parent
commit
a0405519f9
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/generators/genphp7.ml

+ 13 - 1
src/generators/genphp7.ml

@@ -220,10 +220,15 @@ let rec reveal_expr_with_parenthesis expr =
 		| TParenthesis e -> reveal_expr_with_parenthesis e
 		| TParenthesis e -> reveal_expr_with_parenthesis e
 		| _ -> expr
 		| _ -> expr
 
 
+(**
+	Get string representation of specified position in Haxe code.
+*)
+let stringify_pos pos = Lexer.get_error_pos (Printf.sprintf "%s:%d:") pos
+
 (**
 (**
 	@return Error message with position information
 	@return Error message with position information
 *)
 *)
-let error_message pos message = (Lexer.get_error_pos (Printf.sprintf "%s:%d:") pos) ^ ": " ^ message
+let error_message pos message = (stringify_pos pos) ^ ": " ^ message
 
 
 (**
 (**
 	Terminates compiler process and prints user-friendly instructions about filing an issue in compiler repo.
 	Terminates compiler process and prints user-friendly instructions about filing an issue in compiler repo.
@@ -1908,6 +1913,11 @@ class virtual type_builder ctx wrapper =
 			expr_hierarchy <- fake_block :: expr_hierarchy;
 			expr_hierarchy <- fake_block :: expr_hierarchy;
 			self#write_as_block ~inline:true expr;
 			self#write_as_block ~inline:true expr;
 			expr_hierarchy <- List.tl expr_hierarchy
 			expr_hierarchy <- List.tl expr_hierarchy
+		(**
+			Write position of specified expression to output buffer
+		*)
+		method private write_pos expr =
+			self#write ("#" ^ (stringify_pos expr.epos) ^ "\n");
 		(**
 		(**
 			Writes "{ <expressions> }" to output buffer
 			Writes "{ <expressions> }" to output buffer
 		*)
 		*)
@@ -1916,6 +1926,8 @@ class virtual type_builder ctx wrapper =
 			and exprs = match expr.eexpr with TBlock exprs -> exprs | _ -> [expr] in
 			and exprs = match expr.eexpr with TBlock exprs -> exprs | _ -> [expr] in
 			let write_body () =
 			let write_body () =
 				let write_expr expr =
 				let write_expr expr =
+					self#write_pos expr;
+					self#write_indentation;
 					self#write_expr expr;
 					self#write_expr expr;
 					match expr.eexpr with
 					match expr.eexpr with
 						| TBlock _ | TIf _ | TTry _ | TSwitch _ | TWhile (_, _, NormalWhile) -> self#write "\n"
 						| TBlock _ | TIf _ | TTry _ | TSwitch _ | TWhile (_, _, NormalWhile) -> self#write "\n"