Simon Krajewski 12 lat temu
rodzic
commit
d625e34a57
2 zmienionych plików z 7 dodań i 14 usunięć
  1. 3 11
      genas3.ml
  2. 4 3
      typer.ml

+ 3 - 11
genas3.ml

@@ -201,8 +201,6 @@ let parent e =
 	| TParenthesis _ -> e
 	| _ -> mk (TParenthesis e) e.etype e.epos
 
-let is_getset f = match f.cf_kind with Var { v_read = AccCall } | Var { v_write = AccCall } -> true | _ -> false
-
 let default_value tstr =
 	match tstr with
 	| "int" | "uint" -> "0"
@@ -582,15 +580,9 @@ and gen_expr ctx e =
 		gen_expr ctx e1;
 		spr ctx ")";
 		gen_field_access ctx e1.etype (field_name s)
-	| TField (e,fa) ->
+	| TField (e,s) ->
    		gen_value ctx e;
-		let s = match fa with
-			| FStatic(c,cf) | FInstance(c,cf) -> if ctx.curclass == c && is_getset cf then "$" ^ cf.cf_name else cf.cf_name
-			| FClosure (_,cf) | FAnon cf -> cf.cf_name
-			| FEnum(_,ef) -> ef.ef_name
-			| FDynamic n -> n
-		in
-		gen_field_access ctx e.etype s
+		gen_field_access ctx e.etype (field_name s)
 	| TTypeExpr t ->
 		spr ctx (s_path ctx true (t_path t) e.epos)
 	| TParenthesis e ->
@@ -997,7 +989,7 @@ let generate_field ctx static f =
 		h();
 		newline ctx
 	| _ ->
-		let is_getset = is_getset f in
+		let is_getset = (match f.cf_kind with Var { v_read = AccCall } | Var { v_write = AccCall } -> true | _ -> false) in
 		if ctx.curclass.cl_interface then
 			match follow f.cf_type with
 			| TFun (args,r) ->

+ 4 - 3
typer.ml

@@ -859,13 +859,14 @@ let field_access ctx mode f fmode t e p =
 				normal()
 		| AccCall ->
 			let m = (match mode with MSet -> "set_" | _ -> "get_") ^ f.cf_name in
-			if m = ctx.curfield.cf_name && (match e.eexpr with TConst TThis -> true | TTypeExpr (TClassDecl c) when c == ctx.curclass -> true | _ -> false) then begin
+			if m = ctx.curfield.cf_name && (match e.eexpr with TConst TThis -> true | TTypeExpr (TClassDecl c) when c == ctx.curclass -> true | _ -> false) then
+				let prefix = (match ctx.com.platform with Flash when Common.defined ctx.com Define.As3 -> "$" | _ -> "") in
 				if is_extern_field f then begin
 					display_error ctx "This field cannot be accessed because it is not a real variable" p;
 					display_error ctx "Add @:isVar here to enable it" f.cf_pos;
 				end;
-				AKExpr (mk (TField(e, fmode)) t p)
-			end else if (match e.eexpr with TTypeExpr (TClassDecl ({cl_kind = KAbstractImpl _} as c)) when c == ctx.curclass -> true | _ -> false) then begin
+				AKExpr (mk (TField (e,if prefix = "" then fmode else FDynamic (prefix ^ f.cf_name))) t p)
+			else if (match e.eexpr with TTypeExpr (TClassDecl ({cl_kind = KAbstractImpl _} as c)) when c == ctx.curclass -> true | _ -> false) then begin
 				let this = get_this ctx p in
 				if mode = MSet then begin
 					let c,a = match ctx.curclass with {cl_kind = KAbstractImpl a} as c -> c,a | _ -> assert false in