|
@@ -106,6 +106,14 @@ let rec can_be_inlined e = match e.eexpr with
|
|
|
| TParenthesis e1 | TMeta(_,e1) -> can_be_inlined e1
|
|
|
| _ -> false
|
|
|
|
|
|
+let target_handles_unops com = match com.platform with
|
|
|
+ | Lua | Python -> false
|
|
|
+ | _ -> true
|
|
|
+
|
|
|
+let target_handles_assign_ops com = match com.platform with
|
|
|
+ | Lua -> false
|
|
|
+ | _ -> true
|
|
|
+
|
|
|
let rec can_be_used_as_value com e =
|
|
|
let rec loop e = match e.eexpr with
|
|
|
| TBlock [e] -> loop e
|
|
@@ -113,7 +121,7 @@ let rec can_be_used_as_value com e =
|
|
|
| TCall({eexpr = TConst (TString "phi")},_) -> raise Exit
|
|
|
(* | TCall _ | TNew _ when (match com.platform with Cpp | Php -> true | _ -> false) -> raise Exit *)
|
|
|
| TReturn _ | TThrow _ | TBreak | TContinue -> raise Exit
|
|
|
- | TUnop((Increment | Decrement),_,_) when (match com.platform with Python | Lua -> true | _ -> false) -> raise Exit
|
|
|
+ | TUnop((Increment | Decrement),_,_) when not (target_handles_unops com) -> raise Exit
|
|
|
| TNew _ when com.platform = Php -> raise Exit
|
|
|
| TFunction _ -> ()
|
|
|
| _ -> Type.iter loop e
|
|
@@ -1626,7 +1634,7 @@ module TexprTransformer = struct
|
|
|
let eo = Option.map loop eo in
|
|
|
let v' = get_var_origin ctx.graph v in
|
|
|
{e with eexpr = TVar(v',eo)}
|
|
|
- | TBinop(OpAssign,e1,({eexpr = TBinop(op,e2,e3)} as e4)) ->
|
|
|
+ | TBinop(OpAssign,e1,({eexpr = TBinop(op,e2,e3)} as e4)) when target_handles_assign_ops ctx.com ->
|
|
|
let e1 = loop e1 in
|
|
|
let e2 = loop e2 in
|
|
|
let e3 = loop e3 in
|
|
@@ -1641,8 +1649,8 @@ module TexprTransformer = struct
|
|
|
begin match e1.eexpr,e2.eexpr with
|
|
|
| TLocal v1,TLocal v2 when v1 == v2 && is_valid_assign_op op ->
|
|
|
begin match op,e3.eexpr with
|
|
|
- | OpAdd,TConst (TInt i32) when Int32.to_int i32 = 1 -> {e with eexpr = TUnop(Increment,Prefix,e1)}
|
|
|
- | OpSub,TConst (TInt i32) when Int32.to_int i32 = 1 -> {e with eexpr = TUnop(Decrement,Prefix,e1)}
|
|
|
+ | OpAdd,TConst (TInt i32) when Int32.to_int i32 = 1 && target_handles_unops ctx.com -> {e with eexpr = TUnop(Increment,Prefix,e1)}
|
|
|
+ | OpSub,TConst (TInt i32) when Int32.to_int i32 = 1 && target_handles_unops ctx.com -> {e with eexpr = TUnop(Decrement,Prefix,e1)}
|
|
|
| _ -> {e with eexpr = TBinop(OpAssignOp op,e1,e3)}
|
|
|
end
|
|
|
| _ ->
|