internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel) { switch (operation) { // respective operators returns immutable values: case Operations.Plus: case Operations.Minus: case Operations.LogicNegation: case Operations.BitNegation: case Operations.Int8Cast: case Operations.Int16Cast: case Operations.Int32Cast: case Operations.Int64Cast: case Operations.UInt8Cast: case Operations.UInt16Cast: case Operations.UInt32Cast: case Operations.UInt64Cast: case Operations.DecimalCast: case Operations.DoubleCast: case Operations.FloatCast: case Operations.StringCast: case Operations.UnicodeCast: case Operations.BoolCast: case Operations.UnsetCast: case Operations.Clone: case Operations.Print: return(false); // respective operators don't do a deep copy: case Operations.ObjectCast: case Operations.ArrayCast: case Operations.BinaryCast: return(true); // the result depends on what follows @: case Operations.AtSign: return(expr.IsDeeplyCopied(reason, nestingLevel)); default: throw null; } }
/// <summary> /// Emits IL instructions that makes a copy of variable placed on the top of evaluation stack. /// </summary> /// <param name="reason">Reason of the copy.</param> /// <param name="expression">The <see cref="PHP.Core.AST.Expression"/> to be copied.</param> /// <remarks> /// The variable's value is expected on the top of evaluation stack. /// Calls <see cref="PHP.Core.PhpVariable.Copy"/> method to process the value copying. /// The result is left on the evaluation stack. /// </remarks> public void EmitVariableCopy(CopyReason reason, Expression expression) { // checks whether to make a deep copy; starts with level of nesting set to 0: if (expression == null || expression.IsDeeplyCopied(reason, 0)) { // First parameter should already be placed on the evaluation stack il.LdcI4((int)reason); il.Emit(OpCodes.Call, Methods.PhpVariable.Copy); } }
// obsolete: //internal override bool TryEvaluate(out object value) //{ // object o; // if (condExpr.TryEvaluate(out o)) // { // return (Convert.ObjectToBoolean(o)) ? trueExpr.TryEvaluate(out value) : falseExpr.TryEvaluate(out value); // } // else // { // value = null; // return false; // } //} #endregion internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel) { return((trueExpr ?? condExpr).IsDeeplyCopied(reason, nestingLevel) || falseExpr.IsDeeplyCopied(reason, nestingLevel)); }