public override ICodeNode VisitArrayCreationExpression(ArrayCreationExpression node)
 {
     ICodeNode newNode = removePIDStep.VisitArrayCreationExpression(node);
     if (newNode != null)
     {
         return newNode;
     }
     return base.VisitArrayCreationExpression(node);
 }
示例#2
0
 public override Expression CloneExpressionOnly()
 {
     if (this.get_Initializer() != null)
     {
         stackVariable5 = (InitializerExpression)this.get_Initializer().CloneExpressionOnly();
     }
     else
     {
         stackVariable5 = null;
     }
     stackVariable10 = new ArrayCreationExpression(this.get_ElementType(), stackVariable5, null);
     stackVariable10.set_Dimensions(this.get_Dimensions().CloneExpressionsOnly());
     return(stackVariable10);
 }
 private bool TryFillInitializer(ArrayCreationExpression expression, MemberHandleExpression values)
 {
     if (!(values.MemberReference is FieldDefinition))
     {
         return false;
     }
     ExpressionCollection convertedExpressions = ConvertInitialValues((values.MemberReference as FieldDefinition).InitialValue, expression.ElementType.Name);
     if(convertedExpressions == null || CheckElementsCount(convertedExpressions, expression.Dimensions) == false)
     {
         return false;
     }
     RebuildDimensions(ref convertedExpressions, expression.Dimensions);
     expression.Initializer.Expressions = convertedExpressions;
     return true;
 }
        public override bool Equals(Expression other)
        {
            if (!(other is ArrayCreationExpression))
            {
                return(false);
            }
            ArrayCreationExpression array = other as ArrayCreationExpression;

            if (this.Initializer == null)
            {
                if (array.Initializer != null)
                {
                    return(false);
                }
            }
            else if (!this.Initializer.Equals(array.Initializer))
            {
                return(false);
            }
            return(this.ElementType.FullName == array.ElementType.FullName && this.Dimensions.Equals(array.Dimensions));
        }
        public ICodeNode VisitArrayCreationExpression(ArrayCreationExpression node)
        {
            if (node.Initializer == null || node.Initializer.Expressions == null || node.Initializer.Expressions.Count != 1)
            {
                return null;
            }

            MemberHandleExpression runtimeHandle = node.Initializer.Expressions[0] as MemberHandleExpression;

            if (runtimeHandle == null)
            {
                return null;
            }

            if (!TryFillInitializer(node, runtimeHandle))
            {
                return null;
            }

            return node;
        }
        private Expression GetMethodHandleExpression(MethodReference methodReference, IEnumerable<Instruction> instructions)
        {
            TypeDefinition corlibTypeTypeDefinition = GetSystemTypeTypeDefinition();

            string[] parametersNames = methodReference.HasParameters ? new string[] { "System.String", "System.Type[]" } : new string[] { "System.String" };
            MethodReference getMethodReference = GetSystemTypeMethodReference(corlibTypeTypeDefinition, "GetMethod", parametersNames);

            MethodReference getMethodHandleReference = GetHandlePropertyGetterReference(typeof(System.Reflection.MethodBase), "get_MethodHandle");

            TypeOfExpression typeOfExpression = new TypeOfExpression(methodReference.DeclaringType, null);
            MethodReferenceExpression getMethodMethodReferenceExpression = new MethodReferenceExpression(typeOfExpression, getMethodReference, null);
            MethodInvocationExpression getMethodMethodInvocationExpression = new MethodInvocationExpression(getMethodMethodReferenceExpression, null);
            LiteralExpression argument = new LiteralExpression(methodReference.Name, this.typeSystem, null);
            getMethodMethodInvocationExpression.Arguments.Add(argument);

            if (methodReference.HasParameters)
            {
                BlockExpression blockExpression = new BlockExpression(null);
                foreach (ParameterDefinition parameter in methodReference.Parameters)
                {
                    blockExpression.Expressions.Add(new TypeOfExpression(parameter.ParameterType, null));
                }

				InitializerExpression initializer = new InitializerExpression(blockExpression, InitializerType.ArrayInitializer);
				ArrayCreationExpression getMethodTypeParametersArray = new ArrayCreationExpression(corlibTypeTypeDefinition, initializer, null);
                getMethodTypeParametersArray.Dimensions.Add(new LiteralExpression(blockExpression.Expressions.Count, this.typeSystem, null));

                getMethodMethodInvocationExpression.Arguments.Add(getMethodTypeParametersArray);
            }

            MethodReferenceExpression getMethodHandleMethodReferenceExpression = new MethodReferenceExpression(getMethodMethodInvocationExpression, getMethodHandleReference, null);
            MethodInvocationExpression getMethodHandleMethodInvocationExpression = new MethodInvocationExpression(getMethodHandleMethodReferenceExpression, instructions);
            PropertyReferenceExpression methodHandlePropertyReferenceExpression = new PropertyReferenceExpression(getMethodHandleMethodInvocationExpression, null);

            return methodHandlePropertyReferenceExpression;
        }
		public override void VisitArrayCreationExpression(ArrayCreationExpression node)
		{
			WriteKeyword(KeyWordWriter.New);
			WriteSpace();
			WriteReferenceAndNamespaceIfInCollision(GetBaseElementType(node.ElementType));

			bool isInitializerPresent = Utilities.IsInitializerPresent(node.Initializer);

			WriteArrayDimensions(node.Dimensions, node.ElementType, isInitializerPresent);

			if (isInitializerPresent)
			{
				StartInitializer(node.Initializer);
				Visit(node.Initializer);
			}
		}
		public override void VisitArrayCreationExpression(ArrayCreationExpression node)
		{
			TypesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(node.ElementType));
			base.VisitArrayCreationExpression(node);
		}
		public override void VisitArrayCreationExpression(ArrayCreationExpression node)
		{
			base.VisitArrayCreationExpression(node);

			if (!Utilities.IsInitializerPresent(node.Initializer))
			{
				WriteSpace();
				Write("{}");
			}
		}
		public override void VisitArrayCreationExpression(ArrayCreationExpression node)
        {
            expressions.Push(ExpressionKind.None);
            Visit(node.Dimensions);
            expressions.Pop();
            Visit(node.Initializer);
        }
 /// <summary>
 /// Resolves the type of usage of <paramref name="variable"/>, when the expression it's used in is ArrayCreationExpression
 /// </summary>
 /// <param name="arrayCreationExpression">The expression.</param>
 /// <param name="variable">The variable.</param>
 /// <returns>Returns the ClassHierarchyNode coresponding go the infered type.</returns>
 private ClassHierarchyNode GetUseInArrayCreation(ArrayCreationExpression arrayCreationExpression, VariableReference variable)
 {
     foreach (Expression expr in arrayCreationExpression.Dimensions)
     {
         if (expr is VariableReferenceExpression && (expr as VariableReferenceExpression).Variable == variable)
         {
             ///If the variable is used as an index, then it's type is Int32.
             return GetTypeNode(typeSystem.Int32);
         }
     }
     foreach (Expression ex in arrayCreationExpression.Initializer.Expressions)
     {
         if (ex is VariableReferenceExpression && (ex as VariableReferenceExpression).Variable == variable)
         {
             ///If the variable is directly referenced in the Initializer, then its type is the element type of the array.
             return GetTypeNode(arrayCreationExpression.ElementType);
         }
     }
     throw new ArgumentOutOfRangeException("Expression is not evaluated to any type.");
 }
		protected bool TryGetArrayCreation(StatementCollection statements, int startIndex, out ArrayCreationExpression creation, out Expression assignee)
		{
			assignee = null;
			creation = null;

			BinaryExpression binaryExpression;
			if (!TryGetAssignment(statements, startIndex, out binaryExpression))
			{
				return false;
			}

			if (binaryExpression.Right.CodeNodeType != CodeNodeType.ArrayCreationExpression)
			{
				return false;
			}

			var arrayCreation = binaryExpression.Right as ArrayCreationExpression;

			if (!(binaryExpression.Right.HasType && binaryExpression.Right.ExpressionType.IsArray))
			{
				return false;
			}

			/// Implemented for 1-dimentional arrays only.
			/// This covers most of the cases, and is far easier to implement than support
			/// for n-dimentional arrays.
			if (arrayCreation.Dimensions.Count != 1)
			{
				return false;
			}

			foreach (Expression dimention in arrayCreation.Dimensions)
			{
				if (dimention.CodeNodeType != CodeNodeType.LiteralExpression)
				{
					return false;
				}
			}

			creation = binaryExpression.Right as ArrayCreationExpression;
			assignee = binaryExpression.Left;
			return true;
		}
		private uint GetCreatedArraySize(ArrayCreationExpression arrayCreation)
		{
			if (arrayCreation.Dimensions.Count != 1)
			{
				throw new ArgumentOutOfRangeException("Expected one dimentional array creation.");
			}
			LiteralExpression dimention = arrayCreation.Dimensions[0] as LiteralExpression;
			if (dimention == null)
			{
				throw new ArgumentOutOfRangeException("Expected constant-size array");
			}

			return GetIndexFromLiteralExpression(dimention);
		}
 public virtual void VisitArrayCreationExpression(ArrayCreationExpression node)
 {
     Visit(node.Dimensions);
     Visit(node.Initializer);
 }
 public override void VisitArrayCreationExpression(ArrayCreationExpression node)
 {
     if (state == SearchState.Propagation)
     {
         canBePropagated = false;
         return;
     }
     base.VisitArrayCreationExpression(node);
 }
		public override void VisitArrayCreationExpression(ArrayCreationExpression node)
		{
			base.VisitArrayCreationExpression(node);

			if (node.Initializer != null)
			{
				TypeDefinition arrayType = node.ExpressionType.Resolve();
				AddArrayInitializerCasts(arrayType, node.Initializer.Expression);
			}
		}