Пример #1
0
 /// <summary>
 /// Whether the result of binary expression should be deeply copied.
 /// </summary>
 /// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
 /// <returns>All operators returns immutable values. Hence, returns <B>false</B>.</returns>
 internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
 {
     switch (operation)
     {
     // respective operators returns immutable values:
     case Operations.Xor:
     case Operations.Or:
     case Operations.And:
     case Operations.BitOr:
     case Operations.BitXor:
     case Operations.BitAnd:
     case Operations.Equal:
     case Operations.NotEqual:
     case Operations.Identical:
     case Operations.NotIdentical:
     case Operations.LessThan:
     case Operations.GreaterThan:
     case Operations.LessThanOrEqual:
     case Operations.GreaterThanOrEqual:
     case Operations.ShiftLeft:
     case Operations.ShiftRight:
     case Operations.Add:
     case Operations.Sub:
     case Operations.Mul:
     case Operations.Div:
     case Operations.Mod:
     case Operations.Concat:
         return(false);
     }
     Debug.Fail("Illegal operation type.");
     return(true);
 }
Пример #2
0
        public static object Copy(object obj, CopyReason reason)
        {
            // cloneable types:
            IPhpCloneable php_cloneable;

            if ((php_cloneable = obj as IPhpCloneable) != null)
            {
                return(php_cloneable.Copy(reason));
            }

            // string, bool, int, double, null:
            return(obj);
        }
Пример #3
0
 internal static int GetPriority(CopyReason reason, int attempt, ProactiveCopyLocationSource proactiveLocationSource)
 {
     Contract.Requires(attempt >= 0);
     // This prioritization has a few constraints:
     //  - Reason's prioritization is ascending
     //  - Source's prioritization is ascending
     //  - Attempt's prioritization is descending
     // The resulting priorities are ascending (i.e. if a request has priority 0, it is less important than
     // another with priority 1).
     attempt = Math.Min(attempt, MaxAttempt);
     return
         ((MaxLocationSource + MaxAttempt) * (int)reason +
          MaxLocationSource * (MaxAttempt - attempt) +
          (int)proactiveLocationSource);
 }
Пример #4
0
            public override bool IsDeeplyCopied(UnaryEx node, CopyReason reason, int nestingLevel)
            {
                switch (node.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(node.Expr.IsDeeplyCopied(reason, nestingLevel));

                default:
                    throw null;
                }
            }
Пример #5
0
		/// <summary>
		/// Whether the result of binary expression should be deeply copied.
		/// </summary>
		/// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
		/// <returns>All operators returns immutable values. Hence, returns <B>false</B>.</returns>
		internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
		{
            switch (operation)
            {
                // respective operators returns immutable values:
                case Operations.Xor:
                case Operations.Or:
                case Operations.And:
                case Operations.BitOr:
                case Operations.BitXor:
                case Operations.BitAnd:
                case Operations.Equal:
                case Operations.NotEqual:
                case Operations.Identical:
                case Operations.NotIdentical:
                case Operations.LessThan:
                case Operations.GreaterThan:
                case Operations.LessThanOrEqual:
                case Operations.GreaterThanOrEqual:
                case Operations.ShiftLeft:
                case Operations.ShiftRight:
                case Operations.Add:
                case Operations.Sub:
                case Operations.Mul:
                case Operations.Div:
                case Operations.Mod:
                case Operations.Concat:
                    return false;
            }
			Debug.Fail("Illegal operation type.");
			return true;
		}
Пример #6
0
 public override bool IsDeeplyCopied(LambdaFunctionExpr node, CopyReason reason, int nestingLevel)
 {
     return(false);
 }
Пример #7
0
		/// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
		/// <returns>
		/// The copy-on-assignment value of the right hand side.
		/// </returns>
		internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
		{
            return true; // J: once assigned value must be copied again // rvalue.IsDeeplyCopied(reason, nestingLevel + 1);
		}
Пример #8
0
 /// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
 internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
 {
     // J: PhpVariable.Copy is always emitted in Emit method if needed (access == Read && resultTypeCode is copiable)
     return false;
 }
Пример #9
0
		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;
			}
		}
Пример #10
0
 /// <returns>It suffice to make a copy only if assignment nesting level is 1 or above (we are starting from 0).</returns>
 public override bool IsDeeplyCopied(ArrayEx node, CopyReason reason, int nestingLevel)
 {
     return(nestingLevel > 0);
 }
Пример #11
0
 /// <summary>
 /// Retrieves a copy of this instance.
 /// </summary>
 /// <returns>The copy.</returns>
 /// <remarks>
 /// If this <see cref="PhpSmartReference"/> <see cref="IsAliased"/>, this instance is returned without copying.
 /// That is because (deep) copying stops on references in PHP. If this instance is not <see cref="IsAliased"/>,
 /// a new <see cref="PhpSmartReference"/> referencing a copy of the current value is returned.
 /// </remarks>
 public override object Copy(CopyReason reason)
 {
     return(IsAliased ? this : new PhpSmartReference(PhpVariable.Copy(value, reason)));
 }
Пример #12
0
 /// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
 /// <param name="node">Instance.</param>
 /// <returns>
 /// The copy-on-assignment value of the right hand side.
 /// </returns>
 public override bool IsDeeplyCopied(AssignEx node, CopyReason reason, int nestingLevel)
 {
     return(true); // J: once assigned value must be copied again // rvalue.IsDeeplyCopied(reason, nestingLevel + 1);
 }
Пример #13
0
 public virtual bool IsDeeplyCopied(T node, CopyReason reason, int nestingLevel)
 {
     return(true);
 }
Пример #14
0
 bool IExpressionCompiler.IsDeeplyCopied(Expression node, CopyReason reason, int nestingLevel)
 {
     return(IsDeeplyCopied((T)node, reason, nestingLevel));
 }
Пример #15
0
 public override bool IsDeeplyCopied(ConditionalEx node, CopyReason reason, int nestingLevel)
 {
     return
         ((node.TrueExpr ?? node.CondExpr).IsDeeplyCopied(reason, nestingLevel) ||
          node.FalseExpr.IsDeeplyCopied(reason, nestingLevel));
 }
Пример #16
0
 /// <summary>Creates a copy of this instance.</summary>
 /// <remarks>
 /// Instances of the PhpResource class are never cloned.
 /// When assigning a resource to another variable in a script,
 /// only a shallow copy is performed.
 /// </remarks>
 /// <returns>The copy of this instance.</returns>
 public object Copy(CopyReason reason)
 {
     return(this);
 }
Пример #17
0
		// 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);
		}
Пример #18
0
		public object Copy(CopyReason reason)
		{
            if (reason == CopyReason.ReturnedByCopy && this.InplaceCopyOnReturn)
			{
                this.table.InplaceCopyOnReturn = false; // copiesCount = 0
                this.table.Share();                     // copiesCount = 1 => underlaying table is shared and its values will be copied lazily if necessary

				return this;
			}
			else
			{
                // create lazy copied PhpArray,
                // preserve MaxIntegerKey if array was not passed as an argument or within assignment expression:
                return new PhpArray(this, (reason != CopyReason.PassedByCopy && reason != CopyReason.Assigned));
			}
		}
Пример #19
0
		/// <summary>Creates a copy of this instance.</summary>
		/// <remarks>
		/// Instances of the PhpResource class are never cloned.
		/// When assigning a resource to another variable in a script,
		/// only a shallow copy is performed.
		/// </remarks>
		/// <returns>The copy of this instance.</returns>
		public object Copy(CopyReason reason)
		{
			return this;
		}
Пример #20
0
 /// <summary>
 /// Retrieves a copy of this instance.
 /// </summary>
 /// <returns>This instance.</returns>
 /// <remarks>
 /// Actually references are not copied and this instance is returned instead.
 /// </remarks>
 public virtual object Copy(CopyReason reason)
 {
     return(this);
 }
Пример #21
0
        // 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));
        }
Пример #22
0
		/// <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);
			}
		}
Пример #23
0
		public object Copy(CopyReason reason)
		{
			return DeepCopy();
		}
Пример #24
0
 /// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
 internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
 {
     return(false);
 }
Пример #25
0
 internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
 {
     // always returns a string:
     return(false);
 }
Пример #26
0
		/// <summary>
		/// Determines behavior on assignment.
		/// </summary>
		/// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
		/// <returns>Always <B>false</B>, since constants contain immutable objects only.</returns>
		internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
		{
			return false;
		}
Пример #27
0
 public async Task <PutResult> TryCopyAndPutAsync(
     OperationContext operationContext,
     IDistributedContentCopierHost host,
     ContentHashWithSizeAndLocations hashInfo,
     CopyReason reason,
     Func <(CopyFileResult copyResult, AbsolutePath tempLocation, int attemptCount), Task <PutResult> > handleCopyAsync)
Пример #28
0
 public override bool IsDeeplyCopied(NewEx node, CopyReason reason, int nestingLevel)
 {
     return(false);
 }
Пример #29
0
 public override bool IsDeeplyCopied(ShellEx node, CopyReason reason, int nestingLevel)
 {
     // always returns a string:
     return(false);
 }
Пример #30
0
 public object Copy(CopyReason reason)
 {
     return(DeepCopy());
 }
Пример #31
0
		internal override bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
		{
			// always returns a string:
			return false;
		}
Пример #32
0
 /// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
 internal virtual bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
 {
     return(true);
 }
 public record CopyRequest(
     IDistributedContentCopierHost Host,
     ContentHashWithSizeAndLocations HashInfo,
     CopyReason Reason,
     Func <(CopyFileResult copyResult, AbsolutePath tempLocation, int attemptCount), Task <PutResult> > HandleCopyAsync,
Пример #34
0
		/// <include file='Doc/Nodes.xml' path='doc/method[@name="IsDeeplyCopied"]/*'/>
		internal virtual bool IsDeeplyCopied(CopyReason reason, int nestingLevel)
		{
			return true;
		}
Пример #35
0
        public static bool IsDeeplyCopied(this Expression /*!*/ node, CopyReason reason, int nestingLevel)
        {
            var nodecompiler = node.ExpressionCompiler();

            return(nodecompiler.IsDeeplyCopied(node, reason, nestingLevel));
        }