Browse Source

[cpp] use real var name for `HX_STACK_VAR`

see https://github.com/HaxeFoundation/hxcpp/issues/365
Simon Krajewski 9 years ago
parent
commit
84641bf4c6
2 changed files with 19 additions and 4 deletions
  1. 7 0
      filters.ml
  2. 12 4
      gencpp.ml

+ 7 - 0
filters.ml

@@ -540,6 +540,13 @@ let rename_local_vars ctx e =
 		while PMap.mem (v.v_name ^ string_of_int !count) vars do
 			incr count;
 		done;
+		begin match ctx.com.platform with
+			| Cpp ->
+				if not (Meta.has Meta.RealPath v.v_meta) then
+					v.v_meta <- (Meta.RealPath,[EConst (String v.v_name),e.epos],e.epos) :: v.v_meta
+			| _ ->
+				()
+		end;
 		v.v_name <- v.v_name ^ string_of_int !count;
 	in
 	let declare v p =

+ 12 - 4
gencpp.ml

@@ -2331,8 +2331,16 @@ let gen_expression_tree ctx retval expression_tree set_var tail_code =
          | None -> ()
          | Some expression -> output " = "; gen_expression true expression);
          count := !count -1;
+      let get_var_name v =
+         let rec loop meta = match meta with
+            | (Meta.RealPath,[EConst (String s),_],_) :: _ -> s
+            | _ :: meta -> loop meta
+            | [] -> v.v_name
+         in
+         loop v.v_meta
+      in
       if (ctx.ctx_debug_level>0) then
-            output (";\t\tHX_STACK_VAR(" ^name ^",\""^ tvar.v_name ^"\")");
+            output (";\t\tHX_STACK_VAR(" ^name ^",\""^ (get_var_name tvar) ^"\")");
          if (!count > 0) then begin output ";\n"; output_i "" end
       end
    | TFor (tvar, init, loop) ->
@@ -2790,10 +2798,10 @@ let gen_member_def ctx class_def is_static is_interface field =
             end
          end else begin
             let return_type = (type_string function_def.tf_type) in
-   
+
             if ( not is_static && not nonVirtual ) then output "virtual ";
             output (if return_type="Void" && (has_meta_key field.cf_meta Meta.Void) then "void" else return_type );
-   
+
             output (" " ^ remap_name ^ "(" );
             output (gen_arg_list function_def.tf_args "" );
             output ");\n";
@@ -2810,7 +2818,7 @@ let gen_member_def ctx class_def is_static is_interface field =
          (* Variable access *)
          gen_type ctx field.cf_type;
          output (" " ^ remap_name ^ ";\n" );
-   
+
          (* Add a "dyn" function for variable to unify variable/function access *)
          (match follow field.cf_type with
          | _ when nativeGen  -> ()