Exemplo n.º 1
0
 public override Expression CloneExpressionOnly()
 {
     stackVariable4 = new ArrayIndexerExpression(this.get_Target().CloneExpressionOnly(), null);
     stackVariable4.set_Indices(this.get_Indices().CloneExpressionsOnly());
     stackVariable4.set_IsSimpleStore(this.get_IsSimpleStore());
     return(stackVariable4);
 }
Exemplo n.º 2
0
 public override Expression Clone()
 {
     stackVariable5 = new ArrayIndexerExpression(this.get_Target().Clone(), this.instructions);
     stackVariable5.set_Indices(this.get_Indices().Clone());
     stackVariable5.set_IsSimpleStore(this.get_IsSimpleStore());
     return(stackVariable5);
 }
        public override bool Equals(Expression other)
        {
            if (!(other is ArrayIndexerExpression))
            {
                return(false);
            }
            ArrayIndexerExpression indexer = other as ArrayIndexerExpression;

            return(this.Target.Equals(indexer.Target) && this.Indices.Equals(indexer.Indices));
        }
        public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
        {
            MethodReferenceExpression methodReference = node.MethodExpression;
            if ((methodReference == null) ||
                (methodReference.Method.CallingConvention == MethodCallingConvention.StdCall))
            {
                return null;
            }

			MethodReference method = methodReference.Method;

			BinaryOperator binaryOperator;
            if (binaryOperators.TryGetValue (method.Name, out binaryOperator))
            {
                return BuildBinaryExpression(binaryOperator, node.Arguments[0], node.Arguments[1], method.FixedReturnType, node.InvocationInstructions);
            }

			UnaryOperator unaryOperator;
            if (unaryOperators.TryGetValue (method.Name, out unaryOperator))
            {
                return BuildUnaryExpression(unaryOperator, node.Arguments[0], node.InvocationInstructions);
            }
			
            if(method.Name == "op_True")
            {
                return (Expression)codeTransformer.Visit(node.Arguments[0]);
            }
            else if(method.Name == "op_False")
            {
                //TODO: Must consider better representation
                return new ConditionExpression((Expression)codeTransformer.Visit(node.Arguments[0]),
                        new LiteralExpression(false, typeSystem, null), new LiteralExpression(true, typeSystem, null), node.InvocationInstructions);
            }

            if (method.Name == "op_Explicit")
            {
                return new CastExpression((Expression)codeTransformer.Visit(node.Arguments[0]), node.ExpressionType, node.InvocationInstructions);
            }

            if (method.Name == "op_Implicit")
            { 
                return codeTransformer.Visit(node.Arguments[0]);
            }

            if (method.Name == "get_Chars" && node.MethodExpression.Target.ExpressionType.FullName == "System.String")
            {
                ArrayIndexerExpression stringIndexing = new ArrayIndexerExpression(node.MethodExpression.Target, node.InvocationInstructions);
                foreach (Expression arg in node.Arguments)
                {
                    stringIndexing.Indices.Add(arg);
                }
                return stringIndexing;
            }

			return null;
		}
		public override void VisitArrayIndexerExpression(ArrayIndexerExpression node)
		{
			states.Push(Step.Default);
			base.VisitArrayIndexerExpression(node);
			states.Pop();
		}
		public override void VisitArrayIndexerExpression(ArrayIndexerExpression node)
        {
            Visit(node.Target);
            expressions.Push(ExpressionKind.None);
            Visit(node.Indices);
            expressions.Pop();
        }
        /// <summary>
        /// Determines the use type of <paramref name="variable"/> in <paramref name="arrayIndexerExpression"/>.
        /// </summary>
        /// <param name="arrayIndexerExpression">The array indexer expression.</param>
        /// <param name="variable">The variable.</param>
        /// <returns>Returns the ClassHierarchyNode corresponding to the infered type.</returns>
        private ClassHierarchyNode GetUseInArrayIndexer(ArrayIndexerExpression arrayIndexerExpression, VariableReference variable)
        {
            foreach (Expression expr in arrayIndexerExpression.Indices)
            {
                if (expr is VariableReferenceExpression && (expr as VariableReferenceExpression).Variable == variable)
                {
                    return GetTypeNode(typeSystem.Int32);
                }
            }

            ///If the variable is not indexer, it might be of any array type.
            ///System.Array is returned, since it's the parent type of every array type.
            TypeReference result = new TypeReference("System", "Array", typeSystem.Object.Module, typeSystem.Object.Scope);
            return GetTypeNode(result);
        }
 public override ICodeNode VisitArrayIndexerExpression(ArrayIndexerExpression node)
 {
     node.Target = (Expression)VisitTargetExpression(node.Target);
     node.Indices = (ExpressionCollection)Visit(node.Indices);
     return node;
 }
 public virtual void VisitArrayIndexerExpression(ArrayIndexerExpression node)
 {
     VisitIIndexerExpression(node);
 }
 private bool CheckArrayIndexerExpression(ArrayIndexerExpression expression, VariableReference arrayVariable, int index)
 {
     return expression.Target.CodeNodeType == CodeNodeType.VariableReferenceExpression &&
             (expression.Target as VariableReferenceExpression).Variable == arrayVariable &&
             expression.Indices.Count == 1 &&
             expression.Indices[0].CodeNodeType == CodeNodeType.LiteralExpression &&
             Convert.ToInt32((expression.Indices[0] as LiteralExpression).Value) == index;
 }
		public override void VisitArrayIndexerExpression(ArrayIndexerExpression node)
		{
			base.VisitArrayIndexerExpression(node);

			for (int i = 0; i < node.Indices.Count; i++)
			{
				Expression index = node.Indices[i];
				if (index.HasType)
				{
					TypeDefinition indexType = index.ExpressionType.Resolve();
					if (ShouldAddCast(indexType, typeSystem.Int32))
					{
						node.Indices[i] = new CastExpression(index, typeSystem.Int32, null);
					}
				}
			}
		}