Ver Fonte

[inliner] remember original variable name and use it for inlining

Simon Krajewski há 3 anos atrás
pai
commit
60f6ed17bd
3 ficheiros alterados com 16 adições e 3 exclusões
  1. 8 0
      src/core/ast.ml
  2. 6 2
      src/filters/renameVars.ml
  3. 2 1
      src/optimization/inline.ml

+ 8 - 0
src/core/ast.ml

@@ -1251,3 +1251,11 @@ let get_meta_options metas meta =
 			[]
 	in
 	loop metas
+
+let get_meta_string meta key =
+	let rec loop = function
+		| [] -> None
+		| (k,[EConst (String(name,_)),_],_) :: _ when k = key -> Some name
+		| _ :: l -> loop l
+	in
+	loop meta

+ 6 - 2
src/filters/renameVars.ml

@@ -280,10 +280,14 @@ let trailing_numbers = Str.regexp "[0-9]+$"
 	Rename `v` if needed
 *)
 let maybe_rename_var rc reserved (v,overlaps) =
+	let commit name =
+		v.v_meta <- (Meta.RealPath,[EConst (String(v.v_name,SDoubleQuotes)),null_pos],null_pos) :: v.v_meta;
+		v.v_name <- name
+	in
 	(* chop escape char for all local variables generated *)
 	if is_gen_local v then begin
 		let name = String.sub v.v_name 1 (String.length v.v_name - 1) in
-		v.v_name <- "_g" ^ (Str.replace_first trailing_numbers "" name)
+		commit ("_g" ^ (Str.replace_first trailing_numbers "" name))
 	end;
 	let name = ref v.v_name in
 	let count = ref 0 in
@@ -295,7 +299,7 @@ let maybe_rename_var rc reserved (v,overlaps) =
 		incr count;
 		name := v.v_name ^ (string_of_int !count);
 	done;
-	v.v_name <- !name;
+	commit !name;
 	if rc.rc_no_shadowing || (has_var_flag v VCaptured && rc.rc_hoisting) then reserve reserved v.v_name
 
 (**

+ 2 - 1
src/optimization/inline.ml

@@ -308,7 +308,8 @@ class inline_state ctx ethis params cf f p = object(self)
 		try
 			Hashtbl.find locals v.v_id
 		with Not_found ->
-			let v' = alloc_var (match v.v_kind with VUser _ -> VInlined | k -> k) v.v_name v.v_type v.v_pos in
+			let name = Option.default v.v_name (get_meta_string v.v_meta Meta.RealPath) in
+			let v' = alloc_var (match v.v_kind with VUser _ -> VInlined | k -> k) name v.v_type v.v_pos in
 			v'.v_extra <- v.v_extra;
 			let i = {
 				i_var = v;