浏览代码

do not compare "this" variables by name to avoid completion server issues

Simon Krajewski 12 年之前
父节点
当前提交
d6610ab1b8
共有 4 个文件被更改,包括 11 次插入8 次删除
  1. 3 3
      optimizer.ml
  2. 3 2
      type.ml
  3. 3 1
      typeload.ml
  4. 2 2
      typer.ml

+ 3 - 3
optimizer.ml

@@ -341,16 +341,16 @@ let rec type_inline ctx cf f ethis params tret config p force =
 	let force = ref force in
 	let vars = List.fold_left (fun acc (i,e) ->
 		let flag = (match e.eexpr with
-			| TLocal { v_name = "this" } -> true
+			| TLocal {v_extra = _,true} -> true
 			| TLocal _ | TConst _ -> not i.i_write
 			| TFunction _ -> if i.i_write then error "Cannot modify a closure parameter inside inline method" p; true
 			| _ -> not i.i_write && i.i_read <= 1
 		) in
 		let flag = flag && (not i.i_captured || is_constant e) in
 		(* force inlining if we modify 'this' *)
-		if i.i_write && i.i_var.v_name = "this" then force := true;
+		if i.i_write && snd i.i_var.v_extra then force := true;
 		(* force inlining of 'this' variable if the expression is writable *)
-		let flag = if not flag && i.i_var.v_name = "this" then begin
+		let flag = if not flag && snd i.i_var.v_extra then begin
 			if i.i_write && not (is_writable e) then error "Cannot modify the abstract value, store it into a local first" p;
 			true
 		end else flag in

+ 3 - 2
type.ml

@@ -77,7 +77,8 @@ and tvar = {
 	mutable v_name : string;
 	mutable v_type : t;
 	mutable v_capture : bool;
-	mutable v_extra : (type_params * texpr option) option;
+	(* snd = true if abstract "this" argument *)
+	mutable v_extra : (type_params * texpr option) option * bool;
 }
 
 and tfunc = {
@@ -307,7 +308,7 @@ and decision_tree = {
 
 let alloc_var =
 	let uid = ref 0 in
-	(fun n t -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None })
+	(fun n t -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None,false })
 
 let alloc_mid =
 	let mid = ref 0 in

+ 3 - 1
typeload.ml

@@ -1036,7 +1036,9 @@ let type_function ctx args ret fmode f do_display p =
 				| TConst c -> Some c
 				| _ -> display_error ctx "Parameter default value should be constant" p; None
 		) in
-		add_local ctx n t, c
+		let v,c = add_local ctx n t, c in
+		if n = "this" then v.v_extra <- None,true;
+		v,c
 	) args in
 	let old_ret = ctx.ret in
 	let old_fun = ctx.curfun in

+ 2 - 2
typer.ml

@@ -987,7 +987,7 @@ let rec type_ident_raise ?(imported_enums=true) ctx i p mode =
 	| _ ->
 	try
 		let v = PMap.find i ctx.locals in
-		(match v.v_extra with
+		(match fst v.v_extra with
 		| Some (params,e) ->
 			let t = monomorphs params v.v_type in
 			(match e with
@@ -2754,7 +2754,7 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		(match v with
 		| None -> e
 		| Some v ->
-			if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None);
+			if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None),snd v.v_extra;
 			let rec loop = function
 				| Codegen.Block f | Codegen.Loop f | Codegen.Function f -> f loop
 				| Codegen.Use v2 when v == v2 -> raise Exit