|
@@ -25,12 +25,21 @@ open Typecore
|
|
|
(* ---------------------------------------------------------------------- *)
|
|
|
(* API OPTIMIZATIONS *)
|
|
|
|
|
|
+let field_call_has_side_effect f e1 fa el =
|
|
|
+ begin match extract_field fa with
|
|
|
+ | Some cf when Meta.has Meta.Pure cf.cf_meta -> ()
|
|
|
+ | _ -> raise Exit
|
|
|
+ end;
|
|
|
+ f e1;
|
|
|
+ List.iter f el
|
|
|
+
|
|
|
(* tells if an expression causes side effects. This does not account for potential null accesses (fields/arrays/ops) *)
|
|
|
let has_side_effect e =
|
|
|
let rec loop e =
|
|
|
match e.eexpr with
|
|
|
| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ -> ()
|
|
|
| TCall ({ eexpr = TField(_,FStatic({ cl_path = ([],"Std") },{ cf_name = "string" })) },args) -> Type.iter loop e
|
|
|
+ | TCall({eexpr = TField(e1,fa)},el) -> field_call_has_side_effect loop e1 fa el
|
|
|
| TNew _ | TCall _ | TBinop ((OpAssignOp _ | OpAssign),_,_) | TUnop ((Increment|Decrement),_,_) -> raise Exit
|
|
|
| TReturn _ | TBreak | TContinue | TThrow _ | TCast (_,Some _) -> raise Exit
|
|
|
| TArray _ | TEnumParameter _ | TCast (_,None) | TBinop _ | TUnop _ | TParenthesis _ | TMeta _ | TWhile _ | TFor _
|